Java Code Examples for com.google.android.gms.location.DetectedActivity#getConfidence()
The following examples show how to use
com.google.android.gms.location.DetectedActivity#getConfidence() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Constants.java From cordova-background-geolocation-services with Apache License 2.0 | 6 votes |
public static DetectedActivity getProbableActivity(ArrayList<DetectedActivity> detectedActivities) { int highestConfidence = 0; DetectedActivity mostLikelyActivity = new DetectedActivity(0, DetectedActivity.UNKNOWN); for(DetectedActivity da: detectedActivities) { if(da.getType() != DetectedActivity.TILTING || da.getType() != DetectedActivity.UNKNOWN) { Log.w(ConstantsTAG, "Received a Detected Activity that was not tilting / unknown"); if (highestConfidence < da.getConfidence()) { highestConfidence = da.getConfidence(); mostLikelyActivity = da; } } } return mostLikelyActivity; }
Example 2
Source File: ActivityRecognitionLocationProvider.java From background-geolocation-android with Apache License 2.0 | 5 votes |
public static DetectedActivity getProbableActivity(ArrayList<DetectedActivity> detectedActivities) { int highestConfidence = 0; DetectedActivity mostLikelyActivity = new DetectedActivity(0, DetectedActivity.UNKNOWN); for(DetectedActivity da: detectedActivities) { if(da.getType() != DetectedActivity.TILTING || da.getType() != DetectedActivity.UNKNOWN) { Log.w(TAG, "Received a Detected Activity that was not tilting / unknown"); if (highestConfidence < da.getConfidence()) { highestConfidence = da.getConfidence(); mostLikelyActivity = da; } } } return mostLikelyActivity; }
Example 3
Source File: AwarenessImpl.java From Myna with Apache License 2.0 | 5 votes |
private void handleResult(@NonNull DetectedActivityResult detectedActivityResult){ ActivityRecognitionResult ar = detectedActivityResult.getActivityRecognitionResult(); RecognizedActivityResult result = new RecognizedActivityResult(); List<DetectedActivity> acts = ar.getProbableActivities(); result.activities = new RecognizedActivity[acts.size()]; for(int i = 0; i < acts.size(); ++i){ DetectedActivity act = acts.get(i); result.activities[i] = new RecognizedActivity(act.getType(), act.getConfidence()); } resultCallback.onResult(result); }
Example 4
Source File: AndroidActivityRecognitionWrapper.java From gsn with GNU General Public License v3.0 | 5 votes |
@Override public void runOnce() { if (!isRunning()) { disconnectGoogleAPI(); } else { if (mGoogleApiClient == null) { connectGoogleAPI(); } updateWrapperInfo(); if (ActivityRecognitionResult.hasResult(ActivityRecognitionService.getIntent())) { // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(ActivityRecognitionService.getIntent()); DetectedActivity mostProbableActivity = result.getMostProbableActivity(); // Get the confidence % (probability) double confidence = mostProbableActivity.getConfidence(); // Get the type double activityType = mostProbableActivity.getType(); /* types: * DetectedActivity.IN_VEHICLE * DetectedActivity.ON_BICYCLE * DetectedActivity.ON_FOOT * DetectedActivity.STILL * DetectedActivity.UNKNOWN * DetectedActivity.TILTING */ StreamElement streamElement = new StreamElement(FIELD_NAMES, FIELD_TYPES, new Serializable[]{activityType, confidence}); postStreamElement(streamElement); } else { Log.d(TAG, "No results for AndroidActivityRecognition"); } } }
Example 5
Source File: BackgroundActivity.java From background-geolocation-android with Apache License 2.0 | 4 votes |
public BackgroundActivity(Integer locationProvider, DetectedActivity activity) { confidence = activity.getConfidence(); type = activity.getType(); }
Example 6
Source File: MotionIntentService.java From Saiy-PS with GNU Affero General Public License v3.0 | 4 votes |
/** * Store the most recent user activity for use elsewhere in the application. * * @param intent which should contain an {@link ActivityRecognitionResult} * @return a {@link Motion} object */ private Motion extractMotion(final Intent intent) { if (DEBUG) { MyLog.i(CLS_NAME, "extractMotion"); } final ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); if (result != null) { final DetectedActivity detectedActivity = result.getMostProbableActivity(); if (detectedActivity != null) { if (DEBUG) { logActivity(detectedActivity); } final int confidence = detectedActivity.getConfidence(); if (confidence > Motion.CONFIDENCE_THRESHOLD) { switch (detectedActivity.getType()) { case DetectedActivity.WALKING: case DetectedActivity.IN_VEHICLE: case DetectedActivity.ON_BICYCLE: case DetectedActivity.ON_FOOT: case DetectedActivity.RUNNING: case DetectedActivity.STILL: return new Motion(detectedActivity.getType(), confidence, result.getTime()); case DetectedActivity.TILTING: case DetectedActivity.UNKNOWN: default: break; } } else { if (DEBUG) { MyLog.v(CLS_NAME, "detectedActivity: ignoring low confidence"); } } } else { if (DEBUG) { MyLog.i(CLS_NAME, "detectedActivity: null"); } } } else { if (DEBUG) { MyLog.i(CLS_NAME, "detectedActivity: ActivityRecognitionResult: null"); } } return null; }
Example 7
Source File: ActivityRecognizedService.java From xDrip with GNU General Public License v3.0 | 4 votes |
private int handleDetectedActivities(List<DetectedActivity> probableActivities, boolean from_local, long timestamp) { DetectedActivity topActivity = null; int topConfidence = 0; if (timestamp == 0) timestamp = JoH.tsl(); incrementInternalPrefsLong(RECEIVED); for (DetectedActivity activity : probableActivities) { if ((activity.getType() != DetectedActivity.TILTING) && (activity.getType() != DetectedActivity.UNKNOWN)) { if (activity.getConfidence() > topConfidence) { topActivity = activity; topConfidence = activity.getConfidence(); } } } if (topActivity != null) { if (d) UserError.Log.uel(TAG, "Top activity: " + topActivity.toString() + "req: " + getInternalPrefsLong(REQUESTED) + " rec: " + getInternalPrefsLong(RECEIVED)); if ((topActivity.getType() != DetectedActivity.UNKNOWN) && (topActivity.getType() != DetectedActivity.TILTING)) { if (activityState == null) activityState = getLastStoredDetectedActivity(); if (((topActivity.getConfidence() > 89) || ((lastactivity != null) && (topActivity.getType() == lastactivity.getType()) && ((lastactivity.getConfidence() + topActivity.getConfidence()) > 150))) && ((activityState == null) || (activityState.getType() != topActivity.getType()))) { if (Pref.getBoolean("motion_tracking_enabled", false)) { UserError.Log.ueh(TAG, "Changed activity state from " + ((activityState == null) ? "null" : activityState.toString()) + " to: " + topActivity.toString()); activityState = topActivity; if (Pref.getBoolean("plot_motion", true)) saveUpdatedActivityState(timestamp); switch (topActivity.getType()) { case DetectedActivity.IN_VEHICLE: { UserError.Log.e(TAG, "Vehicle: " + topActivity.getConfidence()); // confidence condition above overrides this for non consolidated entries if (topActivity.getConfidence() >= 75) { if (!VehicleMode.isVehicleModeActive()) VehicleMode.setVehicleModeActive(true); // also checks if vehicle mode enabled on this handset if get != set if (is_in_vehicle_mode()) { raise_vehicle_notification("In Vehicle Mode: " + JoH.dateTimeText(JoH.tsl())); } } break; } default: if (is_in_vehicle_mode()) { set_vehicle_mode(false); cancel_vehicle_notification(); } break; } if ((from_local) && Pref.getBoolean("motion_tracking_enabled", false) && (Pref.getBoolean("act_as_motion_master", false))) { if (d) Log.d(TAG, "Sending update: " + activityState.getType()); GcmActivity.sendMotionUpdate(JoH.tsl(), activityState.getType()); } } else { UserError.Log.e(TAG, "Shutting down"); stop(); } } else { if (JoH.ratelimit("check-vehicle-repeat", 60)) checkVehicleRepeatNotification(); if (d) UserError.Log.uel(TAG, "Last: " + ((lastactivity == null) ? "null" : lastactivity.toString()) + " Current: " + topActivity.toString()); } lastactivity = topActivity; } } return topConfidence; }
Example 8
Source File: ActivityRecognizedService.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
private int handleDetectedActivities(List<DetectedActivity> probableActivities, boolean from_local, long timestamp) { DetectedActivity topActivity = null; int topConfidence = 0; if (timestamp == 0) timestamp = JoH.tsl(); incrementInternalPrefsLong(RECEIVED); for (DetectedActivity activity : probableActivities) { if ((activity.getType() != DetectedActivity.TILTING) && (activity.getType() != DetectedActivity.UNKNOWN)) { if (activity.getConfidence() > topConfidence) { topActivity = activity; topConfidence = activity.getConfidence(); } } } if (topActivity != null) { if (d) UserError.Log.uel(TAG, "Top activity: " + topActivity.toString() + "req: " + getInternalPrefsLong(REQUESTED) + " rec: " + getInternalPrefsLong(RECEIVED)); if ((topActivity.getType() != DetectedActivity.UNKNOWN) && (topActivity.getType() != DetectedActivity.TILTING)) { if (activityState == null) activityState = getLastStoredDetectedActivity(); if (((topActivity.getConfidence() > 89) || ((lastactivity != null) && (topActivity.getType() == lastactivity.getType()) && ((lastactivity.getConfidence() + topActivity.getConfidence()) > 150))) && ((activityState == null) || (activityState.getType() != topActivity.getType()))) { if (Pref.getBoolean("motion_tracking_enabled", false)) { UserError.Log.ueh(TAG, "Changed activity state from " + ((activityState == null) ? "null" : activityState.toString()) + " to: " + topActivity.toString()); activityState = topActivity; if (Pref.getBoolean("plot_motion", true)) saveUpdatedActivityState(timestamp); switch (topActivity.getType()) { case DetectedActivity.IN_VEHICLE: { UserError.Log.e(TAG, "Vehicle: " + topActivity.getConfidence()); // confidence condition above overrides this for non consolidated entries if (topActivity.getConfidence() >= 75) { if (!VehicleMode.isVehicleModeActive()) VehicleMode.setVehicleModeActive(true); // also checks if vehicle mode enabled on this handset if get != set if (is_in_vehicle_mode()) { raise_vehicle_notification("In Vehicle Mode: " + JoH.dateTimeText(JoH.tsl())); } } break; } default: if (is_in_vehicle_mode()) { set_vehicle_mode(false); cancel_vehicle_notification(); } break; } if ((from_local) && Pref.getBoolean("motion_tracking_enabled", false) && (Pref.getBoolean("act_as_motion_master", false))) { if (d) Log.d(TAG, "Sending update: " + activityState.getType()); GcmActivity.sendMotionUpdate(JoH.tsl(), activityState.getType()); } } else { UserError.Log.e(TAG, "Shutting down"); stop(); } } else { if (JoH.ratelimit("check-vehicle-repeat", 60)) checkVehicleRepeatNotification(); if (d) UserError.Log.uel(TAG, "Last: " + ((lastactivity == null) ? "null" : lastactivity.toString()) + " Current: " + topActivity.toString()); } lastactivity = topActivity; } } return topConfidence; }
Example 9
Source File: ActivityRecognitionIntentService.java From mytracks with Apache License 2.0 | 4 votes |
@Override protected void onHandleIntent(Intent intent) { if (!ActivityRecognitionResult.hasResult(intent)) { return; } ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent); DetectedActivity detectedActivity = result.getMostProbableActivity(); if (detectedActivity == null) { return; } if (detectedActivity.getConfidence() < REQUIRED_CONFIDENCE) { return; } long recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key); if (recordingTrackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) { return; } boolean recordingTrackPaused = PreferencesUtils.getBoolean( this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT); if (recordingTrackPaused) { return; } int currentType = PreferencesUtils.getInt(this, R.string.activity_recognition_type_key, PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT); switch (detectedActivity.getType()) { case DetectedActivity.IN_VEHICLE: if (currentType != DetectedActivity.IN_VEHICLE) { PreferencesUtils.setInt( this, R.string.activity_recognition_type_key, DetectedActivity.IN_VEHICLE); } break; case DetectedActivity.ON_BICYCLE: if (currentType != DetectedActivity.IN_VEHICLE && currentType != DetectedActivity.ON_BICYCLE) { PreferencesUtils.setInt( this, R.string.activity_recognition_type_key, DetectedActivity.ON_BICYCLE); } break; case DetectedActivity.ON_FOOT: if (currentType != DetectedActivity.IN_VEHICLE && currentType != DetectedActivity.ON_BICYCLE && currentType != DetectedActivity.ON_FOOT) { PreferencesUtils.setInt( this, R.string.activity_recognition_type_key, DetectedActivity.ON_FOOT); } break; default: break; } }
Example 10
Source File: ActivityRecognizedService.java From AndroidDemoProjects with Apache License 2.0 | 4 votes |
private void handleDetectedActivities(List<DetectedActivity> probableActivities) { for( DetectedActivity activity : probableActivities ) { switch( activity.getType() ) { case DetectedActivity.IN_VEHICLE: { Log.e( "ActivityRecogition", "In Vehicle: " + activity.getConfidence() ); break; } case DetectedActivity.ON_BICYCLE: { Log.e( "ActivityRecogition", "On Bicycle: " + activity.getConfidence() ); break; } case DetectedActivity.ON_FOOT: { Log.e( "ActivityRecogition", "On Foot: " + activity.getConfidence() ); break; } case DetectedActivity.RUNNING: { Log.e( "ActivityRecogition", "Running: " + activity.getConfidence() ); break; } case DetectedActivity.STILL: { Log.e( "ActivityRecogition", "Still: " + activity.getConfidence() ); break; } case DetectedActivity.TILTING: { Log.e( "ActivityRecogition", "Tilting: " + activity.getConfidence() ); break; } case DetectedActivity.WALKING: { Log.e( "ActivityRecogition", "Walking: " + activity.getConfidence() ); if( activity.getConfidence() >= 75 ) { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setContentText( "Are you walking?" ); builder.setSmallIcon( R.mipmap.ic_launcher ); builder.setContentTitle( getString( R.string.app_name ) ); NotificationManagerCompat.from(this).notify(0, builder.build()); } break; } case DetectedActivity.UNKNOWN: { Log.e( "ActivityRecogition", "Unknown: " + activity.getConfidence() ); break; } } } }
Example 11
Source File: Database.java From GeoLog with Apache License 2.0 | 4 votes |
public void loadFromDetectedActivity(DetectedActivity detectedActivity) { activity = activityFromDetectedActivity(detectedActivity); confidence = detectedActivity.getConfidence(); }