Java 类com.google.android.gms.location.DetectedActivity 实例源码

项目:GitHub    文件:DetectedActivityToString.java   
private String getNameFromType(int activityType) {
    switch (activityType) {
        case DetectedActivity.RUNNING:
            return "running";
        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";
    }
    return "unknown";
}
项目:cordova-plugin-quintech-background-geolocation    文件:ActivityRecognitionLocationProvider.java   
@Override
public void onLocationChanged(Location location) {
    Log.d(TAG, "onLocationChanged: " + location.toString());

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

    if (config.isDebugging()) {
        Toast.makeText(context, "acy:" + location.getAccuracy() + ",v:" + location.getSpeed() + ",df:" + config.getDistanceFilter(), Toast.LENGTH_LONG).show();
    }

    // if (lastLocation != null && location.distanceTo(lastLocation) < config.getDistanceFilter()) {
    //     return;
    // }

    if (config.isDebugging()) {
        startTone("beep");
    }

    lastLocation = location;
    handleLocation(location);
}
项目:cordova-plugin-quintech-background-geolocation    文件:ActivityRecognitionLocationProvider.java   
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";
      }
}
项目:cordova-plugin-quintech-background-geolocation    文件:ActivityRecognitionLocationProvider.java   
@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);

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

    if (lastActivity.getType() == DetectedActivity.STILL) {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected STILL Activity", Toast.LENGTH_SHORT).show();
        }
        // stopTracking();
        // we will delay stop tracking after position is found
    } else {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected ACTIVE Activity", Toast.LENGTH_SHORT).show();
        }
        startTracking();
    }
    //else do nothing
}
项目:Activity-Recognition-Tools    文件:Constants.java   
/**
 * Returns a human readable String corresponding to a detected activity type.
 */
public 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);
    }
}
项目:ReactiveAwareness    文件:ReactiveSnapshot.java   
/**
 * Provides the current probable {@link DetectedActivity}s of the device which have at least
 * the given probability. Should no activity reach this minimum probability, the resulting list
 * will be empty.
 *
 * @param minimumProbability minimum probabilities of the activities
 * @return Single event of the most probable activities
 */
@RequiresPermission("com.google.android.gms.permission.ACTIVITY_RECOGNITION")
public Single<List<DetectedActivity>> getProbableActivities(int minimumProbability) {
    return getActivity()
            .map(activity -> {
                List<DetectedActivity> probableActivities = activity.getProbableActivities();
                List<DetectedActivity> matchingActivities = new ArrayList<>(probableActivities.size());

                for (DetectedActivity probableActivity : probableActivities) {
                    if (activity.getActivityConfidence(probableActivity.getType()) >= minimumProbability) {
                        matchingActivities.add(probableActivity);
                    }
                }

                return matchingActivities;
            });
}
项目:CycleFrankfurtAndroid    文件:ActivityRecognitionIntentService.java   
/**
 * Map detected activity types to strings
 *@param activityType The detected activity type
 *@return A user-readable name for the type
 */
private String getNameFromType(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";
    }
    return "unknown";
}
项目:react-native-activity-recognition    文件:DetectionService.java   
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";
    }
}
项目:googleplayAPI    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@SuppressWarnings("unchecked")
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    PreferenceManager.getDefaultSharedPreferences(this)
        .edit()
        .putString(Constants.KEY_DETECTED_ACTIVITIES,
            Utils.detectedActivitiesToJson(detectedActivities))
        .apply();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da: detectedActivities) {
        Log.i(TAG, Utils.getActivityString(
            getApplicationContext(),
            da.getType()) + " " + da.getConfidence() + "%"
        );
    }
}
项目:googleplayAPI    文件:Utils.java   
/**
 * 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);
    }
}
项目:googleplayAPI    文件:MainActivity.java   
@Override
protected void onNewIntent(Intent intent) {
    Log.v(TAG, "onNewIntent");

    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
    //get most probable activity
    DetectedActivity probably = result.getMostProbableActivity();
    if (probably.getConfidence() >= 50) {  //doc's say over 50% is likely, under is not sure at all.
        speech(getActivityString(probably.getType()));
    }
    logger.append("Most Probable: " +getActivityString(probably.getType()) + " "+ probably.getConfidence()+"%\n" );
    //or we could go through the list, which is sorted by most likely to least likely.
    List<DetectedActivity> fulllist = result.getProbableActivities();
    for (DetectedActivity da: fulllist) {
        if (da.getConfidence() >=50) {
            logger.append("-->" + getActivityString(da.getType()) + " " + da.getConfidence() + "%\n");
            speech(getActivityString(da.getType()));

        }
    }
}
项目:googleplayAPI    文件:MainActivity.java   
/**
 * Returns a human readable String corresponding to a detected activity type.
 */

