Procházet zdrojové kódy

Use a proper model for classifications

Now merges adjacent duplicates into one another. Closes #55
tags/ActivityRecorder/0.1.0
Chris Smith před 14 roky
rodič
revize
4e570091bc

binární
code/ActivityRecorder/dist/ActivityRecorder.apk Zobrazit soubor


+ 5
- 6
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/ActivityRecorderActivity.java Zobrazit soubor

@@ -22,8 +22,8 @@ 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;
26 25
 import uk.co.md87.android.activityrecorder.rpc.ActivityRecorderBinder;
26
+import uk.co.md87.android.activityrecorder.rpc.Classification;
27 27
 import uk.co.md87.android.common.ExceptionHandler;
28 28
 
29 29
 /**
@@ -93,7 +93,7 @@ public class ActivityRecorderActivity extends Activity {
93 93
         ((Button) findViewById(R.id.togglebutton)).setEnabled(false);
94 94
         ((Button) findViewById(R.id.togglebutton)).setOnClickListener(clickListener);
95 95
         ((ListView) findViewById(R.id.list)).setAdapter(
96
-                new ArrayAdapter<Map.Entry<Long, String>>(this, R.layout.item));
96
+                new ArrayAdapter<Classification>(this, R.layout.item));
97 97
     }
98 98
 
99 99
     /** {@inheritDoc} */
