]> Joshua Wise's Git repositories - dumload.git/blame_incremental - src/com/joshuawise/dumload/NotifSlave.java
GPLv3
[dumload.git] / src / com / joshuawise / dumload / NotifSlave.java
... / ...
CommitLineData
1/* NotifSlave.java
2 * Notification interface glue for Dumload.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License, version 3, as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17package com.joshuawise.dumload;
18
19import java.io.InputStream;
20
21import android.app.Activity;
22import android.app.Service;
23import android.content.Intent;
24import android.net.Uri;
25import android.os.Bundle;
26import android.os.IBinder;
27import android.widget.TextView;
28import android.widget.Button;
29import android.view.View;
30import android.widget.Toast;
31import android.util.Log;
32import android.os.Messenger;
33import android.os.Message;
34import android.app.AlertDialog;
35import android.app.Dialog;
36import android.content.DialogInterface;
37
38public class NotifSlave extends Activity {
39 /** Called when the activity is first created. */
40 @Override
41 public void onCreate(Bundle savedInstanceState) {
42 super.onCreate(savedInstanceState);
43// setContentView(R.layout.main);
44// TextView tv = (TextView)findViewById(R.id.suckit);
45// tv.setText("Suck it.");
46 }
47
48 private void say(String s) {
49 Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
50 }
51
52 private int _nextdialog = 0;
53 private Dialog _hell_ass_balls = null;
54
55 @Override
56 protected Dialog onCreateDialog(int id)
57 {
58 Log.e("DumLoad.NotifSlave", "Create for dialog "+(Integer.toString(id)));
59 if (id != _nextdialog)
60 return null;
61 return _hell_ass_balls;
62 }
63
64 private void showDialog(Dialog d)
65 {
66 _nextdialog++;
67 _hell_ass_balls = d;
68 Log.e("DumLoad.NotifSlave", "Attempting to show dialog "+(Integer.toString(_nextdialog)));
69 showDialog(_nextdialog);
70 }
71
72 public void onStart() {
73 super.onStart();
74
75 Intent i = getIntent(); /* i *am* not an intent! */
76 final Activity thisact = this;
77
78 final Messenger m = (Messenger)i.getParcelableExtra("com.joshuawise.dumload.returnmessenger");
79 String reqtype = i.getStringExtra("com.joshuawise.dumload.reqtype");
80 String prompt = i.getStringExtra("com.joshuawise.dumload.prompt");
81
82 if (prompt == null || reqtype == null || m == null) /* i.e., we got called by a dummy notification */
83 {
84 this.finish();
85 return;
86 }
87
88 if (reqtype.equals("yesno")) {
89 AlertDialog.Builder builder = new AlertDialog.Builder(this);
90 builder.setTitle("Dumload");
91 builder.setMessage(prompt);
92 builder.setCancelable(false);
93 builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
94 public void onClick(DialogInterface dialog, int id) {
95 Log.e("Dumload.NotifSlave", "Responding with a 1.");
96 try {
97 Message me = Message.obtain();
98 me.arg1 = 1;
99 m.send(me);
100 } catch (Exception e) {
101 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
102 }
103 dialog.cancel();
104 thisact.finish();
105 }
106 });
107 builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
108 public void onClick(DialogInterface dialog, int id) {
109 Log.e("Dumload.NotifSlave", "Responding with a 1.");
110 try {
111 Message me = Message.obtain();
112 me.arg1 = 0;
113 m.send(me);
114 } catch (Exception e) {
115 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
116 }
117 dialog.cancel();
118 thisact.finish();
119 }
120 });
121 AlertDialog alert = builder.create();
122 showDialog(alert);
123 } else if (reqtype.equals("message")) {
124 AlertDialog.Builder builder = new AlertDialog.Builder(this);
125 builder.setTitle("Dumload");
126 builder.setMessage(prompt);
127 builder.setCancelable(false);
128 builder.setNeutralButton("OK", new DialogInterface.OnClickListener() {
129 public void onClick(DialogInterface dialog, int id) {
130 try {
131 Message me = Message.obtain();
132 m.send(me);
133 } catch (Exception e) {
134 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
135 }
136 dialog.cancel();
137 thisact.finish();
138 }
139 });
140 AlertDialog alert = builder.create();
141 showDialog(alert);
142 } else if (reqtype.equals("password")) {
143 final Dialog d = new Dialog(this);
144
145 d.setContentView(R.layout.passwd);
146 d.setTitle("Dumload");
147 d.setCancelable(false);
148
149 TextView text = (TextView) d.findViewById(R.id.prompt);
150 text.setText(prompt);
151
152 Button ok = (Button) d.findViewById(R.id.ok);
153 ok.setOnClickListener(new View.OnClickListener() {
154 public void onClick(View v) {
155 try {
156 Message me = Message.obtain();
157 me.arg1 = 1;
158 TextView entry = (TextView) d.findViewById(R.id.entry);
159 Bundle b = new Bundle(1);
160 b.putString("response", entry.getText().toString());
161 me.setData(b);
162 m.send(me);
163 } catch (Exception e) {
164 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
165 }
166 d.cancel();
167 thisact.finish();
168 }
169 });
170
171 Button cancel = (Button) d.findViewById(R.id.cancel);
172 cancel.setOnClickListener(new View.OnClickListener() {
173 public void onClick(View v) {
174 try {
175 Message me = Message.obtain();
176 me.arg1 = 0;
177 m.send(me);
178 } catch (Exception e) {
179 Log.e("Dumload.NotifSlave", "Failed to send a message back to my buddy.");
180 }
181 d.cancel();
182 thisact.finish();
183 }
184 });
185
186
187 showDialog(d);
188 } else {
189 Log.e("Dumload.NotifSlave", "What's a "+reqtype+"?");
190 }
191 }
192}
This page took 0.027574 seconds and 4 git commands to generate.