|
@@ -65,6 +65,8 @@ public class ContextAnalyserService extends Service {
|
65
|
65
|
public static final String PREDICTION_AVAILABLE_INTENT
|
66
|
66
|
= "uk.co.md87.android.contextanalyser.PREDICTION_AVAILABLE";
|
67
|
67
|
|
|
68
|
+ public static final int LOCATION_REPEATS = 2;
|
|
69
|
+
|
68
|
70
|
public static final int CONTEXT_PLACE = 1;
|
69
|
71
|
|
70
|
72
|
private static final int POLLING_DELAY = 10000;
|
|
@@ -136,17 +138,17 @@ public class ContextAnalyserService extends Service {
|
136
|
138
|
lat = newLat;
|
137
|
139
|
lon = newLon;
|
138
|
140
|
locationCount = 1;
|
139
|
|
- updateLastLocation();
|
|
141
|
+ updateLastLocation(false);
|
140
|
142
|
} else {
|
141
|
143
|
// Existing location
|
142
|
144
|
|
143
|
|
- if (++locationCount > 2 && location == null) {
|
|
145
|
+ if (++locationCount > LOCATION_REPEATS && location == null) {
|
144
|
146
|
// But we don't know it yet - add it!
|
145
|
147
|
final String name = lat + "," + lon;
|
146
|
148
|
|
147
|
149
|
final long id = dataHelper.addLocation(name, lat, lon);
|
148
|
150
|
names.put(name, id);
|
149
|
|
- updateLastLocation();
|
|
151
|
+ updateLastLocation(true);
|
150
|
152
|
}
|
151
|
153
|
}
|
152
|
154
|
}
|
|
@@ -178,16 +180,27 @@ public class ContextAnalyserService extends Service {
|
178
|
180
|
}
|
179
|
181
|
}
|
180
|
182
|
|
181
|
|
- public void updateLastLocation() {
|
|
183
|
+ public void updateLastLocation(final boolean added) {
|
182
|
184
|
location = dataHelper.findLocation(lat, lon);
|
183
|
185
|
|
184
|
186
|
if (location != null) {
|
185
|
187
|
if ((lastLocation == null || !lastLocation.equals(location))) {
|
186
|
188
|
Log.i(getClass().getSimpleName(), "New location, broadcasting: " + location);
|
187
|
189
|
|
188
|
|
- if (lastLocation != null && !activityLog.isEmpty()) {
|
189
|
|
- Log.i(getClass().getSimpleName(), "Activity log to here: " + activityLog);
|
190
|
|
- dataHelper.addJourney(lastLocation, location, activityLog);
|
|
190
|
+ if (lastLocation != null) {
|
|
191
|
+ if (added) {
|
|
192
|
+ // The place was newly added, so for the final N
|
|
193
|
+ // elements, the user has been at the place.
|
|
194
|
+
|
|
195
|
+ for (int i = 0; i < Math.min(LOCATION_REPEATS, activityLog.size()); i++) {
|
|
196
|
+ activityLog.remove(activityLog.size() - 1);
|
|
197
|
+ }
|
|
198
|
+ }
|
|
199
|
+
|
|
200
|
+ if (!activityLog.isEmpty()) {
|
|
201
|
+ Log.i(getClass().getSimpleName(), "Activity log to here: " + activityLog);
|
|
202
|
+ dataHelper.addJourney(lastLocation, location, activityLog);
|
|
203
|
+ }
|
191
|
204
|
}
|
192
|
205
|
|
193
|
206
|
final Intent intent = new Intent(CONTEXT_CHANGED_INTENT);
|