Something went wrong on our end
-
Peter Joseph De Jonckheere CESM2014 authoredPeter Joseph De Jonckheere CESM2014 authored
Accelerometer.java 10.47 KiB
package com.notificationFramework.stimulusStrategy;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.notificationFramework.sedentary.frontEnd.R;
import com.notificationFramework.sedentary.frontEnd.SaveFile;
import java.util.Calendar;
/**
* Created by Peter De Jonckheere on 09/01/2018.
* <p>
* The strategy which detects sedentary behaviour using the Accelerometer sensor provided by the
* Android hardware. It uses the previous readings to determine if movement has occurred. Upon
* determining a significant enough movement which lasts for a period of 15 seconds, an alarm which
* is set for one notification period from the current time is cancelled. The Accelerometer sensor
* reports in a streaming fashion and so uses significant power on the device and the listener for
* the sensor is constantly registered.
* </p>
*/
public class Accelerometer extends Service implements StimulusStrategy, SensorEventListener {
/**
* The alarm manager instance which is used to manage alarms via the OS
*/
private AlarmManager am;
/**
* An instance of Shared Preferences used throughout the class to obtain and save settings
*/
private SharedPreferences preferences;
/**
* The previous 3 readings of the accelerometer
*/
private float[] history = new float[3];
/**
* The previous timestamp of the accelerometer reading
*/
private long historyTime;
/**
* The last recorded number of minutes moved
*/
private int prevMinutes = 0;
/**
* The current number of minutes moved
*/
private int minutes;
/**
* The current number of seconds moved up to 60
*/
private double seconds = 0;
/**
* The arbitrary default value of sensitivity
*/
private double sensitivity = 0.8;