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

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

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

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.view.Picker;
import org.solovyev.common.text.Mapper;

/**
 * User: serso
 * Date: 8/10/12
 * Time: 1:58 AM
 */
public abstract class AbstractPickerDialogPreference extends AbstractDialogPreference implements Picker.OnChangedListener {


    protected AbstractPickerDialogPreference(Context context,
                                             AttributeSet attrs,
                                             @Nullable String defaultStringValue,
                                             boolean needValueText,
                                             @NotNull Mapper mapper) {
        super(context, attrs, defaultStringValue, needValueText, mapper);
    }

    @Override
    protected LinearLayout.LayoutParams getParams() {
        final LinearLayout.LayoutParams result = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        result.gravity = Gravity.CENTER;

        return result;
    }

    @NotNull
    @Override
    protected View createPreferenceView(@NotNull Context context) {
        final Picker result = new Picker(context);

        result.setOnChangeListener(this);

        return result;
    }

    @Override
    protected void initPreferenceView(@NotNull View v, @Nullable T value) {
        if (value != null) {
            ((Picker) v).setRange(createRange(value));
        }
    }

    @NotNull
    protected abstract Picker.Range createRange(@NotNull T selected);

    @Override
    public void onChanged(@NotNull Picker picker, @NotNull T o) {
        persistValue(o);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy