浏览代码

Sensor logger changes

Don't autostart service or restart after upload
Include a custom activity name in the upload data
tags/SensorLogger/0.1
Chris Smith 14 年前
父节点
当前提交
54e8c04667

二进制
code/SensorLogger/dist/SensorLogger.apk 查看文件


+ 15
- 3
code/SensorLogger/res/layout/main.xml 查看文件

@@ -8,17 +8,29 @@
8 8
         android:layout_width="fill_parent"
9 9
         android:layout_height="wrap_content"
10 10
         android:text="Hello Android from NetBeans"/>
11
+    <TextView
12
+        android:id="@+id/caption"
13
+        android:layout_width="fill_parent"
14
+        android:layout_height="wrap_content"
15
+        android:layout_below="@id/text"
16
+        android:text="Caption"/>
17
+    <EditText
18
+        android:id="@+id/entry"
19
+        android:layout_width="fill_parent"
20
+        android:layout_height="wrap_content"
21
+        android:background="@android:drawable/editbox_background"
22
+        android:layout_below="@id/caption" />
11 23
     <Button
12 24
         android:id="@+id/start"
13 25
         android:layout_width="wrap_content"
14 26
         android:layout_height="wrap_content"
15
-        android:layout_below="@+id/text"
27
+        android:layout_below="@id/entry"
16 28
         android:text="Start/Stop service"/>
17 29
     <Button
18 30
         android:id="@+id/upload"
19 31
         android:layout_width="wrap_content"
20 32
         android:layout_height="wrap_content"
21
-        android:layout_below="@+id/text"
22
-        android:layout_toRightOf="@+id/start"
33
+        android:layout_below="@id/entry"
34
+        android:layout_toRightOf="@id/start"
23 35
         android:text="Upload data"/>
24 36
 </RelativeLayout>

+ 6
- 2
code/SensorLogger/src/uk/co/md87/android/sensorlogger/MainActivity.java 查看文件

@@ -11,6 +11,7 @@ import android.os.Bundle;
11 11
 import android.view.View;
12 12
 import android.view.View.OnClickListener;
13 13
 import android.widget.Button;
14
+import android.widget.EditText;
14 15
 import android.widget.TextView;
15 16
 
16 17
 /**
@@ -21,13 +22,13 @@ public class MainActivity extends Activity implements OnClickListener {
21 22
 
22 23
     static final String VERSION = "0.1";
23 24
 
25
+    static String ACTIVITY = "Unknown";
26
+
24 27
     /** {@inheritDoc} */
25 28
     @Override
26 29
     public void onCreate(final Bundle icicle) {
27 30
         super.onCreate(icicle);
28 31
 
29
-        startService(new Intent(this, SensorLoggerService.class));
30
-
31 32
         setContentView(R.layout.main);
32 33
 
33 34
         ((Button) findViewById(R.id.start)).setOnClickListener(this);
@@ -42,11 +43,14 @@ public class MainActivity extends Activity implements OnClickListener {
42 43
                 + "Once 1,000 entries have been recorded, the data will be "
43 44
                 + "automatically uploaded and erased from the device. You can "
44 45
                 + "manually trigger an upload using the button below.\n\n");
46
+        ((TextView) findViewById(R.id.caption)).setText("Activity name:");
45 47
     }
46 48
 
47 49
     /** {@inheritDoc} */
48 50
     @Override
49 51
     public void onClick(final View view) {
52
+        ACTIVITY = ((EditText) findViewById(R.id.entry)).getText().toString();
53
+        
50 54
         if (view.getId() == R.id.start) {
51 55
             if (!stopService(new Intent(this, SensorLoggerService.class))) {
52 56
                 startService(new Intent(this, SensorLoggerService.class));

+ 4
- 2
code/SensorLogger/src/uk/co/md87/android/sensorlogger/R.java 查看文件

@@ -11,9 +11,11 @@ public final class R {
11 11
     public static final class attr {
12 12
     }
13 13
     public static final class id {
14
-        public static final int start=0x7f040001;
14
+        public static final int caption=0x7f040001;
15
+        public static final int entry=0x7f040002;
16
+        public static final int start=0x7f040003;
15 17
         public static final int text=0x7f040000;
16
-        public static final int upload=0x7f040002;
18
+        public static final int upload=0x7f040004;
17 19
     }
18 20
     public static final class layout {
19 21
         public static final int main=0x7f020000;

+ 1
- 1
code/SensorLogger/src/uk/co/md87/android/sensorlogger/UploaderService.java 查看文件

@@ -46,6 +46,7 @@ public class UploaderService extends Service implements Runnable {
46 46
         post.addHeader("x-application", "SensorLogger");
47 47
         post.addHeader("x-version", MainActivity.VERSION);
48 48
         post.addHeader("x-imei", ((TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId());
49
+        post.addHeader("x-activity", MainActivity.ACTIVITY);
49 50
 
50 51
         try {
51 52
             int code = new DefaultHttpClient().execute(post).getStatusLine().getStatusCode();
@@ -55,7 +56,6 @@ public class UploaderService extends Service implements Runnable {
55 56
             Log.e("UploaderService", "Unable to upload sensor logs", ex);
56 57
         }
57 58
 
58
-        startService(new Intent(this, SensorLoggerService.class));
59 59
         stopSelf();
60 60
     }
61 61
 

正在加载...
取消
保存