Newer
Older

Peter Joseph De Jonckheere CESM2014
committed
package com.example.stimulus;

Peter Joseph De Jonckheere CESM2014
committed
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

Peter Joseph De Jonckheere CESM2014
committed
import com.example.notification.Notification;
import com.example.notification.SedentaryNotification;
import com.example.stimulusStrategy.StimulusStrategy;
import java.util.Observable;
/**
* Created by pharmacy on 09/01/2018.
*/

Peter Joseph De Jonckheere CESM2014
committed
class SedentaryStimulus extends BroadcastReceiver implements Stimulus {

Peter Joseph De Jonckheere CESM2014
committed
private StimulusStrategy strategy;
public SedentaryStimulus(){

Peter Joseph De Jonckheere CESM2014
committed
// this.context = context;

Peter Joseph De Jonckheere CESM2014
committed
chooseStrategy(null);
}
public SedentaryStimulus(StimulusStrategy s){

Peter Joseph De Jonckheere CESM2014
committed
// this.context = context;

Peter Joseph De Jonckheere CESM2014
committed
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{

Peter Joseph De Jonckheere CESM2014
committed
// strategy = defaultStrategy;
//can no longer have default strategy in interface as strategies require context

Peter Joseph De Jonckheere CESM2014
committed
}

Peter Joseph De Jonckheere CESM2014
committed
//Should be context.startService('selectedstrategy') but require context here first?

Peter Joseph De Jonckheere CESM2014
committed
strategy.monitor();

Peter Joseph De Jonckheere CESM2014
committed
}

Peter Joseph De Jonckheere CESM2014
committed

Peter Joseph De Jonckheere CESM2014
committed
@Override

Peter Joseph De Jonckheere CESM2014
committed
public void onReceive(Context context, Intent intent) {

Peter Joseph De Jonckheere CESM2014
committed
//If a condition - such as time elapsed since last notification or not night time

Peter Joseph De Jonckheere CESM2014
committed
//Intent data used here to configure notification?? Intent would need to be configured properly for this.

Peter Joseph De Jonckheere CESM2014
committed
context.startService(intent);

Peter Joseph De Jonckheere CESM2014
committed

Peter Joseph De Jonckheere CESM2014
committed
}

Peter Joseph De Jonckheere CESM2014
committed