FileDocCategorySizeDatePackage
ColorPickerDialog.javaAPI DocAndroid 5.1 API6422Thu Mar 12 22:22:50 GMT 2015com.android.colorpicker

ColorPickerDialog

public class ColorPickerDialog extends android.app.DialogFragment implements com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener
A dialog which takes in as input an array of colors and creates a palette allowing the user to select a specific color swatch, which invokes a listener.

Fields Summary
public static final int
SIZE_LARGE
public static final int
SIZE_SMALL
protected android.app.AlertDialog
mAlertDialog
protected static final String
KEY_TITLE_ID
protected static final String
KEY_COLORS
protected static final String
KEY_SELECTED_COLOR
protected static final String
KEY_COLUMNS
protected static final String
KEY_SIZE
protected int
mTitleResId
protected int[]
mColors
protected int
mSelectedColor
protected int
mColumns
protected int
mSize
private ColorPickerPalette
mPalette
private android.widget.ProgressBar
mProgress
protected com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener
mListener
Constructors Summary
public ColorPickerDialog()


      
        // Empty constructor required for dialog fragments.
    
Methods Summary
public int[]getColors()

        return mColors;
    
public intgetSelectedColor()

        return mSelectedColor;
    
public voidinitialize(int titleResId, int[] colors, int selectedColor, int columns, int size)

        setArguments(titleResId, columns, size);
        setColors(colors, selectedColor);
    
public static com.android.colorpicker.ColorPickerDialognewInstance(int titleResId, int[] colors, int selectedColor, int columns, int size)

        ColorPickerDialog ret = new ColorPickerDialog();
        ret.initialize(titleResId, colors, selectedColor, columns, size);
        return ret;
    
public voidonColorSelected(int color)

        if (mListener != null) {
            mListener.onColorSelected(color);
        }

        if (getTargetFragment() instanceof OnColorSelectedListener) {
            final OnColorSelectedListener listener =
                    (OnColorSelectedListener) getTargetFragment();
            listener.onColorSelected(color);
        }

        if (color != mSelectedColor) {
            mSelectedColor = color;
            // Redraw palette to show checkmark on newly selected color before dismissing.
            mPalette.drawPalette(mColors, mSelectedColor);
        }

        dismiss();
    
public voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);

        if (getArguments() != null) {
            mTitleResId = getArguments().getInt(KEY_TITLE_ID);
            mColumns = getArguments().getInt(KEY_COLUMNS);
            mSize = getArguments().getInt(KEY_SIZE);
        }

        if (savedInstanceState != null) {
            mColors = savedInstanceState.getIntArray(KEY_COLORS);
            mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR);
        }
    
public android.app.DialogonCreateDialog(android.os.Bundle savedInstanceState)

        final Activity activity = getActivity();

        View view = LayoutInflater.from(getActivity()).inflate(R.layout.color_picker_dialog, null);
        mProgress = (ProgressBar) view.findViewById(android.R.id.progress);
        mPalette = (ColorPickerPalette) view.findViewById(R.id.color_picker);
        mPalette.init(mSize, mColumns, this);

        if (mColors != null) {
            showPaletteView();
        }

        mAlertDialog = new AlertDialog.Builder(activity)
            .setTitle(mTitleResId)
            .setView(view)
            .create();

        return mAlertDialog;
    
public voidonSaveInstanceState(android.os.Bundle outState)

        super.onSaveInstanceState(outState);
        outState.putIntArray(KEY_COLORS, mColors);
        outState.putSerializable(KEY_SELECTED_COLOR, mSelectedColor);
    
private voidrefreshPalette()

        if (mPalette != null && mColors != null) {
            mPalette.drawPalette(mColors, mSelectedColor);
        }
    
public voidsetArguments(int titleResId, int columns, int size)

        Bundle bundle = new Bundle();
        bundle.putInt(KEY_TITLE_ID, titleResId);
        bundle.putInt(KEY_COLUMNS, columns);
        bundle.putInt(KEY_SIZE, size);
        setArguments(bundle);
    
public voidsetColors(int[] colors, int selectedColor)

        if (mColors != colors || mSelectedColor != selectedColor) {
            mColors = colors;
            mSelectedColor = selectedColor;
            refreshPalette();
        }
    
public voidsetColors(int[] colors)

        if (mColors != colors) {
            mColors = colors;
            refreshPalette();
        }
    
public voidsetOnColorSelectedListener(com.android.colorpicker.ColorPickerSwatch.OnColorSelectedListener listener)

        mListener = listener;
    
public voidsetSelectedColor(int color)

        if (mSelectedColor != color) {
            mSelectedColor = color;
            refreshPalette();
        }
    
public voidshowPaletteView()

        if (mProgress != null && mPalette != null) {
            mProgress.setVisibility(View.GONE);
            refreshPalette();
            mPalette.setVisibility(View.VISIBLE);
        }
    
public voidshowProgressBarView()

        if (mProgress != null && mPalette != null) {
            mProgress.setVisibility(View.VISIBLE);
            mPalette.setVisibility(View.GONE);
        }