Commit f412b4ed authored by Mattia Ducci's avatar Mattia Ducci

minor fixes e refactoring

parent 83f59424
...@@ -29,8 +29,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -29,8 +29,8 @@ public class MainActivity extends AppCompatActivity {
private Icarus instance; private Icarus instance;
private EditText eventNameEditText; private EditText eventNameEditText;
private EditText eventCategoryEditText; Switch eventCategorySwitch;
private EditText eventLabelEditText; Switch eventLabelSwitch;
private EditText mostProbableActivityEditText; private EditText mostProbableActivityEditText;
@Override @Override
...@@ -61,8 +61,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -61,8 +61,8 @@ public class MainActivity extends AppCompatActivity {
else intPrefSwitch.setChecked(true); else intPrefSwitch.setChecked(true);
eventNameEditText=findViewById(R.id.editText_eventName); eventNameEditText=findViewById(R.id.editText_eventName);
eventCategoryEditText=findViewById(R.id.editText_eventCategory); eventCategorySwitch=findViewById(R.id.event_category_switch);
eventLabelEditText=findViewById(R.id.editText_eventLabel); eventLabelSwitch=findViewById(R.id.event_label_switch);
mostProbableActivityEditText=findViewById(R.id.editText_mostProbableActivity); mostProbableActivityEditText=findViewById(R.id.editText_mostProbableActivity);
} }
...@@ -106,16 +106,18 @@ public class MainActivity extends AppCompatActivity { ...@@ -106,16 +106,18 @@ public class MainActivity extends AppCompatActivity {
Log.d(CLASS_NAME,"on btn track event"); Log.d(CLASS_NAME,"on btn track event");
String eventName,eventCategory,eventLabel,mostProbableActivity; String eventName,mostProbableActivity;
EventTrackResource.EventCategory eventCategory;
EventTrackResource.EventLabel eventLabel;
if(eventNameEditText.getText().length() == 0) eventName="eventoProva"; if(eventNameEditText.getText().length() == 0) eventName="eventoProva";
else eventName=eventNameEditText.getText().toString(); else eventName=eventNameEditText.getText().toString();
if(eventCategoryEditText.getText().length()==0) eventCategory=EventTrackResource.EventCategories.APPLICATION.name().toLowerCase(); if(!eventCategorySwitch.isChecked()) eventCategory=EventTrackResource.EventCategory.APPLICATION;
else eventCategory=eventCategoryEditText.getText().toString(); else eventCategory=EventTrackResource.EventCategory.ACTION;
if(eventLabelEditText.getText().length()==0) eventLabel = EventTrackResource.EventLabel.FOREGROUND.name().toLowerCase(); if(!eventLabelSwitch.isChecked()) eventLabel = EventTrackResource.EventLabel.FOREGROUND;
else eventLabel=eventLabelEditText.getText().toString(); else eventLabel=EventTrackResource.EventLabel.BACKGROUND;
if(mostProbableActivityEditText.getText().length()==0) mostProbableActivity="running"; if(mostProbableActivityEditText.getText().length()==0) mostProbableActivity="running";
else mostProbableActivity=mostProbableActivityEditText.getText().toString(); else mostProbableActivity=mostProbableActivityEditText.getText().toString();
......
...@@ -75,6 +75,14 @@ ...@@ -75,6 +75,14 @@
android:text="Invia pref changes" /> android:text="Invia pref changes" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Track event"
android:textColor="@android:color/holo_red_light"
android:textSize="24sp" />
<EditText <EditText
android:id="@+id/editText_eventName" android:id="@+id/editText_eventName"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -83,28 +91,35 @@ ...@@ -83,28 +91,35 @@
android:hint="event name" android:hint="event name"
android:inputType="textPersonName" /> android:inputType="textPersonName" />
<EditText <Switch
android:id="@+id/editText_eventCategory" android:id="@+id/event_category_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="18" android:showText="true"
android:hint="event category" android:splitTrack="false"
android:inputType="textPersonName" /> android:text="Event category"
android:textOff="application"
android:textOn="action"
android:textSize="18sp" />
<EditText <Switch
android:id="@+id/editText_eventLabel" android:id="@+id/event_label_switch"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="18" android:showText="true"
android:hint="event label" android:splitTrack="false"
android:inputType="textPersonName" /> android:text="Event label"
android:textOff="foreground"
android:textOn="background"
android:textSize="18sp" />
<EditText <EditText
android:id="@+id/editText_mostProbableActivity" android:id="@+id/editText_mostProbableActivity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ems="18" android:ems="18"
android:hint="most probable activity" android:hint="activity: walking or cycling. empty for running"
android:inputType="textPersonName" /> android:inputType="textPersonName" />
<Button <Button
......
...@@ -5,7 +5,22 @@ import org.json.JSONObject; ...@@ -5,7 +5,22 @@ import org.json.JSONObject;
public class EventTrackResource extends IcarusResource { public class EventTrackResource extends IcarusResource {
public enum EventCategories{ //categorie di evento //------------ JSON KEYS --------------------
private final static String CONFIDENCE_KEY="confidence";
private final static String START_TIMESTAMP_KEY="startTimestamp";
private final static String HEADING_KEY="heading";
private final static String COURSE_KEY="course";
private final static String SPEED_KEY="speed";
private final static String ACTIVITY_KEY="activity";
private final static String DIRECTION_KEY="direction";
private final static String EVENT_NAME_KEY="EventName";
private final static String EVENT_CATEGORY_KEY="EventCategory";
private final static String EVENT_LABEL_KEY="EventLabel";
private final static String EVENT_CONTEXT_KEY="EventContext";
//-----------------------------------------------------
public enum EventCategory{ //categorie di evento
APPLICATION,ACTION,NOTIFICATION; APPLICATION,ACTION,NOTIFICATION;
} }
...@@ -16,8 +31,8 @@ public class EventTrackResource extends IcarusResource { ...@@ -16,8 +31,8 @@ public class EventTrackResource extends IcarusResource {
} }
private String eventName; private String eventName;
private String eventCategory; private EventCategory eventCategory;
private String eventLabel; private EventLabel eventLabel;
private int heading; private int heading;
private int course; private int course;
...@@ -25,7 +40,7 @@ public class EventTrackResource extends IcarusResource { ...@@ -25,7 +40,7 @@ public class EventTrackResource extends IcarusResource {
//i due successivi attributi sono quelli ritornati dall'ActivityRecognition di Google che dev'essere implementata nell'app chiamante //i due successivi attributi sono quelli ritornati dall'ActivityRecognition di Google che dev'essere implementata nell'app chiamante
//convertiti da quelli di Google a quelli del server.. vedi iMoveAndroid per il metodo di mapping tra i valori ritornati da Google e quelli //convertiti da quelli di Google a quelli del server.. vedi iMoveAndroid per il metodo di mapping tra i valori ritornati da Google e quelli
//per il server di ewtech. Fare copia incolla del metodo in progetti futuri. Non lo metto qua perchè non ho accesso ai codici delle attività //per il server di ewtech. Fare copia incolla del metodo in progetti futuri. Non lo metto qua perchè da qua non ho accesso ai codici delle attività
//non avendo la dipendenza all'ActivityRecognition all'interno di questa libreria //non avendo la dipendenza all'ActivityRecognition all'interno di questa libreria
private String mostProbableUserActivityName; private String mostProbableUserActivityName;
private int confidence; private int confidence;
...@@ -34,7 +49,7 @@ public class EventTrackResource extends IcarusResource { ...@@ -34,7 +49,7 @@ public class EventTrackResource extends IcarusResource {
private String[] userActivityToTrack; private String[] userActivityToTrack;
public EventTrackResource(String _eventName, String _eventCategory, String _eventLabel, int _heading, int _course, int _speed, public EventTrackResource(String _eventName, EventCategory _eventCategory, EventLabel _eventLabel, int _heading, int _course, int _speed,
String _mostProbableUserActivityName, int _confidence, boolean _accessibilityEnabled){ String _mostProbableUserActivityName, int _confidence, boolean _accessibilityEnabled){
super(); super();
...@@ -66,8 +81,8 @@ public class EventTrackResource extends IcarusResource { ...@@ -66,8 +81,8 @@ public class EventTrackResource extends IcarusResource {
userActivityJSONObject.put(activityType,false); userActivityJSONObject.put(activityType,false);
} }
userActivityJSONObject.put("confidence",confidence); userActivityJSONObject.put(CONFIDENCE_KEY,confidence);
userActivityJSONObject.put("startTimestamp",System.currentTimeMillis()); userActivityJSONObject.put(START_TIMESTAMP_KEY,System.currentTimeMillis());
} catch (JSONException jsonException){ } catch (JSONException jsonException){
...@@ -78,8 +93,8 @@ public class EventTrackResource extends IcarusResource { ...@@ -78,8 +93,8 @@ public class EventTrackResource extends IcarusResource {
try { try {
directionJSONObject.put("heading",heading); //0..360 directionJSONObject.put(HEADING_KEY,heading); //0..360
directionJSONObject.put("course",course); //0..360 directionJSONObject.put(COURSE_KEY,course); //0..360
} catch (JSONException jsonException){ } catch (JSONException jsonException){
...@@ -90,9 +105,9 @@ public class EventTrackResource extends IcarusResource { ...@@ -90,9 +105,9 @@ public class EventTrackResource extends IcarusResource {
try { try {
eventContextJSONObject.put("speed",speed); eventContextJSONObject.put(SPEED_KEY,speed);
eventContextJSONObject.put("activity",userActivityJSONObject); eventContextJSONObject.put(ACTIVITY_KEY,userActivityJSONObject);
eventContextJSONObject.put("direction",directionJSONObject); eventContextJSONObject.put(DIRECTION_KEY,directionJSONObject);
} catch (JSONException jsonException){ } catch (JSONException jsonException){
...@@ -103,10 +118,10 @@ public class EventTrackResource extends IcarusResource { ...@@ -103,10 +118,10 @@ public class EventTrackResource extends IcarusResource {
try { try {
toSend.put("EventName",eventName); toSend.put(EVENT_NAME_KEY,eventName);
toSend.put("EventCategory",eventCategory); toSend.put(EVENT_CATEGORY_KEY,eventCategory.name().toLowerCase());
toSend.put("EventLabel",eventLabel+"_TalkBack"+(accessibilityEnabled?"_ON":"_OFF")); toSend.put(EVENT_LABEL_KEY,eventLabel.name().toLowerCase()+"_TalkBack"+(accessibilityEnabled?"_ON":"_OFF"));
toSend.put("EventContext",eventContextJSONObject); toSend.put(EVENT_CONTEXT_KEY,eventContextJSONObject);
} catch (JSONException jsonException){ } catch (JSONException jsonException){
......
...@@ -40,6 +40,25 @@ public class Icarus { ...@@ -40,6 +40,25 @@ public class Icarus {
private final static String ICARUS_URL="https://webdev.ewlab.di.unimi.it/icarus/str"; private final static String ICARUS_URL="https://webdev.ewlab.di.unimi.it/icarus/str";
//---------------- JSON KEYS ---------------------
private final static String UTC_KEY="utc";
private final static String USER_KEY="user";
private final static String LANG_KEY="lang";
private final static String ICARUS_VERSION_KEY="icarusversion";
private final static String APP_NAME_KEY="appname";
private final static String APP_VERSION_KEY="appversion";
private final static String OS_VERSION_KEY="osversion";
private final static String PLATFORM_KEY="platform";
private final static String DEVICE_KEY="device";
private final static String UUID_KEY="uuid";
private final static String TALKBACK_KEY="talkback";
private final static String DEBUG_KEY="debug";
private final static String TIMESTAMP_KEY="timestamp";
private final static String APP_DATA_KEY="appdata";
private final static String USER_DATA_KEY="userdata";
//------------------------------------------
private static final Icarus ourInstance = new Icarus(); private static final Icarus ourInstance = new Icarus();
private Queue<JSONObject> pendingResources; //FIFO private Queue<JSONObject> pendingResources; //FIFO
private Lock pendingResourceLock; private Lock pendingResourceLock;
...@@ -190,8 +209,8 @@ public class Icarus { ...@@ -190,8 +209,8 @@ public class Icarus {
long userTime=utcTime+timeOffsetBetweenMeAndGMT; long userTime=utcTime+timeOffsetBetweenMeAndGMT;
JSONObject timeJSON=new JSONObject(); JSONObject timeJSON=new JSONObject();
timeJSON.put("utc",utcTime); timeJSON.put(UTC_KEY,utcTime);
timeJSON.put("user",userTime); timeJSON.put(USER_KEY,userTime);
//---------------------- APP JSON --------------------- //---------------------- APP JSON ---------------------
...@@ -238,22 +257,22 @@ public class Icarus { ...@@ -238,22 +257,22 @@ public class Icarus {
} }
JSONObject appInfoJSON=new JSONObject(); JSONObject appInfoJSON=new JSONObject();
appInfoJSON.put("lang", Locale.getDefault().getLanguage()); appInfoJSON.put(LANG_KEY, Locale.getDefault().getLanguage());
appInfoJSON.put("icarusversion","Icarus:"+curContext.getResources().getInteger(R.integer.lib_version)); appInfoJSON.put(ICARUS_VERSION_KEY,"Icarus:"+curContext.getResources().getInteger(R.integer.lib_version));
appInfoJSON.put("appname",appName.toString()); appInfoJSON.put(APP_NAME_KEY,appName.toString());
appInfoJSON.put("appversion",clientAppVersion); appInfoJSON.put(APP_VERSION_KEY,clientAppVersion);
appInfoJSON.put("osversion", Build.VERSION.SDK_INT); appInfoJSON.put(OS_VERSION_KEY, Build.VERSION.SDK_INT);
appInfoJSON.put("platform","android"); appInfoJSON.put(PLATFORM_KEY,"android");
appInfoJSON.put("device",getDeviceName()); appInfoJSON.put(DEVICE_KEY,getDeviceName());
appInfoJSON.put("uuid",uuid); appInfoJSON.put(UUID_KEY,uuid);
appInfoJSON.put("talkback",accessibilityEnabled); appInfoJSON.put(TALKBACK_KEY,accessibilityEnabled);
//---------------- GENERAL JSON -------------------- //---------------- GENERAL JSON --------------------
toSend.put("debug",debug); toSend.put(DEBUG_KEY,debug);
toSend.put("timestamp",timeJSON); toSend.put(TIMESTAMP_KEY,timeJSON);
toSend.put("appdata",appInfoJSON); toSend.put(APP_DATA_KEY,appInfoJSON);
toSend.put("userdata",userData); toSend.put(USER_DATA_KEY,userData);
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -15,6 +15,12 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -15,6 +15,12 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
private final static String USER_SETTINGS_RES_CLASS="UserSettingsResource"; private final static String USER_SETTINGS_RES_CLASS="UserSettingsResource";
//--------------- JSON KEYS -------------------------
private final static String OLD_KEY="old";
private final static String NEW_KEY="new";
private final static String ACCESSIBILITY_COLOR_INVERSION_ENABLED_KEY="accessibility_color_inversion_enabled";
private final static String FONT_SIZE_KEY="font_size";
private Map<String,String> prefsOldNew; //il secondo String è in realtà un JSONObject convertito in String private Map<String,String> prefsOldNew; //il secondo String è in realtà un JSONObject convertito in String
private SharedPreferences callerSharedPrefs; private SharedPreferences callerSharedPrefs;
private Context c; private Context c;
...@@ -35,31 +41,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -35,31 +41,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
try { try {
if (callerSharedPrefs.contains(prefName + "_old")) { //se ho già toccato quella pref in passato if (callerSharedPrefs.contains(prefName + "_"+OLD_KEY)) { //se ho già toccato quella pref in passato
boolean oldValue=callerSharedPrefs.getBoolean(prefName+"_old",false); boolean oldValue=callerSharedPrefs.getBoolean(prefName+"_"+OLD_KEY,false);
if(oldValue!=newValue){ if(oldValue!=newValue){
jsonObject.put("old", oldValue); jsonObject.put(OLD_KEY, oldValue);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putBoolean(prefName+"_old",newValue); editor.putBoolean(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
} else { //se è la prima volta che l'utente tocca quella pref } else { //se è la prima volta che l'utente tocca quella pref
jsonObject.put("old", null); //TODO: valutare se mettere null come "null" perchè se no nel JSON è come non mettere questo campo, non me lo mette proprio jsonObject.put(OLD_KEY, null); //TODO: valutare se mettere null come "null" perchè se no nel JSON è come non mettere questo campo, non me lo mette proprio
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putBoolean(prefName+"_old",newValue); editor.putBoolean(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
...@@ -73,31 +79,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -73,31 +79,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
try { try {
if (callerSharedPrefs.contains(prefName + "_old")) { if (callerSharedPrefs.contains(prefName + "_"+OLD_KEY)) {
int oldValue=callerSharedPrefs.getInt(prefName+"_old",-1); int oldValue=callerSharedPrefs.getInt(prefName+"_"+OLD_KEY,-1);
if(oldValue!=newValue){ if(oldValue!=newValue){
jsonObject.put("old", oldValue); jsonObject.put(OLD_KEY, oldValue);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putInt(prefName+"_old",newValue); editor.putInt(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
} else { //se è la prima volta che l'utente tocca quella pref } else { //se è la prima volta che l'utente tocca quella pref
jsonObject.put("old", null); jsonObject.put(OLD_KEY, null);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putInt(prefName+"_old",newValue); editor.putInt(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
...@@ -111,31 +117,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -111,31 +117,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
try { try {
if (callerSharedPrefs.contains(prefName + "_old")) { if (callerSharedPrefs.contains(prefName + "_"+OLD_KEY)) {
float oldValue=callerSharedPrefs.getFloat(prefName+"_old",-1); float oldValue=callerSharedPrefs.getFloat(prefName+"_"+OLD_KEY,-1);
if(oldValue!=newValue){ if(oldValue!=newValue){
jsonObject.put("old", oldValue); jsonObject.put(OLD_KEY, oldValue);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putFloat(prefName+"_old",newValue); editor.putFloat(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
} else { //se è la prima volta che l'utente tocca quella pref } else { //se è la prima volta che l'utente tocca quella pref
jsonObject.put("old", null); jsonObject.put(OLD_KEY, null);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putFloat(prefName+"_old",newValue); editor.putFloat(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
...@@ -149,31 +155,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -149,31 +155,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
try { try {
if (callerSharedPrefs.contains(prefName + "_old")) { if (callerSharedPrefs.contains(prefName + "_"+OLD_KEY)) {
long oldValue=callerSharedPrefs.getLong(prefName+"_old",-1); long oldValue=callerSharedPrefs.getLong(prefName+"_"+OLD_KEY,-1);
if(oldValue!=newValue){ if(oldValue!=newValue){
jsonObject.put("old", oldValue); jsonObject.put(OLD_KEY, oldValue);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putFloat(prefName+"_old",newValue); editor.putFloat(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
} else { //se è la prima volta che l'utente tocca quella pref } else { //se è la prima volta che l'utente tocca quella pref
jsonObject.put("old", null); jsonObject.put(OLD_KEY, null);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putFloat(prefName+"_old",newValue); editor.putFloat(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
...@@ -187,31 +193,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -187,31 +193,31 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
try { try {
if (callerSharedPrefs.contains(prefName + "_old")) { if (callerSharedPrefs.contains(prefName + "_"+OLD_KEY)) {
String oldValue=callerSharedPrefs.getString(prefName+"_old",""); String oldValue=callerSharedPrefs.getString(prefName+"_"+OLD_KEY,"");
if(!oldValue.equals(newValue)){ if(!oldValue.equals(newValue)){
jsonObject.put("old", oldValue); jsonObject.put(OLD_KEY, oldValue);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putString(prefName+"_old",newValue); editor.putString(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
} else { //se è la prima volta che l'utente tocca quella pref } else { //se è la prima volta che l'utente tocca quella pref
jsonObject.put("old", null); jsonObject.put(OLD_KEY, null);
jsonObject.put("new",newValue); jsonObject.put(NEW_KEY,newValue);
prefsOldNew.put(prefName,jsonObject.toString()); prefsOldNew.put(prefName,jsonObject.toString());
//update shared preferences dell'app chiamante //update shared preferences dell'app chiamante
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putString(prefName+"_old",newValue); editor.putString(prefName+"_"+OLD_KEY,newValue);
editor.apply(); //apply aggiorna le prefs in bg editor.apply(); //apply aggiorna le prefs in bg
} }
...@@ -237,17 +243,17 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -237,17 +243,17 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
try{ try{
accessibilityDisplayColorInversionEnabled=Settings.Secure.getInt(c.getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED); accessibilityDisplayColorInversionEnabled=Settings.Secure.getInt(c.getContentResolver(), Settings.Secure.ACCESSIBILITY_DISPLAY_INVERSION_ENABLED);
int oldAccessibilityDisplayColorInversion=callerSharedPrefs.getInt("accessibility_color_inversion_enabled",-1); int oldAccessibilityDisplayColorInversion=callerSharedPrefs.getInt(ACCESSIBILITY_COLOR_INVERSION_ENABLED_KEY,-1);
if(oldAccessibilityDisplayColorInversion!=accessibilityDisplayColorInversionEnabled){ if(oldAccessibilityDisplayColorInversion!=accessibilityDisplayColorInversionEnabled){
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
jsonObject.put("old",oldAccessibilityDisplayColorInversion); jsonObject.put(OLD_KEY,oldAccessibilityDisplayColorInversion);
jsonObject.put("new",accessibilityDisplayColorInversionEnabled); jsonObject.put(NEW_KEY,accessibilityDisplayColorInversionEnabled);
prefsOldNew.put("accessibility_color_inversion_enabled",jsonObject.toString()); prefsOldNew.put(ACCESSIBILITY_COLOR_INVERSION_ENABLED_KEY,jsonObject.toString());
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putInt("accessibility_color_inversion_enabled",accessibilityDisplayColorInversionEnabled); editor.putInt(ACCESSIBILITY_COLOR_INVERSION_ENABLED_KEY,accessibilityDisplayColorInversionEnabled);
editor.apply(); editor.apply();
} }
...@@ -263,17 +269,17 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria ...@@ -263,17 +269,17 @@ public class UserSettingsResource extends IcarusResource { //classe da non seria
try { try {
fontSize=Settings.System.getFloat(c.getContentResolver(), Settings.System.FONT_SCALE); fontSize=Settings.System.getFloat(c.getContentResolver(), Settings.System.FONT_SCALE);
float oldFontSize=callerSharedPrefs.getFloat("font_size",-1); float oldFontSize=callerSharedPrefs.getFloat(FONT_SIZE_KEY,-1);
if(oldFontSize!=fontSize){ //se dall'ultimo aggiornamento delle pref è cambiato if(oldFontSize!=fontSize){ //se dall'ultimo aggiornamento delle pref è cambiato
JSONObject jsonObject=new JSONObject(); JSONObject jsonObject=new JSONObject();
jsonObject.put("old",oldFontSize); jsonObject.put(OLD_KEY,oldFontSize);
jsonObject.put("new",fontSize); jsonObject.put(NEW_KEY,fontSize);
prefsOldNew.put("font_size",jsonObject.toString()); prefsOldNew.put(FONT_SIZE_KEY,jsonObject.toString());
SharedPreferences.Editor editor=callerSharedPrefs.edit(); SharedPreferences.Editor editor=callerSharedPrefs.edit();
editor.putFloat("font_size",fontSize); editor.putFloat(FONT_SIZE_KEY,fontSize);
editor.apply(); editor.apply();
} }
} catch (Settings.SettingNotFoundException e){ } catch (Settings.SettingNotFoundException e){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment