Android Open Source - Rejsekort-Reminder S Train 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.  java 2 s.  c  o m
import android.content.res.Resources;

import com.example.publictransportation.R;
import com.example.publictransportation.profiles.AbstractProfile;
import com.example.publictransportation.sensors.AbstractSensor;
import com.example.publictransportation.sensors.CellSensor;
import com.example.publictransportation.sensors.SensorTypes;
import com.example.publictransportation.sensors.WifiGroup;
import com.example.publictransportation.sensors.WifiSensor;
import com.example.publictransportation.service.IModeManager;

/*
 * We can say we are in a train with a certain confidence solely based on wifi.
 * The mode works by setting a lower limit based on initial signal strength,
 * and then changing mode to DefaultMode once this lower limit has been reached.
 */
public class STrainMode extends AbstractMode {

  final String TRAIN = "TRAIN";
  final String TRAIN_TUNNEL = "TRAIN_TUNNEL";
  Boolean allSignalsLost;
  Boolean inTunnel;

  public STrainMode(AbstractProfile profile, IModeManager manager, String latestMacAddress) {
    super(profile, manager, latestMacAddress);

    Resources r = manager.getApplicationContext().getResources();
    String[] trainSsids = r.getStringArray(R.array.train_ssids);
    int[] trainUndergroundCells = r.getIntArray(R.array.train_underground_cells);
    int[] trainUndergrundCellsIgnore = r.getIntArray(R.array.train_underground_cells_ignore);
    
    // if we entered this mode without a MAC address, it is a sure indication we are in a tunnel
    inTunnel = latestMacAddress.isEmpty()? true : false;
    
    WifiGroup trainGroup = new WifiGroup(TRAIN, trainSsids);
    WifiGroup[] wifiGroups = {trainGroup};

    allSignalsLost = false;
    
    AbstractSensor wifiSensor = new WifiSensor(this, wifiGroups, profile.getWifiSensorDelay(), latestMacAddress);
    AbstractSensor trainCellSensor = new CellSensor(this, trainUndergroundCells, trainUndergrundCellsIgnore, TRAIN_TUNNEL);
    
    addSensor(wifiSensor);
    addSensor(trainCellSensor);
  }

  @Override
  public void input(AbstractSensor sensor, String data) {
    if (sensor.getType() == SensorTypes.CELL && data.equals(CellSensor.NOTHING_FOUND)) {
      inTunnel = false;
    }
    else if (sensor.getType() == SensorTypes.WIFI) {
      // only a total absence of whitelisted SSIDS will exit this mode!
      if (data.equals(WifiSensor.NOTHING_FOUND)) {
        allSignalsLost = true;
      }
    }

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

  @Override
  protected void evaluate() {    
    if (allSignalsLost && !inTunnel) {
      changeMode(ModeTypes.DEFAULT, "");
    }
  }

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




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