This source file includes following definitions.
- onColorChanged
- showAdvancedView
- tryNotifyColorSet
- updateCurrentColor
package org.chromium.ui;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class ColorPickerDialog extends AlertDialog implements OnColorChangedListener {
private final ColorPickerAdvanced mAdvancedColorPicker;
private final ColorPickerSimple mSimpleColorPicker;
private final Button mMoreButton;
private final View mCurrentColorView;
private final OnColorChangedListener mListener;
private final int mInitialColor;
private int mCurrentColor;
public ColorPickerDialog(Context context,
OnColorChangedListener listener,
int color,
ColorSuggestion[] suggestions) {
super(context, 0);
mListener = listener;
mInitialColor = color;
mCurrentColor = mInitialColor;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View title = inflater.inflate(R.layout.color_picker_dialog_title, null);
setCustomTitle(title);
mCurrentColorView = title.findViewById(R.id.selected_color_view);
TextView titleText = (TextView) title.findViewById(R.id.title);
titleText.setText(R.string.color_picker_dialog_title);
String positiveButtonText = context.getString(R.string.color_picker_button_set);
setButton(BUTTON_POSITIVE, positiveButtonText,
new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
tryNotifyColorSet(mCurrentColor);
}
});
String negativeButtonText = context.getString(R.string.color_picker_button_cancel);
setButton(BUTTON_NEGATIVE, negativeButtonText,
new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
tryNotifyColorSet(mInitialColor);
}
});
setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface arg0) {
tryNotifyColorSet(mInitialColor);
}
});
View content = inflater.inflate(R.layout.color_picker_dialog_content, null);
setView(content);
mMoreButton = (Button) content.findViewById(R.id.more_colors_button);
mMoreButton.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
showAdvancedView();
}
});
mAdvancedColorPicker =
(ColorPickerAdvanced) content.findViewById(R.id.color_picker_advanced);
mAdvancedColorPicker.setVisibility(View.GONE);
mSimpleColorPicker = (ColorPickerSimple) content.findViewById(R.id.color_picker_simple);
mSimpleColorPicker.init(suggestions, this);
updateCurrentColor(mInitialColor);
}
@Override
public void onColorChanged(int color) {
updateCurrentColor(color);
}
private void showAdvancedView() {
View buttonBorder = findViewById(R.id.more_colors_button_border);
buttonBorder.setVisibility(View.GONE);
View simpleView = findViewById(R.id.color_picker_simple);
simpleView.setVisibility(View.GONE);
mAdvancedColorPicker.setVisibility(View.VISIBLE);
mAdvancedColorPicker.setListener(this);
mAdvancedColorPicker.setColor(mCurrentColor);
}
private void tryNotifyColorSet(int color) {
if (mListener != null) mListener.onColorChanged(color);
}
private void updateCurrentColor(int color) {
mCurrentColor = color;
if (mCurrentColorView != null) mCurrentColorView.setBackgroundColor(color);
}
}