Java Code Examples for com.google.android.gms.location.DetectedActivity#IN_VEHICLE
The following examples show how to use
com.google.android.gms.location.DetectedActivity#IN_VEHICLE .
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: ActivityRecognitionIntentService.java From android-notification-log with MIT License | 6 votes |
private String getActivityString(int detectedActivityType) { switch(detectedActivityType) { case DetectedActivity.IN_VEHICLE: return "IN_VEHICLE"; case DetectedActivity.ON_BICYCLE: return "ON_BICYCLE"; case DetectedActivity.ON_FOOT: return "ON_FOOT"; case DetectedActivity.RUNNING: return "RUNNING"; case DetectedActivity.STILL: return "STILL"; case DetectedActivity.TILTING: return "TILTING"; case DetectedActivity.UNKNOWN: return "UNKNOWN"; case DetectedActivity.WALKING: return "WALKING"; default: return detectedActivityType + ""; } }
Example 2
Source File: BackgroundActivity.java From background-geolocation-android with Apache License 2.0 | 6 votes |
public static String getActivityString(int detectedActivityType) { switch(detectedActivityType) { case DetectedActivity.IN_VEHICLE: return "IN_VEHICLE"; case DetectedActivity.ON_BICYCLE: return "ON_BICYCLE"; case DetectedActivity.ON_FOOT: return "ON_FOOT"; case DetectedActivity.RUNNING: return "RUNNING"; case DetectedActivity.STILL: return "STILL"; case DetectedActivity.TILTING: return "TILTING"; case DetectedActivity.UNKNOWN: return "UNKNOWN"; case DetectedActivity.WALKING: return "WALKING"; default: return "UNKNOWN"; } }
Example 3
Source File: AndroidActivityRecognitionWrapper.java From gsn with GNU General Public License v3.0 | 6 votes |
public static String getType(double type) { if (type == DetectedActivity.UNKNOWN) return "Unknown"; else if (type == DetectedActivity.IN_VEHICLE) return "In Vehicle"; else if (type == DetectedActivity.ON_BICYCLE) return "On Bicycle"; else if (type == DetectedActivity.ON_FOOT) return "On Foot"; else if (type == DetectedActivity.STILL) return "Still"; else if (type == DetectedActivity.TILTING) return "Tilting"; else return ""; }
Example 4
Source File: Utils.java From location-samples with Apache License 2.0 | 6 votes |
/** * Returns a human readable String corresponding to a detected activity type. */ static String getActivityString(Context context, int detectedActivityType) { Resources resources = context.getResources(); switch(detectedActivityType) { case DetectedActivity.IN_VEHICLE: return resources.getString(R.string.in_vehicle); case DetectedActivity.ON_BICYCLE: return resources.getString(R.string.on_bicycle); case DetectedActivity.ON_FOOT: return resources.getString(R.string.on_foot); case DetectedActivity.RUNNING: return resources.getString(R.string.running); case DetectedActivity.STILL: return resources.getString(R.string.still); case DetectedActivity.TILTING: return resources.getString(R.string.tilting); case DetectedActivity.UNKNOWN: return resources.getString(R.string.unknown); case DetectedActivity.WALKING: return resources.getString(R.string.walking); default: return resources.getString(R.string.unidentifiable_activity, detectedActivityType); } }
Example 5
Source File: Constants.java From cordova-background-geolocation-services with Apache License 2.0 | 6 votes |
public static String getActivityString(int detectedActivityType) { switch(detectedActivityType) { case DetectedActivity.IN_VEHICLE: return "IN_VEHICLE"; case DetectedActivity.ON_BICYCLE: return "ON_BICYCLE"; case DetectedActivity.ON_FOOT: return "ON_FOOT"; case DetectedActivity.RUNNING: return "RUNNING"; case DetectedActivity.STILL: return "STILL"; case DetectedActivity.TILTING: return "TILTING"; case DetectedActivity.UNKNOWN: return "UNKNOWN"; case DetectedActivity.WALKING: return "WALKING"; default: return "Unknown"; } }
Example 6
Source File: BackgroundService.java From BackPackTrackII with GNU General Public License v3.0 | 6 votes |
public static String getActivityName(int activityType, Context context) { switch (activityType) { case DetectedActivity.STILL: return context.getString(R.string.still); case DetectedActivity.TILTING: return context.getString(R.string.tilting); case DetectedActivity.ON_FOOT: return context.getString(R.string.on_foot); case DetectedActivity.WALKING: return context.getString(R.string.walking); case DetectedActivity.RUNNING: return context.getString(R.string.running); case DetectedActivity.ON_BICYCLE: return context.getString(R.string.on_bicycle); case DetectedActivity.IN_VEHICLE: return context.getString(R.string.in_vehicle); case DetectedActivity.UNKNOWN: return context.getString(R.string.unknown); case -1: return context.getString(R.string.motion); case -2: return context.getString(R.string.displacement); default: return context.getString(R.string.undefined); } }
Example 7
Source File: DetectionService.java From react-native-activity-recognition with GNU General Public License v2.0 | 6 votes |
public static String getActivityString(int detectedActivityType) { switch(detectedActivityType) { case DetectedActivity.IN_VEHICLE: return "IN_VEHICLE"; case DetectedActivity.ON_BICYCLE: return "ON_BICYCLE"; case DetectedActivity.ON_FOOT: return "ON_FOOT"; case DetectedActivity.RUNNING: return "RUNNING"; case DetectedActivity.STILL: return "STILL"; case DetectedActivity.TILTING: return "TILTING"; case DetectedActivity.UNKNOWN: return "UNKNOWN"; case DetectedActivity.WALKING: return "WALKING"; default: return "UNIDENTIFIABLE"; } }
Example 8
Source File: Database.java From GeoLog with Apache License 2.0 | 5 votes |
public static Activity activityFromDetectedActivity(DetectedActivity activity) { switch (activity.getType()) { case DetectedActivity.UNKNOWN: return Activity.UNKNOWN; case DetectedActivity.STILL: return Activity.STILL; case DetectedActivity.ON_FOOT: return Activity.FOOT; case DetectedActivity.ON_BICYCLE: return Activity.BICYCLE; case DetectedActivity.IN_VEHICLE: return Activity.VEHICLE; } return Activity.UNKNOWN; }
Example 9
Source File: PressureService.java From BackPackTrackII with GNU General Public License v3.0 | 5 votes |
public static float getAltitude(Location location, Context context) { // Get settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int maxage = Integer.parseInt(prefs.getString(SettingsFragment.PREF_PRESSURE_MAXAGE, SettingsFragment.DEFAULT_PRESSURE_MAXAGE)); int maxdist = Integer.parseInt(prefs.getString(SettingsFragment.PREF_PRESSURE_MAXDIST, SettingsFragment.DEFAULT_PRESSURE_MAXDIST)); boolean invehicle = prefs.getBoolean(SettingsFragment.PREF_PRESSURE_INVEHICLE, SettingsFragment.DEFAULT_PRESSURE_INVEHICLE); Log.i(TAG, "Get altitude location=" + location + " maxage=" + maxage + " maxdist=" + maxdist + " vehicle=" + invehicle); // Check last activity int lastActivity = prefs.getInt(SettingsFragment.PREF_LAST_ACTIVITY, DetectedActivity.STILL); if (lastActivity == DetectedActivity.IN_VEHICLE && !invehicle) { Log.i(TAG, "No altitude from pressure in vehicle"); return Float.NaN; } // Get current pressure float pressure = prefs.getFloat(SettingsFragment.PREF_PRESSURE_VALUE, 0); if (pressure <= 0) { Log.i(TAG, "No pressure value"); return Float.NaN; } // Get reference pressure float ref_pressure = prefs.getFloat(SettingsFragment.PREF_PRESSURE_REF_VALUE, 0); Location station = new Location("station"); station.setLatitude(prefs.getFloat(SettingsFragment.PREF_PRESSURE_REF_LAT, 0)); station.setLongitude(prefs.getFloat(SettingsFragment.PREF_PRESSURE_REF_LON, 0)); long ref_time = prefs.getLong(SettingsFragment.PREF_PRESSURE_REF_TIME, 0); // Check if reference if (ref_pressure == 0 || ref_time == 0) { Log.i(TAG, "No reference pressure"); return Float.NaN; } // Check age if (ref_time + maxage * 60 * 1000 <= location.getTime()) { Log.i(TAG, "Reference pressure too old, time=" + SimpleDateFormat.getDateTimeInstance().format(ref_time)); return Float.NaN; } // Check distance float distance = location.distanceTo(station); if (distance > maxdist * 1000) { Log.i(TAG, "Reference pressure too far, distance=" + distance + "m"); return Float.NaN; } // Get altitude float altitude = SensorManager.getAltitude(ref_pressure, pressure); Log.i(TAG, "Altitude " + altitude + "m " + ref_pressure + "/" + pressure + "mb"); return altitude; }
Example 10
Source File: MotionIntentService.java From Saiy-PS with GNU Affero General Public License v3.0 | 5 votes |
/** * Logging only * * @param detectedActivity the {@link DetectedActivity} */ private void logActivity(final DetectedActivity detectedActivity) { MyLog.v(CLS_NAME, "detectedActivity: confidence: " + detectedActivity.getConfidence()); switch (detectedActivity.getType()) { case DetectedActivity.WALKING: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.WALKING"); break; case DetectedActivity.IN_VEHICLE: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.IN_VEHICLE"); break; case DetectedActivity.ON_BICYCLE: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.ON_BICYCLE"); break; case DetectedActivity.ON_FOOT: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.ON_FOOT"); break; case DetectedActivity.RUNNING: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.RUNNING"); break; case DetectedActivity.STILL: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.STILL"); break; case DetectedActivity.TILTING: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.TILTING"); break; case DetectedActivity.UNKNOWN: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.UNKNOWN"); break; default: MyLog.i(CLS_NAME, "detectedActivity: DetectedActivity.default"); break; } }
Example 11
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 12
Source File: TrackRecordingService.java From mytracks with Apache License 2.0 | 4 votes |
/** * Ends the current track. */ private void endCurrentTrack() { if (!isRecording()) { Log.d(TAG, "Ignore endCurrentTrack. Not recording."); return; } // Need to remember the recordingTrackId before setting it to -1L long trackId = recordingTrackId; boolean paused = recordingTrackPaused; // Update shared preferences updateRecordingState(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, true); // Update database Track track = myTracksProviderUtils.getTrack(trackId); if (track != null) { // If not paused, add the last location if (!paused) { insertLocation(track, lastLocation, getLastValidTrackPointInCurrentSegment(trackId)); // Update the recording track time updateRecordingTrack(track, myTracksProviderUtils.getLastTrackPointId(trackId), false); } String trackName = TrackNameUtils.getTrackName(this, trackId, track.getTripStatistics().getStartTime(), myTracksProviderUtils.getFirstValidTrackPoint(trackId)); if (trackName != null && !trackName.equals(track.getName())) { track.setName(trackName); myTracksProviderUtils.updateTrack(track); } if (track.getCategory().equals(PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT)) { int activityRecognitionType = PreferencesUtils.getInt(this, R.string.activity_recognition_type_key, PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT); if (activityRecognitionType != PreferencesUtils.ACTIVITY_RECOGNITION_TYPE_DEFAULT) { String iconValue = null; switch (activityRecognitionType) { case DetectedActivity.IN_VEHICLE: iconValue = TrackIconUtils.DRIVE; break; case DetectedActivity.ON_BICYCLE: iconValue = TrackIconUtils.BIKE; break; case DetectedActivity.ON_FOOT: iconValue = TrackIconUtils.WALK; break; default: break; } if (iconValue != null) { track.setIcon(iconValue); track.setCategory(getString(TrackIconUtils.getIconActivityType(iconValue))); myTracksProviderUtils.updateTrack(track); CalorieUtils.updateTrackCalorie(context, track); } } } } endRecording(true, trackId); }
Example 13
Source File: BgGraphBuilder.java From xDrip-plus with GNU General Public License v3.0 | 4 votes |
private List<Line> motionLine() { final ArrayList<ActivityRecognizedService.motionData> motion_datas = ActivityRecognizedService.getForGraph((long) start_time * FUZZER, (long) end_time * FUZZER); List<PointValue> linePoints = new ArrayList<>(); final float ypos = (float)highMark; int last_type = -9999; final ArrayList<Line> line_array = new ArrayList<>(); Log.d(TAG,"Motion datas size: "+motion_datas.size()); if (motion_datas.size() > 0) { motion_datas.add(new ActivityRecognizedService.motionData((long) end_time * FUZZER, DetectedActivity.UNKNOWN)); // terminator for (ActivityRecognizedService.motionData item : motion_datas) { Log.d(TAG, "Motion detail: " + JoH.dateTimeText(item.timestamp) + " activity: " + item.activity); if ((last_type != -9999) && (last_type != item.activity)) { extend_line(linePoints, item.timestamp / FUZZER, ypos); Line new_line = new Line(linePoints); new_line.setHasLines(true); new_line.setPointRadius(0); new_line.setStrokeWidth(1); new_line.setAreaTransparency(40); new_line.setHasPoints(false); new_line.setFilled(true); switch (last_type) { case DetectedActivity.IN_VEHICLE: new_line.setColor(Color.parseColor("#70445599")); break; case DetectedActivity.ON_FOOT: new_line.setColor(Color.parseColor("#70995599")); break; } line_array.add(new_line); linePoints = new ArrayList<>(); } //current switch (item.activity) { case DetectedActivity.ON_FOOT: case DetectedActivity.IN_VEHICLE: extend_line(linePoints, item.timestamp / FUZZER, ypos); last_type = item.activity; break; default: // do nothing? break; } } } Log.d(TAG,"Motion array size: "+line_array.size()); return line_array; }
Example 14
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 15
Source File: BgGraphBuilder.java From xDrip with GNU General Public License v3.0 | 4 votes |
private List<Line> motionLine() { final ArrayList<ActivityRecognizedService.motionData> motion_datas = ActivityRecognizedService.getForGraph((long) start_time * FUZZER, (long) end_time * FUZZER); List<PointValue> linePoints = new ArrayList<>(); final float ypos = (float)highMark; int last_type = -9999; final ArrayList<Line> line_array = new ArrayList<>(); Log.d(TAG,"Motion datas size: "+motion_datas.size()); if (motion_datas.size() > 0) { motion_datas.add(new ActivityRecognizedService.motionData((long) end_time * FUZZER, DetectedActivity.UNKNOWN)); // terminator for (ActivityRecognizedService.motionData item : motion_datas) { Log.d(TAG, "Motion detail: " + JoH.dateTimeText(item.timestamp) + " activity: " + item.activity); if ((last_type != -9999) && (last_type != item.activity)) { extend_line(linePoints, item.timestamp / FUZZER, ypos); Line new_line = new Line(linePoints); new_line.setHasLines(true); new_line.setPointRadius(0); new_line.setStrokeWidth(1); new_line.setAreaTransparency(40); new_line.setHasPoints(false); new_line.setFilled(true); switch (last_type) { case DetectedActivity.IN_VEHICLE: new_line.setColor(Color.parseColor("#70445599")); break; case DetectedActivity.ON_FOOT: new_line.setColor(Color.parseColor("#70995599")); break; } line_array.add(new_line); linePoints = new ArrayList<>(); } //current switch (item.activity) { case DetectedActivity.ON_FOOT: case DetectedActivity.IN_VEHICLE: extend_line(linePoints, item.timestamp / FUZZER, ypos); last_type = item.activity; break; default: // do nothing? break; } } } Log.d(TAG,"Motion array size: "+line_array.size()); return line_array; }
Example 16
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 17
Source File: MotionHelper.java From Saiy-PS with GNU Affero General Public License v3.0 | 4 votes |
/** * Check if we need to react to the detected ActivityRecognition type. * * @param ctx the application context * @param motion the detection {@link Motion} object */ private static void reactMotion(@NonNull final Context ctx, @NonNull final Motion motion) { if (DEBUG) { MyLog.i(CLS_NAME, "reactMotion"); } switch (motion.getType()) { case DetectedActivity.WALKING: break; case DetectedActivity.IN_VEHICLE: if (DEBUG) { MyLog.i(CLS_NAME, "reactMotion: IN_VEHICLE"); } if (SPH.getHotwordDriving(ctx)) { if (DEBUG) { MyLog.i(CLS_NAME, "reactMotion: IN_VEHICLE: enabled"); } final LocalRequest request = new LocalRequest(ctx); request.prepareDefault(LocalRequest.ACTION_START_HOTWORD, null); request.execute(); } else { if (DEBUG) { MyLog.i(CLS_NAME, "reactMotion: IN_VEHICLE: disabled"); } } break; case DetectedActivity.ON_BICYCLE: break; case DetectedActivity.ON_FOOT: break; case DetectedActivity.RUNNING: break; case DetectedActivity.STILL: break; case DetectedActivity.TILTING: break; case DetectedActivity.UNKNOWN: break; default: break; } }
Example 18
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 19
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 20
Source File: SKActivityData.java From SensingKit-Android with GNU Lesser General Public License v3.0 | 3 votes |
public static String getNameFromActivityType(int activityType) { switch (activityType) { case DetectedActivity.IN_VEHICLE: return "in_vehicle"; case DetectedActivity.ON_BICYCLE: return "on_bicycle"; case DetectedActivity.ON_FOOT: return "on_foot"; case DetectedActivity.STILL: return "still"; case DetectedActivity.UNKNOWN: return "unknown"; case DetectedActivity.TILTING: return "tilting"; case DetectedActivity.WALKING: return "walking"; case DetectedActivity.RUNNING: return "running"; default: return "unsupported"; } }