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

Added feature goal notification.

parent 3cc1ef6a
No related branches found
No related tags found
No related merge requests found
......@@ -30,15 +30,18 @@
</activity>
<service android:name="com.notificationFramework.notification.SedentaryNotification">
</service>
<service android:name="com.notificationFramework.notification.GoalNotification">
</service>
<service android:name="com.notificationFramework.stimulusStrategy.Accelerometer">
</service>
<service android:name="com.notificationFramework.stimulusStrategy.SigMotionDetect">
</service>
<service android:name="com.notificationFramework.stimulusStrategy.StepCounter">
</service>
<receiver android:name="com.notificationFramework.stimulus.SedentaryStimulus">
</receiver>
<receiver android:name="com.notificationFramework.stimulus.GoalStimulus">
</receiver>
<receiver android:name="com.notificationFramework.stimulus.BootLauncher">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED">
......@@ -46,5 +49,4 @@
</intent-filter>
</receiver>
</application>
</manifest>
\ No newline at end of file
package com.notificationFramework.notification;
import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.support.v4.app.NotificationCompat;
import com.notificationFramework.sedentary.frontEnd.R;
/**
* Created by Peter De Jonckheere on 09/03/2018.
*/
public class GoalNotification extends SedentaryNotification {
protected NotificationCompat.Builder setParameters(NotificationCompat.Builder builder) {
builder = super.setParameters(builder);
builder.setContentTitle(this.getClass().getSimpleName());
builder.setContentText(preferences.getString(getString(R.string.daily_goal_text), getString(R.string.default_notification_message)));
if(preferences.getBoolean(getString(R.string.vibration), false)) {
builder.setVibrate(new long[]{0, 500, 0, 500});
}
return builder;
}
@TargetApi(26)
protected NotificationChannel setChannelParameters(NotificationChannel nc) {
nc = super.setChannelParameters(nc);
nc.setDescription(this.getClass().getName());
return nc;
}
}
......@@ -50,7 +50,7 @@ public class Settings extends AppCompatActivity{
((CheckBox)findViewById(R.id.LEDFlash)).setChecked(shared.getBoolean(getString(R.string.led), false));
((Spinner)findViewById(R.id.PeriodSpinner)).setSelection(shared.getInt(getString(R.string.notify_me), 0));
((EditText)findViewById(R.id.notificationMessage)).setText(shared.getString(getString(R.string.daily_goal_text), getString(R.string.notf_text)));
((SeekBar)findViewById(R.id.seekBar2)).setProgress(shared.getInt(getString(R.string.daily_goal_set), R.integer.daily_goal_minutes));
((SeekBar)findViewById(R.id.seekBar2)).setProgress(shared.getInt(getString(R.string.daily_goal_set), getResources().getInteger(R.integer.daily_goal_minutes)));
((Switch)findViewById(R.id.NotSwitch)).setChecked(shared.getBoolean(getString(R.string.notf_switch), true));
}
......
package com.notificationFramework.stimulus;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import com.notificationFramework.sedentary.frontEnd.R;
import java.util.Calendar;
/**
* Created by Peter De Jonckheere on 09/03/2018.
*/
public class GoalStimulus extends BroadcastReceiver implements Stimulus {
@Override
public void onReceive(Context context, Intent intent) {
SharedPreferences shared = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE);
if ((shared.getBoolean(context.getString(R.string.notf_switch), true)) && (checkTime(shared, context))) {
Intent i = new Intent(context.getApplicationContext(), com.notificationFramework.notification.GoalNotification.class);
context.getApplicationContext().startService(i);
}
}
private boolean checkTime(SharedPreferences shared, Context context){
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, shared.getInt(context.getString(R.string.dnd_shour), 23));
cal.set(Calendar.MINUTE, shared.getInt(context.getString(R.string.dnd_smin), 0));
Calendar cal2 = Calendar.getInstance();
int days = checkMonth(cal2.get(Calendar.MONTH));
if(shared.getInt(context.getString(R.string.dnd_shour), 23) > shared.getInt(context.getString(R.string.dnd_ehour), 9)) {
cal2.set(Calendar.DATE, ((cal2.get(Calendar.DATE) + 1) % days));
}
cal2.set(Calendar.HOUR_OF_DAY, shared.getInt(context.getString(R.string.dnd_ehour), 9));
cal2.set(Calendar.MINUTE, shared.getInt(context.getString(R.string.dnd_emin), 0));
Calendar curCal = Calendar.getInstance();
if(curCal.getTime().after(cal.getTime()) && curCal.getTime().before(cal2.getTime())){
return false;
} else {
return true;
}
}
private int checkMonth(int month){
switch (month){
case Calendar.JANUARY:
case Calendar.MARCH:
case Calendar.MAY:
case Calendar.JULY:
case Calendar.AUGUST:
case Calendar.OCTOBER:
case Calendar.DECEMBER:
return 31;
case Calendar.APRIL:
case Calendar.JUNE:
case Calendar.SEPTEMBER:
case Calendar.NOVEMBER:
return 30;
case Calendar.FEBRUARY:
Calendar cal = Calendar.getInstance();
if (cal.getActualMaximum(Calendar.DAY_OF_YEAR) > 365){
return 29;
} else {
return 28;
}
}
return -1;
}
}
......@@ -60,7 +60,6 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus {
Intent intent1 = new Intent(context, strategy.getClass());
context.stopService(intent1);
chooseStrategy(strategy, context.getApplicationContext());
}
private boolean checkTime(SharedPreferences shared, Context context){
......
......@@ -5,6 +5,7 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.Loader;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
......@@ -13,6 +14,7 @@ import android.hardware.SensorManager;
import android.os.IBinder;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import android.widget.Toast;
......@@ -58,14 +60,19 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
int currentDay = Calendar.getInstance().get(Calendar.DAY_OF_YEAR);
if(currentDay == sharedPref.getInt(getString(R.string.progress_day), 0)) {
minutes = sharedPref.getInt(getString(R.string.daily_progress), 0);
if(minutes >= sharedPref.getInt(getString(R.string.daily_goal_set), getResources().getInteger(R.integer.daily_goal_minutes))
&& !(sharedPref.getBoolean((getString(R.string.goal_met)), false))){
goalNotify();
sharedPref.edit().putBoolean(getString(R.string.goal_met), true).commit();
}
} else {
minutes = 0;
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.progress_day), currentDay);
editor.putInt(getString(R.string.daily_progress), minutes);
editor.putBoolean(getString(R.string.goal_met), false);
editor.commit();
}
prevMinutes = minutes;
}
......@@ -87,6 +94,12 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv
setUpClock();
}
public void goalNotify(){
Intent i = new Intent(getBaseContext(), com.notificationFramework.stimulus.GoalStimulus.class);
SaveFile.recordNotification(1,1,0, this);
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.sendBroadcast(i);
}
@Override
public void onSensorChanged(SensorEvent event) {
......
......@@ -42,4 +42,5 @@
<string name="dnd">Do not disturb time : </string>
<string name="strat_switch">Switch detection method</string>
<string name="strategy">Current strategy</string>
<string name="goal_met">Goal Met</string>
</resources>
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