OSDN Git Service

スケジューリングのロジック作成。未テスト。テストクラスを作成すること
[train-delayed/source.git] / workspace / TrainDelayed / src / com / td / TrainDelayedActivity.java
1 package com.td;
2
3 import twitter4j.AsyncTwitter;
4 import twitter4j.AsyncTwitterFactory;
5 import android.app.AlarmManager;
6 import android.app.Notification;
7 import android.app.NotificationManager;
8 import android.app.PendingIntent;
9 import android.content.Context;
10 import android.content.Intent;
11 import android.os.Bundle;
12 import android.view.View;
13 import android.view.View.OnClickListener;
14 import android.widget.Button;
15
16 import com.td.db.HistoryDao;
17 import com.td.service.TrainDelayedServiceImpl;
18 import com.td.utility.BaseActivity;
19
20 public class TrainDelayedActivity extends BaseActivity {
21         private AsyncTwitterFactory factory = new AsyncTwitterFactory();
22         private AsyncTwitter twitter = factory.getInstance();
23
24         // private TrainTwitterAdapter listener = new TrainTwitterAdapter(this, 1);
25         // private List<TrainTwitterAdapter> adapterList = new
26         // ArrayList<TrainTwitterAdapter>();
27
28         @Override
29         public void onCreate(Bundle savedInstanceState) {
30                 super.onCreate(savedInstanceState);
31                 setContentView(R.layout.main);
32
33                 final TrainTwitterAdapter listener = new TrainTwitterAdapter(this);
34                 twitter.addListener(listener);
35
36                 Button button1 = (Button) this.findViewById(R.id.button01);
37                 button1.setOnClickListener(new OnClickListener() {
38                         public void onClick(View v) {
39                                 
40                         }});
41
42                 Button button2 = (Button) this.findViewById(R.id.button02);
43                 button2.setOnClickListener(new OnClickListener() {
44                         public void onClick(View view) {
45                                 Intent intent = new Intent(TrainDelayedActivity.this,
46                                                 (Class<?>) TrainListActivity.class);
47                                 startActivityForResult(intent, -1);
48                         }
49                 });
50
51                 Button button3 = (Button) this.findViewById(R.id.button03);
52                 button3.setOnClickListener(new OnClickListener() {
53                         public void onClick(View view) {
54                                 Intent intent = new Intent(TrainDelayedActivity.this,
55                                                 (Class<?>)MonitorTimeActivity.class);
56                                 startActivityForResult(intent, -1);
57                         }
58                 });
59                 
60                 Button button4 = (Button) this.findViewById(R.id.button04);
61                 button4.setOnClickListener(new OnClickListener() {
62                         public void onClick(View view) {
63                                 // \83T\81[\83r\83X\82ð\8aJ\8en
64                                 Intent intent = new Intent(TrainDelayedActivity.this,
65                                                 TrainDelayedServiceImpl.class);
66                                 startService(intent);
67                         }
68                 });
69
70                 Button button5 = (Button) this.findViewById(R.id.button05);
71                 button5.setOnClickListener(new OnClickListener() {
72                         public void onClick(View view) {
73                                 // TODO
74                                 HistoryDao.getInstance().delete(TrainDelayedActivity.this);
75
76                                 Intent intent = new Intent(TrainDelayedActivity.this,
77                                                 TrainDelayedServiceImpl.class);
78                                 PendingIntent alarmSender = PendingIntent.getService(
79                                                 TrainDelayedActivity.this, 0, intent, 0);
80                                 AlarmManager alerm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
81                                 alerm.cancel(alarmSender);
82                         }
83                 });
84                 
85                 Button button6 = (Button) this.findViewById(R.id.button06);
86                 button6.setOnClickListener(new OnClickListener() {
87                         public void onClick(View view) {
88                                 HistoryActivity.init(TrainDelayedActivity.this);
89                                 Intent intent = new Intent(TrainDelayedActivity.this,
90                                                 (Class<?>) HistoryActivity.class);
91                                 startActivityForResult(intent, -1);
92                         }
93                 });
94                         
95                 Button button7 = (Button) this.findViewById(R.id.button07);
96                 button7.setOnClickListener(new OnClickListener() {
97                         public void onClick(View view) {
98                                 Intent intent = new Intent(TrainDelayedActivity.this,
99                                                 (Class<?>)SearchWordActivity.class);
100                                 startActivityForResult(intent, -1);
101                         }
102                 });
103
104                 Button button9 = (Button) this.findViewById(R.id.button09);
105                 button9.setOnClickListener(new OnClickListener() {
106                         public void onClick(View view) {
107                                 TrainDelayedActivity.this.finish();
108                         }
109                 });
110         }
111
112         // private class TrainDelayedReceiver extends BroadcastReceiver {
113         // @Override
114         // public void onReceive(Context context, Intent intent) {
115         // Debug.d(this, "onReceive");
116         // }
117         // }
118         //
119         // private TrainDelayedServiceImpl trainDelayedService;
120         // private final TrainDelayedReceiver receiver = new TrainDelayedReceiver();
121         //
122         // private ServiceConnection serviceConnection = new ServiceConnection() {
123         // public void onServiceConnected(ComponentName name, IBinder service) {
124         // Debug.d(this, "onServiceConnected");
125         //
126         // trainDelayedService =
127         // ((TrainDelayedServiceImpl.TrainDelayedBinder)service).getService();
128         // //trainDelayedService.schedule(10 * 60 * 1000);
129         // }
130         //
131         // public void onServiceDisconnected(ComponentName name) {
132         // Debug.d(this, "onServiceDisconnected");
133         // trainDelayedService = null;
134         // }
135         // };
136
137         @Override
138         public void onDestroy() {
139                 super.onDestroy();
140
141                 // Intent intent = new Intent(this, TrainDelayedServiceImpl.class);
142                 // stopService(intent);
143                 // trainDelayedService.scheduleStop();
144
145                 // unbindService(serviceConnection); // \83o\83C\83\93\83h\89ð\8f\9c
146                 // unregisterReceiver(receiver); // \93o\98^\89ð\8f\9c
147                 // trainDelayedService.stopSelf(); // \83T\81[\83r\83X\82Í\95K\97v\82È\82¢\82Ì\82Å\8fI\97¹\82³\82¹\82é\81B
148         }
149
150         // private void getColumnData(Cursor cur) {
151         // if (cur.moveToFirst()) {
152         // do {
153         // int val = cur.getInt(0);
154         // Debug.d(this, "VAL=" + val);
155         // } while (cur.moveToNext());
156         //
157         // }
158         // }
159 }