OSDN Git Service

サービスによるツイートの取得
authorYuji Konishi <yuji.k64613@gmail.com>
Sat, 2 Jul 2011 06:49:49 +0000 (15:49 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Sat, 2 Jul 2011 06:49:49 +0000 (15:49 +0900)
履歴表示

27 files changed:
memo.txt
workspace/TrainDelayed/.classpath
workspace/TrainDelayed/AndroidManifest.xml
workspace/TrainDelayed/bin/TrainDelayed.apk
workspace/TrainDelayed/bin/classes.dex
workspace/TrainDelayed/bin/com/td/service/TrainDelayedService.aidl [new file with mode: 0644]
workspace/TrainDelayed/bin/resources.ap_
workspace/TrainDelayed/gen/com/td/R.java
workspace/TrainDelayed/gen/com/td/service/TrainDelayedService.java [new file with mode: 0644]
workspace/TrainDelayed/lib/afreechart-0.0.2.jar [new file with mode: 0644]
workspace/TrainDelayed/lib/twitter4j-async-android-2.2.3.jar [new file with mode: 0644]
workspace/TrainDelayed/lib/twitter4j-core-android-2.2.3.jar [new file with mode: 0644]
workspace/TrainDelayed/res/layout/history.xml [new file with mode: 0644]
workspace/TrainDelayed/res/layout/main.xml
workspace/TrainDelayed/res/values/strings.xml
workspace/TrainDelayed/src/com/td/HistoryActivity.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/HistoryContentProvider.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/HistoryView.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/SQLiteOpenHelperImpl.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/TrainDelayedActivity.java
workspace/TrainDelayed/src/com/td/TrainTwitterAdapter.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/db/History.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/db/HistoryDao.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/service/TrainDelayedService.aidl [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/service/TrainDelayedServiceImpl.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/utility/BaseActivity.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/utility/Debug.java [new file with mode: 0644]

index 1882165..c1c3255 100644 (file)
--- a/memo.txt
+++ b/memo.txt
@@ -1,10 +1,3 @@
-TrainDelayed\r
-train_delayed\r
-train-delayed\r
-\r
-git push git://git.sourceforge.jp/gitroot/train-delayed/source.git master\r
-\83`\83P\83b\83g\82Ì\93o\98^\r
-\r
 \83}\83C\83\8b\83X\83g\81[\83\93\82Ì\90Ý\92è\r
 \8b@\94\\88ê\97\97\81¨ToDO\r
        Yahoo!\98H\90ü\8fî\95ñ\8eæ\93¾\r
@@ -17,3 +10,16 @@ git push git://git.sourceforge.jp/gitroot/train-delayed/source.git master
        \91Î\8fÛ\98H\90ü\91I\91ð\89æ\96Ê\r
 \r
 \93d\8eÔ\82ª\92x\82ê\82Ä\82é?\r
+\r
+\r
+\r
+\97\9a\97ð\95\\8e¦\82Ì\90Ý\92è\r
+       \93ú\82É\82¿\r
+       \8e\9e\8aÔ\r
+       \8aÔ\8au(10\95ª,30\95ª,60\95ª)\r
+\r
+\92Ê\92m\r
+       \8a´\93x\r
+\r
+\8c\9f\8dõ\r
+       \83L\81[\83\8f\81[\83h\r
index 6e9239f..38666bd 100644 (file)
@@ -3,5 +3,8 @@
        <classpathentry kind="src" path="src"/>\r
        <classpathentry kind="src" path="gen"/>\r
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>\r
+       <classpathentry kind="lib" path="lib/twitter4j-async-android-2.2.3.jar"/>\r
+       <classpathentry kind="lib" path="lib/twitter4j-core-android-2.2.3.jar"/>\r
+       <classpathentry kind="lib" path="lib/afreechart-0.0.2.jar"/>\r
        <classpathentry kind="output" path="bin"/>\r
 </classpath>\r
index 32607bb..f6d77b1 100644 (file)
@@ -2,10 +2,10 @@
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
       package="com.td"
       android:versionCode="1"
-      android:versionName="1.0">
+      android:versionName="0.1.0">
     <uses-sdk android:minSdkVersion="7" />
 
-    <application android:icon="@drawable/icon" android:label="@string/app_name">
+    <application android:icon="@drawable/icon" android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen" android:label="@string/app_name">
         <activity android:name=".TrainDelayedActivity"
                   android:label="@string/app_name">
             <intent-filter>
                 <category android:name="android.intent.category.LAUNCHER" />
             </intent-filter>
         </activity>
-
+               <provider android:name="HistoryContentProvider" android:authorities="com.td.history"></provider>
+       <activity android:name=".HistoryActivity"></activity>
+               
+       <service android:enabled="true" android:name="com.td.service.TrainDelayedServiceImpl" />
     </application>
+       <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 </manifest>
\ No newline at end of file
index a009dea..040af1e 100644 (file)
Binary files a/workspace/TrainDelayed/bin/TrainDelayed.apk and b/workspace/TrainDelayed/bin/TrainDelayed.apk differ
index 62cb008..d7657d4 100644 (file)
Binary files a/workspace/TrainDelayed/bin/classes.dex and b/workspace/TrainDelayed/bin/classes.dex differ
diff --git a/workspace/TrainDelayed/bin/com/td/service/TrainDelayedService.aidl b/workspace/TrainDelayed/bin/com/td/service/TrainDelayedService.aidl
new file mode 100644 (file)
index 0000000..0a3bae5
--- /dev/null
@@ -0,0 +1,5 @@
+package com.td.service;\r
+\r
+interface TrainDelayedService {\r
+       void notify(int id);\r
+}\r
index 22f49b8..3592daf 100644 (file)
Binary files a/workspace/TrainDelayed/bin/resources.ap_ and b/workspace/TrainDelayed/bin/resources.ap_ differ
index a34e886..d917113 100644 (file)
@@ -13,11 +13,23 @@ public final class R {
     public static final class drawable {\r
         public static final int icon=0x7f020000;\r
     }\r
+    public static final class id {\r
+        public static final int button1=0x7f050001;\r
+        public static final int button2=0x7f050002;\r
+        public static final int button3=0x7f050003;\r
+        public static final int button4=0x7f050004;\r
+        public static final int button5=0x7f050005;\r
+        public static final int spcv=0x7f050000;\r
+    }\r
     public static final class layout {\r
-        public static final int main=0x7f030000;\r
+        public static final int history=0x7f030000;\r
+        public static final int main=0x7f030001;\r
     }\r
     public static final class string {\r
         public static final int app_name=0x7f040001;\r
         public static final int hello=0x7f040000;\r
+        public static final int history_button=0x7f040002;\r
+        public static final int start_service_button=0x7f040003;\r
+        public static final int stop_service_button=0x7f040004;\r
     }\r
 }\r
diff --git a/workspace/TrainDelayed/gen/com/td/service/TrainDelayedService.java b/workspace/TrainDelayed/gen/com/td/service/TrainDelayedService.java
new file mode 100644 (file)
index 0000000..7b793ff
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * This file is auto-generated.  DO NOT MODIFY.
+ * Original file: C:\\yuji\\prog\\Android\\workspaces\\train_delayed\\workspace\\TrainDelayed\\src\\com\\td\\service\\TrainDelayedService.aidl
+ */
+package com.td.service;
+public interface TrainDelayedService extends android.os.IInterface
+{
+/** Local-side IPC implementation stub class. */
+public static abstract class Stub extends android.os.Binder implements com.td.service.TrainDelayedService
+{
+private static final java.lang.String DESCRIPTOR = "com.td.service.TrainDelayedService";
+/** Construct the stub at attach it to the interface. */
+public Stub()
+{
+this.attachInterface(this, DESCRIPTOR);
+}
+/**
+ * Cast an IBinder object into an com.td.service.TrainDelayedService interface,
+ * generating a proxy if needed.
+ */
+public static com.td.service.TrainDelayedService asInterface(android.os.IBinder obj)
+{
+if ((obj==null)) {
+return null;
+}
+android.os.IInterface iin = (android.os.IInterface)obj.queryLocalInterface(DESCRIPTOR);
+if (((iin!=null)&&(iin instanceof com.td.service.TrainDelayedService))) {
+return ((com.td.service.TrainDelayedService)iin);
+}
+return new com.td.service.TrainDelayedService.Stub.Proxy(obj);
+}
+public android.os.IBinder asBinder()
+{
+return this;
+}
+@Override public boolean onTransact(int code, android.os.Parcel data, android.os.Parcel reply, int flags) throws android.os.RemoteException
+{
+switch (code)
+{
+case INTERFACE_TRANSACTION:
+{
+reply.writeString(DESCRIPTOR);
+return true;
+}
+case TRANSACTION_notify:
+{
+data.enforceInterface(DESCRIPTOR);
+int _arg0;
+_arg0 = data.readInt();
+this.notify(_arg0);
+reply.writeNoException();
+return true;
+}
+}
+return super.onTransact(code, data, reply, flags);
+}
+private static class Proxy implements com.td.service.TrainDelayedService
+{
+private android.os.IBinder mRemote;
+Proxy(android.os.IBinder remote)
+{
+mRemote = remote;
+}
+public android.os.IBinder asBinder()
+{
+return mRemote;
+}
+public java.lang.String getInterfaceDescriptor()
+{
+return DESCRIPTOR;
+}
+public void notify(int id) throws android.os.RemoteException
+{
+android.os.Parcel _data = android.os.Parcel.obtain();
+android.os.Parcel _reply = android.os.Parcel.obtain();
+try {
+_data.writeInterfaceToken(DESCRIPTOR);
+_data.writeInt(id);
+mRemote.transact(Stub.TRANSACTION_notify, _data, _reply, 0);
+_reply.readException();
+}
+finally {
+_reply.recycle();
+_data.recycle();
+}
+}
+}
+static final int TRANSACTION_notify = (android.os.IBinder.FIRST_CALL_TRANSACTION + 0);
+}
+public void notify(int id) throws android.os.RemoteException;
+}
diff --git a/workspace/TrainDelayed/lib/afreechart-0.0.2.jar b/workspace/TrainDelayed/lib/afreechart-0.0.2.jar
new file mode 100644 (file)
index 0000000..e805a15
Binary files /dev/null and b/workspace/TrainDelayed/lib/afreechart-0.0.2.jar differ
diff --git a/workspace/TrainDelayed/lib/twitter4j-async-android-2.2.3.jar b/workspace/TrainDelayed/lib/twitter4j-async-android-2.2.3.jar
new file mode 100644 (file)
index 0000000..525839e
Binary files /dev/null and b/workspace/TrainDelayed/lib/twitter4j-async-android-2.2.3.jar differ
diff --git a/workspace/TrainDelayed/lib/twitter4j-core-android-2.2.3.jar b/workspace/TrainDelayed/lib/twitter4j-core-android-2.2.3.jar
new file mode 100644 (file)
index 0000000..c06ffed
Binary files /dev/null and b/workspace/TrainDelayed/lib/twitter4j-core-android-2.2.3.jar differ
diff --git a/workspace/TrainDelayed/res/layout/history.xml b/workspace/TrainDelayed/res/layout/history.xml
new file mode 100644 (file)
index 0000000..bb9e3c9
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+    <com.td.HistoryView
+              android:id="@+id/spcv"
+              android:layout_margin="10dip"
+              android:layout_width="wrap_content"
+              android:layout_height="wrap_content" />
+</LinearLayout>
index 3a5f117..1104348 100644 (file)
@@ -4,9 +4,9 @@
     android:layout_width="fill_parent"
     android:layout_height="fill_parent"
     >
-<TextView  
-    android:layout_width="fill_parent" 
-    android:layout_height="wrap_content" 
-    android:text="@string/hello"
-    />
+<Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
+<Button android:text="Button" android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
+<Button android:text="@+string/history_button" android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
+<Button android:text="@+string/start_service_button" android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
+<Button android:text="@+string/stop_service_button" android:id="@+id/button5" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
 </LinearLayout>
index 2f63ea3..bcce324 100644 (file)
@@ -2,4 +2,7 @@
 <resources>
     <string name="hello">Hello World, TrainDelayedActivity!</string>
     <string name="app_name">TrainDelayed</string>
+    <string name="history_button">履歴表示</string>
+    <string name="start_service_button">スタート</string>
+    <string name="stop_service_button">ストップ</string>
 </resources>
diff --git a/workspace/TrainDelayed/src/com/td/HistoryActivity.java b/workspace/TrainDelayed/src/com/td/HistoryActivity.java
new file mode 100644 (file)
index 0000000..c735376
--- /dev/null
@@ -0,0 +1,54 @@
+package com.td;\r
+\r
+import java.util.List;\r
+\r
+import org.afree.chart.AFreeChart;\r
+import org.afree.chart.ChartFactory;\r
+import org.afree.chart.plot.PlotOrientation;\r
+import org.afree.data.category.DefaultCategoryDataset;\r
+\r
+import android.os.Bundle;\r
+\r
+import com.td.db.History;\r
+import com.td.db.HistoryDao;\r
+import com.td.utility.BaseActivity;\r
+import com.td.utility.Debug;\r
+\r
+public class HistoryActivity extends BaseActivity {\r
+       @Override\r
+       public void onCreate(Bundle savedInstanceState) {\r
+               super.onCreate(savedInstanceState);\r
+               setContentView(R.layout.history);\r
+\r
+               HistoryDao dao = HistoryDao.getInstance();\r
+               List<History> list = dao.search(this);\r
+\r
+               DefaultCategoryDataset dataset = new DefaultCategoryDataset();\r
+               for (History history : list) {\r
+                       double val = history.getNum() * 10 * 60 / history.getPeriod();\r
+                       int hm = history.getHm();\r
+                       String text = (hm / 100) + ":" + (hm %  100);\r
+                       String route = "<none>";\r
+                       switch (history.getRouteId()){\r
+                       case 1:\r
+                               route = "\8b\9e\95l\93\8c\96k\90ü";\r
+                               break;\r
+                       case 2:\r
+                               route = "\93\8c\8aC\93¹\90ü";\r
+                               break;\r
+                       case 3:\r
+                               route = "\8b\9e\8b}\90ü";\r
+                               break;\r
+                       }\r
+                       Debug.d(this, route + " " + text + " " + val);\r
+                       dataset.setValue(val, route, text);\r
+               }\r
+\r
+               AFreeChart chart = ChartFactory.createLineChart("\82Â\82Ô\82â\82«\97\9a\97ð", "\8e\9e\8d\8f",\r
+                               "\82Â\82Ô\82â\82«\90\94(\89ñ/\8e\9e)", dataset, PlotOrientation.VERTICAL, true, false,\r
+                               false);\r
+\r
+               HistoryView spcv = (HistoryView) findViewById(R.id.spcv);\r
+               spcv.setChart(chart);\r
+       }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/HistoryContentProvider.java b/workspace/TrainDelayed/src/com/td/HistoryContentProvider.java
new file mode 100644 (file)
index 0000000..4a27b8b
--- /dev/null
@@ -0,0 +1,151 @@
+package com.td;\r
+\r
+import android.content.ContentProvider;\r
+import android.content.ContentUris;\r
+import android.content.ContentValues;\r
+import android.content.UriMatcher;\r
+import android.database.Cursor;\r
+import android.database.sqlite.SQLiteDatabase;\r
+import android.net.Uri;\r
+\r
+public class HistoryContentProvider extends ContentProvider {\r
+       public class Fields {\r
+               public static final String ID = android.provider.BaseColumns._ID;\r
+               public static final String ROUTE_ID = "ROUTE_ID";\r
+               public static final String YMD = "YMD";\r
+               public static final String HM = "HM";\r
+               public static final String WEEK = "WEEK";\r
+               public static final String PERIOD = "PERIOD";\r
+               public static final String NUM = "NUM";\r
+               public static final String STATUS = "STATUS";           \r
+       }\r
+       public static class Projection {\r
+               public static final String[] projection = {\r
+                       Fields.ID,\r
+                       Fields.ROUTE_ID,\r
+                       Fields.YMD,\r
+                       Fields.HM,\r
+                       Fields.WEEK,\r
+                       Fields.PERIOD,\r
+                       Fields.NUM,\r
+                       Fields.STATUS\r
+               };\r
+       }\r
+               \r
+       public static final String AUTHORITY = "com.td.history";\r
+       public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/" + "numbers");\r
+\r
+       private static final int CODE_NUMBERS = 1;\r
+       private static final int CODE_NUMBER = 2;\r
+       private static final String HISTORY_TABLE = "history";\r
+       \r
+       /** \83f\83B\83\8c\83N\83g\83\8a\82ÌMIME\83^\83C\83v */\r
+       private static final String CONTENT_TYPE = "vnd.android.cursor.dir/com.td.history";\r
+\r
+       /** \92P\88ê\82ÌMIME\83^\83C\83v */\r
+       private static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/com.td.history";\r
+\r
+       private UriMatcher uriMatcher;\r
+       private SQLiteOpenHelperImpl sqlSupport;\r
+\r
+       @Override\r
+       public boolean onCreate() {\r
+               uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);\r
+               uriMatcher.addURI(AUTHORITY, "numbers", CODE_NUMBERS);\r
+               uriMatcher.addURI(AUTHORITY, "numbers/#", CODE_NUMBER);\r
+               sqlSupport = new SQLiteOpenHelperImpl(getContext());\r
+               return true;\r
+       }\r
+       \r
+       @Override\r
+       public String getType(Uri uri) {\r
+               switch (uriMatcher.match(uri)) {\r
+               case CODE_NUMBERS:\r
+                       return CONTENT_TYPE;\r
+               case CODE_NUMBER:\r
+                       return CONTENT_ITEM_TYPE;\r
+               default:\r
+                       // TODO\r
+                       throw new IllegalArgumentException("Unknown URI " + uri);\r
+               }\r
+       }\r
+       \r
+       @Override\r
+       public int delete(Uri uri, String selection, String[] selectionArgs) {\r
+               final SQLiteDatabase db = sqlSupport.getWritableDatabase();\r
+               final int deleteCount;\r
+               switch (uriMatcher.match(uri)) {\r
+               case CODE_NUMBERS:\r
+                       deleteCount = db.delete(HISTORY_TABLE, selection, selectionArgs);\r
+                       break;\r
+               case CODE_NUMBER:\r
+                       final long id = Long.parseLong(uri.getPathSegments().get(1));\r
+                       final String idPlusSelection = android.provider.BaseColumns._ID + "=" + Long.toString(id) + (selection == null ? "" : "AND (" + selection + ")");\r
+                       deleteCount = db.delete(HISTORY_TABLE, idPlusSelection, selectionArgs);\r
+                       break;\r
+               default:\r
+                       // TODO\r
+                       throw new IllegalArgumentException("Unknown URI " + uri);\r
+               }\r
+\r
+               return deleteCount;\r
+       }\r
+\r
+       @Override\r
+       public Uri insert(Uri uri, ContentValues values) {\r
+               final SQLiteDatabase db = sqlSupport.getWritableDatabase();\r
+               if(uriMatcher.match(uri) != CODE_NUMBERS) {\r
+                       // TODO\r
+                       throw new IllegalArgumentException("Unknown URI " + uri);\r
+               }\r
+\r
+               final long id = db.insertOrThrow(HISTORY_TABLE, null, values);\r
+\r
+               // \95Ï\8dX\82ð\92Ê\92m\82·\82é\r
+           final Uri newUri = ContentUris.withAppendedId(CONTENT_URI, id);\r
+           getContext().getContentResolver().notifyChange(newUri, null);\r
+\r
+               return newUri;\r
+       }\r
+\r
+\r
+       @Override\r
+       public Cursor query(Uri uri, String[] projection, String selection,\r
+                       String[] selectionArgs, String sortOrder) {\r
+               if (uriMatcher.match(uri) == CODE_NUMBER) {\r
+                       final long id = Long.parseLong(uri.getPathSegments().get(1));\r
+                       selection = android.provider.BaseColumns._ID + "=" + Long.toString(id) + (selection == null ? "" : "AND (" + selection + ")");\r
+               }\r
+               final SQLiteDatabase db = sqlSupport.getWritableDatabase();\r
+               Cursor cursor = db.query(HISTORY_TABLE, projection, selection, selectionArgs, null, null, sortOrder);\r
+\r
+               cursor.setNotificationUri(getContext().getContentResolver(), uri);\r
+\r
+               return cursor;\r
+       }\r
+\r
+       @Override\r
+       public int update(Uri uri, ContentValues values, String selection,\r
+                       String[] selectionArgs) {\r
+               final SQLiteDatabase db = sqlSupport.getWritableDatabase();\r
+               final int updateCount;\r
+               switch (uriMatcher.match(uri)) {\r
+               case CODE_NUMBERS:\r
+                       updateCount = db.update(HISTORY_TABLE, values, selection, selectionArgs);\r
+                       break;\r
+               case CODE_NUMBER:\r
+                       final long id = Long.parseLong(uri.getPathSegments().get(1));\r
+                       final String idPlusSelection = android.provider.BaseColumns._ID + "=" + Long.toString(id) + (selection == null ? "" : "AND (" + selection + ")");\r
+                       updateCount = db.update(HISTORY_TABLE, values, idPlusSelection, selectionArgs);\r
+                       break;\r
+               default:\r
+                       // TODO\r
+                       throw new IllegalArgumentException("Unknown URI " + uri);\r
+               }\r
+\r
+               // \95Ï\8dX\82ð\92Ê\92m\82·\82é\r
+               getContext().getContentResolver().notifyChange(uri, null);\r
+\r
+               return updateCount;\r
+       }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/HistoryView.java b/workspace/TrainDelayed/src/com/td/HistoryView.java
new file mode 100644 (file)
index 0000000..6fd2aa5
--- /dev/null
@@ -0,0 +1,35 @@
+package com.td;\r
+\r
+import org.afree.chart.AFreeChart;\r
+import org.afree.graphics.geom.RectShape;\r
+\r
+import android.content.Context;\r
+import android.graphics.Canvas;\r
+import android.util.AttributeSet;\r
+import android.view.View;\r
+\r
+public class HistoryView extends View {\r
+    private AFreeChart chart;\r
+\r
+    public HistoryView(Context context, AttributeSet attrs) {\r
+        super(context, attrs);\r
+    }\r
+\r
+    @Override\r
+    protected void onDraw(Canvas canvas) {\r
+        super.onDraw(canvas);\r
+//        RectShape chartArea = new RectShape(0.0, 0.0, 200.0, 200.0);\r
+//        RectShape chartArea = new RectShape();\r
+        RectShape chartArea = new RectShape(0.0, 0.0, this.getWidth(), this.getHeight());\r
+        this.chart.draw(canvas, chartArea);\r
+    }\r
+\r
+//    @Override\r
+//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {\r
+//        setMeasuredDimension(200, 200);\r
+//    }\r
+\r
+    public void setChart(AFreeChart chart) {\r
+        this.chart = chart;\r
+    }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/SQLiteOpenHelperImpl.java b/workspace/TrainDelayed/src/com/td/SQLiteOpenHelperImpl.java
new file mode 100644 (file)
index 0000000..4398918
--- /dev/null
@@ -0,0 +1,35 @@
+package com.td;\r
+\r
+import android.content.Context;\r
+import android.database.sqlite.SQLiteDatabase;\r
+import android.database.sqlite.SQLiteOpenHelper;\r
+\r
+public class SQLiteOpenHelperImpl extends SQLiteOpenHelper {\r
+       private static final String DATABASE_NAME = "history.db";\r
+       private static final int DATABASE_VERSION = 1;\r
+       \r
+       public SQLiteOpenHelperImpl(Context context) {\r
+               super(context, DATABASE_NAME, null, DATABASE_VERSION);\r
+       }\r
+\r
+       @Override\r
+       public void onCreate(SQLiteDatabase db) {\r
+               db.execSQL(\r
+                               "CREATE TABLE HISTORY ("\r
+                               + android.provider.BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"\r
+                               + "ROUTE_ID INTEGER,"\r
+                               + "YMD INTEGER,"\r
+                               + "HM INTEGER,"\r
+                               + "WEEK INTEGER,"\r
+                               + "PERIOD INTEGER,"\r
+                               + "NUM INTEGER,"\r
+                               + "STATUS INTEGER"\r
+                               + ");");\r
+       }\r
+\r
+       @Override\r
+       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {\r
+               db.execSQL("DROP TABLE IF EXISTS HISTORY");\r
+       }\r
+\r
+}\r
index 2e1b4f2..61f913d 100644 (file)
 package com.td;
 
-import android.app.Activity;
+import java.util.Calendar;
+
+import twitter4j.AsyncTwitter;
+import twitter4j.AsyncTwitterFactory;
+import twitter4j.Query;
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.ServiceConnection;
+import android.database.Cursor;
 import android.os.Bundle;
+import android.os.IBinder;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+
+import com.td.service.TrainDelayedServiceImpl;
+import com.td.utility.BaseActivity;
+import com.td.utility.Debug;
 
-public class TrainDelayedActivity extends Activity {
-    /** Called when the activity is first created. */
+public class TrainDelayedActivity extends BaseActivity {
+    private AsyncTwitterFactory factory = new AsyncTwitterFactory();
+    private AsyncTwitter twitter = factory.getInstance();
+    //private TrainTwitterAdapter listener = new TrainTwitterAdapter(this, 1);
+    //private List<TrainTwitterAdapter> adapterList = new ArrayList<TrainTwitterAdapter>();
+    
     @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.main);
+       public void onCreate(Bundle savedInstanceState) {
+               super.onCreate(savedInstanceState);
+               setContentView(R.layout.main);
+
+               final TrainTwitterAdapter listener = new TrainTwitterAdapter(this);             
+               twitter.addListener(listener);
+               
+        Button button1 = (Button) this.findViewById(R.id.button1);
+               button1.setOnClickListener(new OnClickListener() {
+                       public void onClick(View view) {
+                               Calendar cal = Calendar.getInstance();
+                               listener.setCalender(cal);
+                               
+                               Query query;
+                               
+                               query = new Query();
+                               query.setRpp(100);
+                               query.setQuery("\8b\9e\95l\93\8c\96k");
+                               twitter.search(query);
+
+                               query = new Query();
+                               query.setRpp(100);
+                               query.setQuery("\93\8c\8aC\93¹");
+                               twitter.search(query);
+
+                               query = new Query();
+                               query.setRpp(100);
+                               query.setQuery("\8b\9e\8b}");
+                               twitter.search(query);
+                       }
+               });
+
+        Button button2 = (Button) this.findViewById(R.id.button2);
+        button2.setOnClickListener(new OnClickListener() {
+                       public void onClick(View view) {
+
+                       }
+               });
+
+        Button button3 = (Button) this.findViewById(R.id.button3);
+               button3.setOnClickListener(new OnClickListener() {
+                       public void onClick(View view) {
+                               Intent intent = new Intent(TrainDelayedActivity.this, (Class<?>)HistoryActivity.class);
+                               //intent.putExtra("INDEX", 1);//TODO
+                               startActivityForResult(intent, -1);
+                       }
+               });
+
+        Button button4 = (Button) this.findViewById(R.id.button4);
+               button4.setOnClickListener(new OnClickListener() {
+                       public void onClick(View view) {
+                               // \83T\81[\83r\83X\82ð\8aJ\8en
+                               Intent intent = new Intent(TrainDelayedActivity.this, TrainDelayedServiceImpl.class);
+                               startService(intent);
+                               IntentFilter filter = new IntentFilter(TrainDelayedServiceImpl.ACTION);
+                               registerReceiver(receiver, filter);
+                               
+                               // \83T\81[\83r\83X\82É\83o\83C\83\93\83h
+                               bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
+                       }
+               });
+
+        Button button5 = (Button) this.findViewById(R.id.button5);
+        button5.setOnClickListener(new OnClickListener() {
+                       public void onClick(View view) {
+                               unbindService(serviceConnection); // \83o\83C\83\93\83h\89ð\8f\9c
+                               unregisterReceiver(receiver); // \93o\98^\89ð\8f\9c
+                               trainDelayedService.stopSelf(); // \83T\81[\83r\83X\82Í\95K\97v\82È\82¢\82Ì\82Å\8fI\97¹\82³\82¹\82é\81B
+                       }
+               });
+
+    }
+    
+       private class TrainDelayedReceiver extends BroadcastReceiver {
+               @Override
+               public void onReceive(Context context, Intent intent) {
+                       Debug.d(this, "onReceive");
+               }
+       }
+       
+       private TrainDelayedServiceImpl trainDelayedService;
+       private final TrainDelayedReceiver receiver = new TrainDelayedReceiver();
+       
+       private ServiceConnection serviceConnection = new ServiceConnection() {
+               public void onServiceConnected(ComponentName name, IBinder service) {
+                       Debug.d(this, "onServiceConnected");
+                       
+                       trainDelayedService = ((TrainDelayedServiceImpl.TrainDelayedBinder)service).getService();                       
+                       trainDelayedService.schedule(10 * 60 * 1000);
+               }
+
+               public void onServiceDisconnected(ComponentName name) {
+                       Debug.d(this, "onServiceDisconnected");
+                       trainDelayedService = null;
+               }
+       };
+
+       @Override
+       public void onDestroy() {
+               super.onDestroy();
+               
+//             Intent intent = new Intent(this, TrainDelayedServiceImpl.class);
+//             stopService(intent);
+//             trainDelayedService.scheduleStop();
+               
+//             unbindService(serviceConnection); // \83o\83C\83\93\83h\89ð\8f\9c
+//             unregisterReceiver(receiver); // \93o\98^\89ð\8f\9c
+//             trainDelayedService.stopSelf(); // \83T\81[\83r\83X\82Í\95K\97v\82È\82¢\82Ì\82Å\8fI\97¹\82³\82¹\82é\81B
+       }
+
+       private void getColumnData(Cursor cur){ 
+        if (cur.moveToFirst()) {
+            do {
+                int val = cur.getInt(0);
+                Debug.d(this, "VAL=" + val);
+            } while (cur.moveToNext());
+
+        }
     }
 }
\ No newline at end of file
diff --git a/workspace/TrainDelayed/src/com/td/TrainTwitterAdapter.java b/workspace/TrainDelayed/src/com/td/TrainTwitterAdapter.java
new file mode 100644 (file)
index 0000000..2af2d97
--- /dev/null
@@ -0,0 +1,145 @@
+package com.td;\r
+\r
+import java.util.Calendar;\r
+import java.util.Date;\r
+import java.util.List;\r
+\r
+import twitter4j.QueryResult;\r
+import twitter4j.Tweet;\r
+import twitter4j.TwitterAdapter;\r
+import twitter4j.TwitterException;\r
+import twitter4j.TwitterMethod;\r
+import android.content.ContentValues;\r
+import android.content.Context;\r
+import android.net.Uri;\r
+\r
+import com.td.utility.Debug;\r
+\r
+public class TrainTwitterAdapter extends TwitterAdapter {\r
+       private Context context;\r
+       private Calendar cal;\r
+       \r
+       public TrainTwitterAdapter(Context context){\r
+               this.context = context;\r
+       }\r
+       \r
+       public void setCalender(Calendar cal){\r
+               this.cal = cal;\r
+       }\r
+       \r
+    @Override\r
+       public void searched(QueryResult result) {\r
+               super.searched(result);\r
+               \r
+               long min = Long.MAX_VALUE;\r
+               long max = 0;\r
+               \r
+               Date minDate = null;\r
+               Date maxDate = null;\r
+               Date curDate = cal.getTime();\r
+               \r
+               long cur = curDate.getTime();\r
+               long from = cur - 10 * 60 * 1000;\r
+               int count = 0;\r
+               long diff = 0;\r
+               \r
+               List<Tweet> tweets = result.getTweets();\r
+               for (Tweet tweet : tweets){\r
+                       String text = tweet.getText();\r
+                       Date at = tweet.getCreatedAt();\r
+                       long l = at.getTime();\r
+                       \r
+                       if (l < from){\r
+                               continue;\r
+                       }\r
+                       if (!filter(text)){\r
+                               Debug.d(this, "NO MATCH:" + text);\r
+                               continue;\r
+                       }\r
+                       if (l < min){\r
+                               min = l;\r
+                               minDate = at;\r
+                       }\r
+                       if (l > max){\r
+                               max = l;\r
+                               maxDate = at;\r
+                       }\r
+                       \r
+                       Debug.d(this, at.toString() + " " + text);\r
+                       count++;\r
+               }\r
+               if (count > 0){\r
+                       diff = (maxDate.getTime() - minDate.getTime()) / 1000;\r
+                       String query = result.getQuery();\r
+                       int routeId = 0;\r
+                       if (query.compareTo("\8b\9e\95l\93\8c\96k") == 0){\r
+                               routeId = 1;\r
+                       }\r
+                       else if (query.compareTo("\93\8c\8aC\93¹") == 0){\r
+                               routeId = 2;\r
+                       }\r
+                       else if (query.compareTo("\8b\9e\8b}") == 0){\r
+                               routeId = 3;\r
+                       }\r
+                       \r
+                       Debug.d(this, minDate.toString());\r
+                       Debug.d(this, maxDate.toString());\r
+                       Debug.d(this, "routeId=" + routeId);\r
+                       Debug.d(this, "diff=" + diff);\r
+                       Debug.d(this, "count=" + count);\r
+                       \r
+                       insert(routeId, diff, count, 0);\r
+               }\r
+       }\r
+\r
+    private boolean filter(String text){\r
+       final String[] keywords = {\r
+               "\90l\90g\8e\96\8cÌ",\r
+               "\92x\82ê",\r
+               "\8e~\82Ü\82Á\82Ä",\r
+               "\92x\89\84",\r
+               "\89^\93]\92â\8e~",\r
+               "\89^\93]\8c©\8d\87",\r
+               "\89^\93]\82ð\8c©\8d\87",\r
+       };\r
+       for (String keyword : keywords){\r
+               if (text.indexOf(keyword) >= 0){\r
+                       return true;\r
+               }\r
+       }\r
+       return false;\r
+    }\r
+    \r
+    private void insert(int routeId, long diff, int count, int status){\r
+               Date date = cal.getTime();\r
+       \r
+       int y = date.getYear() + 1900;\r
+       int m = date.getMonth() + 1;\r
+       int d = date.getDate();\r
+       int h = date.getHours();\r
+       int mi = date.getMinutes();\r
+       int w = cal.get(Calendar.DAY_OF_WEEK) - 1;\r
+       \r
+       int ymd = y * 10000 + m * 100 + d;\r
+       int hm = h * 100 + mi;\r
+       \r
+       Debug.d(this, "" + ymd + " " + hm + " " + w);\r
+       \r
+               ContentValues values = new ContentValues();\r
+               values.put(HistoryContentProvider.Fields.ROUTE_ID, routeId);\r
+               values.put(HistoryContentProvider.Fields.YMD, ymd);\r
+               values.put(HistoryContentProvider.Fields.HM, hm);\r
+               values.put(HistoryContentProvider.Fields.WEEK, w);\r
+               values.put(HistoryContentProvider.Fields.PERIOD, diff);\r
+               values.put(HistoryContentProvider.Fields.NUM, count);\r
+               values.put(HistoryContentProvider.Fields.STATUS, status);\r
+               \r
+               Uri uri = context.getContentResolver().insert(HistoryContentProvider.CONTENT_URI, values);\r
+               Debug.d(this, uri.toString());          \r
+    }\r
+    \r
+       @Override\r
+    public void onException(TwitterException e, TwitterMethod method) {\r
+       e.printStackTrace();\r
+    }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/db/History.java b/workspace/TrainDelayed/src/com/td/db/History.java
new file mode 100644 (file)
index 0000000..61685a9
--- /dev/null
@@ -0,0 +1,56 @@
+package com.td.db;\r
+\r
+public class History {\r
+       private int id;\r
+       private int routeId;\r
+       private int ymd;\r
+       private int hm;\r
+       private int week;\r
+       private int period;\r
+       private int num;\r
+       private int status;\r
+       \r
+       public History(int id, int routeId, int ymd, int hm, int week, int period,\r
+                       int num, int status) {\r
+               this.id = id;\r
+               this.routeId = routeId;\r
+               this.ymd = ymd;\r
+               this.hm = hm;\r
+               this.week = week;\r
+               this.period = period;\r
+               this.num = num;\r
+               this.status = status;\r
+       }\r
+\r
+       public int getId() {\r
+               return id;\r
+       }\r
+\r
+       public int getRouteId() {\r
+               return routeId;\r
+       }\r
+\r
+       public int getYmd() {\r
+               return ymd;\r
+       }\r
+\r
+       public int getHm() {\r
+               return hm;\r
+       }\r
+\r
+       public int getWeek() {\r
+               return week;\r
+       }\r
+\r
+       public int getPeriod() {\r
+               return period;\r
+       }\r
+\r
+       public int getNum() {\r
+               return num;\r
+       }\r
+\r
+       public int getStatus() {\r
+               return status;\r
+       }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/db/HistoryDao.java b/workspace/TrainDelayed/src/com/td/db/HistoryDao.java
new file mode 100644 (file)
index 0000000..412d225
--- /dev/null
@@ -0,0 +1,59 @@
+package com.td.db;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import android.content.ContentResolver;\r
+import android.content.Context;\r
+import android.database.Cursor;\r
+\r
+import com.td.HistoryContentProvider;\r
+import com.td.utility.Debug;\r
+\r
+public class HistoryDao {\r
+       private static HistoryDao instance = null;\r
+       \r
+       public static HistoryDao getInstance(){\r
+               if (instance == null){\r
+                       instance = new HistoryDao();\r
+               }\r
+               return instance;\r
+       }\r
+       \r
+       public List<History> search(Context context, String selection, String[] selectionArgs){\r
+               ContentResolver resolver = context.getContentResolver();\r
+               Cursor cursor = resolver.query(HistoryContentProvider.CONTENT_URI,\r
+                               HistoryContentProvider.Projection.projection,\r
+                               selection,\r
+                               selectionArgs,\r
+                               HistoryContentProvider.Fields.ID + " ASC");\r
+               \r
+               List<History> list = new ArrayList<History>();\r
+        if (cursor.moveToFirst()) {\r
+            do {\r
+               int n = 0;\r
+                       int id = cursor.getInt(n++);\r
+                       int routeId = cursor.getInt(n++);\r
+                       int ymd = cursor.getInt(n++);\r
+                       int hm = cursor.getInt(n++);\r
+                       int week = cursor.getInt(n++);\r
+                       int period = cursor.getInt(n++);\r
+                       int num = cursor.getInt(n++);\r
+                       int status = cursor.getInt(n++);\r
+                       \r
+                       // TODO\r
+                               Debug.d(this, "" + id + " " + routeId + " " + ymd + " " + hm\r
+                                               + " " + week + " " + period + " " + num + " " + status);\r
+                               \r
+                               History history = new History(id, routeId, ymd, hm, week,\r
+                                               period, num, status);\r
+                               list.add(history);\r
+            } while (cursor.moveToNext());\r
+        }              \r
+        return list;\r
+       }\r
+\r
+       public List<History> search(Context context){\r
+               return search(context, null, null);\r
+       }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/service/TrainDelayedService.aidl b/workspace/TrainDelayed/src/com/td/service/TrainDelayedService.aidl
new file mode 100644 (file)
index 0000000..0a3bae5
--- /dev/null
@@ -0,0 +1,5 @@
+package com.td.service;\r
+\r
+interface TrainDelayedService {\r
+       void notify(int id);\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/service/TrainDelayedServiceImpl.java b/workspace/TrainDelayed/src/com/td/service/TrainDelayedServiceImpl.java
new file mode 100644 (file)
index 0000000..5832723
--- /dev/null
@@ -0,0 +1,134 @@
+package com.td.service;\r
+\r
+import java.util.Calendar;\r
+import java.util.Timer;\r
+import java.util.TimerTask;\r
+\r
+import twitter4j.AsyncTwitter;\r
+import twitter4j.AsyncTwitterFactory;\r
+import twitter4j.Query;\r
+\r
+import android.app.Service;\r
+import android.content.Intent;\r
+import android.os.Binder;\r
+import android.os.IBinder;\r
+import android.widget.Toast;\r
+\r
+import com.td.TrainTwitterAdapter;\r
+import com.td.utility.Debug;\r
+\r
+public class TrainDelayedServiceImpl extends Service {\r
+       public static final String ACTION = TrainDelayedServiceImpl.class\r
+                       .getSimpleName();\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 AsyncTwitter twitter = factory.getInstance();\r
+    private TrainTwitterAdapter listener = new TrainTwitterAdapter(this);\r
+       \r
+    private Timer timer = null;\r
+       private int id = 0;\r
+       \r
+       // http://www.atmarkit.co.jp/fjava/javatips/078java008.html\r
+       // \83N\83\89\83C\83A\83\93\83g\82©\82ç\8cÄ\82Ñ\8fo\82³\82ê\82é\83\81\83\\83b\83h\r
+       public void schedule(long delay) {\r
+        twitter.addListener(listener);\r
+\r
+               if (timer != null) {\r
+                       timer.cancel();\r
+               }\r
+               timer = new Timer();\r
+               TimerTask timerTask = new TimerTask() {\r
+                       \r
+                       public void run() {\r
+                               try {\r
+//                             Toast toast = Toast.makeText(getApplicationContext(), "run()", Toast.LENGTH_SHORT);\r
+//                             toast.show();\r
+                                       Debug.d(this, "run() " + id);\r
+       \r
+                                       Calendar cal = Calendar.getInstance();\r
+                                       listener.setCalender(cal);\r
+                                       \r
+                                       Query query;\r
+                                       \r
+                                       query = new Query();\r
+                                       query.setRpp(100);\r
+                                       query.setQuery("\8b\9e\95l\93\8c\96k");\r
+                                       twitter.search(query);\r
+\r
+                                       query = new Query();\r
+                                       query.setRpp(100);\r
+                                       query.setQuery("\93\8c\8aC\93¹");\r
+                                       twitter.search(query);\r
+\r
+                                       query = new Query();\r
+                                       query.setRpp(100);\r
+                                       query.setQuery("\8b\9e\8b}");\r
+                                       twitter.search(query);\r
+                                       \r
+                                       id++;\r
+                               }\r
+                               catch (Exception e){\r
+                                       Debug.d(this, null, e);\r
+                               }\r
+                       }\r
+                       \r
+               };\r
+               timer.schedule(timerTask, 0, delay);\r
+       }\r
+       \r
+       public void scheduleStop(){\r
+               if (timer != null) {\r
+                       timer.cancel();\r
+               }               \r
+       }\r
+       \r
+       @Override\r
+       public IBinder onBind(Intent intent) {\r
+               return new TrainDelayedBinder();\r
+       }\r
+\r
+       @Override\r
+       public void onCreate() {\r
+               super.onCreate();\r
+               \r
+               Debug.d(this, Debug.ON_CREATE);\r
+       }\r
+       \r
+       @Override\r
+       public void onStart(Intent intent, int startId) {\r
+               super.onStart(intent, startId);\r
+\r
+               Debug.d(this, Debug.ON_START);\r
+       }\r
+       \r
+       @Override\r
+       public void onDestroy() {\r
+               Debug.d(this, Debug.ON_DESTROY);\r
+               scheduleStop();\r
+               \r
+               super.onDestroy();\r
+       }\r
+\r
+       @Override\r
+       public void onRebind(Intent intent) {\r
+               super.onRebind(intent);\r
+\r
+               Debug.d(this, Debug.ON_REBIND);\r
+       }\r
+       \r
+       @Override\r
+       public boolean onUnbind(Intent intent) {\r
+               Debug.d(this, Debug.ON_UNBIND);\r
+\r
+               super.onUnbind(intent);\r
+               // \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
+               return true; \r
+       }       \r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/utility/BaseActivity.java b/workspace/TrainDelayed/src/com/td/utility/BaseActivity.java
new file mode 100644 (file)
index 0000000..4e5a0b0
--- /dev/null
@@ -0,0 +1,125 @@
+package com.td.utility;\r
+\r
+import android.app.Activity;\r
+import android.app.AlertDialog;\r
+import android.content.DialogInterface;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.view.KeyEvent;\r
+import android.view.Window;\r
+import android.view.WindowManager;\r
+\r
+public class BaseActivity extends Activity {\r
+       @Override\r
+    public void onCreate(Bundle savedInstanceState) {\r
+        super.onCreate(savedInstanceState);\r
+               Debug.d(this, Debug.ON_CREATE);\r
+        \r
+//        try {\r
+//                     DatabaseHelper.init(getApplicationContext());\r
+//             } catch (JmException e) {\r
+//                     terminate(e);\r
+//             }\r
+    }\r
+    \r
+    @Override\r
+       protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
+       super.onActivityResult(requestCode, resultCode, data);\r
+       }\r
+    \r
+    @Override\r
+       protected void onRestart() {\r
+               super.onRestart();\r
+               Debug.d(this, Debug.ON_RESTART);\r
+       }\r
+\r
+       @Override\r
+       protected void onResume() {\r
+               super.onResume();\r
+               Debug.d(this, Debug.ON_RESUME);\r
+       }\r
+\r
+       @Override\r
+       protected void onStart() {\r
+               super.onStart();\r
+               Debug.d(this, Debug.ON_START);\r
+       }\r
+\r
+       @Override\r
+       protected void onStop() {\r
+               super.onStop();\r
+               Debug.d(this, Debug.ON_STOP);\r
+       }\r
+\r
+    @Override\r
+       protected void onDestroy() {\r
+               super.onDestroy();\r
+               Debug.d(this, Debug.ON_DESTROY);\r
+       }\r
+\r
+//     @Override\r
+//     public boolean onCreateOptionsMenu(Menu menu) {\r
+//             boolean ret = super.onCreateOptionsMenu(menu);\r
+//             menu.add(0, Menu.FIRST, Menu.NONE, R.string.help);\r
+//             return ret;\r
+//     }\r
+//    \r
+//    @Override\r
+//    public boolean onOptionsItemSelected(MenuItem item) {\r
+//     try {\r
+//             Intent intent = new Intent(this, (Class<?>)Help.class);\r
+//                     startActivity(intent);\r
+//     }\r
+//     catch (Exception e){\r
+//                     terminate(e);\r
+//     }\r
+//             return super.onOptionsItemSelected(item);\r
+//     }\r
+\r
+       @Override\r
+       public boolean dispatchKeyEvent(KeyEvent event) {\r
+               if (event.getAction() == KeyEvent.ACTION_DOWN) {\r
+                       switch (event.getKeyCode()) {\r
+                       case KeyEvent.KEYCODE_SEARCH:\r
+                               return true;\r
+                       }\r
+               }\r
+               return super.dispatchKeyEvent(event);\r
+       }\r
+    \r
+       protected void setFullscreen() {\r
+       requestWindowFeature(Window.FEATURE_NO_TITLE);\r
+       getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,\r
+       WindowManager.LayoutParams.FLAG_FULLSCREEN);\r
+    }\r
+       \r
+       protected void showDialog(String title, String msg, final boolean isFinish) {\r
+               new AlertDialog.Builder(this).setTitle(title).setMessage(msg)\r
+                               .setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {\r
+                                       public void onClick(DialogInterface dialog, int whichButton) {\r
+                                               if (isFinish){\r
+                                                       finish();\r
+                                               }\r
+                                       }\r
+                               }).show();\r
+       }\r
+\r
+       protected void showDialog(String title, String msg) {\r
+               showDialog(title, msg, false);\r
+       }\r
+\r
+       protected void showDialog(Object target, Throwable t) {\r
+       if (t != null){\r
+               Debug.d(target, null, t);\r
+       }\r
+//             showDialog(getString(R.string.title_system_error),\r
+//                             getString(R.string.error_unexpected));\r
+       }\r
+\r
+    public void terminate(Throwable t){\r
+       if (t != null){\r
+               Debug.d(this, null, t);\r
+       }\r
+       moveTaskToBack(true);\r
+    }\r
+}\r
diff --git a/workspace/TrainDelayed/src/com/td/utility/Debug.java b/workspace/TrainDelayed/src/com/td/utility/Debug.java
new file mode 100644 (file)
index 0000000..36a2390
--- /dev/null
@@ -0,0 +1,37 @@
+package com.td.utility;\r
+\r
+import android.util.Log;\r
+\r
+public class Debug {\r
+       public static final String ON_CREATE = "onCreate";\r
+       public static final String ON_DESTROY = "onDestroy";\r
+       public static final String ON_START = "onStart";\r
+       public static final String ON_STOP = "onStop";\r
+       public static final String ON_RESTART = "onRestart";\r
+       public static final String ON_RESUME = "onResume";\r
+       public static final String ON_REBIND = "onRebind";\r
+       public static final String ON_UNBIND = "onUnbind";\r
+\r
+       private static final String FILTER = "com.td";\r
+       \r
+       public static void d(Object target, String msg){\r
+               d(target, msg, null);\r
+       }\r
+\r
+       public static void d(Object target, String msg, Throwable t){\r
+               if (!Log.isLoggable(FILTER, Log.DEBUG)){\r
+                       return;\r
+               }\r
+       \r
+               String text = target.getClass().getName();\r
+               if (msg != null){\r
+                        text += " " + msg;                     \r
+               }\r
+               if (t == null){\r
+                       Log.d(FILTER, text);\r
+               }\r
+               else {\r
+                       Log.d(FILTER, text, t);                 \r
+               }\r
+       }\r
+}\r