Skip to content

Commit 2e29ab0

Browse files
committed
Merge branch 'PerfectCarl_develop' into develop
2 parents f370cdc + c4c4c7c commit 2e29ab0

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/sharedpreferences/FloatPrefField.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ public float get() {
3131
}
3232

3333
public float getOr(float defaultValue) {
34-
return sharedPreferences.getFloat(key, defaultValue);
34+
try {
35+
return sharedPreferences.getFloat(key, defaultValue);
36+
} catch (ClassCastException e) {
37+
// The pref could be a String, if that is the case try this
38+
// recovery bit
39+
try {
40+
String value = sharedPreferences.getString(key, "" + defaultValue);
41+
return Float.parseFloat(value);
42+
} catch (Exception e2) {
43+
// our recovery bit failed. The problem is elsewhere. Send the original error
44+
throw e;
45+
}
46+
}
47+
3548
}
3649

3750
public void put(float value) {

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/sharedpreferences/IntPrefField.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ public int get() {
3131
}
3232

3333
public int getOr(int defaultValue) {
34-
return sharedPreferences.getInt(key, defaultValue);
34+
try {
35+
return sharedPreferences.getInt(key, defaultValue);
36+
} catch (ClassCastException e) {
37+
// The pref could be a String, if that is the case try this
38+
// recovery bit
39+
try {
40+
String value = sharedPreferences.getString(key, "" + defaultValue);
41+
return Integer.parseInt(value);
42+
} catch (Exception e2) {
43+
// our recovery bit failed. The problem is elsewhere. Send the original error
44+
throw e;
45+
}
46+
}
47+
3548
}
3649

3750
public void put(int value) {

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/api/sharedpreferences/LongPrefField.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ public long get() {
3131
}
3232

3333
public long getOr(long defaultValue) {
34-
return sharedPreferences.getLong(key, defaultValue);
34+
try {
35+
return sharedPreferences.getLong(key, defaultValue);
36+
} catch (ClassCastException e) {
37+
// The pref could be a String, if that is the case try this
38+
// recovery bit
39+
try {
40+
String value = sharedPreferences.getString(key, "" + defaultValue);
41+
return Long.parseLong(value);
42+
} catch (Exception e2) {
43+
// our recovery bit failed. The problem is elsewhere. Send the original error
44+
throw e;
45+
}
46+
}
3547
}
3648

3749
public void put(long value) {

0 commit comments

Comments
 (0)