5 import android.app.AlarmManager;
6 import android.app.AlertDialog;
7 import android.app.PendingIntent;
8 import android.content.Context;
9 import android.content.DialogInterface;
10 import android.content.Intent;
11 import android.graphics.Color;
12 import android.os.Bundle;
13 import android.view.View;
14 import android.view.View.OnClickListener;
15 import android.widget.Button;
16 import android.widget.LinearLayout;
17 import android.widget.TextView;
19 import com.td.db.Monitor;
20 import com.td.db.MonitorDao;
21 import com.td.db.Train;
22 import com.td.db.TrainDao;
23 import com.td.service.TrainDelayedServiceImpl;
24 import com.td.utility.BaseActivity;
25 import com.td.utility.EditPrefUtil;
26 import com.td.utility.Util;
28 public class TrainDelayedActivity extends BaseActivity {
29 public static final String PREF_TRD_SFLG = "TRD_SFLG";
31 private TextView textView1;
32 private Button button1;
33 private Button button2;
34 private Button button3;
35 private Button button4;
36 private Button button5;
37 private Button button6;
38 private Button button7;
39 private Button button9;
40 private LinearLayout linearLayout1;
41 private LinearLayout linearLayout2;
42 private LinearLayout linearLayout3;
43 private LinearLayout linearLayout4;
44 private LinearLayout linearLayout5;
45 private LinearLayout linearLayout6;
46 private LinearLayout linearLayout7;
47 private LinearLayout linearLayout9;
49 private EditPrefUtil pref = new EditPrefUtil(this);
50 private int prefSFlag;
53 public void onCreate(Bundle savedInstanceState) {
54 super.onCreate(savedInstanceState);
55 setContentView(R.layout.main);
57 button1 = (Button) this.findViewById(R.id.button01);
58 button1.setOnClickListener(new OnClickListener() {
59 public void onClick(View v) {
60 pref.put(TrainDelayedServiceImpl.PREF_SVS_DBFLG, 0);
62 //SchedulerTest.repeat(TrainDelayedActivity.this);
63 //SchedulerTest.main();
66 button2 = (Button) this.findViewById(R.id.button02);
67 button2.setOnClickListener(new OnClickListener() {
68 public void onClick(View view) {
69 Intent intent = new Intent(TrainDelayedActivity.this,
70 (Class<?>) TrainListActivity.class);
71 startActivityForResult(intent, -1);
75 button3 = (Button) this.findViewById(R.id.button03);
76 button3.setOnClickListener(new OnClickListener() {
77 public void onClick(View view) {
78 Intent intent = new Intent(TrainDelayedActivity.this,
79 (Class<?>)MonitorTimeActivity.class);
80 startActivityForResult(intent, -1);
84 button4 = (Button) this.findViewById(R.id.button04);
85 button4.setOnClickListener(new OnClickListener() {
86 public void onClick(View view) {
87 new AlertDialog.Builder(TrainDelayedActivity.this)
88 .setTitle(getString(R.string.warn_dialog_title))
89 .setMessage(getString(R.string.start_service_qmsg))
90 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
91 public void onClick(DialogInterface dialog, int whichButton) {
92 //
\83T
\81[
\83r
\83X
\82ð
\8aJ
\8en
93 Intent intent = new Intent(TrainDelayedActivity.this,
94 TrainDelayedServiceImpl.class);
98 pref.put(PREF_TRD_SFLG, 1);
103 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
104 public void onClick(DialogInterface dialog, int whichButton) {
112 button5 = (Button) this.findViewById(R.id.button05);
113 button5.setOnClickListener(new OnClickListener() {
114 public void onClick(View view) {
116 //HistoryDao.getInstance().delete(TrainDelayedActivity.this);
118 new AlertDialog.Builder(TrainDelayedActivity.this)
119 .setTitle(getString(R.string.warn_dialog_title))
120 .setMessage(getString(R.string.end_service_qmsg))
121 .setPositiveButton(getString(R.string.yes_button), new DialogInterface.OnClickListener() {
122 public void onClick(DialogInterface dialog, int whichButton) {
123 Intent intent = new Intent(TrainDelayedActivity.this,
124 TrainDelayedServiceImpl.class);
125 PendingIntent alarmSender = PendingIntent.getService(
126 TrainDelayedActivity.this, 0, intent, 0);
127 AlarmManager alerm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
128 alerm.cancel(alarmSender);
131 pref.put(PREF_TRD_SFLG, 0);
136 .setNegativeButton(getString(R.string.cancel_button), new DialogInterface.OnClickListener() {
137 public void onClick(DialogInterface dialog, int whichButton) {
145 button6 = (Button) this.findViewById(R.id.button06);
146 button6.setOnClickListener(new OnClickListener() {
147 public void onClick(View view) {
148 HistoryActivity.init(TrainDelayedActivity.this);
149 Intent intent = new Intent(TrainDelayedActivity.this,
150 (Class<?>) HistoryActivity.class);
151 startActivityForResult(intent, -1);
155 button7 = (Button) this.findViewById(R.id.button07);
156 button7.setOnClickListener(new OnClickListener() {
157 public void onClick(View view) {
158 Intent intent = new Intent(TrainDelayedActivity.this,
159 (Class<?>)SearchWordActivity.class);
160 startActivityForResult(intent, -1);
164 button9 = (Button) this.findViewById(R.id.button09);
165 button9.setOnClickListener(new OnClickListener() {
166 public void onClick(View view) {
167 TrainDelayedActivity.this.finish();
171 linearLayout1 = (LinearLayout) this.findViewById(R.id.linearLayout01);
172 linearLayout2 = (LinearLayout) this.findViewById(R.id.linearLayout02);
173 linearLayout3 = (LinearLayout) this.findViewById(R.id.linearLayout03);
174 linearLayout4 = (LinearLayout) this.findViewById(R.id.linearLayout04);
175 linearLayout5 = (LinearLayout) this.findViewById(R.id.linearLayout05);
176 linearLayout6 = (LinearLayout) this.findViewById(R.id.linearLayout06);
177 linearLayout7 = (LinearLayout) this.findViewById(R.id.linearLayout07);
178 linearLayout9 = (LinearLayout) this.findViewById(R.id.linearLayout09);
180 textView1 = (TextView) this.findViewById(R.id.textView01);
184 protected void onStart() {
190 private void setStatus() {
192 prefSFlag = pref.getInt(PREF_TRD_SFLG, 0);
194 boolean enabled1 = true;
195 boolean enabled2 = true;
196 boolean enabled3 = true;
197 boolean enabled4 = true;
198 boolean enabled5 = true;
199 boolean enabled6 = true;
200 boolean enabled7 = true;
201 boolean enabled9 = true;
203 int c0 = Color.rgb(0xff, 0xff, 0xff);
204 int c1 = Color.rgb(0xff, 0x33, 0x33);
216 List<Train> trainList = TrainDao.getInstance().search(true);
217 int trainCount = trainList.size();
218 if (trainCount == 0){
220 msgNo = (msgNo < 0)? 2 : msgNo;
223 List<Monitor> listMonitor = MonitorDao.getInstance().search();
224 int monitorCount = listMonitor.size();
225 if (monitorCount == 0){
227 msgNo = (msgNo < 0)? 3 : msgNo;
230 if (Util.toBoolean(prefSFlag)){
234 msgNo = (msgNo < 0)? 4 : msgNo;
238 button1.setEnabled(enabled1);
239 button2.setEnabled(enabled2);
240 button3.setEnabled(enabled3);
241 button4.setEnabled(enabled4);
242 button5.setEnabled(enabled5);
243 button6.setEnabled(enabled6);
244 button7.setEnabled(enabled7);
245 button9.setEnabled(enabled9);
249 text = getString(R.string.conf_route_msg);
253 text = getString(R.string.conf_time_msg);
257 text = getString(R.string.start_service_msg);
262 StringBuffer sb = new StringBuffer();
263 for (Train train : trainList){
264 if (sb.length() > 0){
265 sb.append(getString(R.string.comma_msg));
267 sb.append(train.getName());
269 sb.append(getString(R.string.do_service_msg));
270 text = sb.toString();
275 textView1.setText(text);
276 linearLayout1.setBackgroundColor(color1);
277 linearLayout2.setBackgroundColor(color2);
278 linearLayout3.setBackgroundColor(color3);
279 linearLayout4.setBackgroundColor(color4);
280 linearLayout5.setBackgroundColor(color5);
281 linearLayout6.setBackgroundColor(color6);
282 linearLayout7.setBackgroundColor(color7);
283 linearLayout9.setBackgroundColor(color9);