import twitter4j.AsyncTwitterFactory;\r
import twitter4j.Query;\r
import android.app.AlarmManager;\r
+import android.app.Notification;\r
+import android.app.NotificationManager;\r
import android.app.PendingIntent;\r
import android.app.Service;\r
import android.content.Context;\r
import android.os.Binder;\r
import android.os.IBinder;\r
\r
+import com.td.R;\r
+import com.td.TrainDelayedActivity;\r
import com.td.TrainTwitterAdapter;\r
import com.td.db.Train;\r
import com.td.db.TrainDao;\r
public static final String ACTION = TrainDelayedServiceImpl.class\r
.getSimpleName();\r
private final IBinder binder = new Binder();\r
- \r
-// private boolean isCanceled = false;\r
-// \r
-// public class TrainDelayedBinder extends Binder {\r
-// public TrainDelayedServiceImpl getService() {\r
-// return TrainDelayedServiceImpl.this;\r
-// }\r
-// }\r
+\r
+ // private boolean isCanceled = false;\r
+ //\r
+ // public class TrainDelayedBinder extends Binder {\r
+ // public TrainDelayedServiceImpl getService() {\r
+ // return TrainDelayedServiceImpl.this;\r
+ // }\r
+ // }\r
\r
// TODO\r
private AsyncTwitterFactory factory = new AsyncTwitterFactory();\r
private TrainTwitterAdapter listener = new TrainTwitterAdapter(this);\r
\r
private Timer timer = null;\r
- private int id = 0;\r
+ private static int id = 0;\r
\r
@Override\r
public IBinder onBind(Intent intent) {\r
}\r
\r
// TODO\r
- //private PendingIntent alarmSender;\r
+ // private PendingIntent alarmSender;\r
\r
public void schedule2(long delay) {\r
try {\r
query.setQuery(text);\r
twitter.search(query);\r
}\r
-\r
+ // TODO\r
+ //notificate("id = " + id);\r
+ \r
id++;\r
} catch (Exception e) {\r
Debug.d(this, null, e);\r
}\r
}\r
\r
-// public void scheduleStop() {\r
-// if (timer != null) {\r
-// timer.cancel();\r
-// }\r
-// }\r
+ private void notificate(String msg) {\r
+ try {\r
+ String ns = Context.NOTIFICATION_SERVICE;\r
+ NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);\r
+\r
+ int icon = R.drawable.icon;\r
+ CharSequence tickerText = "\93d\8eÔ\82ª\92x\82ê\82Ä\82é?";\r
+ long when = System.currentTimeMillis();\r
+ Notification notification = new Notification(icon, tickerText, when);\r
+\r
+ Context context = getApplicationContext();\r
+ CharSequence contentTitle = "My notification";\r
+ CharSequence contentText = msg;\r
+ Intent notificationIntent = new Intent(this,\r
+ TrainDelayedActivity.class);\r
+ PendingIntent contentIntent = PendingIntent.getActivity(this, 0,\r
+ notificationIntent, 0);\r
+ notification.setLatestEventInfo(context, contentTitle, contentText,\r
+ contentIntent);\r
+\r
+ int HELLO_ID = 1;\r
+ mNotificationManager.notify(HELLO_ID, notification);\r
+ } catch (Exception e) {\r
+ Debug.d(this, null, e);\r
+ }\r
+ }\r
+\r
+ // public void scheduleStop() {\r
+ // if (timer != null) {\r
+ // timer.cancel();\r
+ // }\r
+ // }\r
\r
@Override\r
public void onCreate() {\r
Debug.d(this, null, e);\r
}\r
}\r
- \r
+\r
// \8e\9f\89ñ\8bN\93®\93o\98^\r
long now = System.currentTimeMillis();\r
PendingIntent alarmSender = PendingIntent.getService(\r
TrainDelayedServiceImpl.this,\r
TrainDelayedServiceImpl.class), 0);\r
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);\r
- alarm.set(AlarmManager.RTC, now + DateUtil.LEN * 60 * 1000, alarmSender);\r
+ alarm.set(AlarmManager.RTC, now + DateUtil.LEN * 60 * 1000,\r
+ alarmSender);\r
\r
// \83T\81[\83r\83X\8fI\97¹\r
TrainDelayedServiceImpl.this.stopSelf();\r
@Override\r
public void onDestroy() {\r
Debug.d(this, Debug.ON_DESTROY);\r
- //TODO\r
- //scheduleStop();\r
+ // TODO\r
+ // scheduleStop();\r
\r
super.onDestroy();\r
}\r