2010-11-07 21:21:32 -05:00
|
|
|
package com.fsck.k9.activity;
|
2013-01-17 02:57:49 -05:00
|
|
|
|
2010-05-19 14:17:06 -04:00
|
|
|
import com.fsck.k9.R;
|
2010-11-07 21:21:32 -05:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.*;
|
2013-01-17 02:57:49 -05:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.View;
|
2010-12-12 19:18:00 -05:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
import com.larswerkman.colorpicker.ColorPicker;
|
2010-11-07 21:21:32 -05:00
|
|
|
|
2012-06-08 19:28:43 -04:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
/**
|
|
|
|
* Dialog displaying a color picker.
|
|
|
|
*/
|
|
|
|
public class ColorPickerDialog extends AlertDialog {
|
2012-06-08 19:28:43 -04:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
/**
|
|
|
|
* The interface users of {@link ColorPickerDialog} have to implement to learn the selected
|
|
|
|
* color.
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public interface OnColorChangedListener {
|
2013-01-17 02:57:49 -05:00
|
|
|
/**
|
|
|
|
* This is called after the user pressed the "OK" button of the dialog.
|
|
|
|
*
|
|
|
|
* @param color
|
|
|
|
* The ARGB value of the selected color.
|
|
|
|
*/
|
2010-04-25 04:46:37 -04:00
|
|
|
void colorChanged(int color);
|
|
|
|
}
|
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
OnColorChangedListener mColorChangedListener;
|
|
|
|
ColorPicker mColorPicker;
|
2010-11-07 21:21:32 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public ColorPickerDialog(Context context, OnColorChangedListener listener, int color) {
|
2012-06-08 19:28:43 -04:00
|
|
|
super(context);
|
2013-01-17 02:57:49 -05:00
|
|
|
mColorChangedListener = listener;
|
2010-11-07 21:21:32 -05:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
View view = LayoutInflater.from(context).inflate(R.layout.color_picker_dialog, null);
|
2010-04-25 04:46:37 -04:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
mColorPicker = (ColorPicker) view.findViewById(R.id.color_picker);
|
|
|
|
mColorPicker.setColor(color);
|
2010-04-25 04:46:37 -04:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
setView(view);
|
2010-04-25 04:46:37 -04:00
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
setButton(BUTTON_POSITIVE, context.getString(R.string.okay_action),
|
2012-06-08 19:28:43 -04:00
|
|
|
new DialogInterface.OnClickListener() {
|
2010-11-07 21:21:32 -05:00
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2013-01-17 02:57:49 -05:00
|
|
|
if (mColorChangedListener != null) {
|
|
|
|
mColorChangedListener.colorChanged(mColorPicker.getColor());
|
2010-11-07 21:21:32 -05:00
|
|
|
}
|
2010-04-25 04:46:37 -04:00
|
|
|
}
|
2012-06-08 19:28:43 -04:00
|
|
|
});
|
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
setButton(BUTTON_NEGATIVE, context.getString(R.string.cancel_action),
|
|
|
|
(OnClickListener) null);
|
2012-06-08 19:28:43 -04:00
|
|
|
}
|
|
|
|
|
2013-01-17 02:57:49 -05:00
|
|
|
/**
|
|
|
|
* Set the color the color picker should highlight as selected color.
|
|
|
|
*
|
|
|
|
* @param color
|
|
|
|
* The (A)RGB value of a color (the alpha channel will be ignored).
|
|
|
|
*/
|
2012-06-08 19:28:43 -04:00
|
|
|
public void setColor(int color) {
|
2013-01-17 02:57:49 -05:00
|
|
|
mColorPicker.setColor(color);
|
2010-11-07 21:21:32 -05:00
|
|
|
}
|
2010-04-25 04:46:37 -04:00
|
|
|
}
|