All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.solovyev.android.prefs.NumberToStringPreference Maven / Gradle / Ivy

There is a newer version: 1.1.18
Show newest version
package org.solovyev.android.prefs;

import android.content.SharedPreferences;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.common.text.Mapper;
import org.solovyev.common.text.NumberMapper;

/**
 * User: serso
 * Date: 4/23/12
 * Time: 1:07 AM
 */
public class NumberToStringPreference extends AbstractPreference {

    @NotNull
    private final Mapper mapper;

    public NumberToStringPreference(@NotNull String key, @Nullable N defaultValue, @NotNull Class clazz) {
        super(key, defaultValue);

        this.mapper = new NumberMapper(clazz);
    }

    @Override
    protected N getPersistedValue(@NotNull SharedPreferences preferences) {
        return mapper.parseValue(preferences.getString(getKey(), "0"));
    }

    @Override
    protected void putPersistedValue(@NotNull SharedPreferences.Editor editor, @NotNull N value) {
        editor.putString(getKey(), mapper.formatValue(value));
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy