Java Code Examples for com.google.android.gms.location.DetectedActivity#STILL

The following examples show how to use com.google.android.gms.location.DetectedActivity#STILL . 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: BackgroundActivity.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
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 2
Source File: ActivityRecognitionLocationProvider.java    From background-geolocation-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    //Find the activity with the highest percentage
    lastActivity = getProbableActivity(detectedActivities);

    logger.debug("Detected activity={} confidence={}", BackgroundActivity.getActivityString(lastActivity.getType()), lastActivity.getConfidence());

    handleActivity(lastActivity);

    if (lastActivity.getType() == DetectedActivity.STILL) {
        showDebugToast("Detected STILL Activity");
        // stopTracking();
        // we will delay stop tracking after position is found
    } else {
        showDebugToast("Detected ACTIVE Activity");
        startTracking();
    }
    //else do nothing
}
 
Example 3
Source File: ActivityRecognitionIntentService.java    From android-notification-log with MIT License 6 votes vote down vote up
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 4
Source File: DetectedToFitnessActivityAdapater.java    From JayPS-AndroidApp with MIT License 6 votes vote down vote up
public DetectedToFitnessActivityAdapater(int activity) {
    switch (activity) {
        case DetectedActivity.ON_BICYCLE:
            _activity = FitnessActivities.BIKING;
            break;
        case DetectedActivity.STILL:
            _activity = FitnessActivities.STILL;
            break;
        case DetectedActivity.WALKING:
            _activity = FitnessActivities.WALKING;
            break;
        case DetectedActivity.RUNNING:
            _activity = FitnessActivities.RUNNING;
            break;
        case DetectedActivity.ON_FOOT:
            _activity = FitnessActivities.ON_FOOT;
    }
}
 
Example 5
Source File: DetectionService.java    From react-native-activity-recognition with GNU General Public License v2.0 6 votes vote down vote up
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 6
Source File: BackgroundService.java    From BackPackTrackII with GNU General Public License v3.0 6 votes vote down vote up
private static void startActivityRecognition(final Context context) {
    if (Util.hasPlayServices(context)) {
        GoogleApiClient gac = new GoogleApiClient.Builder(context).addApi(ActivityRecognition.API).build();
        if (gac.blockingConnect().isSuccess()) {
            Log.i(TAG, "GoogleApiClient connected");
            Intent activityIntent = new Intent(context, BackgroundService.class);
            activityIntent.setAction(BackgroundService.ACTION_ACTIVITY);
            PendingIntent pi = PendingIntent.getService(context, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
            boolean still = (prefs.getInt(SettingsFragment.PREF_LAST_ACTIVITY, DetectedActivity.STILL) == DetectedActivity.STILL);
            String setting = (still ? SettingsFragment.PREF_RECOGNITION_INTERVAL_STILL : SettingsFragment.PREF_RECOGNITION_INTERVAL_MOVING);
            String standard = (still ? SettingsFragment.DEFAULT_RECOGNITION_INTERVAL_STILL : SettingsFragment.DEFAULT_RECOGNITION_INTERVAL_MOVING);
            int interval = Integer.parseInt(prefs.getString(setting, standard));

            ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(gac, interval * 1000, pi);
            Log.i(TAG, "Activity updates frequency=" + interval + "s");
        }
    }
}
 
Example 7
Source File: BackgroundService.java    From BackPackTrackII with GNU General Public License v3.0 6 votes vote down vote up
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 8
Source File: BackgroundLocationUpdateService.java    From cordova-background-geolocation-services with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
  ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
  ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

  //Find the activity with the highest percentage
  lastActivity = Constants.getProbableActivity(detectedActivities);

  Log.w(TAG, "MOST LIKELY ACTIVITY: " + Constants.getActivityString(lastActivity.getType()) + " " + lastActivity.getConfidence());

  Intent mIntent = new Intent(Constants.CALLBACK_ACTIVITY_UPDATE);
  mIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
  getApplicationContext().sendBroadcast(mIntent);
  Log.w(TAG, "Activity is recording" + isRecording);

  if(lastActivity.getType() == DetectedActivity.STILL && isRecording) {
      showDebugToast(context, "Detected Activity was STILL, Stop recording");
      stopRecording();
  } else if(lastActivity.getType() != DetectedActivity.STILL && !isRecording) {
      showDebugToast(context, "Detected Activity was ACTIVE, Start Recording");
      startRecording();
  }
  //else do nothing
}
 
Example 9
Source File: Constants.java    From cordova-background-geolocation-services with Apache License 2.0 6 votes vote down vote up
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 10
Source File: Utils.java    From location-samples with Apache License 2.0 6 votes vote down vote up
/**
 * 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 11
Source File: AndroidActivityRecognitionWrapper.java    From gsn with GNU General Public License v3.0 6 votes vote down vote up
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 12
Source File: Database.java    From GeoLog with Apache License 2.0 5 votes vote down vote up
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 13
Source File: ActivityRecognitionServiceCommand.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
@Subscribe
public void onNewActivityEvent(NewActivityEvent event) {
    boolean autoStart = _sharedPreferences.getBoolean("ACTIVITY_RECOGNITION",false);

    if(autoStart) {
        if (event.getActivityType() != DetectedActivity.STILL) {
            _serviceStarter.startLocationServices();
            _timer.cancel();
        } else {
            if (!_timer.getActive()) {
                _timer.setTimer(Constants.ACTIVITY_RECOGNITION_STILL_TIME, this);
            }
        }
    }
}
 
Example 14
Source File: ActivityRecognitionIntentService.java    From JayPS-AndroidApp with MIT License 5 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    ((PebbleBikeApplication)getApplication()).inject(this);

    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

        switch(result.getMostProbableActivity().getType()) {

            case DetectedActivity.ON_BICYCLE:
                Log.d(TAG, "ON_BICYCLE");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.WALKING:
                Log.d(TAG, "WALKING");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.RUNNING:
                Log.d(TAG, "RUNNING");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.ON_FOOT:
                Log.d(TAG, "ON_FOOT");
                sendReply(result.getMostProbableActivity().getType());
                break;
            case DetectedActivity.TILTING:
                Log.d(TAG, "TILTING");
                break;
            case DetectedActivity.STILL:
                Log.d(TAG, "STILL");
                sendReply(result.getMostProbableActivity().getType());
                break;
            default:
                logActivity(result);
        }
    }
}
 
Example 15
Source File: MotionIntentService.java    From Saiy-PS with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 16
Source File: ActivityRecognitionLocationProvider.java    From background-geolocation-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onLocationChanged(Location location) {
    logger.debug("Location change: {}", location.toString());

    if (lastActivity.getType() == DetectedActivity.STILL) {
        handleStationary(location);
        stopTracking();
        return;
    }

    showDebugToast("acy:" + location.getAccuracy() + ",v:" + location.getSpeed());

    lastLocation = location;
    handleLocation(location);
}
 
Example 17
Source File: ActivityRecognizedService.java    From AndroidDemoProjects with Apache License 2.0 4 votes vote down vote up
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 18
Source File: MotionHelper.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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 19
Source File: MotionIntentService.java    From Saiy-PS with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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 vote down vote up
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";
        }

    }