@@ -112,11 +112,10 @@ public class ActivityRecorderActivity extends Activity {
112 112
             ((Button) findViewById(R.id.togglebutton)).setEnabled(true);
113 113
             
114 114
             // Hacky
115
-            ((ArrayAdapter<Map.Entry<Long, String>>) ((ListView) findViewById(R.id.list))
115
+            ((ArrayAdapter<Classification>) ((ListView) findViewById(R.id.list))
116 116
                     .getAdapter()).clear();
117
-            for (Map.Entry<Long, String> entry : ((Map<Long, String>) service
118
-                    .getClassifications()).entrySet()) {
119
-                ((ArrayAdapter<Map.Entry<Long, String>>) ((ListView) findViewById(R.id.list))
117
+            for (Classification entry : service.getClassifications()) {
118
+                ((ArrayAdapter<Classification>) ((ListView) findViewById(R.id.list))
120 119
                     .getAdapter()).add(entry);
121 120
             }
122 121
         } catch (RemoteException ex) {

+ 12
- 4
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/RecorderService.java Zobrazit soubor

@@ -20,10 +20,12 @@ import android.util.Log;
20 20
 import java.io.IOException;
21 21
 import java.io.InputStream;
22 22
 import java.io.ObjectInputStream;
23
-import java.util.HashMap;
23
+import java.util.ArrayList;
24
+import java.util.List;
24 25
 import java.util.Map;
25 26
 
26 27
 import uk.co.md87.android.activityrecorder.rpc.ActivityRecorderBinder;
28
+import uk.co.md87.android.activityrecorder.rpc.Classification;
27 29
 
28 30
 /**
29 31
  *
@@ -35,10 +37,16 @@ public class RecorderService extends Service {
35 37
 
36 38
         public void submitClassification(String classification) throws RemoteException {
37 39
             Log.i(getClass().getName(), "Adding classification: " + classification);
38
-            classifications.put(System.currentTimeMillis(), classification);
40
+
41
+            if (!classifications.isEmpty() && classification.equals(classifications
42
+                    .get(classifications.size() - 1).getClassification())) {
43
+                classifications.get(classifications.size() - 1).updateEnd(System.currentTimeMillis());
44
+            } else {
45
+                classifications.add(new Classification(classification, System.currentTimeMillis()));
46
+            }
39 47
         }
40 48
 
41
-        public Map getClassifications() throws RemoteException {
49
+        public List<Classification> getClassifications() throws RemoteException {
42 50
             return classifications;
43 51
         }
44 52
 
@@ -75,7 +83,7 @@ public class RecorderService extends Service {
75 83
 
76 84
     boolean running;
77 85
     public static Map<Float[], String> model;
78
-    private final Map<Long, String> classifications = new HashMap<Long, String>();
86
+    private final List<Classification> classifications = new ArrayList<Classification>();
79 87
 
80 88
     private final SensorEventListener accelListener = new SensorEventListener() {
81 89
 

+ 3
- 1
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/rpc/ActivityRecorderBinder.aidl Zobrazit soubor

@@ -5,6 +5,8 @@
5 5
 
6 6
 package uk.co.md87.android.activityrecorder.rpc;
7 7
 
8
+import uk.co.md87.android.activityrecorder.rpc.Classification;
9
+
8 10
 /**
9 11
  *
10 12
  * @author chris
@@ -15,6 +17,6 @@ interface ActivityRecorderBinder {
15 17
 
16 18
     void submitClassification(String classification);
17 19
 
18
-    Map getClassifications();
20
+    List<Classification> getClassifications();
19 21
 
20 22
 }

+ 8
- 9
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/rpc/ActivityRecorderBinder.java Zobrazit soubor

@@ -1,15 +1,15 @@
1 1
 /*
2 2
  * This file is auto-generated.  DO NOT MODIFY.
3
- * Original file: src/uk/co/md87/android/activityrecorder/rpc/ActivityRecorderBinder.aidl
3
+ * Original file: uk/co/md87/android/activityrecorder/rpc/ActivityRecorderBinder.aidl
4 4
  */
5 5
 package uk.co.md87.android.activityrecorder.rpc;
6 6
 import java.lang.String;
7
-import java.util.Map;
8 7
 import android.os.RemoteException;
9 8
 import android.os.IBinder;
10 9
 import android.os.IInterface;
11 10
 import android.os.Binder;
12 11
 import android.os.Parcel;
12
+import java.util.List;
13 13
 /**
14 14
  *
15 15
  * @author chris
@@ -73,9 +73,9 @@ return true;
73 73
 case TRANSACTION_getClassifications:
74 74
 {
75 75
 data.enforceInterface(DESCRIPTOR);
76
-java.util.Map _result = this.getClassifications();
76
+java.util.List<uk.co.md87.android.activityrecorder.rpc.Classification> _result = this.getClassifications();
77 77
 reply.writeNoException();
78
-reply.writeMap(_result);
78
+reply.writeTypedList(_result);
79 79
 return true;
80 80
 }
81 81
 }
@@ -128,17 +128,16 @@ _reply.recycle();
128 128
 _data.recycle();
129 129
 }
130 130
 }
131
-public java.util.Map getClassifications() throws android.os.RemoteException
131
+public java.util.List<uk.co.md87.android.activityrecorder.rpc.Classification> getClassifications() throws android.os.RemoteException
132 132
 {
133 133
 android.os.Parcel _data = android.os.Parcel.obtain();
134 134
 android.os.Parcel _reply = android.os.Parcel.obtain();
135
-java.util.Map _result;
135
+java.util.List<uk.co.md87.android.activityrecorder.rpc.Classification> _result;
136 136
 try {
137 137
 _data.writeInterfaceToken(DESCRIPTOR);
138 138
 mRemote.transact(Stub.TRANSACTION_getClassifications, _data, _reply, 0);
139 139
 _reply.readException();
140
-java.lang.ClassLoader cl = (java.lang.ClassLoader)this.getClass().getClassLoader();
141
-_result = _reply.readHashMap(cl);
140
+_result = _reply.createTypedArrayList(uk.co.md87.android.activityrecorder.rpc.Classification.CREATOR);
142 141
 }
143 142
 finally {
144 143
 _reply.recycle();
@@ -153,5 +152,5 @@ static final int TRANSACTION_getClassifications = (IBinder.FIRST_CALL_TRANSACTIO
153 152
 }
154 153
 public boolean isRunning() throws android.os.RemoteException;
155 154
 public void submitClassification(java.lang.String classification) throws android.os.RemoteException;
156
-public java.util.Map getClassifications() throws android.os.RemoteException;
155
+public java.util.List<uk.co.md87.android.activityrecorder.rpc.Classification> getClassifications() throws android.os.RemoteException;
157 156
 }

+ 3
- 0
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/rpc/Classification.aidl Zobrazit soubor

@@ -0,0 +1,3 @@
1
+package uk.co.md87.android.activityrecorder.rpc;
2
+
3
+parcelable Classification;

+ 73
- 0
code/ActivityRecorder/src/uk/co/md87/android/activityrecorder/rpc/Classification.java Zobrazit soubor

@@ -0,0 +1,73 @@
1
+/*
2
+ * To change this template, choose Tools | Templates
3
+ * and open the template in the editor.
4
+ */
5
+
6
+package uk.co.md87.android.activityrecorder.rpc;
7
+
8
+import android.os.Parcel;
9
+import android.os.Parcelable;
10
+
11
+/**
12
+ *
13
+ * @author chris
14
+ */
15
+public class Classification implements Parcelable {
16
+
17
+    private final String classification;
18
+    private final long start;
19
+    private long end;
20
+
21
+    public Classification(final String classification, final long start) {
22
+        this.classification = classification;
23
+        this.start = start;
24
+        this.end = start;
25
+    }
26
+
27
+    public void updateEnd(final long end) {
28
+        this.end = end;
29
+    }
30
+
31
+    public int describeContents() {
32
+        return 0;
33
+    }
34
+
35
+    public String getClassification() {
36
+        return classification;
37
+    }
38
+
39
+    public long getEnd() {
40
+        return end;
41
+    }
42
+
43
+    public long getStart() {
44
+        return start;
45
+    }
46
+
47
+    @Override
48
+    public String toString() {
49
+        return classification + "\n" + start + " -- " + (end - start);
50
+    }
51
+
52
+    public void writeToParcel(Parcel arg0, int arg1) {
53
+        arg0.writeString(classification);
54
+        arg0.writeLong(start);
55
+        arg0.writeLong(end);
56
+    }
57
+
58
+    public static final Parcelable.Creator<Classification> CREATOR
59
+             = new Parcelable.Creator<Classification>() {
60
+
61
+        public Classification createFromParcel(Parcel arg0) {
62
+            final Classification res = new Classification(arg0.readString(), arg0.readLong());
63
+            res.updateEnd(arg0.readLong());
64
+            return res;
65
+        }
66
+
67
+        public Classification[] newArray(int arg0) {
68
+            return new Classification[arg0];
69
+        }
70
+
71
+    };
72
+
73
+}

Načítá se…
Zrušit
Uložit