OSDN Git Service

#25728 broadcast
authorYuji Konishi <yuji.k64613@gmail.com>
Sun, 17 Jul 2011 11:55:07 +0000 (20:55 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Sun, 17 Jul 2011 11:55:07 +0000 (20:55 +0900)
workspace/TrainDelayed/AndroidManifest.xml
workspace/TrainDelayed/bin/TrainDelayed.apk
workspace/TrainDelayed/bin/classes.dex
workspace/TrainDelayed/bin/resources.ap_
workspace/TrainDelayed/res/layout/main.xml
workspace/TrainDelayed/src/com/td/TrainDelayedActivity.java
workspace/TrainDelayed/src/com/td/broadcast/DelayReceiver.java [new file with mode: 0644]
workspace/TrainDelayed/src/com/td/service/TrainDelayedServiceImpl.java
workspace/TrainDelayed/src/com/td/utility/DateUtil.java
workspace/TrainDelayed/src/com/td/utility/Debug.java

index bdc39d5..f770ab1 100644 (file)
 <!--           
        <service android:enabled="true" android:name="com.td.service.TrainDelayedServiceImpl" android:process=":service" />
 -->
+
+               <receiver android:name=".broadcast.DelayReceiver">
+                       <intent-filter>
+                               <action android:name="com.td.broadcast.DelayReceiver.DEBUG" />
+                       </intent-filter>
+               </receiver>
     </application>
        <uses-permission android:name="android.permission.INTERNET"></uses-permission>
 </manifest>
\ No newline at end of file
index 15ec42b..6dd0c23 100644 (file)
Binary files a/workspace/TrainDelayed/bin/TrainDelayed.apk and b/workspace/TrainDelayed/bin/TrainDelayed.apk differ
index e6e50af..eb30e5e 100644 (file)
Binary files a/workspace/TrainDelayed/bin/classes.dex and b/workspace/TrainDelayed/bin/classes.dex differ
index 4d64609..d95611b 100644 (file)
Binary files a/workspace/TrainDelayed/bin/resources.ap_ and b/workspace/TrainDelayed/bin/resources.ap_ differ
index f5169e1..44ef55a 100644 (file)
@@ -26,7 +26,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/update_route_button" android:id="@+id/button01" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/update_route_button" android:id="@+id/button01" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 <LinearLayout
         android:id="@+id/linearLayout02"
@@ -34,7 +34,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/route_button" android:id="@+id/button02" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/route_button" android:id="@+id/button02" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 <LinearLayout
         android:id="@+id/linearLayout03"
@@ -42,7 +42,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/monitor_button" android:id="@+id/button03" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/monitor_button" android:id="@+id/button03" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 <LinearLayout
         android:id="@+id/linearLayout04"
@@ -50,7 +50,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/start_service_button" android:id="@+id/button04" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/start_service_button" android:id="@+id/button04" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 <LinearLayout
         android:id="@+id/linearLayout05"
@@ -58,7 +58,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/stop_service_button" android:id="@+id/button05" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/stop_service_button" android:id="@+id/button05" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 <LinearLayout
         android:id="@+id/linearLayout06"
@@ -66,7 +66,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/history_button" android:id="@+id/button06" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/history_button" android:id="@+id/button06" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 <LinearLayout
         android:id="@+id/linearLayout07"
@@ -74,7 +74,7 @@
         android:background="#ffffff"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/keyword_button" android:id="@+id/button07" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/keyword_button" android:id="@+id/button07" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 </LinearLayout>
 </ScrollView>
@@ -83,6 +83,6 @@
         android:layout_height="wrap_content"
         android:padding="1dip"
         android:layout_width="fill_parent">
-       <Button android:text="@+string/exit_button" android:id="@+id/button09" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
+       <Button android:text="@+string/exit_button" android:id="@+id/button09" android:layout_marginTop="4dip" android:layout_width="fill_parent" android:layout_height="wrap_content"></Button>
 </LinearLayout>
 </LinearLayout>
index 153099d..ab5a209 100644 (file)
@@ -57,8 +57,13 @@ public class TrainDelayedActivity extends BaseActivity {
                button1 = (Button) this.findViewById(R.id.button01);
                button1.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {
-                               pref.put(TrainDelayedServiceImpl.PREF_SVS_DBFLG, 0);
-                               pref.update();
+                               Intent intent = new Intent("com.td.broadcast.DelayReceiver");
+                               intent.putExtra("TEXT", "\83T\83\93\83v\83\8b\83\81\83b\83Z\81[\83W");
+                               sendBroadcast(intent);
+                               
+                               //pref.put(TrainDelayedServiceImpl.PREF_SVS_DBFLG, 0);
+                               //pref.update();
+
                                //SchedulerTest.repeat(TrainDelayedActivity.this);
                                //SchedulerTest.main();
                        }});
diff --git a/workspace/TrainDelayed/src/com/td/broadcast/DelayReceiver.java b/workspace/TrainDelayed/src/com/td/broadcast/DelayReceiver.java
new file mode 100644 (file)
index 0000000..ce75348
--- /dev/null
@@ -0,0 +1,21 @@
+package com.td.broadcast;\r
+\r
+import android.content.BroadcastReceiver;\r
+import android.content.Context;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.widget.Toast;\r
+\r
+public class DelayReceiver extends BroadcastReceiver {\r
+       public static String DEBUG = "com.td.broadcast.DelayReceiver.DEBUG";\r
+       \r
+       @Override\r
+       public void onReceive(Context context, Intent intent) {\r
+               Bundle bundle = intent.getExtras();\r
+               String action = intent.getAction();\r
+               if (action.equals(DEBUG)){\r
+                       String text = bundle.getString("TEXT");\r
+                       Toast.makeText(context, text, Toast.LENGTH_LONG).show();                        \r
+               }\r
+       }\r
+}\r
index 9103574..b601fb2 100644 (file)
@@ -19,9 +19,11 @@ import android.os.IBinder;
 import com.td.R;\r
 import com.td.TrainDelayedActivity;\r
 import com.td.TrainTwitterAdapter;\r
+import com.td.broadcast.DelayReceiver;\r
 import com.td.db.DatabaseHelper;\r
 import com.td.db.Keyword;\r
 import com.td.db.Train;\r
+import com.td.utility.DateUtil;\r
 import com.td.utility.Debug;\r
 import com.td.utility.EditPrefUtil;\r
 import com.td.utility.Util;\r
@@ -139,11 +141,15 @@ public class TrainDelayedServiceImpl extends Service {
                                                schedule(-1);\r
                                        } catch (Exception e) {\r
                                                // TODO\r
+                                               Debug.t(TrainDelayedServiceImpl.this, e.getMessage());\r
                                                Debug.d(this, null, e);\r
                                        }\r
                                }\r
                                \r
                                long next = scheduler.calcSchedule(now);\r
+                               String nextStr = DateUtil.formatted(next);\r
+                               Debug.t(TrainDelayedServiceImpl.this, nextStr);\r
+                               Debug.d(this, "calcSchedule " + nextStr);\r
                                \r
                                // \8e\9f\89ñ\8bN\93®\93o\98^\r
                                PendingIntent alarmSender = PendingIntent.getService(\r
@@ -159,6 +165,7 @@ public class TrainDelayedServiceImpl extends Service {
                                \r
                                id = (id + 1) % 1000000;\r
                        } catch (Exception e) {\r
+                               Debug.t(TrainDelayedServiceImpl.this, e.getMessage());\r
                                Debug.d(this, null, e);\r
                        }\r
                }\r
index 29438e6..7da1874 100644 (file)
@@ -41,6 +41,19 @@ public class DateUtil {
                return names[index];\r
        }\r
        \r
+       public static String formatted(Calendar cal){\r
+               Date d = cal.getTime();\r
+               int ymd = getYmd(d);\r
+               int hm = getHm(d);\r
+               return formattedYmd(ymd) + " " + formattedHm(hm);\r
+       }\r
+       \r
+       public static String formatted(long t){\r
+               Calendar cal = Calendar.getInstance();\r
+               cal.setTimeInMillis(t);\r
+               return formatted(cal);\r
+       }\r
+       \r
        public static String formattedHm(int hm){\r
                StringBuffer sb = new StringBuffer();\r
                sb.append(fmt2.format((int) (hm / 100)));\r
index 451be58..f74e93c 100644 (file)
@@ -1,7 +1,11 @@
 package com.td.utility;\r
 \r
+import android.content.Context;\r
+import android.content.Intent;\r
 import android.util.Log;\r
 \r
+import com.td.broadcast.DelayReceiver;\r
+\r
 public class Debug {\r
        public static final String ON_CREATE = "onCreate";\r
        public static final String ON_DESTROY = "onDestroy";\r
@@ -46,4 +50,15 @@ public class Debug {
                        Log.d(FILTER, text, t);                 \r
                }\r
        }\r
+       \r
+       public static void t(Context context, String msg){\r
+               if (!Log.isLoggable(FILTER, Log.DEBUG)){\r
+                       return;\r
+               }\r
+       \r
+               Intent intent = new Intent(DelayReceiver.DEBUG);\r
+               intent.putExtra("TEXT", msg);\r
+               context.sendBroadcast(intent);                                          \r
+               \r
+       }\r
 }\r