public static String getActivityString(int detectedActivityType) {
    switch (detectedActivityType) {
        case DetectedActivity.IN_VEHICLE:
            return "In a Vehicle";
        case DetectedActivity.ON_BICYCLE:
            return "On a bicycle";
        case DetectedActivity.ON_FOOT:
            return "On Foot";
        case DetectedActivity.RUNNING:
            return "Running";
        case DetectedActivity.STILL:
            return "Still (not moving)";
        case DetectedActivity.TILTING:
            return "Tilting";
        case DetectedActivity.UNKNOWN:
            return "Unknown Activity";
        case DetectedActivity.WALKING:
            return "Walking";
        default:
            return "Unknown Type";
    }
}
项目:googleplayAPI    文件:myAdapter.java   
/**
 * Returns a human readable String corresponding to a detected activity type.
 */

public static int getActivityPic(int detectedActivityType) {
    switch (detectedActivityType) {
        case DetectedActivity.IN_VEHICLE:
            return R.drawable.car;
        case DetectedActivity.ON_BICYCLE:
            return R.drawable.bike;
        case DetectedActivity.ON_FOOT:
            return R.drawable.walk;
        case DetectedActivity.RUNNING:
            return R.drawable.run;
        case DetectedActivity.STILL:
            return R.drawable.still;
        case DetectedActivity.TILTING:
            return R.drawable.tilt;
        case DetectedActivity.UNKNOWN:
            return R.drawable.unknown;
        case DetectedActivity.WALKING:
            return R.drawable.walk;
        default:
            return R.drawable.unknown;
    }
}
项目:activity-recognition-example    文件:Constants.java   
public 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);
    }
}
项目:BackPackTrackII    文件:BackgroundService.java   
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");
        }
    }
}
项目:BackPackTrackII    文件:BackgroundService.java   
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);
    }
}
项目:cordova-background-geolocation-services    文件:BackgroundLocationUpdateService.java   
@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
}
项目:cordova-background-geolocation-services    文件:Constants.java   
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";
    }
}
项目:cordova-background-geolocation-services    文件:Constants.java   
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;
}
项目:mCerebrum-PhoneSensor    文件:Constants.java   
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 "UNDEFINED";
    }
}
项目:mCerebrum-PhoneSensor    文件:ActivityType.java   
private int getActivityType(int type) {
    switch (type) {
        case DetectedActivity.STILL:
            return ResultType.ActivityType.STILL;
        case DetectedActivity.ON_FOOT:
            return ResultType.ActivityType.ON_FOOT;
        case DetectedActivity.TILTING:
            return ResultType.ActivityType.TILTING;
        case DetectedActivity.WALKING:
            return ResultType.ActivityType.WALKING;
        case DetectedActivity.RUNNING:
            return ResultType.ActivityType.RUNNING;
        case DetectedActivity.ON_BICYCLE:
            return ResultType.ActivityType.ON_BICYCLE;
        case DetectedActivity.IN_VEHICLE:
            return ResultType.ActivityType.IN_VEHICLE;
        default:
            return ResultType.ActivityType.UNKNOWN;
    }
}
项目:footstep    文件:DetectedActivitiesIntentService.java   
/**
 * 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.BROADCAST_ACTION);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da : detectedActivities) {
        Log.i(TAG, Constants.getActivityString(
                        getApplicationContext(),
                        da.getType()) + " " + da.getConfidence() + "%"
        );
    }

    // Broadcast the list of detected activities.
    localIntent.putExtra(Constants.ACTIVITY_EXTRA, detectedActivities);
    LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent);
}
项目:footstep    文件:DetectedActivitiesAdapter.java   
@Override
public View getView(int position, View view, 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.
    activityName.setText(Constants.getActivityString(getContext(),
            detectedActivity.getType()));
    activityConfidenceLevel.setText(detectedActivity.getConfidence() + "%");
    progressBar.setProgress(detectedActivity.getConfidence());
    return view;
}
项目:footstep    文件:Constants.java   
/**
 * Returns a human readable String corresponding to a detected activity type.
 */
