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

Notification work.

parent a1086c1a
No related branches found
No related tags found
No related merge requests found
......@@ -39,22 +39,12 @@ public abstract class Notification extends Service{
mBuilder = new NotificationCompat.Builder(this, nc.getId());
} else {
mBuilder = new NotificationCompat.Builder(this, "sednc");
mBuilder = setParameters(mBuilder);
}
mBuilder = setParameters(mBuilder);
//Up to set Content Intent taken from developers page and must be refined or if works cited.
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(this, NotificationClicked.class);
// The stack builder object will contain an artificial back stack for the
// started Activity.
// This ensures that navigating backward from the Activity leads out of
// your application to the Home screen.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
// Adds the back stack for the Intent (but not the Intent itself)
stackBuilder.addParentStack(NotificationClicked.class);
// Adds the Intent that starts the Activity to the top of the stack
stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
......@@ -62,7 +52,6 @@ public abstract class Notification extends Service{
PendingIntent.FLAG_UPDATE_CURRENT
);
mBuilder.setContentIntent(resultPendingIntent);
// mId allows you to update the notification later on.
nm.notify(snId, mBuilder.build());
}
......
......@@ -31,19 +31,17 @@ public class SedentaryNotification extends Notification {
builder.setSmallIcon(0);
builder.setContentTitle(this.getClass().getName());
builder.setContentText(preferences.getString(getString(R.string.daily_goal_text), getString(R.string.notf_text)));
builder.setCategory(NotificationCompat.CATEGORY_ALARM);
return builder;
}
@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});
nc.setDescription(this.getClass().getName());
nc.enableLights(preferences.getBoolean(getString(R.string.led), false));
nc.enableVibration(preferences.getBoolean(getString(R.string.vibration), false));
//Play empty sound for sound??
return nc;
}
}
package com.example.pharmacy.frontEnd;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import java.io.BufferedReader;
import java.io.BufferedWriter;
......@@ -23,6 +29,7 @@ public class NotificationClicked extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recordClick();
setUpButtons();
}
private void recordClick() {
......@@ -76,4 +83,17 @@ public class NotificationClicked extends AppCompatActivity {
}
return file;
}
private void setUpButtons(){
Button settings = (Button)findViewById(R.id.settings);
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(view.getContext(), Settings.class);
startActivity(intent);
}
});
SharedPreferences shared = this.getSharedPreferences(getString(R.string.preference_file_key), Context.MODE_PRIVATE);
ProgressBar progress = (ProgressBar) findViewById(R.id.progressBar);
progress.setMax((shared.getInt(getString(R.string.daily_goal_set), R.integer.daily_goal_minutes)));
}
}
package com.example.stimulus;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
......@@ -48,8 +49,10 @@ 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);
if(shared.getBoolean())
context.startService(intent);
//possibly check here for android notification settings
if(shared.getBoolean(context.getString(R.string.notf_switch), true)) {
context.startService(intent);
}
//Restarts the chosen strategy process.
chooseStrategy(strategy);
......
......@@ -3,6 +3,10 @@ package com.example.stimulusStrategy;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.app.job.JobWorkItem;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
......@@ -10,6 +14,7 @@ import android.hardware.SensorManager;
import android.hardware.TriggerEvent;
import android.hardware.TriggerEventListener;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
......@@ -17,6 +22,8 @@ import android.widget.Toast;
import com.example.notification.Notification;
import com.example.pharmacy.frontEnd.R;
import java.util.List;
/**
* Created by pharmacy on 17/01/2018.
*/
......@@ -57,12 +64,27 @@ public class SigMotionDetect extends Service implements StimulusStrategy {
public void monitor() {
//Use step counter sensor? to detect if movement lasted for a prolonged period of time.
//Anything over 60 steps per minute counts as a minute of activity.
//Check every minute until the change is less than this.
//Then register to daily progress for number of minutes > 60.
Log.d("MOTION", "HUZZAH");
am.cancel(am.getNextAlarmClock().getShowIntent());
stepCounter();
setUpClock();
mSensorManager.requestTriggerSensor(tel, md);
}
private void stepCounter(){
Sensor sc = mSensorManager.getDefaultSensor(Sensor.TYPE_STEP_COUNTER);
//Use job scheduler to check once every minute while change > 60.
JobScheduler jobs = (JobScheduler) this.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder builder = new JobInfo.Builder(R.integer.step_job ,new ComponentName(this, this.getClass()));
//
// builder.setPeriodic();
// jobs.schedule();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
......
......@@ -2,4 +2,5 @@
<resources>
<integer name="daily_goal_minutes">75</integer>
<integer name="notify_period_minutes">60</integer>
<integer name="step_job">1</integer>
</resources>
\ No newline at end of file
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