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.utility.StatusFlagTest;
32 import com.td.wait.InitializeWating;
33 import com.td.wait.TrainServiceWaiting;
35 public class TrainDelayedActivity extends BaseActivity {
36 private TextView textView1;
37 private Button button1;
38 private Button button2;
39 private Button button3;
40 private Button button4;
41 private Button button5;
42 private Button button6;
43 private Button button7;
44 private Button button9;
45 private Button buttonf;
46 private Button buttonz;
47 private LinearLayout linearLayout1;
48 private LinearLayout linearLayout2;
49 private LinearLayout linearLayout3;
50 private LinearLayout linearLayout4;
51 private LinearLayout linearLayout5;
52 private LinearLayout linearLayout6;
53 private LinearLayout linearLayout7;
54 private LinearLayout linearLayout9;
56 private EditPrefUtil pref = new EditPrefUtil(this);
57 private int prefSvsStatus;
58 private boolean isClick = false;
60 private BroadcastReceiver receiver = new BroadcastReceiver(){
62 public void onReceive(Context context, Intent intent) {
63 String action = intent.getAction();
65 if (action.compareTo(DelayReceiver.START_SERVICE) == 0){
68 else if (action.compareTo(DelayReceiver.STOP_SERVICE) == 0){
75 public void onCreate(Bundle savedInstanceState) {
76 super.onCreate(savedInstanceState);
77 setContentView(R.layout.main);
79 IntentFilter intentFilter = new IntentFilter();
80 intentFilter.addAction(DelayReceiver.START_SERVICE);
81 intentFilter.addAction(DelayReceiver.STOP_SERVICE);
82 registerReceiver(receiver, intentFilter);
84 button1 = (Button) this.findViewById(R.id.button01);
85 button1.setOnClickListener(new OnClickListener() {
86 public void onClick(View v) {
87 Intent intent = new Intent(TrainDelayedActivity.this,
88 (Class<?>) WaitActivity.class);
89 intent.putExtra(WaitActivity.CLASS,
90 TrainServiceWaiting.class.getName());
91 intent.putExtra(WaitActivity.MESSAGE1,
92 getString(R.string.start_rouote_msg));
93 intent.putExtra(WaitActivity.MESSAGE2,
94 getString(R.string.end_rouote_msg));
95 intent.putExtra(WaitActivity.MESSAGE3,
98 WaitActivity.init(TrainDelayedActivity.this);
99 startActivityForResult(intent, -1);
102 button2 = (Button) this.findViewById(R.id.button02);
103 button2.setOnClickListener(new OnClickListener() {
104 public void onClick(View view) {
105 Intent intent = new Intent(TrainDelayedActivity.this,
106 (Class<?>) PrefectureListActivity.class);
107 startActivityForResult(intent, -1);
111 button3 = (Button) this.findViewById(R.id.button03);
112 button3.setOnClickListener(new OnClickListener() {
113 public void onClick(View view) {
114 Intent intent = new Intent(TrainDelayedActivity.this,
115 (Class<?>)MonitorTimeActivity.class);
116 startActivityForResult(intent, -1);
120 button4 = (Button) this.findViewById(R.id.button04);
121 button4.setOnClickListener(new OnClickListener() {
122 public void onClick(View view) {
128 new AlertDialog.Builder(TrainDelayedActivity.this)
129 .setTitle(getString(R.string.warn_dialog_title))
130 .setMessage(getString(R.string.start_service_qmsg))
131 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
132 public void onClick(DialogInterface dialog, int whichButton) {
133 //
\83T
\81[
\83r
\83X
\82ð
\8aJ
\8en
134 Intent intent = new Intent(TrainDelayedActivity.this,
135 TrainDelayedServiceImpl.class);
136 intent.setAction(TrainDelayedServiceImpl.START_ACTION);
137 startService(intent);
139 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 1);
146 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
147 public void onClick(DialogInterface dialog, int whichButton) {
155 button5 = (Button) this.findViewById(R.id.button05);
156 button5.setOnClickListener(new OnClickListener() {
157 public void onClick(View view) {
163 new AlertDialog.Builder(TrainDelayedActivity.this)
164 .setTitle(getString(R.string.warn_dialog_title))
165 .setMessage(getString(R.string.end_service_qmsg))
166 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
167 public void onClick(DialogInterface dialog, int whichButton) {
168 Intent intent = new Intent(TrainDelayedActivity.this,
169 TrainDelayedServiceImpl.class);
170 PendingIntent alarmSender = PendingIntent.getService(
171 TrainDelayedActivity.this, 0, intent, 0);
172 AlarmManager alerm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
173 alerm.cancel(alarmSender);
175 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
182 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
183 public void onClick(DialogInterface dialog, int whichButton) {
191 button6 = (Button) this.findViewById(R.id.button06);
192 button6.setOnClickListener(new OnClickListener() {
193 public void onClick(View view) {
194 HistoryActivity.init(TrainDelayedActivity.this);
195 Intent intent = new Intent(TrainDelayedActivity.this,
196 (Class<?>) HistoryActivity.class);
197 startActivityForResult(intent, -1);
201 button7 = (Button) this.findViewById(R.id.button07);
202 button7.setOnClickListener(new OnClickListener() {
203 public void onClick(View view) {
204 Intent intent = new Intent(TrainDelayedActivity.this,
205 (Class<?>)SearchWordActivity.class);
206 startActivityForResult(intent, -1);
210 button9 = (Button) this.findViewById(R.id.button09);
211 button9.setOnClickListener(new OnClickListener() {
212 public void onClick(View view) {
213 TrainDelayedActivity.this.finish();
217 buttonf = (Button) this.findViewById(R.id.button0f);
218 buttonf.setOnClickListener(new OnClickListener() {
219 public void onClick(View view) {
220 // TODO
\83_
\83C
\83A
\83\8d\83O
\82Å
\8am
\94F
225 buttonz = (Button) this.findViewById(R.id.button0z);
226 buttonz.setOnClickListener(new OnClickListener() {
227 public void onClick(View view) {
231 if (!Debug.isDebug()){
232 buttonz.setVisibility(View.GONE);
235 linearLayout1 = (LinearLayout) this.findViewById(R.id.linearLayout01);
236 linearLayout2 = (LinearLayout) this.findViewById(R.id.linearLayout02);
237 linearLayout3 = (LinearLayout) this.findViewById(R.id.linearLayout03);
238 linearLayout4 = (LinearLayout) this.findViewById(R.id.linearLayout04);
239 linearLayout5 = (LinearLayout) this.findViewById(R.id.linearLayout05);
240 linearLayout6 = (LinearLayout) this.findViewById(R.id.linearLayout06);
241 linearLayout7 = (LinearLayout) this.findViewById(R.id.linearLayout07);
242 linearLayout9 = (LinearLayout) this.findViewById(R.id.linearLayout09);
244 textView1 = (TextView) this.findViewById(R.id.textView01);
248 protected void onDestroy() {
249 if (receiver != null){
250 unregisterReceiver(receiver);
257 protected void onStart() {
263 private void setStatus() {
265 prefSvsStatus = pref.getInt(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
267 boolean enabled1 = true;
268 boolean enabled2 = true;
269 boolean enabled3 = true;
270 boolean enabled4 = true;
271 boolean enabled5 = true;
272 boolean enabled6 = true;
273 boolean enabled7 = true;
274 boolean enabled9 = true;
276 int c0 = Color.rgb(0xff, 0xff, 0xff);
277 int c1 = Color.rgb(0xcc, 0x33, 0x33);
289 int count = TrainDao.getInstance().count();
300 List<Train> trainList = TrainDao.getInstance().search(true);
301 int trainCount = trainList.size();
302 if (trainCount == 0){
304 msgNo = (msgNo < 0)? 2 : msgNo;
307 List<Monitor> listMonitor = MonitorDao.getInstance().search();
308 int monitorCount = listMonitor.size();
309 if (monitorCount == 0){
311 msgNo = (msgNo < 0)? 3 : msgNo;
314 switch (prefSvsStatus){
316 msgNo = (msgNo < 0)? 4 : msgNo;
320 msgNo = (msgNo < 0)? 5 : msgNo;
334 button1.setEnabled(enabled1);
335 button2.setEnabled(enabled2);
336 button3.setEnabled(enabled3);
337 button4.setEnabled(enabled4);
338 button5.setEnabled(enabled5);
339 button6.setEnabled(enabled6);
340 button7.setEnabled(enabled7);
341 button9.setEnabled(enabled9);
345 text = getString(R.string.update_route_msg);
349 text = getString(R.string.conf_route_msg);
353 text = getString(R.string.conf_time_msg);
357 text = getString(R.string.start_service_msg);
361 text = getString(R.string.starting_service_msg);
365 StringBuffer sb = new StringBuffer();
366 for (Train train : trainList){
367 if (sb.length() > 0){
368 sb.append(getString(R.string.comma_msg));
370 sb.append(train.getName());
372 sb.append(getString(R.string.do_service_msg));
373 text = sb.toString();
378 textView1.setText(text);
379 linearLayout1.setBackgroundColor(color1);
380 linearLayout2.setBackgroundColor(color2);
381 linearLayout3.setBackgroundColor(color3);
382 linearLayout4.setBackgroundColor(color4);
383 linearLayout5.setBackgroundColor(color5);
384 linearLayout6.setBackgroundColor(color6);
385 linearLayout7.setBackgroundColor(color7);
386 linearLayout9.setBackgroundColor(color9);
389 private void initizlize(){
390 Intent intent = new Intent(this,
391 (Class<?>) WaitActivity.class);
392 intent.putExtra(WaitActivity.CLASS,
393 InitializeWating.class.getName());
394 intent.putExtra(WaitActivity.MESSAGE1,
395 getString(R.string.start_rouote_msg));
396 intent.putExtra(WaitActivity.MESSAGE2,
397 getString(R.string.end_rouote_msg));
398 intent.putExtra(WaitActivity.MESSAGE3,
401 WaitActivity.init(this);
402 startActivityForResult(intent, -1);
405 private void debug(){
410 //
\83T
\81[
\83r
\83X
\83t
\83\89\83O
\83N
\83\8a\83A
411 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
416 //
\83X
\83P
\83W
\83\85\81[
\83\8b\82Ì
\83e
\83X
\83g
417 SchedulerTest.repeat(TrainDelayedActivity.this);
418 SchedulerTest.main();
421 //
\83u
\83\8d\81[
\83h
\83L
\83\83\83X
\83g
422 Intent intent = new Intent("com.td.broadcast.DelayReceiver");
423 intent.putExtra("TEXT", "
\83T
\83\93\83v
\83\8b\83\81\83b
\83Z
\81[
\83W");
424 sendBroadcast(intent);
427 // StatusFlag
\82Ì
\83e
\83X
\83g
428 StatusFlagTest.main(this);