diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java index 6184c14246ec710a43614eca4ef34b4a16705250..d7bf75ab59fe265dddce8aa093ea9c466f52ec43 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/DataAnalysis.java @@ -68,4 +68,8 @@ public class DataAnalysis { editor.commit(); } + + private void placeAnalysis(){ + + } } \ No newline at end of file diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java index f135b127637d649a09e3bf9d91f5748b2c7fa2e9..8966aeec071f9d14729193c71dbb1cc66544b31e 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java @@ -15,6 +15,7 @@ import com.google.android.gms.awareness.snapshot.PlacesResponse; import com.google.android.gms.awareness.snapshot.WeatherResponse; import com.google.android.gms.awareness.state.Weather; import com.google.android.gms.common.api.GoogleApiClient; +import com.google.android.gms.location.places.Place; import com.google.android.gms.location.places.PlaceLikelihood; import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.RuntimeExecutionException; @@ -297,22 +298,14 @@ 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)); - Type type = new TypeToken<List<PlaceLikelihood>>(){}.getType(); - Gson gson = new Gson(); - String placelikelihood = preferences.getString(context.getString(R.string.store_place), ""); - List<PlaceLikelihood> placeLikelihoods = gson.fromJson(placelikelihood, type); + 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 line; ArrayList<String> contents = new ArrayList<String>(); - if(placeLikelihoods != null) { - for (PlaceLikelihood p : placeLikelihoods) { - places = places + " " + String.valueOf(p.getPlace().getName()) + " " - + String.valueOf(p.getLikelihood() + "\n"); - } - } - String writeLine = String.valueOf(latitude) + " " + String.valueOf(longitude) + " " + places - + String.valueOf(temperature); + String writeLine = String.valueOf(latitude) + " " + String.valueOf(longitude) + " " + place + + " " + placeType + " " + String.valueOf(temperature); if (isExternalStorageMounted()) { File dir = getDirectory(context); File file = new File(dir, "DATALOG.txt"); @@ -384,9 +377,20 @@ public class SaveFile { Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); List<PlaceLikelihood> placeLikelihoods = task.getResult().getPlaceLikelihoods(); - Gson gson = new Gson(); - editor.putString(context.getString(R.string.store_place), - gson.toJson(placeLikelihoods)); + for(int i = 0; i < 3; i++) { + try { + PlaceLikelihood placeLikelihood = placeLikelihoods.get(i); + Place place = placeLikelihood.getPlace(); + editor.putFloat(context.getString(R.string.store_place_like) + + String.valueOf(i), placeLikelihood.getLikelihood()); + editor.putString(context.getString(R.string.store_place) + + 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) { + + } + } editor.commit(); } }); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 6e69134ad39165be02eb76f4414e7df1b9cf749f..d94911b3bfd825d3db48b0898397a90eb0df652a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -51,6 +51,7 @@ <string name="store_lat">Latitude</string> <string name="store_long">Longitude</string> <string name="store_place">Place</string> - <string name="store_placelike">Place Likelihood</string> <string name="store_temp">Temperature</string> + <string name="store_place_type">Place Type</string> + <string name="store_place_like">Place Likelihood</string> </resources>