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

org.solovyev.android.prefs.AbstractEnumPickerDialogPreference 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 org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.solovyev.android.Labeled;
import org.solovyev.android.LabeledFormatter;
import org.solovyev.android.view.ListRange;
import org.solovyev.android.view.Picker;
import org.solovyev.common.text.EnumMapper;

import java.util.Arrays;

/**
 * User: serso
 * Date: 8/10/12
 * Time: 2:02 AM
 */
public abstract class AbstractEnumPickerDialogPreference extends AbstractPickerDialogPreference {

    @NotNull
    private final Class enumClass;

    protected AbstractEnumPickerDialogPreference(Context context,
                                                 AttributeSet attrs,
                                                 @Nullable String defaultStringValue,
                                                 boolean needValueText,
                                                 @NotNull Class enumClass) {
        super(context, attrs, defaultStringValue, needValueText, new EnumMapper(enumClass));
        this.enumClass = enumClass;
    }

    @NotNull
    @Override
    protected Picker.Range createRange(@NotNull T selected) {
        return new ListRange(Arrays.asList(enumClass.getEnumConstants()), selected, new LabeledFormatter(getContext()));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy