Android Open Source - Rejsekort-Reminder Abstract 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;
/*  ww w . j  a v a  2s.  c o m*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.widget.Toast;

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.sensors.WifiSensor;
import com.example.publictransportation.service.IModeManager;
import com.example.publictransportation.service.LogTypes;

public abstract class AbstractMode {

  protected IModeManager manager;
  protected AbstractProfile profile;
  protected List<AbstractSensor> sensors;
  final String BUS = "BUS";
  final String TRAIN = "TRAIN";
  final String TRAIN_STATION = "TRAIN_STATION";
  protected String latestMacAddress; // Contains the MAC address to be passed to other modes

  public AbstractMode(AbstractProfile profile, IModeManager manager, String latestMacAddress) {
    this.profile = profile;
    this.manager = manager;
    this.latestMacAddress = latestMacAddress;
    sensors = new ArrayList<AbstractSensor>();
  }
  
  public Boolean isForced() {
    return false;
  }

  protected void changeMode(ModeTypes newMode, String latestMacAddress) {
    manager.changeMode(newMode, latestMacAddress);
  }

  // called by a child sensor
  abstract public void input(AbstractSensor sensor, String data);

  // where all transportation mode changing decisions are made
  // should be called every time input() is called
  abstract protected void evaluate();

  // called by the parent activity
  public void kill() {
    killAllSensors();
  }

  // needed for the Activity to ID the mode
  abstract public ModeTypes getType();

  // needed to give sensors access to system services (e.g. TelephonyManager)
  public Context getContext() {
    return manager.getApplicationContext();
  }

  protected void addSensor(AbstractSensor sensor) {
    sensors.add(sensor);
  }

  // called upon getting a kill signal
  protected void killAllSensors() {
    for (AbstractSensor sensor : sensors) {
      sensor.kill();
    }
  }

  public void log(SensorTypes type, String label, String data) {
    manager.log(LogTypes.SENSOR, String.valueOf(type) + " (" + label + "): " + data);
  }
}




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