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.EditPrefUtil;
30 import com.td.webapi.RouteUpdater;
32 public class TrainDelayedActivity extends BaseActivity {
33 private TextView textView1;
34 private Button button1;
35 private Button button2;
36 private Button button3;
37 private Button button4;
38 private Button button5;
39 private Button button6;
40 private Button button7;
41 private Button button9;
42 private LinearLayout linearLayout1;
43 private LinearLayout linearLayout2;
44 private LinearLayout linearLayout3;
45 private LinearLayout linearLayout4;
46 private LinearLayout linearLayout5;
47 private LinearLayout linearLayout6;
48 private LinearLayout linearLayout7;
49 private LinearLayout linearLayout9;
51 private EditPrefUtil pref = new EditPrefUtil(this);
52 private int prefSvsStatus;
53 private boolean isClick = false;
55 //private DelayReceiver receiver = new DelayReceiver(this);
56 private BroadcastReceiver receiver = new BroadcastReceiver(){
58 public void onReceive(Context context, Intent intent) {
59 String action = intent.getAction();
61 if (action.compareTo(DelayReceiver.START_SERVICE) == 0){
64 else if (action.compareTo(DelayReceiver.STOP_SERVICE) == 0){
71 public void onCreate(Bundle savedInstanceState) {
72 super.onCreate(savedInstanceState);
73 setContentView(R.layout.main);
75 IntentFilter intentFilter = new IntentFilter();
76 intentFilter.addAction(DelayReceiver.START_SERVICE);
77 intentFilter.addAction(DelayReceiver.STOP_SERVICE);
78 registerReceiver(receiver, intentFilter);
80 button1 = (Button) this.findViewById(R.id.button01);
81 button1.setOnClickListener(new OnClickListener() {
82 public void onClick(View v) {
83 RouteUpdater up = new RouteUpdater();
86 // HistoryDao.getInstance().delete(TrainDelayedActivity.this);
88 // Intent intent = new Intent("com.td.broadcast.DelayReceiver");
89 // intent.putExtra("TEXT", "
\83T
\83\93\83v
\83\8b\83\81\83b
\83Z
\81[
\83W");
90 // sendBroadcast(intent);
92 // SchedulerTest.repeat(TrainDelayedActivity.this);
93 // SchedulerTest.main();
96 button2 = (Button) this.findViewById(R.id.button02);
97 button2.setOnClickListener(new OnClickListener() {
98 public void onClick(View view) {
100 // PrefectureListActivity
101 Intent intent = new Intent(TrainDelayedActivity.this,
102 (Class<?>) TrainListActivity.class);
103 startActivityForResult(intent, -1);
107 button3 = (Button) this.findViewById(R.id.button03);
108 button3.setOnClickListener(new OnClickListener() {
109 public void onClick(View view) {
110 Intent intent = new Intent(TrainDelayedActivity.this,
111 (Class<?>)MonitorTimeActivity.class);
112 startActivityForResult(intent, -1);
116 button4 = (Button) this.findViewById(R.id.button04);
117 button4.setOnClickListener(new OnClickListener() {
118 public void onClick(View view) {
124 new AlertDialog.Builder(TrainDelayedActivity.this)
125 .setTitle(getString(R.string.warn_dialog_title))
126 .setMessage(getString(R.string.start_service_qmsg))
127 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
128 public void onClick(DialogInterface dialog, int whichButton) {
129 //
\83T
\81[
\83r
\83X
\82ð
\8aJ
\8en
130 Intent intent = new Intent(TrainDelayedActivity.this,
131 TrainDelayedServiceImpl.class);
132 intent.setAction(TrainDelayedServiceImpl.START_ACTION);
133 startService(intent);
135 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 1);
142 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
143 public void onClick(DialogInterface dialog, int whichButton) {
151 button5 = (Button) this.findViewById(R.id.button05);
152 button5.setOnClickListener(new OnClickListener() {
153 public void onClick(View view) {
159 new AlertDialog.Builder(TrainDelayedActivity.this)
160 .setTitle(getString(R.string.warn_dialog_title))
161 .setMessage(getString(R.string.end_service_qmsg))
162 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
163 public void onClick(DialogInterface dialog, int whichButton) {
164 Intent intent = new Intent(TrainDelayedActivity.this,
165 TrainDelayedServiceImpl.class);
166 PendingIntent alarmSender = PendingIntent.getService(
167 TrainDelayedActivity.this, 0, intent, 0);
168 AlarmManager alerm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
169 alerm.cancel(alarmSender);
171 pref.put(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
178 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
179 public void onClick(DialogInterface dialog, int whichButton) {
187 button6 = (Button) this.findViewById(R.id.button06);
188 button6.setOnClickListener(new OnClickListener() {
189 public void onClick(View view) {
190 HistoryActivity.init(TrainDelayedActivity.this);
191 Intent intent = new Intent(TrainDelayedActivity.this,
192 (Class<?>) HistoryActivity.class);
193 startActivityForResult(intent, -1);
197 button7 = (Button) this.findViewById(R.id.button07);
198 button7.setOnClickListener(new OnClickListener() {
199 public void onClick(View view) {
200 Intent intent = new Intent(TrainDelayedActivity.this,
201 (Class<?>)SearchWordActivity.class);
202 startActivityForResult(intent, -1);
206 button9 = (Button) this.findViewById(R.id.button09);
207 button9.setOnClickListener(new OnClickListener() {
208 public void onClick(View view) {
209 TrainDelayedActivity.this.finish();
213 linearLayout1 = (LinearLayout) this.findViewById(R.id.linearLayout01);
214 linearLayout2 = (LinearLayout) this.findViewById(R.id.linearLayout02);
215 linearLayout3 = (LinearLayout) this.findViewById(R.id.linearLayout03);
216 linearLayout4 = (LinearLayout) this.findViewById(R.id.linearLayout04);
217 linearLayout5 = (LinearLayout) this.findViewById(R.id.linearLayout05);
218 linearLayout6 = (LinearLayout) this.findViewById(R.id.linearLayout06);
219 linearLayout7 = (LinearLayout) this.findViewById(R.id.linearLayout07);
220 linearLayout9 = (LinearLayout) this.findViewById(R.id.linearLayout09);
222 textView1 = (TextView) this.findViewById(R.id.textView01);
226 protected void onStart() {
232 private void setStatus() {
234 prefSvsStatus = pref.getInt(TrainDelayedServiceImpl.PREF_SVS_STATUS, 0);
236 boolean enabled1 = true;
237 boolean enabled2 = true;
238 boolean enabled3 = true;
239 boolean enabled4 = true;
240 boolean enabled5 = true;
241 boolean enabled6 = true;
242 boolean enabled7 = true;
243 boolean enabled9 = true;
245 int c0 = Color.rgb(0xff, 0xff, 0xff);
246 int c1 = Color.rgb(0xcc, 0x33, 0x33);
258 List<Train> trainList = TrainDao.getInstance().search(true);
259 int trainCount = trainList.size();
260 if (trainCount == 0){
262 msgNo = (msgNo < 0)? 2 : msgNo;
265 List<Monitor> listMonitor = MonitorDao.getInstance().search();
266 int monitorCount = listMonitor.size();
267 if (monitorCount == 0){
269 msgNo = (msgNo < 0)? 3 : msgNo;
272 switch (prefSvsStatus){
274 msgNo = (msgNo < 0)? 4 : msgNo;
286 button1.setEnabled(enabled1);
287 button2.setEnabled(enabled2);
288 button3.setEnabled(enabled3);
289 button4.setEnabled(enabled4);
290 button5.setEnabled(enabled5);
291 button6.setEnabled(enabled6);
292 button7.setEnabled(enabled7);
293 button9.setEnabled(enabled9);
297 text = getString(R.string.conf_route_msg);
301 text = getString(R.string.conf_time_msg);
305 text = getString(R.string.start_service_msg);
310 StringBuffer sb = new StringBuffer();
311 for (Train train : trainList){
312 if (sb.length() > 0){
313 sb.append(getString(R.string.comma_msg));
315 sb.append(train.getName());
317 sb.append(getString(R.string.do_service_msg));
318 text = sb.toString();
323 textView1.setText(text);
324 linearLayout1.setBackgroundColor(color1);
325 linearLayout2.setBackgroundColor(color2);
326 linearLayout3.setBackgroundColor(color3);
327 linearLayout4.setBackgroundColor(color4);
328 linearLayout5.setBackgroundColor(color5);
329 linearLayout6.setBackgroundColor(color6);
330 linearLayout7.setBackgroundColor(color7);
331 linearLayout9.setBackgroundColor(color9);