diff --git a/src/main/java/com/notificationFramework/notification/FeedbackNotification.java b/src/main/java/com/notificationFramework/notification/FeedbackNotification.java index f730a5ca7fe522ac374de2152b9ae1715fcc1e40..693bce2bfcc8c205c9d3a623174240decdb5faed 100644 --- a/src/main/java/com/notificationFramework/notification/FeedbackNotification.java +++ b/src/main/java/com/notificationFramework/notification/FeedbackNotification.java @@ -1,8 +1,13 @@ package com.notificationFramework.notification; import android.annotation.TargetApi; +import android.app.AlarmManager; import android.app.NotificationChannel; +import android.app.PendingIntent; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; +import android.os.SystemClock; import android.support.v4.app.NotificationCompat; import com.notificationFramework.sedentary.frontEnd.R; @@ -13,6 +18,8 @@ import com.notificationFramework.sedentary.frontEnd.R; public class FeedbackNotification extends SedentaryNotification { + + protected int snId = this.getResources().getInteger(R.integer.notffeedback_id); /** * Called when the service is started. Uses the Notification implementation of this method. * @param intent the intent used to start the service @@ -41,6 +48,7 @@ public class FeedbackNotification extends SedentaryNotification { if (preferences.getBoolean(getString(R.string.vibration), false)) { builder.setVibrate(new long[]{0, 500, 0, 500}); } + setCancellingAlarm(); return builder; } @@ -57,4 +65,16 @@ public class FeedbackNotification extends SedentaryNotification { nc.setDescription(this.getClass().getName()); return nc; } + + private void setCancellingAlarm(){ + AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); + Intent i = new Intent(this, + com.notificationFramework.notification.FeedbackNotificationCanceller.class); + PendingIntent pi = PendingIntent.getBroadcast(this, + R.integer.alarm_fnc, i, 0); + SharedPreferences shared = this.getSharedPreferences(getString( + R.string.preference_file_key), Context.MODE_PRIVATE); + am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, + SystemClock.elapsedRealtime() + (1000 * 60 * 2), pi); + } } diff --git a/src/main/java/com/notificationFramework/notification/FeedbackNotificationCanceller.java b/src/main/java/com/notificationFramework/notification/FeedbackNotificationCanceller.java new file mode 100644 index 0000000000000000000000000000000000000000..abe4160253303b80e0645ab42dd88360ab9f20ec --- /dev/null +++ b/src/main/java/com/notificationFramework/notification/FeedbackNotificationCanceller.java @@ -0,0 +1,27 @@ +package com.notificationFramework.notification; + +import android.app.NotificationManager; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.util.Log; + +import com.notificationFramework.sedentary.frontEnd.R; + +/** + * Created by pharmacy on 25/06/2018. + */ + +public class FeedbackNotificationCanceller extends BroadcastReceiver { + + @Override + public void onReceive(Context context, Intent intent) { + NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + try { + nm.cancel(context.getResources().getInteger(R.integer.notffeedback_id)); + } catch(NullPointerException e){ + Log.i("NOTIFICATION", "NOTIFICATION WAS CLICKED ON"); + } + + } +} diff --git a/src/main/res/values/integers.xml b/src/main/res/values/integers.xml index ecb73a5acbf1774912ab1e3319643a07f16261c2..da39a004df71223e35c67ab9e35899778b553864 100644 --- a/src/main/res/values/integers.xml +++ b/src/main/res/values/integers.xml @@ -5,4 +5,6 @@ <integer name="step_job">1</integer> <integer name="alarm_rc">23</integer> <integer name="notf_id">1240</integer> + <integer name="notffeedback_id">1983</integer> + <integer name="alarm_fnc">1903</integer> </resources> \ No newline at end of file