Skip to content
Snippets Groups Projects
Commit a615f560 authored by Peter Joseph De Jonckheere CESM2014's avatar Peter Joseph De Jonckheere CESM2014
Browse files

Discovered new sensors which were added as possible strategies.Combinations of...

Discovered new sensors which were added as possible strategies.Combinations of these and existing will be used to provide best range of possible strategies for detecting sedentary behaviour. To show framework aspects possibly implement a step counter alone to send notifications on each multiple of 100 steps or at the end of each day? Continued to try to refine the notification setup.
parent 3ab8963d
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ public abstract class Notification extends Service{
mBuilder = new NotificationCompat.Builder(this, "sednc");
} else {
mBuilder = new NotificationCompat.Builder(this, "sednc");
setParameters();
setParameters(mBuilder);
}
......@@ -65,12 +65,12 @@ public abstract class Notification extends Service{
@TargetApi(26)
private NotificationChannel createNotificationChannel(){
NotificationChannel nc = new NotificationChannel("sednc", "sedentaryNotification", NotificationManager.IMPORTANCE_DEFAULT);
setChannelParameters();
setChannelParameters(nc);
return nc;
}
//TBC used to alter alert type - audio, visual, haptic etc. May need separate methods for these
protected abstract void setParameters();
protected abstract NotificationCompat.Builder setParameters(NotificationCompat.Builder builder);
protected abstract void setChannelParameters();
protected abstract NotificationChannel setChannelParameters(NotificationChannel nc);
}
......@@ -8,6 +8,7 @@ import android.app.Service;
import android.app.TaskStackBuilder;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.IBinder;
import android.support.annotation.Nullable;
......@@ -25,18 +26,31 @@ import com.example.pharmacy.frontEnd.R;
public class SedentaryNotification extends Notification {
protected void setParameters() {
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
protected void setChannelParameters() {
protected NotificationCompat.Builder setParameters(NotificationCompat.Builder builder) {
//Get parameters from settings? or set strings?
builder.setSmallIcon(0);
builder.setContentTitle("");
builder.setContentText("");
return builder;
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
@TargetApi(26)
protected NotificationChannel setChannelParameters(NotificationChannel nc) {
nc.setDescription("");
nc.enableLights(true);
// Sets the notification light color for notifications posted to this
// channel, if the device supports this feature.
nc.setLightColor(Color.RED);
nc.enableVibration(true);
nc.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
return nc;
}
}
......@@ -17,32 +17,29 @@ import java.util.Observable;
class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
private StimulusStrategy strategy;
private Context context;
public SedentaryStimulus(){
// this.context = context;
public SedentaryStimulus(Context context){
this.context = context;
chooseStrategy(null);
}
public SedentaryStimulus(StimulusStrategy s){
// this.context = context;
public SedentaryStimulus(Context context, StimulusStrategy s){
this.context = context;
chooseStrategy(s);
}
public Notification createNotification() {
Notification notification = new SedentaryNotification();
//Either further define this notification here or change to one line;
return notification;
}
public void chooseStrategy(StimulusStrategy s) {
if(s != null){
strategy = s;
} else{
// strategy = defaultStrategy;
strategy = defaultStrategy;
//can no longer have default strategy in interface as strategies require context
}
//Should be context.startService('selectedstrategy') but require context here first?
strategy.monitor();
Intent intent = new Intent(this.context, strategy.getClass());
this.context.startService(intent);
}
......@@ -53,6 +50,9 @@ class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
//If a condition - such as time elapsed since last notification or not night time
//Intent data used here to configure notification?? Intent would need to be configured properly for this.
context.startService(intent);
//For clock-based detection/alarm setting needs to be restarted here.
//chooseStrategy(context.);
}
......
......@@ -15,12 +15,7 @@ import java.util.Observer;
public interface Stimulus {
//StimulusStrategy defaultStrategy = new Clock(context);
//Creates an instance of the desired notifcation type (Factory Method)
//TBD if this is to be public
Notification createNotification();
StimulusStrategy defaultStrategy = new Clock();
//Allows the Stimulus Strategy to be used with this stimlus to be chosen
void chooseStrategy(StimulusStrategy s);
......
package com.example.stimulusStrategy;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.IBinder;
import android.support.annotation.Nullable;
/**
* Created by pharmacy on 17/01/2018.
*/
public class LinearAcceleration extends Service implements StimulusStrategy {
private SensorManager mSensorManager;
private Sensor laccl;
@Override
public void onCreate(){
mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
laccl = mSensorManager.getDefaultSensor(Sensor.TYPE_LINEAR_ACCELERATION);
}
public void monitor() {
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
package com.example.stimulusStrategy;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.hardware.TriggerEvent;
import android.hardware.TriggerEventListener;
import android.os.IBinder;
import android.support.annotation.Nullable;
import com.example.notification.Notification;
/**
* Created by pharmacy on 17/01/2018.
*/
public class SigMotionDetect extends Service implements StimulusStrategy {
private SensorManager mSensorManager;
private Sensor md;
private TriggerEventListener tel;
private AlarmManager am;
//Set up alarm manager to fire in one hour, and set up significant motion sensor to fire and call monitor which
// will then cancel the alarm and reschedule it for one hour from now. Monitor should also use step-counter? to monitor the length
// of unsedentary behaviour for progress monitoring.
@Override
public void onCreate(){
am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
setUpClock();
mSensorManager = (SensorManager) this.getSystemService(Context.SENSOR_SERVICE);
md = mSensorManager.getDefaultSensor(Sensor.TYPE_SIGNIFICANT_MOTION);
tel = new TriggerEventListener() {
@Override
public void onTrigger(TriggerEvent triggerEvent) {
monitor();
}
};
}
private void setUpClock() {
Intent i = new Intent(this, Notification.class);
PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0);
am.set(AlarmManager.ELAPSED_REALTIME, AlarmManager.INTERVAL_HOUR, pi);
}
public void monitor() {
//Use step counter sensor? to detect if movement lasted for a prolonged period of time.
am.cancel(am.getNextAlarmClock().getShowIntent());
setUpClock();
mSensorManager.requestTriggerSensor(tel, md);
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
......@@ -19,6 +19,7 @@ public interface StimulusStrategy {
/*
TBD whether required, observable cannot be extended by an interface so either concrete classes extend this (preferred i think)
or this becomes an abstract class
SOLVED NOT REQUIRED NOW USING SERVICES
@Override
//Will notify the Stimulus when monitoring is true. Monitoring only started by method monitor() then carried out internally
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment