/** * Initialize the size, columns, and listener. Size should be a pre-defined size (SIZE_LARGE * or SIZE_SMALL) from ColorPickerDialogFragment. */ public void init(int size, int columns, OnColorSelectedListener listener) { mNumColumns = columns; Resources res = getResources(); if (size == ColorPickerDialog.SIZE_LARGE) { mSwatchLength = res.getDimensionPixelSize(R.dimen.color_swatch_large); mMarginSize = res.getDimensionPixelSize(R.dimen.color_swatch_margins_large); } else { mSwatchLength = res.getDimensionPixelSize(R.dimen.color_swatch_small); mMarginSize = res.getDimensionPixelSize(R.dimen.color_swatch_margins_small); } mOnColorSelectedListener = listener; mDescription = res.getString(R.string.color_swatch_description); mDescriptionSelected = res.getString(R.string.color_swatch_description_selected); }
/** * Initialize the size, columns, and listener. Size should be a pre-defined size (SIZE_LARGE * or SIZE_SMALL) from ColorPickerDialogFragment. */ public void init(int size, int columns, OnColorSelectedListener listener) { mNumColumns = columns; Resources res = getResources(); if (size == ColorPickerDialog.SIZE_LARGE) { mSwatchLength = res.getDimensionPixelSize(R.dimen.color_swatch_large); mMarginSize = res.getDimensionPixelSize(R.dimen.color_swatch_margins_large); } else { mSwatchLength = res.getDimensionPixelSize(R.dimen.color_swatch_small); mMarginSize = res.getDimensionPixelSize(R.dimen.color_swatch_margins_small); } mOnColorSelectedListener = listener; mDescription = res.getString(R.string.color_swatch_description); mDescriptionSelected = res.getString(R.string.color_swatch_description_selected); }
public void onGlobalLayout() { if (this.ignoreNextUpdate) { this.ignoreNextUpdate = false; return; } // Calculate number of swatches to display int swatchSize = ColorPreference.this.palette.getResources().getDimensionPixelSize(R.dimen.color_swatch_small); ColorPreference.this.palette.init(ColorPickerDialog.SIZE_SMALL, (view.getWidth() - (swatchSize * 2 / 3)) / swatchSize, ColorPreference.this); // Cause redraw and (by extension) also a layout recalculation this.ignoreNextUpdate = true; ColorPreference.this.drawPalette(); } });