From cd88dcdcf161452587a4f4c64050ac697c292874 Mon Sep 17 00:00:00 2001 From: Peter De Jonckheere <peter.de-jonckheere.2014@uni.strath.ac.uk> Date: Thu, 5 Jul 2018 15:59:17 +0100 Subject: [PATCH] status error code 7503 needs to be resolved from awareness api --- src/main/AndroidManifest.xml | 4 +++ .../sedentary/frontEnd/SaveFile.java | 19 ++++++++----- .../stimulus/SedentaryStimulus.java | 9 ++++--- .../stimulusStrategy/SigMotionDetect.java | 27 +------------------ 4 files changed, 24 insertions(+), 35 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index d83a033..07a4247 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -9,6 +9,7 @@ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> + <uses-permission android:name="android.permission.INTERNET"/> <application android:allowBackup="true" @@ -20,6 +21,9 @@ <meta-data android:name="com.google.android.awareness.API_KEY" android:value="AIzaSyDqliqBcEQQAvMZR-RengdLUJaAYeRKbgs"/> + <meta-data + android:name="com.google.android.gms.version" + android:value="@integer/google_play_services_version" /> <activity android:name="com.notificationFramework.sedentary.frontEnd.MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> diff --git a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java index 35cc69e..b21cb87 100644 --- a/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java +++ b/src/main/java/com/notificationFramework/sedentary/frontEnd/SaveFile.java @@ -8,6 +8,7 @@ import android.support.annotation.NonNull; import android.util.Log; import com.google.android.gms.awareness.Awareness; +import com.google.android.gms.awareness.AwarenessStatusCodes; import com.google.android.gms.awareness.snapshot.LocationResponse; import com.google.android.gms.awareness.snapshot.PlacesResponse; import com.google.android.gms.awareness.snapshot.WeatherResponse; @@ -15,6 +16,7 @@ import com.google.android.gms.awareness.state.Weather; import com.google.android.gms.common.api.GoogleApiClient; import com.google.android.gms.location.places.PlaceLikelihood; import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.RuntimeExecutionException; import com.google.android.gms.tasks.Task; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -302,11 +304,12 @@ public class SaveFile { String places = ""; String line; ArrayList<String> contents = new ArrayList<String>(); - for (PlaceLikelihood p : placeLikelihoods) { - places = places + " " + String.valueOf(p.getPlace().getName()) + " " - + String.valueOf(p.getLikelihood() + "\n"); + 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); if (isExternalStorageMounted()) { @@ -361,8 +364,12 @@ public class SaveFile { SharedPreferences preferences = context.getSharedPreferences(context.getString(R.string.preference_file_key), Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); - editor.putLong(context.getString(R.string.store_lat),Double.doubleToLongBits(task.getResult().getLocation().getLatitude())); - editor.putLong(context.getString(R.string.store_long),Double.doubleToLongBits(task.getResult().getLocation().getLongitude())); + try { + editor.putLong(context.getString(R.string.store_lat), Double.doubleToLongBits(task.getResult().getLocation().getLatitude())); + editor.putLong(context.getString(R.string.store_long), Double.doubleToLongBits(task.getResult().getLocation().getLongitude())); + }catch(RuntimeExecutionException e){ + Log.d("ERROR", e.getMessage()); + } editor.commit(); } diff --git a/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java b/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java index ba174c5..d3cad58 100644 --- a/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java +++ b/src/main/java/com/notificationFramework/stimulus/SedentaryStimulus.java @@ -159,9 +159,12 @@ public class SedentaryStimulus extends BroadcastReceiver implements Stimulus { //Returns true if notification is to be sent private boolean checkAcknowledged(SharedPreferences shared, Context context){ int period = shared.getInt(context.getString(R.string.daily_goal), context.getResources().getInteger(R.integer.daily_goal_minutes)); - float ackThreshold = (24/period) * threshold; - float avgAck = shared.getFloat(context.getString(R.string.avg_ack), 4); - if(avgAck < ackThreshold){ + float ackThreshold = (24/period); + ackThreshold = ackThreshold * threshold; + Log.d("AVGTHRESH", String.valueOf(ackThreshold)); + float avgAck = shared.getFloat(context.getString(R.string.avg_ack), 0); + Log.d("AVGACK", String.valueOf(avgAck)); + if(avgAck > ackThreshold){ Intent i = new Intent(context.getApplicationContext(), com.notificationFramework.stimulus.FeedbackStimulus.class); LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context.getApplicationContext()); diff --git a/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java b/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java index 964ed7d..96251c6 100644 --- a/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java +++ b/src/main/java/com/notificationFramework/stimulusStrategy/SigMotionDetect.java @@ -163,7 +163,6 @@ public class SigMotionDetect extends Service implements StimulusStrategy { R.integer.alarm_rc, i, 0); am.cancel(pi); SaveFile.recordNotification(0, 0, 1, 0, this); - getExtraData(); setUpClock(); prevSeconds = seconds; } @@ -268,31 +267,7 @@ public class SigMotionDetect extends Service implements StimulusStrategy { lbm.sendBroadcast(i); } - private void getExtraData(){ - SharedPreferences preferences = this.getSharedPreferences(getString( - R.string.preference_file_key), Context.MODE_PRIVATE); - try { - double latitude = Awareness.getSnapshotClient(this).getLocation() - .getResult().getLocation().getLatitude(); - double longitude = Awareness.getSnapshotClient(this).getLocation() - .getResult().getLocation().getLongitude(); - List<PlaceLikelihood> placeLikelihoods = Awareness.getSnapshotClient(this) - .getPlaces().getResult().getPlaceLikelihoods(); - Weather weather = Awareness.getSnapshotClient(this).getWeather().getResult() - .getWeather(); - SharedPreferences.Editor editor = preferences.edit(); - editor.putLong(this.getString(R.string.store_lat),Double.doubleToLongBits(latitude)); - editor.putLong(this.getString(R.string.store_long),Double.doubleToLongBits(longitude)); - editor.putString(this.getString(R.string.store_place), String.valueOf(placeLikelihoods.get(0).getPlace().getName())); - editor.putFloat(this.getString(R.string.store_placelike), placeLikelihoods.get(0).getLikelihood()); - editor.putFloat(this.getString(R.string.store_temp),weather.getTemperature(Weather.CELSIUS)); - editor.commit(); - SaveFile.recordData(latitude, longitude, placeLikelihoods, weather, this); - }catch(SecurityException e){ - Intent i = new Intent(this, RequestPermission.class); - startActivity(i); - } - } + /** * The method which reponds to a bind request for this service. -- GitLab