Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Better handling of float/integer in preferences #503

Copy link
Copy link
@PerfectCarl

Description

@PerfectCarl
Issue body actions

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).

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.