in ActivityRecognition/app/src/main/java/com/google/android/gms/location/sample/activityrecognition/DetectedActivitiesAdapter.java [80:107]
void updateActivities(ArrayList<DetectedActivity> detectedActivities) {
HashMap<Integer, Integer> detectedActivitiesMap = new HashMap<>();
for (DetectedActivity activity : detectedActivities) {
detectedActivitiesMap.put(activity.getType(), activity.getConfidence());
}
// Every time we detect new activities, we want to reset the confidence level of ALL
// activities that we monitor. Since we cannot directly change the confidence
// of a DetectedActivity, we use a temporary list of DetectedActivity objects. If an
// activity was freshly detected, we use its confidence level. Otherwise, we set the
// confidence level to zero.
ArrayList<DetectedActivity> tempList = new ArrayList<>();
for (int i = 0; i < Constants.MONITORED_ACTIVITIES.length; i++) {
int confidence = detectedActivitiesMap.containsKey(Constants.MONITORED_ACTIVITIES[i]) ?
detectedActivitiesMap.get(Constants.MONITORED_ACTIVITIES[i]) : 0;
tempList.add(new DetectedActivity(Constants.MONITORED_ACTIVITIES[i],
confidence));
}
// Remove all items.
this.clear();
// Adding the new list items notifies attached observers that the underlying data has
// changed and views reflecting the data should refresh.
for (DetectedActivity detectedActivity: tempList) {
this.add(detectedActivity);
}
}