use of com.google.android.gms.location.DetectedActivity in project android-play-location by googlesamples.
the class DetectedActivitiesAdapter method getView.
@NonNull
@Override
public View getView(int position, @Nullable View view, @NonNull ViewGroup parent) {
DetectedActivity detectedActivity = getItem(position);
if (view == null) {
view = LayoutInflater.from(getContext()).inflate(R.layout.detected_activity, parent, false);
}
// Find the UI widgets.
TextView activityName = (TextView) view.findViewById(R.id.detected_activity_name);
TextView activityConfidenceLevel = (TextView) view.findViewById(R.id.detected_activity_confidence_level);
ProgressBar progressBar = (ProgressBar) view.findViewById(R.id.detected_activity_progress_bar);
// Populate widgets with values.
if (detectedActivity != null) {
activityName.setText(Utils.getActivityString(getContext(), detectedActivity.getType()));
activityConfidenceLevel.setText(getContext().getString(R.string.percent, detectedActivity.getConfidence()));
progressBar.setProgress(detectedActivity.getConfidence());
}
return view;
}
use of com.google.android.gms.location.DetectedActivity in project android-play-location by googlesamples.
the class MainActivity method onCreate.
@SuppressWarnings("unchecked")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
mContext = this;
// Get the UI widgets.
mRequestActivityUpdatesButton = (Button) findViewById(R.id.request_activity_updates_button);
mRemoveActivityUpdatesButton = (Button) findViewById(R.id.remove_activity_updates_button);
ListView detectedActivitiesListView = (ListView) findViewById(R.id.detected_activities_listview);
// Enable either the Request Updates button or the Remove Updates button depending on
// whether activity updates have been requested.
setButtonsEnabledState();
ArrayList<DetectedActivity> detectedActivities = Utils.detectedActivitiesFromJson(PreferenceManager.getDefaultSharedPreferences(this).getString(Constants.KEY_DETECTED_ACTIVITIES, ""));
// Bind the adapter to the ListView responsible for display data for detected activities.
mAdapter = new DetectedActivitiesAdapter(this, detectedActivities);
detectedActivitiesListView.setAdapter(mAdapter);
mActivityRecognitionClient = new ActivityRecognitionClient(this);
}
use of com.google.android.gms.location.DetectedActivity in project androidApp by InspectorIncognito.
the class DetectionServiceTest method testGetOutOfBus.
@Test
public void testGetOutOfBus() throws TimeoutException {
DetectionService spyService = spy(service);
BusStop mockBusStop = mock(BusStop.class);
when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
Bus bus = new Bus("506", "GGWP00", "");
spyService.setCurrentState(new VehicleState(new IdleState(spyService), bus, mock(StateLocationSender.class)));
spyService.onBusDetected(bus);
assertTrue(spyService.isRunningInForeground());
spyService.onActivityChanged(new DetectedActivity(DetectedActivity.WALKING, 100));
spyService.onActivityChanged(new DetectedActivity(DetectedActivity.IN_VEHICLE, 100));
spyService.onActivityChanged(new DetectedActivity(DetectedActivity.WALKING, 100));
spyService.fakeOnTimePassed();
assertFalse(spyService.isRunningInForeground());
}
use of com.google.android.gms.location.DetectedActivity in project androidApp by InspectorIncognito.
the class DetectionServiceTest method testBusDetectedNotificationIsSent.
@Test
public void testBusDetectedNotificationIsSent() throws TimeoutException {
DetectionService spyService = spy(service);
BusStop mockBusStop = mock(BusStop.class);
when(mockBusStop.getIncomingBuses()).thenReturn(new ArrayList<Bus>());
// IdleState is set
spyService.setCurrentState(new IdleState(spyService));
// BusStop is selected
spyService.busStopSelected(mockBusStop);
// New IN_VEHICLE Detected Activity
spyService.onActivityChanged(new DetectedActivity(DetectedActivity.IN_VEHICLE, 100));
// TODO(aantoine): REDO this test
// verify(spyService).sendNotification(anyInt(), any(NotificationCompat.Builder.class));
}
use of com.google.android.gms.location.DetectedActivity in project androidApp by InspectorIncognito.
the class DetectedActivitiesIntentService method onHandleIntent.
/**
* Handles incoming intents.
*
* @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
* is called.
*/
@Override
protected void onHandleIntent(Intent intent) {
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
Intent localIntent = new Intent(Constants.ACTIVITY_BROADCAST_ACTION);
if (result == null) {
return;
}
ArrayList<DetectedActivity> res = new ArrayList<>();
for (DetectedActivity d : result.getProbableActivities()) {
if (d.getConfidence() > Constants.MIN_ACTIVITY_CONFIDENCE) {
res.add(d);
}
}
// Broadcast the list of detected activities.
localIntent.putExtra(Constants.ACTIVITY_EXTRA, res);
LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
Aggregations