]> Joshua Wise's Git repositories - dumload.git/blob - src/com/joshuawise/dumload/NotifSlave.java
Initial commit.
[dumload.git] / src / com / joshuawise / dumload / NotifSlave.java
1 package com.joshuawise.dumload;
2
3 import java.io.InputStream;
4
5 import android.app.Activity;
6 import android.app.Service;
7 import android.content.Intent;
8 import android.net.Uri;
9 import android.os.Bundle;
10 import android.os.IBinder;
11 import android.widget.TextView;
12 import android.widget.Button;
13 import android.view.View;
14 import android.widget.Toast;
15 import android.util.Log;
16 import android.os.Messenger;
17 import android.os.Message;
18 import android.app.AlertDialog;
19 import android.app.Dialog;
20 import android.content.DialogInterface;
21
22 public class NotifSlave extends Activity {
23         /** Called when the activity is first created. */
24         @Override
25         public void onCreate(Bundle savedInstanceState) {
26                 super.onCreate(savedInstanceState);
27 //              setContentView(R.layout.main);
28 //              TextView tv = (TextView)findViewById(R.id.suckit);
29 //              tv.setText("Suck it.");
30         }
31         
32         private void say(String s) {
33                 Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
34         }
35         
36         private int _nextdialog = 0;
37         private Dialog _hell_ass_balls = null;
38         
39         @Override
40         protected Dialog onCreateDialog(int id)
41         {
42                 Log.e("DumLoad.NotifSlave", "Create for dialog "+(Integer.toString(id)));
43                 if (id != _nextdialog)
44                         return null;
45                 return _hell_ass_balls;
46         }
47         
48         private void showDialog(Dialog d)
49         {
50                 _nextdialog++;
51                 _hell_ass_balls = d;
52                 Log.e("DumLoad.NotifSlave", "Attempting to show dialog "+(Integer.toString(_nextdialog)));
53                 showDialog(_nextdialog);
54         }
55         
56         public void onStart() {
57                 super.onStart();
58         
59                 Intent i = getIntent(); /* i *am* not an intent! */
60                 final Activity thisact = this;
61                 
62                 final Messenger m = (Messenger)i.getParcelableExtra("com.joshuawise.dumload.returnmessenger");
63                 String reqtype = i.getStringExtra("com.joshuawise.dumload.reqtype");
64                 String prompt = i.getStringExtra("com.joshuawise.dumload.prompt");
65                 /* If any of these were null, we'll just take the exception. */
66         
67                 if (reqtype.equals("yesno")) {
68                         AlertDialog.Builder builder = new AlertDialog.Builder(this);
69                         builder.setTitle("Dumload");
70                         builder.setMessage(prompt);
71                         builder.setCancelable(false);
72                         builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
73                                 public void onClick(DialogInterface dialog, int id) {
74                                         Log.e("Dumload.NotifSlave", "Responding with a 1.");
75                                         try {
76                                                 Message me = Message.obtain();
77                                                 me.arg1 = 1;
78                                                 m.send(me);
79                                         } catch (Exception e) {
80                                                 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
81                                         }
82                                         dialog.cancel();
83                                         thisact.finish();
84                                 }
85                         });
86                         builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
87                                 public void onClick(DialogInterface dialog, int id) {
88                                         Log.e("Dumload.NotifSlave", "Responding with a 1.");
89                                         try {
90                                                 Message me = Message.obtain();
91                                                 me.arg1 = 0;
92                                                 m.send(me);
93                                         } catch (Exception e) {
94                                                 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
95                                         }
96                                         dialog.cancel();
97                                         thisact.finish();
98                                 }
99                         });
100                         AlertDialog alert = builder.create();
101                         showDialog(alert);
102                 } else if (reqtype.equals("message")) {
103                         AlertDialog.Builder builder = new AlertDialog.Builder(this);
104                         builder.setTitle("Dumload");
105                         builder.setMessage(prompt);
106                         builder.setCancelable(false);
107                         builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
108                                 public void onClick(DialogInterface dialog, int id) {
109                                         try {
110                                                 Message me = Message.obtain();
111                                                 m.send(me);
112                                         } catch (Exception e) {
113                                                 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
114                                         }
115                                         dialog.cancel();
116                                         thisact.finish();
117                                 }
118                         });
119                         AlertDialog alert = builder.create();
120                         showDialog(alert);
121                 } else if (reqtype.equals("password")) {
122                         final Dialog d = new Dialog(this);
123                         
124                         d.setContentView(R.layout.passwd);
125                         d.setTitle("Dumload");
126                         d.setCancelable(false);
127                         
128                         TextView text = (TextView) d.findViewById(R.id.prompt);
129                         text.setText(prompt);
130                         
131                         Button ok = (Button) d.findViewById(R.id.ok);
132                         ok.setOnClickListener(new View.OnClickListener() {
133                                 public void onClick(View v) {
134                                         try {
135                                                 Message me = Message.obtain();
136                                                 me.arg1 = 1;
137                                                 TextView entry = (TextView) d.findViewById(R.id.entry);
138                                                 Bundle b = new Bundle(1);
139                                                 b.putString("response", entry.getText().toString());
140                                                 me.setData(b);
141                                                 m.send(me);
142                                         } catch (Exception e) {
143                                                 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
144                                         }
145                                         d.cancel();
146                                         thisact.finish();
147                                 }
148                         });
149                         
150                         Button cancel = (Button) d.findViewById(R.id.cancel);
151                         cancel.setOnClickListener(new View.OnClickListener() {
152                                 public void onClick(View v) {
153                                         try {
154                                                 Message me = Message.obtain();
155                                                 me.arg1 = 0;
156                                                 m.send(me);
157                                         } catch (Exception e) {
158                                                 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
159                                         }
160                                         d.cancel();
161                                         thisact.finish();
162                                 }
163                         });
164                         
165                         
166                         showDialog(d);
167                 } else {
168                         Log.e("Dumload.NotifSlave", "What's a "+reqtype+"?");
169                 }
170         }
171 }
This page took 0.033226 seconds and 4 git commands to generate.