k-9/src/com/fsck/k9/activity/ColorPickerDialog.java

69 lines
2.0 KiB
Java
Raw Normal View History

package com.fsck.k9.activity;
2013-01-17 02:57:49 -05:00
import com.fsck.k9.R;
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;
2013-01-17 02:57:49 -05:00
/**
* Dialog displaying a color picker.
*/
public class ColorPickerDialog extends AlertDialog {
2013-01-17 02:57:49 -05:00
/**
* The interface users of {@link ColorPickerDialog} have to implement to learn the selected
* color.
*/
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.
*/
void colorChanged(int color);
}
2013-01-17 02:57:49 -05:00
OnColorChangedListener mColorChangedListener;
ColorPicker mColorPicker;
public ColorPickerDialog(Context context, OnColorChangedListener listener, int color) {
super(context);
2013-01-17 02:57:49 -05:00
mColorChangedListener = listener;
2013-01-17 02:57:49 -05:00
View view = LayoutInflater.from(context).inflate(R.layout.color_picker_dialog, null);
2013-01-17 02:57:49 -05:00
mColorPicker = (ColorPicker) view.findViewById(R.id.color_picker);
mColorPicker.setColor(color);
2013-01-17 02:57:49 -05:00
setView(view);
2013-01-17 02:57:49 -05:00
setButton(BUTTON_POSITIVE, context.getString(R.string.okay_action),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
2013-01-17 02:57:49 -05:00
if (mColorChangedListener != null) {
mColorChangedListener.colorChanged(mColorPicker.getColor());
}
}
});
2013-01-17 02:57:49 -05:00
setButton(BUTTON_NEGATIVE, context.getString(R.string.cancel_action),
(OnClickListener) null);
}
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).
*/
public void setColor(int color) {
2013-01-17 02:57:49 -05:00
mColorPicker.setColor(color);
}
}