Android Open Source - Rejsekort-Reminder Time Sensor






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.sensors;
/*from  w  ww  .j a va2s  .  c om*/
import java.util.Timer;
import java.util.TimerTask;

import android.os.Handler;

import com.example.publictransportation.modes.AbstractMode;

/*
 * This is a "fake" sensor... in that it actually isn't a sensor,
 * but rather a simple timer placed into the existing Mode/Sensor logic.
 * 
 * In this way, stopwatch operations are implemented the same as any other sensor.
 */
public class TimeSensor extends AbstractSensor {

  Timer timer;
  TimerTask timerTask;
  Handler handler;
  final static String TICK = "TICK";

  public TimeSensor(AbstractMode parentMode, int delayInMilliseconds) {
    super(parentMode);
    
    handler = new Handler();

    timer = new Timer();
    timerTask = new TimerTask() {

      @Override
      public void run() {
        handler.post(new Runnable() {
          @Override 
          public void run(){
            output(TICK);
          }});
      }

    };

    timer.scheduleAtFixedRate(timerTask, delayInMilliseconds, delayInMilliseconds);
  }

  @Override
  public void kill() {
    timerTask.cancel();
    timer.cancel();
  }

  @Override
  public SensorTypes getType() {
    return SensorTypes.TIME;
  }

  @Override
  public String getLabel() {
    return "timer";
  }

}




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