@Override protected void onPrepareDialogBuilder(Builder builder) { mController = ColorPickerDialog.Controller.applyToDialogBuilder(builder); mController.setAlphaEnabled(mAlphaSliderEnabled); final Resources res = builder.getContext().getResources(); for (int presetColor : PRESET_COLORS) { mController.addColor(res.getColor(presetColor)); } mController.setInitialColor(getValue()); builder.setPositiveButton(res.getString(android.R.string.ok), this); builder.setNegativeButton(res.getString(android.R.string.cancel), this); }
@Override public void onClick(final DialogInterface dialog, final int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: if (mController == null) return; final int color = mController.getColor(); if (isPersistent()) { persistInt(color); } final OnPreferenceChangeListener listener = getOnPreferenceChangeListener(); if (listener != null) { listener.onPreferenceChange(this, color); } break; } }