public 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);
    }
}
项目:dslink-java-android    文件:ActivityRecognitionIntentService.java   
private String getNameFromType(int activityType) {
    switch (activityType) {
        case DetectedActivity.IN_VEHICLE:
            return "in_vehicle";
        case DetectedActivity.ON_BICYCLE:
            return "on_bicycle";
        case DetectedActivity.RUNNING:
            return "running";
        case DetectedActivity.WALKING:
            return "walking";
        case DetectedActivity.ON_FOOT:
            return "on_foot";
        case DetectedActivity.STILL:
            return "still";
        case DetectedActivity.TILTING:
            return "tilting";
        case DetectedActivity.UNKNOWN:
            return "unknown";
    }
    return "unknown";
}
项目:androidApp    文件:Constants.java   
/**
 * Returns a human readable String corresponding to a detected activity type.
 */
public 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);
    }
}
项目:androidApp    文件:Constants.java   
public static int getActivityCode(Context context, String detectedActivityType) {
    Resources resources = context.getResources();
    if (detectedActivityType.equals(resources.getString(R.string.in_vehicle)))
        return DetectedActivity.IN_VEHICLE;
    if (detectedActivityType.equals(resources.getString(R.string.on_bicycle)))
        return DetectedActivity.ON_BICYCLE;
    if (detectedActivityType.equals(resources.getString(R.string.on_foot)))
        return DetectedActivity.ON_FOOT;
    if (detectedActivityType.equals(resources.getString(R.string.running)))
        return DetectedActivity.RUNNING;
    if (detectedActivityType.equals(resources.getString(R.string.still)))
        return DetectedActivity.STILL;
    if (detectedActivityType.equals(resources.getString(R.string.tilting)))
        return DetectedActivity.TILTING;
    if (detectedActivityType.equals(resources.getString(R.string.unknown)))
        return DetectedActivity.UNKNOWN;
    if (detectedActivityType.equals(resources.getString(R.string.walking)))
        return DetectedActivity.WALKING;

    return -1;
}
项目:androidApp    文件:BusStopState.java   
@Override
public IState onActivityChange(DetectedActivity activity) {
    if (activity.getType() == DetectedActivity.IN_VEHICLE) {
        //TODO(aantoine): inCooldown first instant velocity!
        //return new NotificationState(this, this.busStop.getIncomingBuses());
        this.checkForInstantVelocity = true;
        setInstantVelocityTimer();
    }
    if (activity.getType() != DetectedActivity.IN_VEHICLE ||
            activity.getType() == DetectedActivity.TILTING ||
            activity.getType() == DetectedActivity.UNKNOWN) {
        //DEFINETLY NOT IN VEHICLE!
        if (currentTask != null) {
            currentTask.cancel();
        }
        this.checkForInstantVelocity = false;
    }
    return this;
}
项目:androidApp    文件:DetectedActivitiesIntentService.java   
/**
 * 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);
}
项目:androidApp    文件:DetectionServiceTest.java   
@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));
}
项目:androidApp    文件:DetectionServiceTest.java   
@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());
}
项目:cordova-plugin-mauron85-background-geolocation-phonegapbuild    文件:FusedLocationService.java   
@Override
public void onLocationChanged(Location location) {
    Log.d(TAG, "- onLocationChanged" + location.toString());

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

    if (config.isDebugging()) {
        Toast.makeText(FusedLocationService.this, "acy:" + location.getAccuracy() + ",v:" + location.getSpeed() + ",df:" + config.getDistanceFilter(), Toast.LENGTH_LONG).show();
    }

    // if (lastLocation != null && location.distanceTo(lastLocation) < config.getDistanceFilter()) {
    //     return;
    // }

    if (config.isDebugging()) {
        startTone("beep");
    }

    lastLocation = location;
    handleLocation(location);
}
项目:cordova-plugin-mauron85-background-geolocation-phonegapbuild    文件:FusedLocationService.java   
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";
      }
}
项目:cordova-plugin-mauron85-background-geolocation-phonegapbuild    文件:FusedLocationService.java   
@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);

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

    if (lastActivity.getType() == DetectedActivity.STILL) {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected STILL Activity", Toast.LENGTH_SHORT).show();
        }
        // stopTracking();
        // we will delay stop tracking after position is found
    } else {
        if (config.isDebugging()) {
            Toast.makeText(context, "Detected ACTIVE Activity", Toast.LENGTH_SHORT).show();
        }
        startTracking();
    }
    //else do nothing
}
项目:Pandora-sdk-android    文件:PandoraSDK.java   
@Subscribe 
public void messageAvailable(AndroidEventMessage m) {

     if(m.getId().equals(Configuration.NO_CONNECTION)){
         //detener geo e ibacon services
         Log.i("pandora","stoping services because NO CONNECTION");
         stopServices(contexto);
     }else if(m.getId().equals(Configuration.CONNECTION)){
        //activar geo e ibacon services
         Log.i("pandora","restarting services because CONNECTION");
         startServices(contexto, this.iBeacon, true);
     }else if(m.getId().equals(Configuration.NEW_ACTIVITY) && GeoService.receivedFix>2){ 

         ActivityRecognitionResult result = (ActivityRecognitionResult) m.getContent(); 
         String activity = parseActivity(result.getMostProbableActivity());
         Log.i("pandora","new activity: "+activity);  
         if(result.getMostProbableActivity().getType()==DetectedActivity.STILL && result.getMostProbableActivity().getConfidence()>80){
             Log.i("pandora","stoping services because STILL");
             stopServices(contexto);
         }else {
             Log.i("pandora","restarting services because NOT STILL");  
             startServices(contexto, this.iBeacon, true);
         }
     } 
}
项目:Pandora-sdk-android    文件:PandoraSDK.java   
private String parseActivity(DetectedActivity activity){
    String log;

    switch(activity.getType()){
    case DetectedActivity.IN_VEHICLE:
        log = "In car.";
        break;
    case DetectedActivity.ON_BICYCLE:
        log = "On bike.";
        break;
    case DetectedActivity.ON_FOOT:
        log = "On foot.";
        break;
    case DetectedActivity.STILL:
        log = "Standing still.";
        break;
    case DetectedActivity.TILTING:
        log = "Tilting.";
        break;
default:
    log = "Unknown.";
    }

    return activity.getConfidence() + "%:\t\t\t" + log;
  }
项目:android-play-location    文件:DetectedActivitiesIntentService.java   
/**
 * Handles incoming intents.
 * @param intent The Intent is provided (inside a PendingIntent) when requestActivityUpdates()
 *               is called.
 */
