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

Further sensor work. Now monitoring and sending broadcast upon change, for...

Further sensor work. Now monitoring and sending broadcast upon change, for accelerometer this might need to be tuned slightly. However no reception of broadcast this may require a rethink for methodlogy.
parent fc83cbee
No related branches found
No related tags found
No related merge requests found
......@@ -22,10 +22,17 @@
</activity>
<service android:name="com.example.notification.SedentaryNotification">
</service>
<service android:name="com.example.stimulusStrategy.Accelerometer">
</service>
<service android:name="com.example.stimulusStrategy.SigMotionDetect">
</service>
<service android:name="com.example.stimulusStrategy.Clock">
</service>
<receiver android:name="com.example.stimulus.SedentaryStimulus">
<intent-filter>
<action android:name="com.example.stimulusStrategy.Accelerometer" />
</intent-filter>
</receiver>
</application>
</manifest>
\ No newline at end of file
......@@ -4,7 +4,9 @@ import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.util.Log;
import com.example.pharmacy.frontEnd.R;
......@@ -20,6 +22,10 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
private StimulusStrategy strategy;
private Context context;
public SedentaryStimulus(){
}
public SedentaryStimulus(Context context){
this.context = context;
chooseStrategy(null);
......@@ -39,7 +45,6 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
}
// strategy.monitor();
Intent intent = new Intent(this.context, strategy.getClass());
SharedPreferences shared = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
if(shared.getBoolean(context.getString(R.string.notf_switch), true)) {
......@@ -57,6 +62,8 @@ public 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.
SharedPreferences shared = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
Log.d("CALLBACK", "SERVICE STARTED");
//possibly check here for android notification settings
if(shared.getBoolean(context.getString(R.string.notf_switch), true)) {
......
......@@ -14,6 +14,7 @@ import android.util.Log;
import android.widget.Toast;
import com.example.pharmacy.frontEnd.R;
import com.example.stimulus.SedentaryStimulus;
/**
......@@ -43,10 +44,12 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
}*/
public void monitor() {
Log.d("ACCEL", "MONITORING");
Toast saved = Toast.makeText(this, R.string.motion,Toast.LENGTH_LONG);
saved.show();
mSensorManager.unregisterListener(this);
Intent i = new Intent(this, Notification.class);
Intent i = new Intent(this, com.example.notification.Notification.class);
this.sendBroadcast(i);
stopSelf();
}
......@@ -54,7 +57,29 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
@Override
public void onSensorChanged(SensorEvent event) {
monitor();
float[] gravity = new float[3];
float[] linearAcc = new float[3];
int moved = 0;
final float alpha = (float) 0.8;
gravity[0] = alpha * gravity[0] + (1 - alpha) * event.values[0];
gravity[1] = alpha * gravity[1] + (1 - alpha) * event.values[1];
gravity[2] = alpha * gravity[2] + (1 - alpha) * event.values[2];
linearAcc[0] = event.values[0] - gravity[0];
linearAcc[1] = event.values[1] - gravity[1];
linearAcc[2] = event.values[2] - gravity[2];
Log.d("ACCEL", "SENSOR EVENT");
for(int i = 0; i < 3; i++){
if(linearAcc[i] > 1){
moved++;
}
}
if(moved >= 2) {
monitor();
}
}
@Override
......
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