1 package com.td.service;
\r
3 import java.util.Calendar;
\r
4 import java.util.Timer;
\r
5 import java.util.TimerTask;
\r
7 import twitter4j.AsyncTwitter;
\r
8 import twitter4j.AsyncTwitterFactory;
\r
9 import twitter4j.Query;
\r
11 import android.app.Service;
\r
12 import android.content.Intent;
\r
13 import android.os.Binder;
\r
14 import android.os.IBinder;
\r
15 import android.widget.Toast;
\r
17 import com.td.TrainTwitterAdapter;
\r
18 import com.td.utility.Debug;
\r
20 public class TrainDelayedServiceImpl extends Service {
\r
21 public static final String ACTION = TrainDelayedServiceImpl.class
\r
24 public class TrainDelayedBinder extends Binder {
\r
25 public TrainDelayedServiceImpl getService() {
\r
26 return TrainDelayedServiceImpl.this;
\r
31 private AsyncTwitterFactory factory = new AsyncTwitterFactory();
\r
32 private AsyncTwitter twitter = factory.getInstance();
\r
33 private TrainTwitterAdapter listener = new TrainTwitterAdapter(this);
\r
35 private Timer timer = null;
\r
38 // http://www.atmarkit.co.jp/fjava/javatips/078java008.html
\r
39 //
\83N
\83\89\83C
\83A
\83\93\83g
\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82³
\82ê
\82é
\83\81\83\
\83b
\83h
\r
40 public void schedule(long delay) {
\r
41 twitter.addListener(listener);
\r
43 if (timer != null) {
\r
46 timer = new Timer();
\r
47 TimerTask timerTask = new TimerTask() {
\r
51 // Toast toast = Toast.makeText(getApplicationContext(), "run()", Toast.LENGTH_SHORT);
\r
53 Debug.d(this, "run() " + id);
\r
55 Calendar cal = Calendar.getInstance();
\r
56 listener.setCalender(cal);
\r
60 query = new Query();
\r
62 query.setQuery("
\8b\9e\95l
\93\8c\96k");
\r
63 twitter.search(query);
\r
65 query = new Query();
\r
67 query.setQuery("
\93\8c\8aC
\93¹");
\r
68 twitter.search(query);
\r
70 query = new Query();
\r
72 query.setQuery("
\8b\9e\8b}");
\r
73 twitter.search(query);
\r
77 catch (Exception e){
\r
78 Debug.d(this, null, e);
\r
83 timer.schedule(timerTask, 0, delay);
\r
86 public void scheduleStop(){
\r
87 if (timer != null) {
\r
93 public IBinder onBind(Intent intent) {
\r
94 return new TrainDelayedBinder();
\r
98 public void onCreate() {
\r
101 Debug.d(this, Debug.ON_CREATE);
\r
105 public void onStart(Intent intent, int startId) {
\r
106 super.onStart(intent, startId);
\r
108 Debug.d(this, Debug.ON_START);
\r
112 public void onDestroy() {
\r
113 Debug.d(this, Debug.ON_DESTROY);
\r
120 public void onRebind(Intent intent) {
\r
121 super.onRebind(intent);
\r
123 Debug.d(this, Debug.ON_REBIND);
\r
127 public boolean onUnbind(Intent intent) {
\r
128 Debug.d(this, Debug.ON_UNBIND);
\r
130 super.onUnbind(intent);
\r
131 //
\8dÄ
\93x
\83N
\83\89\83C
\83A
\83\93\83g
\82©
\82ç
\90Ú
\91±
\82³
\82ê
\82½
\8dÛ
\82É onRebind
\82ð
\8cÄ
\82Ñ
\8fo
\82³
\82¹
\82é
\8fê
\8d\87\82Í true
\82ð
\95Ô
\82·
\r