package com.example.stimulus; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import com.example.stimulusStrategy.StimulusStrategy; /** * Created by pharmacy on 09/01/2018. */ class SedentaryStimulus extends BroadcastReceiver implements Stimulus { private StimulusStrategy strategy; private Context context; public SedentaryStimulus(Context context){ this.context = context; chooseStrategy(null); } public SedentaryStimulus(Context context, StimulusStrategy s){ this.context = context; chooseStrategy(s); } public void chooseStrategy(StimulusStrategy s) { if(s != null){ strategy = s; } else{ strategy = defaultStrategy; //can no longer have default strategy in interface as strategies require context } strategy.monitor(); Intent intent = new Intent(this.context, strategy.getClass()); this.context.startService(intent); } @Override public void onReceive(Context context, Intent intent) { //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); //Restarts the chosen strategy process. chooseStrategy(strategy); } }