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