Android Open Source - Rejsekort-Reminder Moving Mode






From Project

Back to project page Rejsekort-Reminder.

License

The source code is released under:

GNU General Public License

If you think the Android project Rejsekort-Reminder listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.publictransportation.modes;
//from   www. jav a 2  s.c  o  m
import com.example.publictransportation.profiles.AbstractProfile;
import com.example.publictransportation.sensors.AbstractSensor;
import com.example.publictransportation.sensors.ActivitySensor;
import com.example.publictransportation.sensors.SensorTypes;
import com.example.publictransportation.service.IModeManager;

/*
 * The point of this mode is to limit resource use.
 * The mode is triggered by another mode and then only enables the ActivitySensor.
 * Once we can safely say we are not moving, the mode switches to default again.
 */
public class MovingMode extends AbstractMode {

  final int NOT_ON_FOOT_LIMIT = 1;
  final int TILTING_LIMIT = 2;

  int notOnFootCount;
  int tiltingCount;

  public MovingMode(AbstractProfile profile, IModeManager manager) {
    super(profile, manager, "");

    AbstractSensor activitySensor = new ActivitySensor(this, profile.getHighFrequencyDelay(), profile.getLowActivitySensorCutoff());
    addSensor(activitySensor);
  }

  @Override
  public void input(AbstractSensor sensor, String data) {
    if (sensor.getType() == SensorTypes.ACTIVITY) {

      if (!data.equals(ActivitySensor.ON_FOOT)) {
        if(data.equals(ActivitySensor.TILTING)) {
          tiltingCount += 1;
        } 
        else {
          notOnFootCount += 1;
          tiltingCount = 0;
        }
      }
    }

    // always end with call to evaluate()
    evaluate();
  }

  @Override
  protected void evaluate() {

    // If counted 2 or more tilting results, change to Default Mode
    if (tiltingCount >= TILTING_LIMIT) {
      changeMode(ModeTypes.DEFAULT, "");
    } 
    // If counted more than 1 not on foot results, change to Default Mode
    else if(notOnFootCount >= NOT_ON_FOOT_LIMIT) {
      changeMode(ModeTypes.DEFAULT, "");
    }
  }

  @Override
  public ModeTypes getType() {
    return ModeTypes.MOVING;
  }
}




Java Source Code List

com.example.publictransportation.MainActivity.java
com.example.publictransportation.WidgetProvider.java
com.example.publictransportation.modes.AbstractMode.java
com.example.publictransportation.modes.ActivityResults.java
com.example.publictransportation.modes.BusMode.java
com.example.publictransportation.modes.DefaultMode.java
com.example.publictransportation.modes.ForcedMode.java
com.example.publictransportation.modes.MetroMode.java
com.example.publictransportation.modes.ModeTypes.java
com.example.publictransportation.modes.MovingMode.java
com.example.publictransportation.modes.STrainMode.java
com.example.publictransportation.modes.WaitingMode.java
com.example.publictransportation.profiles.AbstractProfile.java
com.example.publictransportation.profiles.DefaultProfile.java
com.example.publictransportation.sensors.AbstractSensor.java
com.example.publictransportation.sensors.ActivitySensorIntentService.java
com.example.publictransportation.sensors.ActivitySensor.java
com.example.publictransportation.sensors.CellSensor.java
com.example.publictransportation.sensors.SensorTypes.java
com.example.publictransportation.sensors.TimeSensor.java
com.example.publictransportation.sensors.WifiGroup.java
com.example.publictransportation.sensors.WifiSensor.java
com.example.publictransportation.service.IModeManager.java
com.example.publictransportation.service.LogItem.java
com.example.publictransportation.service.LogTypes.java
com.example.publictransportation.service.Logger.java
com.example.publictransportation.service.TrackerService.java