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

org.solovyev.android.prefs.NumberIntervalPreference 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.interval.Interval;
import org.solovyev.common.text.Mapper;
import org.solovyev.common.text.NumberIntervalMapper;

/**
 * User: serso
 * Date: 8/8/12
 * Time: 11:53 PM
 */
public class NumberIntervalPreference> extends AbstractPreference> {

    @NotNull
    private final Mapper> mapper;

    public NumberIntervalPreference(@NotNull String key, @Nullable Interval defaultValue, @NotNull Class clazz) {
        super(key, defaultValue);
        this.mapper = new NumberIntervalMapper(clazz);

    }

    @Override
    protected Interval getPersistedValue(@NotNull SharedPreferences preferences) {
        final String result = preferences.getString(getKey(), null);
        if ( result == null ) {
            return null;
        } else {
            return mapper.parseValue(result);
        }
    }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy