diff --git a/src/main/java/com/notificationFramework/notification/Notification.java b/src/main/java/com/notificationFramework/notification/Notification.java index cc8657ddd8d89a390e112eb0166fcd7b797dcbbc..008e4178e2100bd2d8fa0df1783b142a989f722f 100644 --- a/src/main/java/com/notificationFramework/notification/Notification.java +++ b/src/main/java/com/notificationFramework/notification/Notification.java @@ -95,7 +95,7 @@ public abstract class Notification extends Service { mBuilder.setContentIntent(resultPendingIntent); nm.notify(snId, mBuilder.build()); //To record information about the notification sent - SaveFile.recordNotification(1, 0, 0, this); + SaveFile.recordNotification(1, 0, 0, 0,this); SaveFile.recordNotificationType(this); //Stops this service stopSelf(); diff --git a/src/main/java/com/notificationFramework/notification/SedentaryNotification.java b/src/main/java/com/notificationFramework/notification/SedentaryNotification.java index a7003188cf6d466283216639b84b5e7fef295eb6..10aae50680a88f78540448ea52c03e2c06c0c588 100644 --- a/src/main/java/com/notificationFramework/notification/SedentaryNotification.java +++ b/src/main/java/com/notificationFramework/notification/SedentaryNotification.java @@ -16,7 +16,7 @@ import com.notificationFramework.sedentary.frontEnd.R; /** * Created by Peter De Jonckheere on 09/01/2018. * <p> - * The concrete implementation of the Notification class which provides the propertis when the + * The concrete implementation of the Notification class which provides the properties when the * notification is to be sent when the user has been sedentary for a prolonged period of time. * </p> */ diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java new file mode 100644 index 0000000000000000000000000000000000000000..eadbfbf9e2cc2c881b8eeeddd70ff767254242a2 --- /dev/null +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java @@ -0,0 +1,36 @@ +package com.notificationFramework.sedentary.frontEnd; + +import android.util.Log; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +/** + * Created by pharmacy on 19/06/2018. + */ + +public class DataAnalysis { + + static boolean analyse(String line, Calendar cal){ + Calendar compCal = Calendar.getInstance(); + SimpleDateFormat sdf = new SimpleDateFormat("EEEMMMddHH:mm:sszyyyy", Locale.ENGLISH); + String items[] = line.split(" "); + String dateString = items[0] + items[1] + items[2] + items[3] + items[4] + items[5]; + try { + compCal.setTime(sdf.parse(dateString)); + }catch(ParseException e){ + Log.e("ANALYSING", "PARSINGERROR"); + } + compCal.add(Calendar.MINUTE, -6); + if(compCal.before(cal.getTime())){ + return true; + }else{ + return false; + } + } + } + diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/NotificationClicked.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/NotificationClicked.java index 60a219dca10f64a0c0abb2471f9965f8adf353c1..8f99f14a626fdf24c783d5414e99a476657bb207 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/NotificationClicked.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/NotificationClicked.java @@ -42,7 +42,7 @@ public class NotificationClicked extends AppCompatActivity { @Override protected void onStart() { super.onStart(); - SaveFile.recordNotification(0, 1, 0, this); + SaveFile.recordNotification(0, 1, 0,0, this); } /** diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java index 4e73d52b6e506f6ff6649d8feb71e3a27671bf1f..3df862878e5d29cf72f764b4fd7461e3c4245964 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java @@ -40,7 +40,6 @@ public class SaveFile { * 0 otherwise * @param clicked 1 if a notification has been clicked on, 1 if a goal notification has been * sent, 0 otherwise - * @param acknowledged 1 if a movement has been registered, 0 otherwise * @param context the application context which the method has been called from and which will * be used to access and write to the external storage of the device */ @@ -48,6 +47,8 @@ public class SaveFile { Calendar cal = Calendar.getInstance(); ArrayList<String> contents = new ArrayList<String>(); String line; + String prevLine = null; + String[] items; //Checks for external storage if (isExternalStorageMounted()) { File dir = getDirectory(context); @@ -66,6 +67,17 @@ public class SaveFile { BufferedReader br = new BufferedReader(new FileReader(file)); while ((line = br.readLine()) != null) { contents.add(line + '\n'); + prevLine = line; + } + try { + items = prevLine.split(" "); + if (items[6].equals("10")){ + if(DataAnalysis.analyse(prevLine, cal)){ + recordNotification(0,0,0,1, context); + } + } + }catch(NullPointerException e){ + } } //Adds the new log to the file up to 1000 items. At 1000 items the oldest is removed @@ -77,7 +89,7 @@ public class SaveFile { for (String ts : contents) { bw.write(ts); } - bw.write(cal.getTime().toString() + " " + sent + "" + clicked); + bw.write(cal.getTime().toString() + " " + sent + "" + clicked + " " + acknowledged); bw.close(); } @@ -96,13 +108,15 @@ public class SaveFile { * sent 0 otherwise * @param clicked 1 if a notification has been clicked on, 1 if a goal notification has * been sent, 0 otherwise - * @param acknowledged 1 if a movement has been registered, 0 otherwise + * @param movement 1 if a movement has been registered, 0 otherwise + * @param acknowledged 1 if a notification has been acknowledged by a movement * @param context the application context which the method has been called from and which * will be used to access and write to the external storage of the device */ - public static void recordNotification(int sent, int clicked, int acknowledged, Context context){ + public static void recordNotification(int sent, int clicked, int movement, int acknowledged, Context context){ int ns = 0; int nc = 0; + int nm = 0; int na = 0; //Checks if external storage is present if (isExternalStorageMounted()) { @@ -120,6 +134,7 @@ public class SaveFile { try { ns = Integer.parseInt(br.readLine()); nc = Integer.parseInt(br.readLine()); + nm = Integer.parseInt(br.readLine()); na = Integer.parseInt(br.readLine()); } catch (NumberFormatException e) { Log.e("FILEERROR", "COULD NOT READ FILE"); @@ -129,11 +144,14 @@ public class SaveFile { BufferedWriter bw = new BufferedWriter(new FileWriter(file)); ns += sent; nc += clicked; + nm += movement; na += acknowledged; bw.write(String.valueOf(ns)); bw.newLine(); bw.write(String.valueOf(nc)); bw.newLine(); + bw.write(String.valueOf(nm)); + bw.newLine(); bw.write(String.valueOf(na)); bw.close(); } diff --git a/src/main/java/com/notificationFramework/stimulusStrategy/Accelerometer.java b/src/main/java/com/notificationFramework/stimulusStrategy/Accelerometer.java index d2ac0e4339713c426e90f147283ed8fbe1af3400..dc66c73d91bcf08b27c06a719331cfdca1635f4b 100644 --- a/src/main/java/com/notificationFramework/stimulusStrategy/Accelerometer.java +++ b/src/main/java/com/notificationFramework/stimulusStrategy/Accelerometer.java @@ -165,7 +165,7 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv PendingIntent pi = PendingIntent.getBroadcast(getBaseContext(), R.integer.alarm_rc, i, PendingIntent.FLAG_UPDATE_CURRENT); am.cancel(pi); - SaveFile.recordNotification(0, 0, 1, this); + SaveFile.recordNotification(0, 0, 1,0, this); setUpClock(); } @@ -177,7 +177,7 @@ public class Accelerometer extends Service implements StimulusStrategy, SensorEv public void goalNotify() { Intent i = new Intent(getBaseContext(), com.notificationFramework.stimulus.GoalStimulus.class); - SaveFile.recordNotification(1, 1, 0, this); + SaveFile.recordNotification(1, 1, 0, 0, this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.sendBroadcast(i); } diff --git a/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java b/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java index 49024c7d85101e4d876c7a56469e32662c0ceaad..4587e844869fdf20df02753bd45e3b10dc2ee891 100644 --- a/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java +++ b/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java @@ -149,7 +149,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy { PendingIntent pi = PendingIntent.getBroadcast(this, R.integer.alarm_rc, i, 0); am.cancel(pi); - SaveFile.recordNotification(0, 0, 1, this); + SaveFile.recordNotification(0, 0, 1, 0, this); setUpClock(); prevSeconds = seconds; } @@ -250,7 +250,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy { public void goalNotify() { Intent i = new Intent(getBaseContext(), com.notificationFramework.stimulus.GoalStimulus.class); - SaveFile.recordNotification(1, 1, 0, this); + SaveFile.recordNotification(1, 1, 0, 0, this); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this); lbm.sendBroadcast(i); }