Android Open Source - yousense-android-tracker Small Movement






From Project

Back to project page yousense-android-tracker.

License

The source code is released under:

Energy-efficent motion and location tracker for Android. Based on Mattias's power and tracking work. I plan to release it as GPL, once I have a paper published that goes with it. Might also release i...

If you think the Android project yousense-android-tracker 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.linnap.locationtracker.movement;
//from w w w .  j av a2  s  .  c om
import android.os.Handler;
import android.util.Log;

import com.linnap.locationtracker.LocationTrackerService;
import com.linnap.locationtracker.SensorConfig;
import com.linnap.locationtracker.StateChange;
import com.linnap.locationtracker.movement.DutyCycledAccelerometer.MovementDetectedListener;
import com.linnap.locationtracker.wifi.WifiPlaceChange;
import com.linnap.locationtracker.wifi.WifiPlaceChange.MaybePlaceChangedListener;

public class SmallMovement implements MovementDetectedListener, MaybePlaceChangedListener {
  
  LocationTrackerService service;
  Handler handler;
  SmallMovementDistanceListener listener;
  DutyCycledAccelerometer accel;
  WifiPlaceChange placeChange;
  BooleanState state;
  int accelMovementPeriods;
  
  public SmallMovement(LocationTrackerService service, SmallMovementDistanceListener listener) {
    this.service = service;
    this.handler = new Handler();
    this.listener = listener;
    this.accel = new DutyCycledAccelerometer(service, handler, this);
    if (SensorConfig.MOVEMENT_USES_WIFI) {
      this.placeChange = new WifiPlaceChange(service, handler, this);
    }
    this.state = BooleanState.OFF;
    this.accelMovementPeriods = 0;
  }
  
  public synchronized void start() {
    service.event("smallmovement_state", new StateChange(state, BooleanState.ON));
    state = BooleanState.ON;
    accelMovementPeriods = 0;
    if (SensorConfig.MOVEMENT_USES_WIFI) {
      placeChange.clearCheckpoint();
      placeChange.startCheckpoint();
    }
    accel.start();
  }
  
  public synchronized void stop() {
    service.event("smallmovement_state", new StateChange(state, BooleanState.OFF));
    state = BooleanState.OFF;
    accelMovementPeriods = 0;
    if (SensorConfig.MOVEMENT_USES_WIFI) {
      placeChange.clearCheckpoint();
    }
    accel.stop();
  }
  
  public interface SmallMovementDistanceListener {
    public void maybeSmallMovement();
  }

  /// Internal Sensor Callbacks
  
  public synchronized void movementDetected() {
    if (state == BooleanState.ON) {
      accelMovementPeriods += 1;
      if (accelMovementPeriods >= SensorConfig.MOVEMENT_MIN_ACCEL_MOVEMENT_PERIODS) {
        if (SensorConfig.MOVEMENT_USES_WIFI) {
          service.log("SM starting WiFi comparison");
          placeChange.startComparison();
        } else {
          service.log("SM not using WiFi, maybe moved");
          listener.maybeSmallMovement();
        }
      }
    }
  }

  public void maybePlaceChanged(boolean changed) {
    if (!SensorConfig.MOVEMENT_USES_WIFI)
      Log.wtf(SensorConfig.TAG, "MOVEMENT_USES_WIFI is off, but maybePlaceChanged() called");
    
    if (state == BooleanState.ON) {
      if (changed) {
        // Wifi agrees with place change. Report.
        service.log("SM maybe WiFi change");
        listener.maybeSmallMovement();
        // Do not accel periods, stopping movement detection is up to SensorScheduler.
      } else {
        // No actual place change. Walking around in the same room. Reset distance.
        service.log("SM WiFi not changed");
        accelMovementPeriods = 0;
      }
    }
  }
  
}




Java Source Code List

com.linnap.locationtracker.EventBindings.java
com.linnap.locationtracker.ExpectedState.java
com.linnap.locationtracker.LocationTrackerService.java
com.linnap.locationtracker.SensorConfig.java
com.linnap.locationtracker.Sets.java
com.linnap.locationtracker.StateChange.java
com.linnap.locationtracker.gps.DistanceCycledGps.java
com.linnap.locationtracker.gps.GpsHistory.java
com.linnap.locationtracker.gps.LocationFix.java
com.linnap.locationtracker.movement.AccelerometerData.java
com.linnap.locationtracker.movement.BooleanState.java
com.linnap.locationtracker.movement.DutyCycledAccelerometer.java
com.linnap.locationtracker.movement.SmallMovement.java
com.linnap.locationtracker.movement.StatsAccumulator.java
com.linnap.locationtracker.schedule.SensorScheduler.java
com.linnap.locationtracker.wifi.ScanResultsData.java
com.linnap.locationtracker.wifi.ScanStartedData.java
com.linnap.locationtracker.wifi.TimeoutScan.java
com.linnap.locationtracker.wifi.WifiFingerprint.java
com.linnap.locationtracker.wifi.WifiPlaceChange.java