@SuppressWarnings("unchecked")
@Override
protected void onHandleIntent(Intent intent) {
    ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

    // Get the list of the probable activities associated with the current state of the
    // device. Each activity is associated with a confidence level, which is an int between
    // 0 and 100.
    ArrayList<DetectedActivity> detectedActivities = (ArrayList) result.getProbableActivities();

    PreferenceManager.getDefaultSharedPreferences(this)
            .edit()
            .putString(Constants.KEY_DETECTED_ACTIVITIES,
                    Utils.detectedActivitiesToJson(detectedActivities))
            .apply();

    // Log each activity.
    Log.i(TAG, "activities detected");
    for (DetectedActivity da: detectedActivities) {
        Log.i(TAG, Utils.getActivityString(
                        getApplicationContext(),
                        da.getType()) + " " + da.getConfidence() + "%"
        );
    }
}
项目:android-play-location    文件:Utils.java   
/**
 * 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);
    }
}
项目:ShutUpAndDrive    文件:DetectedActivityIntentService.java   
@Override
protected void onHandleIntent(Intent intent) {
    if (ActivityRecognitionResult.hasResult(intent)) {
        ActivityRecognitionResult result =
                ActivityRecognitionResult.extractResult(intent);
        DetectedActivity mostProbableActivity = result.getMostProbableActivity();
        int confidence = mostProbableActivity.getConfidence();
        int activityType = mostProbableActivity.getType();
        long waitTime = UserSettings.getNotDrivingTime(this);
        boolean diffTimeOK = (new Date().getTime() - waitTime) >= Utils.minutesToMillis(10);
        if (confidence >= Utils.DETECTION_THRESHOLD && activityType == DetectedActivity.IN_VEHICLE && diffTimeOK) {
            if (!CarMode.running) {
                if (UserSettings.getGPS(this) && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
                    startService(new Intent(this, SpeedService.class));
                else
                    startService(new Intent(this, CarMode.class));
            }
        } else if (confidence >= Utils.DETECTION_THRESHOLD) {
            stopService(new Intent(this, CarMode.class));
            UserSettings.setGPSDrive(this, false);
        }

    }
}
项目:dslink-java-android    文件:ActivityRecognitionIntentService.java   
private String getNameFromType(int activityType) {
    switch (activityType) {
        case DetectedActivity.IN_VEHICLE:
            return "in_vehicle";
        case DetectedActivity.ON_BICYCLE:
            return "on_bicycle";
        case DetectedActivity.RUNNING:
            return "running";
        case DetectedActivity.WALKING:
            return "walking";
        case DetectedActivity.ON_FOOT:
            return "on_foot";
        case DetectedActivity.STILL:
            return "still";
        case DetectedActivity.TILTING:
            return "tilting";
        case DetectedActivity.UNKNOWN:
            return "unknown";
    }
    return "unknown";
}