Search in sources :

Example 6 with DetectedActivity

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;
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar) NonNull(android.support.annotation.NonNull)

Example 7 with DetectedActivity

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);
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ListView(android.widget.ListView) ActivityRecognitionClient(com.google.android.gms.location.ActivityRecognitionClient)

Example 8 with DetectedActivity

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());
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) DetectedActivity(com.google.android.gms.location.DetectedActivity) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 9 with DetectedActivity

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));
}
Also used : Bus(cl.smartcities.isci.transportinspector.backend.Bus) DetectedActivity(com.google.android.gms.location.DetectedActivity) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Test(org.junit.Test)

Example 10 with DetectedActivity

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);
}
Also used : DetectedActivity(com.google.android.gms.location.DetectedActivity) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ActivityRecognitionResult(com.google.android.gms.location.ActivityRecognitionResult)

Aggregations

DetectedActivity (com.google.android.gms.location.DetectedActivity)15 ArrayList (java.util.ArrayList)7 ActivityRecognitionResult (com.google.android.gms.location.ActivityRecognitionResult)6 Intent (android.content.Intent)2 PowerManager (android.os.PowerManager)2 Bus (cl.smartcities.isci.transportinspector.backend.Bus)2 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)2 HashMap (java.util.HashMap)2 Test (org.junit.Test)2 NonNull (android.support.annotation.NonNull)1 ListView (android.widget.ListView)1 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 ActivityRecognitionClient (com.google.android.gms.location.ActivityRecognitionClient)1 Gson (com.google.gson.Gson)1 Type (java.lang.reflect.Type)1 Date (java.util.Date)1