]> Joshua Wise's Git repositories - dumload.git/blob - src/com/joshuawise/dumload/NotifSlave.java
Fix port usage and always try to add the generated key
[dumload.git] / src / com / joshuawise / dumload / NotifSlave.java
1 package com.joshuawise.dumload;
2
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.app.Dialog;
6 import android.content.DialogInterface;
7 import android.content.Intent;
8 import android.os.Bundle;
9 import android.os.Message;
10 import android.os.Messenger;
11 import android.util.Log;
12 import android.view.View;
13 import android.widget.Button;
14 import android.widget.TextView;
15 import android.widget.Toast;
16
17 public class NotifSlave extends Activity {
18         /** Called when the activity is first created. */
19         @Override
20         public void onCreate(Bundle savedInstanceState) {
21                 super.onCreate(savedInstanceState);
22 //              setContentView(R.layout.main);
23 //              TextView tv = (TextView)findViewById(R.id.suckit);
24 //              tv.setText("Suck it.");
25         }
26         
27         private void say(String s) {
28                 Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
29         }
30         
31         private int _nextdialog = 0;
32         private Dialog _hell_ass_balls = null;
33         
34         @Override
35         protected Dialog onCreateDialog(int id)
36         {
37                 Log.e("DumLoad.NotifSlave", "Create for dialog "+(Integer.toString(id)));
38                 if (id != _nextdialog)
39                         return null;
40                 return _hell_ass_balls;
41         }
42         
43         private void showDialog(Dialog d)
44         {
45                 _nextdialog++;
46                 _hell_ass_balls = d;
47                 Log.e("DumLoad.NotifSlave", "Attempting to show dialog "+(Integer.toString(_nextdialog)));
48                 showDialog(_nextdialog);
49         }
50         
51         public void onStart() {
52                 super.onStart();
53         
54                 Intent i = getIntent(); /* i *am* not an intent! */
55                 final Activity thisact = this;
56                 
57                 final Messenger m = (Messenger)i.getParcelableExtra("com.joshuawise.dumload.returnmessenger");
58                 String reqtype = i.getStringExtra("com.joshuawise.dumload.reqtype");
59                 String prompt = i.getStringExtra("com.joshuawise.dumload.prompt");
60                 
61                 if (prompt == null || reqtype == null || m == null)     /* i.e., we got called by a dummy notification */
62                 {
63                         this.finish();
64                         return;
65                 }
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.039138 seconds and 4 git commands to generate.