5 import android.app.AlarmManager;
6 import android.app.AlertDialog;
7 import android.app.PendingIntent;
8 import android.content.BroadcastReceiver;
9 import android.content.Context;
10 import android.content.DialogInterface;
11 import android.content.Intent;
12 import android.content.IntentFilter;
13 import android.graphics.Color;
14 import android.os.Bundle;
15 import android.view.View;
16 import android.view.View.OnClickListener;
17 import android.widget.Button;
18 import android.widget.LinearLayout;
19 import android.widget.TextView;
21 import com.td.broadcast.DelayReceiver;
22 import com.td.db.Monitor;
23 import com.td.db.MonitorDao;
24 import com.td.db.Train;
25 import com.td.db.TrainDao;
26 import com.td.service.SchedulerTest;
27 import com.td.service.TrainDelayedServiceImpl;
28 import com.td.utility.BaseActivity;
29 import com.td.utility.Debug;
30 import com.td.utility.EditPrefUtil;
31 import com.td.wait.InitializeWating;
32 import com.td.wait.TrainServiceWaiting;
34 public class TrainDelayedActivity extends BaseActivity {
35 private TextView textView1;
36 private Button button1;
37 private Button button2;
38 private Button button3;
39 private Button button4;
40 private Button button5;
41 private Button button6;
42 private Button button7;
43 private Button button9;
44 private Button buttonf;
45 private Button buttonz;
46 private LinearLayout linearLayout1;
47 private LinearLayout linearLayout2;
48 private LinearLayout linearLayout3;
49 private LinearLayout linearLayout4;
50 private LinearLayout linearLayout5;
51 private LinearLayout linearLayout6;
52 private LinearLayout linearLayout7;
53 private LinearLayout linearLayout9;
55 private EditPrefUtil pref = new EditPrefUtil(this);
56 private int prefSvsStatus;
57 private boolean isClick = false;
59 private BroadcastReceiver receiver = new BroadcastReceiver(){
61 public void onReceive(Context context, Intent intent) {
62 String action = intent.getAction();
64 if (action.compareTo(DelayReceiver.START_SERVICE) == 0){
67 else if (action.compareTo(DelayReceiver.STOP_SERVICE) == 0){
74 public void onCreate(Bundle savedInstanceState) {
75 super.onCreate(savedInstanceState);
76 setContentView(R.layout.main);
78 IntentFilter intentFilter = new IntentFilter();
79 intentFilter.addAction(DelayReceiver.START_SERVICE);
80 intentFilter.addAction(DelayReceiver.STOP_SERVICE);
81 registerReceiver(receiver, intentFilter);
83 button1 = (Button) this.findViewById(R.id.button01);
84 button1.setOnClickListener(new OnClickListener() {
85 public void onClick(View v) {
86 Intent intent = new Intent(TrainDelayedActivity.this,
87 (Class<?>) WaitActivity.class);
88 intent.putExtra(WaitActivity.CLASS,
89 TrainServiceWaiting.class.getName());
90 intent.putExtra(WaitActivity.MESSAGE1,
91 getString(R.string.start_rouote_msg));
92 intent.putExtra(WaitActivity.MESSAGE2,
93 getString(R.string.end_rouote_msg));
94 intent.putExtra(WaitActivity.MESSAGE3,
97 WaitActivity.init(TrainDelayedActivity.this);
98 startActivityForResult(intent, -1);
101 button2 = (Button) this.findViewById(R.id.button02);
102 button2.setOnClickListener(new OnClickListener() {
103 public void onClick(View view) {
104 Intent intent = new Intent(TrainDelayedActivity.this,
105 (Class<?>) PrefectureListActivity.class);
106 startActivityForResult(intent, -1);
110 button3 = (Button) this.findViewById(R.id.button03);
111 button3.setOnClickListener(new OnClickListener() {
112 public void onClick(View view) {
113 Intent intent = new Intent(TrainDelayedActivity.this,
114 (Class<?>)MonitorTimeActivity.class);
115 startActivityForResult(intent, -1);
119 button4 = (Button) this.findViewById(R.id.button04);
120 button4.setOnClickListener(new OnClickListener() {
121 public void onClick(View view) {
127 new AlertDialog.Builder(TrainDelayedActivity.this)
128 .setTitle(getString(R.string.warn_dialog_title))
129 .setMessage(getString(R.string.start_service_qmsg))
130 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
131 public void onClick(DialogInterface dialog, int whichButton) {
132 //
\83T
\81[
\83r
\83X
\82ð
\8aJ
\8en
133 Intent intent = new Intent(TrainDelayedActivity.this,
134 TrainDelayedServiceImpl.class);
135 intent.setAction(TrainDelayedServiceImpl.START_ACTION);
136 startService(intent);
138 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 1);
145 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
146 public void onClick(DialogInterface dialog, int whichButton) {
154 button5 = (Button) this.findViewById(R.id.button05);
155 button5.setOnClickListener(new OnClickListener() {
156 public void onClick(View view) {
162 new AlertDialog.Builder(TrainDelayedActivity.this)
163 .setTitle(getString(R.string.warn_dialog_title))
164 .setMessage(getString(R.string.end_service_qmsg))
165 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
166 public void onClick(DialogInterface dialog, int whichButton) {
167 Intent intent = new Intent(TrainDelayedActivity.this,
168 TrainDelayedServiceImpl.class);
169 PendingIntent alarmSender = PendingIntent.getService(
170 TrainDelayedActivity.this, 0, intent, 0);
171 AlarmManager alerm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
172 alerm.cancel(alarmSender);
174 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
181 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
182 public void onClick(DialogInterface dialog, int whichButton) {
190 button6 = (Button) this.findViewById(R.id.button06);
191 button6.setOnClickListener(new OnClickListener() {
192 public void onClick(View view) {
193 HistoryActivity.init(TrainDelayedActivity.this);
194 Intent intent = new Intent(TrainDelayedActivity.this,
195 (Class<?>) HistoryActivity.class);
196 startActivityForResult(intent, -1);
200 button7 = (Button) this.findViewById(R.id.button07);
201 button7.setOnClickListener(new OnClickListener() {
202 public void onClick(View view) {
203 Intent intent = new Intent(TrainDelayedActivity.this,
204 (Class<?>)SearchWordActivity.class);
205 startActivityForResult(intent, -1);
209 button9 = (Button) this.findViewById(R.id.button09);
210 button9.setOnClickListener(new OnClickListener() {
211 public void onClick(View view) {
212 TrainDelayedActivity.this.finish();
216 buttonf = (Button) this.findViewById(R.id.button0f);
217 buttonf.setOnClickListener(new OnClickListener() {
218 public void onClick(View view) {
219 // TODO
\83_
\83C
\83A
\83\8d\83O
\82Å
\8am
\94F
224 buttonz = (Button) this.findViewById(R.id.button0z);
225 buttonz.setOnClickListener(new OnClickListener() {
226 public void onClick(View view) {
230 if (!Debug.isDebug()){
231 buttonz.setVisibility(View.GONE);
234 linearLayout1 = (LinearLayout) this.findViewById(R.id.linearLayout01);
235 linearLayout2 = (LinearLayout) this.findViewById(R.id.linearLayout02);
236 linearLayout3 = (LinearLayout) this.findViewById(R.id.linearLayout03);
237 linearLayout4 = (LinearLayout) this.findViewById(R.id.linearLayout04);
238 linearLayout5 = (LinearLayout) this.findViewById(R.id.linearLayout05);
239 linearLayout6 = (LinearLayout) this.findViewById(R.id.linearLayout06);
240 linearLayout7 = (LinearLayout) this.findViewById(R.id.linearLayout07);
241 linearLayout9 = (LinearLayout) this.findViewById(R.id.linearLayout09);
243 textView1 = (TextView) this.findViewById(R.id.textView01);
247 protected void onDestroy() {
248 if (receiver != null){
249 unregisterReceiver(receiver);
256 protected void onStart() {
262 private void setStatus() {
264 prefSvsStatus = pref.getInt(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
266 boolean enabled1 = true;
267 boolean enabled2 = true;
268 boolean enabled3 = true;
269 boolean enabled4 = true;
270 boolean enabled5 = true;
271 boolean enabled6 = true;
272 boolean enabled7 = true;
273 boolean enabled9 = true;
275 int c0 = Color.rgb(0xff, 0xff, 0xff);
276 int c1 = Color.rgb(0xcc, 0x33, 0x33);
288 int count = TrainDao.getInstance().count();
299 List<Train> trainList = TrainDao.getInstance().search(true);
300 int trainCount = trainList.size();
301 if (trainCount == 0){
303 msgNo = (msgNo < 0)? 2 : msgNo;
306 List<Monitor> listMonitor = MonitorDao.getInstance().search();
307 int monitorCount = listMonitor.size();
308 if (monitorCount == 0){
310 msgNo = (msgNo < 0)? 3 : msgNo;
313 switch (prefSvsStatus){
315 msgNo = (msgNo < 0)? 4 : msgNo;
319 msgNo = (msgNo < 0)? 5 : msgNo;
333 button1.setEnabled(enabled1);
334 button2.setEnabled(enabled2);
335 button3.setEnabled(enabled3);
336 button4.setEnabled(enabled4);
337 button5.setEnabled(enabled5);
338 button6.setEnabled(enabled6);
339 button7.setEnabled(enabled7);
340 button9.setEnabled(enabled9);
344 text = getString(R.string.update_route_msg);
348 text = getString(R.string.conf_route_msg);
352 text = getString(R.string.conf_time_msg);
356 text = getString(R.string.start_service_msg);
360 text = getString(R.string.starting_service_msg);
364 StringBuffer sb = new StringBuffer();
365 for (Train train : trainList){
366 if (sb.length() > 0){
367 sb.append(getString(R.string.comma_msg));
369 sb.append(train.getName());
371 sb.append(getString(R.string.do_service_msg));
372 text = sb.toString();
377 textView1.setText(text);
378 linearLayout1.setBackgroundColor(color1);
379 linearLayout2.setBackgroundColor(color2);
380 linearLayout3.setBackgroundColor(color3);
381 linearLayout4.setBackgroundColor(color4);
382 linearLayout5.setBackgroundColor(color5);
383 linearLayout6.setBackgroundColor(color6);
384 linearLayout7.setBackgroundColor(color7);
385 linearLayout9.setBackgroundColor(color9);
388 private void initizlize(){
389 Intent intent = new Intent(this,
390 (Class<?>) WaitActivity.class);
391 intent.putExtra(WaitActivity.CLASS,
392 InitializeWating.class.getName());
393 intent.putExtra(WaitActivity.MESSAGE1,
394 getString(R.string.start_rouote_msg));
395 intent.putExtra(WaitActivity.MESSAGE2,
396 getString(R.string.end_rouote_msg));
397 intent.putExtra(WaitActivity.MESSAGE3,
400 WaitActivity.init(this);
401 startActivityForResult(intent, -1);
404 private void debug(){
409 //
\83T
\81[
\83r
\83X
\83t
\83\89\83O
\83N
\83\8a\83A
410 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
415 //
\83X
\83P
\83W
\83\85\81[
\83\8b\82Ì
\83e
\83X
\83g
416 SchedulerTest.repeat(TrainDelayedActivity.this);
417 SchedulerTest.main();
420 //
\83u
\83\8d\81[
\83h
\83L
\83\83\83X
\83g
421 Intent intent = new Intent("com.td.broadcast.DelayReceiver");
422 intent.putExtra("TEXT", "
\83T
\83\93\83v
\83\8b\83\81\83b
\83Z
\81[
\83W");
423 sendBroadcast(intent);