]> Joshua Wise's Git repositories - dumload.git/blame - src/com/joshuawise/dumload/NotifSlave.java
Add location prompt and pubkey support
[dumload.git] / src / com / joshuawise / dumload / NotifSlave.java
CommitLineData
0763e16d
JW
1package com.joshuawise.dumload;
2
3import java.io.InputStream;
4
5import android.app.Activity;
6import android.app.Service;
7import android.content.Intent;
8import android.net.Uri;
9import android.os.Bundle;
10import android.os.IBinder;
11import android.widget.TextView;
12import android.widget.Button;
13import android.view.View;
14import android.widget.Toast;
15import android.util.Log;
16import android.os.Messenger;
17import android.os.Message;
18import android.app.AlertDialog;
19import android.app.Dialog;
20import android.content.DialogInterface;
21
22public 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");
ae61bba6
JW
65
66 if (prompt == null || reqtype == null || m == null) /* i.e., we got called by a dummy notification */
67 {
68 this.finish();
69 return;
70 }
0763e16d
JW
71
72 if (reqtype.equals("yesno")) {
73 AlertDialog.Builder builder = new AlertDialog.Builder(this);
74 builder.setTitle("Dumload");
75 builder.setMessage(prompt);
76 builder.setCancelable(false);
77 builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
78 public void onClick(DialogInterface dialog, int id) {
79 Log.e("Dumload.NotifSlave", "Responding with a 1.");
80 try {
81 Message me = Message.obtain();
82 me.arg1 = 1;
83 m.send(me);
84 } catch (Exception e) {
85 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
86 }
87 dialog.cancel();
88 thisact.finish();
89 }
90 });
91 builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
92 public void onClick(DialogInterface dialog, int id) {
93 Log.e("Dumload.NotifSlave", "Responding with a 1.");
94 try {
95 Message me = Message.obtain();
96 me.arg1 = 0;
97 m.send(me);
98 } catch (Exception e) {
99 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
100 }
101 dialog.cancel();
102 thisact.finish();
103 }
104 });
105 AlertDialog alert = builder.create();
106 showDialog(alert);
107 } else if (reqtype.equals("message")) {
108 AlertDialog.Builder builder = new AlertDialog.Builder(this);
109 builder.setTitle("Dumload");
110 builder.setMessage(prompt);
111 builder.setCancelable(false);
112 builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
113 public void onClick(DialogInterface dialog, int id) {
114 try {
115 Message me = Message.obtain();
116 m.send(me);
117 } catch (Exception e) {
118 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
119 }
120 dialog.cancel();
121 thisact.finish();
122 }
123 });
124 AlertDialog alert = builder.create();
125 showDialog(alert);
126 } else if (reqtype.equals("password")) {
127 final Dialog d = new Dialog(this);
128
129 d.setContentView(R.layout.passwd);
130 d.setTitle("Dumload");
131 d.setCancelable(false);
132
133 TextView text = (TextView) d.findViewById(R.id.prompt);
134 text.setText(prompt);
135
136 Button ok = (Button) d.findViewById(R.id.ok);
137 ok.setOnClickListener(new View.OnClickListener() {
138 public void onClick(View v) {
139 try {
140 Message me = Message.obtain();
141 me.arg1 = 1;
142 TextView entry = (TextView) d.findViewById(R.id.entry);
143 Bundle b = new Bundle(1);
144 b.putString("response", entry.getText().toString());
145 me.setData(b);
146 m.send(me);
147 } catch (Exception e) {
148 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
149 }
150 d.cancel();
151 thisact.finish();
152 }
153 });
154
155 Button cancel = (Button) d.findViewById(R.id.cancel);
156 cancel.setOnClickListener(new View.OnClickListener() {
157 public void onClick(View v) {
158 try {
159 Message me = Message.obtain();
160 me.arg1 = 0;
161 m.send(me);
162 } catch (Exception e) {
163 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
164 }
165 d.cancel();
166 thisact.finish();
167 }
168 });
169
170
171 showDialog(d);
172 } else {
173 Log.e("Dumload.NotifSlave", "What's a "+reqtype+"?");
174 }
175 }
176}
This page took 0.041937 seconds and 4 git commands to generate.