Hello,
I'm using the @PREF annotations along with PreferenceFragment so that the built-in preference UI can publish my AA generated preferences.
It works great with string/checkbox pref (edited with : EditTextPreference / CheckBoxPreference), but there is an issue with a number (int or float).
I use a this declaration to publish my float preference :
<EditTextPreference
android:key="listMaxSpeed"
android:numeric="integer"
android:title="Max speed for list" />
When I update the value and try to use it with the Pref_ class, I get this error :
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Float
at android.app.SharedPreferencesImpl.getFloat(SharedPreferencesImpl.java:254)
at com.googlecode.androidannotations.api.sharedpreferences.FloatPrefField.getOr(FloatPrefField.java:34)
The reason is EditTextPreference convert the value to string which is not very smart.
Of course, the Pref_ class expects a float (and rightfully so).
Would it possible to add this use case when doing :
public float getOr(float defaultValue) {
return sharedPreferences.getFloat(key, defaultValue);
}
... and add a conversion from string to float if the value has been converted to a string by the (stupid) preference UI ?
Note : I can provide a patch (and tests).