diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java index d7bf75ab59fe265dddce8aa093ea9c466f52ec43..fe504c319c37957372383206fe5c1241a69759cc 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java @@ -10,8 +10,11 @@ import android.util.Log; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; +import java.util.List; import java.util.Locale; +import static com.notificationFramework.sedentary.frontEnd.SaveFile.getPlaces; + /** * Created by Peter De Jonckheere on 19/06/2018. */ @@ -69,7 +72,9 @@ public class DataAnalysis { } - private void placeAnalysis(){ - + private void placeAnalysis(Context context){ + List<Place> places = SaveFile.getPlaces(context); + } + } \ No newline at end of file diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/Place.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/Place.java new file mode 100644 index 0000000000000000000000000000000000000000..66a3e2a49ba5fca0df17ec8ee402dddbb7fb44d0 --- /dev/null +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/Place.java @@ -0,0 +1,31 @@ +package com.notificationFramework.sedentary.frontEnd; + +/** + * Created by pharmacy on 11/07/2018. + */ + +public class Place { + + private String name; + private float likelihood; + private int type; + + public Place(String name, float likelihood, int type){ + this.name = name; + this.likelihood = likelihood; + this.type = type; + } + public String getName(){ + return name; + } + + public float getLikelihood(){ + return likelihood; + } + + public int getType(){ + return type; + } + +} + diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java index 8966aeec071f9d14729193c71dbb1cc66544b31e..cae3153df2e54435c35974d0b818f3f4497858d8 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java @@ -298,14 +298,23 @@ public class SaveFile { Context.MODE_PRIVATE); double latitude = Double.longBitsToDouble(preferences.getLong(context.getString(R.string.store_lat), 0)); double longitude = Double.longBitsToDouble(preferences.getLong(context.getString(R.string.store_long), 0)); - String place = preferences.getString(context.getString(R.string.store_place), ""); - String placeType = String.valueOf(preferences.getInt(context.getString(R.string.store_place_type), 0)); - float temperature = preferences.getFloat(context.getString(R.string.store_temp), 0); String places = ""; + for(int i = 0 ; i < 3; i++) { + try { + String place = preferences.getString(context.getString(R.string.store_place) + String.valueOf(i), ""); + place = place.replace( " ", ""); + String placeType = String.valueOf(preferences.getInt(context.getString(R.string.store_place_type) + String.valueOf(i), 0)); + String placeLikelihood = String.valueOf(preferences.getFloat(context.getString(R.string.store_place_like) + String.valueOf(i), 0)); + places = places + place + " " + placeType + " " + placeLikelihood + " "; + }catch(NullPointerException | IndexOutOfBoundsException e){ + + } + } + float temperature = preferences.getFloat(context.getString(R.string.store_temp), 0); String line; ArrayList<String> contents = new ArrayList<String>(); - String writeLine = String.valueOf(latitude) + " " + String.valueOf(longitude) + " " + place - + " " + placeType + " " + String.valueOf(temperature); + String writeLine = String.valueOf(latitude) + " " + String.valueOf(longitude) + " " + places + + String.valueOf(temperature); if (isExternalStorageMounted()) { File dir = getDirectory(context); File file = new File(dir, "DATALOG.txt"); @@ -387,7 +396,7 @@ public class SaveFile { + String.valueOf(i), String.valueOf(place.getName())); editor.putInt(context.getString(R.string.store_place_type) + String.valueOf(i), place.getPlaceTypes().get(i)); - } catch (NullPointerException e) { + } catch (NullPointerException | IndexOutOfBoundsException e) { } } @@ -410,6 +419,41 @@ public class SaveFile { context.startActivity(i); } } + + static List<com.notificationFramework.sedentary.frontEnd.Place> getPlaces(Context context){ + String line = ""; + String[] items; + List<com.notificationFramework.sedentary.frontEnd.Place> places = new ArrayList<>(); + if (isExternalStorageMounted()) { + File dir = getDirectory(context); + File file = new File(dir, "DATALOG.txt"); + //Creates a new file if one doesn't already exist + if (!file.exists()) { + try { + file.createNewFile(); + } catch (IOException e) { + 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)); + while ((line = br.readLine()) != null) { + items = line.split(" "); + //Need to get other 2 places + com.notificationFramework.sedentary.frontEnd.Place place = new com.notificationFramework.sedentary.frontEnd.Place( + items[2], Float.parseFloat(items[4]), Integer.parseInt(items[3])); + places.add(place); + } + } + }catch(IOException e){ + + } + } + return places; + } + /** * Checks if external storage is available on the device. *