This source file includes following definitions.
- init
- onColorSuggestionClick
package org.chromium.ui;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.ListView;
import org.chromium.ui.ColorSuggestionListAdapter.OnColorSuggestionClickListener;
public class ColorPickerSimple extends ListView implements OnColorSuggestionClickListener {
private OnColorChangedListener mOnColorChangedListener;
private static final int[] DEFAULT_COLORS = {
Color.RED,
Color.CYAN,
Color.BLUE,
Color.GREEN,
Color.MAGENTA,
Color.YELLOW,
Color.BLACK,
Color.WHITE
};
private static final int[] DEFAULT_COLOR_LABEL_IDS = {
R.string.color_picker_button_red,
R.string.color_picker_button_cyan,
R.string.color_picker_button_blue,
R.string.color_picker_button_green,
R.string.color_picker_button_magenta,
R.string.color_picker_button_yellow,
R.string.color_picker_button_black,
R.string.color_picker_button_white
};
public ColorPickerSimple(Context context) {
super(context);
}
public ColorPickerSimple(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ColorPickerSimple(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void init(ColorSuggestion[] suggestions,
OnColorChangedListener onColorChangedListener) {
mOnColorChangedListener = onColorChangedListener;
if (suggestions == null) {
suggestions = new ColorSuggestion[DEFAULT_COLORS.length];
for (int i = 0; i < suggestions.length; ++i) {
suggestions[i] = new ColorSuggestion(DEFAULT_COLORS[i],
getContext().getString(DEFAULT_COLOR_LABEL_IDS[i]));
}
}
ColorSuggestionListAdapter adapter = new ColorSuggestionListAdapter(
getContext(), suggestions);
adapter.setOnColorSuggestionClickListener(this);
setAdapter(adapter);
}
@Override
public void onColorSuggestionClick(ColorSuggestion suggestion) {
mOnColorChangedListener.onColorChanged(suggestion.mColor);
}
}