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

Get 2 more places from file

parent 71467553
No related branches found
Tags vm-only
No related merge requests found
...@@ -10,8 +10,11 @@ import android.util.Log; ...@@ -10,8 +10,11 @@ import android.util.Log;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import static com.notificationFramework.sedentary.frontEnd.SaveFile.getPlaces;
/** /**
* Created by Peter De Jonckheere on 19/06/2018. * Created by Peter De Jonckheere on 19/06/2018.
*/ */
...@@ -69,7 +72,9 @@ public class DataAnalysis { ...@@ -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
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;
}
}
...@@ -298,14 +298,23 @@ public class SaveFile { ...@@ -298,14 +298,23 @@ public class SaveFile {
Context.MODE_PRIVATE); Context.MODE_PRIVATE);
double latitude = Double.longBitsToDouble(preferences.getLong(context.getString(R.string.store_lat), 0)); 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)); 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 = ""; 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; String line;
ArrayList<String> contents = new ArrayList<String>(); ArrayList<String> contents = new ArrayList<String>();
String writeLine = String.valueOf(latitude) + " " + String.valueOf(longitude) + " " + place String writeLine = String.valueOf(latitude) + " " + String.valueOf(longitude) + " " + places
+ " " + placeType + " " + String.valueOf(temperature); + String.valueOf(temperature);
if (isExternalStorageMounted()) { if (isExternalStorageMounted()) {
File dir = getDirectory(context); File dir = getDirectory(context);
File file = new File(dir, "DATALOG.txt"); File file = new File(dir, "DATALOG.txt");
...@@ -387,7 +396,7 @@ public class SaveFile { ...@@ -387,7 +396,7 @@ public class SaveFile {
+ String.valueOf(i), String.valueOf(place.getName())); + String.valueOf(i), String.valueOf(place.getName()));
editor.putInt(context.getString(R.string.store_place_type) editor.putInt(context.getString(R.string.store_place_type)
+ String.valueOf(i), place.getPlaceTypes().get(i)); + String.valueOf(i), place.getPlaceTypes().get(i));
} catch (NullPointerException e) { } catch (NullPointerException | IndexOutOfBoundsException e) {
} }
} }
...@@ -410,6 +419,41 @@ public class SaveFile { ...@@ -410,6 +419,41 @@ public class SaveFile {
context.startActivity(i); 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. * Checks if external storage is available on the device.
* *
......
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