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

Some more.

parent b2121f6c
No related branches found
No related tags found
No related merge requests found
......@@ -21,17 +21,38 @@ import java.util.zip.ZipOutputStream;
/**
* Created by Peter De Jonckheere on 12/02/2018.
*
* Contains the static methods which record various information about the notifications in the log
* files stored in the external storage of the device.
*/
public class SaveFile {
/**
* Saves a general timestamp which logs that a notification was either sent, clicked or
* acknowledged. The timestamp is saved in standard Android calendar format with 2 bits after.
* "00" - acknowledged
* "01" - clicked
* "10" - sent
* "11" - goal notification
*
* @param sent 1 if a notification has been sent, 1 if a goal notification has been 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 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
*/
private static void recordTimeStamp(int sent, int clicked, int acknowledged, Context context) {
Calendar cal = Calendar.getInstance();
ArrayList<String> contents = new ArrayList<String>();
String line = "";
String line;
//Checks for external storage
if (isExternalStorageMounted()) {
File dir = getDirectory(context);
File file = new File(dir, "TIMESTAMPLOG.txt");
//Creates a new file if one doesn't already exist
if (!file.exists()) {
try {
file.createNewFile();
......@@ -39,6 +60,7 @@ public class SaveFile {
Log.e("FILE_ERROR", "COULDN'T CREATE NEW FILE");
}
}
//Reads the current contents of the log file
try {
if (file.isFile() && file.canRead()) {
BufferedReader br = new BufferedReader(new FileReader(file));
......@@ -46,6 +68,7 @@ public class SaveFile {
contents.add(line + '\n');
}
}
//Adds the new log to the file up to 1000 items. At 1000 items the oldest is removed
if (file.isFile() & file.canWrite()) {
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
if (contents.size() > 999) {
......@@ -64,6 +87,14 @@ public class SaveFile {
}
}
/**
* Keeps track of the number of each type of record stored in a file. Three integers only are
* written to the file used in this method. The first is
* @param sent
* @param clicked
* @param acknowledged
* @param context
*/
public static void recordNotification(int sent, int clicked, int acknowledged, Context context) {
int ns = 0;
int nc = 0;
......@@ -83,7 +114,7 @@ public class SaveFile {
nc = Integer.parseInt(br.readLine());
na = Integer.parseInt(br.readLine());
}catch(NumberFormatException e){
Log.e("FILEERROR", "COULD NOT READ FILE");
}
if (file.isFile() & file.canWrite()) {
BufferedWriter bw = new BufferedWriter(new FileWriter(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