| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.ui; | 5 package org.chromium.ui; |
| 6 | 6 |
| 7 import android.app.AlertDialog; | 7 import android.app.AlertDialog; |
| 8 import android.app.Dialog; | 8 import android.app.Dialog; |
| 9 import android.content.Context; | 9 import android.content.Context; |
| 10 import android.content.DialogInterface; | 10 import android.content.DialogInterface; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 private final int mInitialColor; | 32 private final int mInitialColor; |
| 33 | 33 |
| 34 private int mCurrentColor; | 34 private int mCurrentColor; |
| 35 | 35 |
| 36 /** | 36 /** |
| 37 * @param context The context the dialog is to run in. | 37 * @param context The context the dialog is to run in. |
| 38 * @param theme The theme to display the dialog in. | 38 * @param theme The theme to display the dialog in. |
| 39 * @param listener The object to notify when the color is set. | 39 * @param listener The object to notify when the color is set. |
| 40 * @param color The initial color to set. | 40 * @param color The initial color to set. |
| 41 * @param suggestions The list of suggestions. |
| 41 */ | 42 */ |
| 42 public ColorPickerDialog(Context context, OnColorChangedListener listener, i
nt color) { | 43 public ColorPickerDialog(Context context, |
| 44 OnColorChangedListener listener, |
| 45 int color, |
| 46 ColorSuggestion[] suggestions) { |
| 43 super(context, 0); | 47 super(context, 0); |
| 44 | 48 |
| 45 mListener = listener; | 49 mListener = listener; |
| 46 mInitialColor = color; | 50 mInitialColor = color; |
| 47 mCurrentColor = mInitialColor; | 51 mCurrentColor = mInitialColor; |
| 48 | 52 |
| 49 // Initialize title | 53 // Initialize title |
| 50 LayoutInflater inflater = (LayoutInflater) context | 54 LayoutInflater inflater = (LayoutInflater) context |
| 51 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); | 55 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
| 52 View title = inflater.inflate(R.layout.color_picker_dialog_title, null); | 56 View title = inflater.inflate(R.layout.color_picker_dialog_title, null); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 } | 107 } |
| 104 }); | 108 }); |
| 105 | 109 |
| 106 // Initialize advanced color view (hidden initially). | 110 // Initialize advanced color view (hidden initially). |
| 107 mAdvancedColorPicker = | 111 mAdvancedColorPicker = |
| 108 (ColorPickerAdvanced) content.findViewById(R.id.color_picker_adv
anced); | 112 (ColorPickerAdvanced) content.findViewById(R.id.color_picker_adv
anced); |
| 109 mAdvancedColorPicker.setVisibility(View.GONE); | 113 mAdvancedColorPicker.setVisibility(View.GONE); |
| 110 | 114 |
| 111 // Initialize simple color view (default view). | 115 // Initialize simple color view (default view). |
| 112 mSimpleColorPicker = (ColorPickerSimple) content.findViewById(R.id.color
_picker_simple); | 116 mSimpleColorPicker = (ColorPickerSimple) content.findViewById(R.id.color
_picker_simple); |
| 113 mSimpleColorPicker.init(this); | 117 mSimpleColorPicker.init(suggestions, this); |
| 114 | 118 |
| 115 updateCurrentColor(mInitialColor); | 119 updateCurrentColor(mInitialColor); |
| 116 } | 120 } |
| 117 | 121 |
| 118 /** | 122 /** |
| 119 * Listens to the ColorPicker for when the user has changed the selected col
or, and | 123 * Listens to the ColorPicker for when the user has changed the selected col
or, and |
| 120 * updates the current color (the color shown in the title) accordingly. | 124 * updates the current color (the color shown in the title) accordingly. |
| 121 * | 125 * |
| 122 * @param color The new color chosen by the user. | 126 * @param color The new color chosen by the user. |
| 123 */ | 127 */ |
| 124 @Override | 128 @Override |
| 125 public void onColorChanged(int color) { | 129 public void onColorChanged(int color) { |
| 126 updateCurrentColor(color); | 130 updateCurrentColor(color); |
| 127 } | 131 } |
| 128 | 132 |
| 129 /** | 133 /** |
| 130 * Hides the simple view (the default) and shows the advanced one instead, h
iding the | 134 * Hides the simple view (the default) and shows the advanced one instead, h
iding the |
| 131 * "More" button at the same time. | 135 * "More" button at the same time. |
| 132 */ | 136 */ |
| 133 private void showAdvancedView() { | 137 private void showAdvancedView() { |
| 134 // Only need to hide the borders, not the Views themselves, since the Vi
ews are | 138 // Only need to hide the borders, not the Views themselves, since the Vi
ews are |
| 135 // contained within the borders. | 139 // contained within the borders. |
| 136 View buttonBorder = findViewById(R.id.more_colors_button_border); | 140 View buttonBorder = findViewById(R.id.more_colors_button_border); |
| 137 buttonBorder.setVisibility(View.GONE); | 141 buttonBorder.setVisibility(View.GONE); |
| 138 | 142 |
| 139 View simpleViewBorder = findViewById(R.id.color_picker_simple_border); | 143 View simpleView = findViewById(R.id.color_picker_simple); |
| 140 simpleViewBorder.setVisibility(View.GONE); | 144 simpleView.setVisibility(View.GONE); |
| 141 | 145 |
| 142 mAdvancedColorPicker.setVisibility(View.VISIBLE); | 146 mAdvancedColorPicker.setVisibility(View.VISIBLE); |
| 143 mAdvancedColorPicker.setListener(this); | 147 mAdvancedColorPicker.setListener(this); |
| 144 mAdvancedColorPicker.setColor(mCurrentColor); | 148 mAdvancedColorPicker.setColor(mCurrentColor); |
| 145 } | 149 } |
| 146 | 150 |
| 147 /** | 151 /** |
| 148 * Tries to notify any listeners that the color has been set. | 152 * Tries to notify any listeners that the color has been set. |
| 149 */ | 153 */ |
| 150 private void tryNotifyColorSet(int color) { | 154 private void tryNotifyColorSet(int color) { |
| 151 if (mListener != null) { | 155 if (mListener != null) { |
| 152 mListener.onColorChanged(color); | 156 mListener.onColorChanged(color); |
| 153 } | 157 } |
| 154 } | 158 } |
| 155 | 159 |
| 156 /** | 160 /** |
| 157 * Updates the internal cache of the currently selected color, updating the
colorful little | 161 * Updates the internal cache of the currently selected color, updating the
colorful little |
| 158 * box in the title at the same time. | 162 * box in the title at the same time. |
| 159 */ | 163 */ |
| 160 private void updateCurrentColor(int color) { | 164 private void updateCurrentColor(int color) { |
| 161 mCurrentColor = color; | 165 mCurrentColor = color; |
| 162 if (mCurrentColorView != null) { | 166 if (mCurrentColorView != null) { |
| 163 mCurrentColorView.setBackgroundColor(color); | 167 mCurrentColorView.setBackgroundColor(color); |
| 164 } | 168 } |
| 165 } | 169 } |
| 166 } | 170 } |
| OLD | NEW |