Browse Source

Improvements to Activity Recorder UI

Activity classifications are now localised. Closes #54
Times and durations are formatted properly. Closes #57
tags/ActivityRecorder/0.1.0
Chris Smith 14 years ago
parent
commit
411bb57670

BIN
code/ActivityRecorder/dist/ActivityRecorder.apk View File


+ 10
- 0
code/ActivityRecorder/res/values/strings.xml View File

@@ -6,4 +6,14 @@
6 6
 
7 7
     <string name="service_enabled">Stop background service</string>
8 8
     <string name="service_disabled">Start background service</string>
9
+
10
+    <string name="activity_unknown">Unknown</string>
11
+    <string name="activity_walking">Walking</string>
12
+    <string name="activity_walking_stairs_up">Walking (up stairs)</string>
13
+    <string name="activity_walking_stairs_down">Walking (down stairs)</string>
14
+    <string name="activity_dancing">Dancing</string>
15
+    <string name="activity_idle_standing">Standing still</string>
16
+    <string name="activity_idle_sitting">Sitting down</string>
17
+    <string name="activity_vehicle_bus">Travelling by bus</string>
18
+    <string name="activity_vehicle_car">Travelling by car</string>
9 19
 </resources>

+ 2
- 1
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/ActivityRecorderActivity.java View File

@@ -22,6 +22,7 @@ import android.widget.ArrayAdapter;
22 22
 import android.widget.Button;
23 23
 import android.widget.ListView;
24 24
 import android.widget.Toast;
25
+import java.util.Map;
25 26
 import uk.co.md87.android.activityrecorder.rpc.ActivityRecorderBinder;
26 27
 import uk.co.md87.android.activityrecorder.rpc.Classification;
27 28
 import uk.co.md87.android.common.ExceptionHandler;
@@ -116,7 +117,7 @@ public class ActivityRecorderActivity extends Activity {
116 117
                     .getAdapter()).clear();
117 118
             for (Classification entry : service.getClassifications()) {
118 119
                 ((ArrayAdapter<Classification>) ((ListView) findViewById(R.id.list))
119
-                    .getAdapter()).add(entry);
120
+                    .getAdapter()).add(entry.withContext(this));
120 121
             }
121 122
         } catch (RemoteException ex) {
122 123
             Log.e(getClass().getName(), "Unable to get service state", ex);

+ 9
- 0
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/R.java View File

@@ -25,6 +25,15 @@ public final class R {
25 25
         public static final int basic_model=0x7f040000;
26 26
     }
27 27
     public static final class string {
28
+        public static final int activity_dancing=0x7f050008;
29
+        public static final int activity_idle_sitting=0x7f05000a;
30
+        public static final int activity_idle_standing=0x7f050009;
31
+        public static final int activity_unknown=0x7f050004;
32
+        public static final int activity_vehicle_bus=0x7f05000b;
33
+        public static final int activity_vehicle_car=0x7f05000c;
34
+        public static final int activity_walking=0x7f050005;
35
+        public static final int activity_walking_stairs_down=0x7f050007;
36
+        public static final int activity_walking_stairs_up=0x7f050006;
28 37
         public static final int app_name=0x7f050000;
29 38
         public static final int error_disconnected=0x7f050001;
30 39
         public static final int service_disabled=0x7f050003;

+ 1
- 1
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/RecorderService.java View File

@@ -167,7 +167,7 @@ public class RecorderService extends Service {
167 167
         }
168 168
 
169 169
         manager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
170
-        handler.postDelayed(registerRunnable, 60000);
170
+        handler.postDelayed(registerRunnable, 1000);
171 171
     }
172 172
 
173 173
     void register() {

+ 35
- 1
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/rpc/Classification.java View File

@@ -5,8 +5,11 @@
5 5
 
6 6
 package uk.co.md87.android.activityrecorder.rpc;
7 7
 
8
+import android.content.Context;
8 9
 import android.os.Parcel;
9 10
 import android.os.Parcelable;
11
+import android.text.format.DateFormat;
12
+import java.util.Date;
10 13
 
11 14
 /**
12 15
  *
@@ -14,6 +17,8 @@ import android.os.Parcelable;
14 17
  */
15 18
 public class Classification implements Parcelable {
16 19
 
20
+    private CharSequence niceClassification;
21
+    private String startTime;
17 22
     private final String classification;
18 23
     private final long start;
19 24
     private long end;
@@ -46,7 +51,19 @@ public class Classification implements Parcelable {
46 51
 
47 52
     @Override
48 53
     public String toString() {
49
-        return classification + "\n" + start + " -- " + (end - start);
54
+        final String duration;
55
+        final int length = (int) ((end - start) / 1000);
56
+
57
+        if (length < 60) {
58
+            duration = length + " secs";
59
+        } else if (length < 60 * 60) {
60
+            duration = (length / 60) + " mins";
61
+        } else {
62
+            duration = (length / (60 * 60)) + " hrs";
63
+        }
64
+
65
+
66
+        return niceClassification + "\n" + startTime + " for " + duration;
50 67
     }
51 68
 
52 69
     public void writeToParcel(Parcel arg0, int arg1) {
@@ -55,6 +72,23 @@ public class Classification implements Parcelable {
55 72
         arg0.writeLong(end);
56 73
     }
57 74
 
75
+    public Classification withContext(final Context context) {
76
+        String name = "activity_" + getClassification().substring(11)
77
+                .replace("/", "_").toLowerCase();
78
+
79
+        niceClassification = context.getResources().getText(
80
+                context.getResources().getIdentifier(name, "string",
81
+                "uk.co.md87.android.activityrecorder"));
82
+
83
+        Date date = new Date(start);
84
+        java.text.DateFormat dateFormat = DateFormat.getDateFormat(context);
85
+        java.text.DateFormat timeFormat = DateFormat.getTimeFormat(context);
86
+
87
+        startTime = dateFormat.format(date) + " " + timeFormat.format(date);
88
+        
89
+        return this;
90
+    }
91
+
58 92
     public static final Parcelable.Creator<Classification> CREATOR
59 93
              = new Parcelable.Creator<Classification>() {
60 94
 

Loading…
Cancel
Save