2 * Copyright (C) 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.gallery3d.filtershow.editors;
19 import android.content.Context;
20 import android.content.res.Resources;
21 import android.graphics.Color;
22 import android.graphics.drawable.GradientDrawable;
23 import android.view.LayoutInflater;
24 import android.view.View;
25 import android.view.ViewGroup;
26 import android.widget.Button;
27 import android.widget.LinearLayout;
28 import android.widget.SeekBar;
29 import android.widget.TextView;
31 import com.android.gallery3d.R;
32 import com.android.gallery3d.filtershow.colorpicker.ColorCompareView;
33 import com.android.gallery3d.filtershow.colorpicker.ColorHueView;
34 import com.android.gallery3d.filtershow.colorpicker.ColorListener;
35 import com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
36 import com.android.gallery3d.filtershow.colorpicker.ColorSVRectView;
37 import com.android.gallery3d.filtershow.controller.BasicParameterInt;
38 import com.android.gallery3d.filtershow.controller.ParameterColor;
39 import com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation;
41 import java.util.Arrays;
43 public class EditorColorBorderTabletUI {
44 private EditorColorBorder mEditorDraw;
45 private static int sIconDim = 120;
46 private int mSelectedColorButton;
47 private FilterColorBorderRepresentation mRep;
48 private Button[] mColorButton;
49 private ColorHueView mHueView;
50 private ColorSVRectView mSatValView;
51 private ColorOpacityView mOpacityView;
52 private ColorCompareView mColorCompareView;
54 private int[] mBasColors;
55 private int mSelected;
56 private int mTransparent;
57 private SeekBar mCBSizeSeekBar;
58 private SeekBar mCBCornerSizeSeekBar;
59 TextView mCBCornerSizeValue;
60 TextView mCBSizeValue;
63 R.id.draw_color_button01,
64 R.id.draw_color_button02,
65 R.id.draw_color_button03,
66 R.id.draw_color_button04,
67 R.id.draw_color_button05,
70 public void setColorBorderRepresentation(FilterColorBorderRepresentation rep) {
72 BasicParameterInt size;
73 size = (BasicParameterInt) mRep.getParam(FilterColorBorderRepresentation.PARAM_SIZE);
74 mCBSizeSeekBar.setMax(size.getMaximum() - size.getMinimum());
75 mCBSizeSeekBar.setProgress(size.getValue());
77 BasicParameterInt radius;
78 radius = (BasicParameterInt) mRep.getParam(FilterColorBorderRepresentation.PARAM_RADIUS);
79 mCBCornerSizeSeekBar.setMax(radius.getMaximum() - radius.getMinimum());
80 mCBCornerSizeSeekBar.setProgress(radius.getValue());
83 color = (ParameterColor) mRep.getParam(FilterColorBorderRepresentation.PARAM_COLOR);
84 mBasColors = color.getColorPalette();
85 color.setValue(mBasColors[mSelectedColorButton]);
88 public EditorColorBorderTabletUI(EditorColorBorder editorDraw, Context context, View base) {
89 mEditorDraw = editorDraw;
90 mBasColors = editorDraw.mBasColors;
91 LayoutInflater inflater =
92 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
93 LinearLayout lp = (LinearLayout) inflater.inflate(
94 R.layout.filtershow_color_border_ui, (ViewGroup) base, true);
96 Resources res = context.getResources();
97 sIconDim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
98 LinearLayout buttonContainer = (LinearLayout) lp.findViewById(R.id.listStyles);
100 mCBCornerSizeSeekBar = (SeekBar) lp.findViewById(R.id.colorBorderCornerSizeSeekBar);
101 mCBCornerSizeValue = (TextView) lp.findViewById(R.id.colorBorderCornerValue);
102 mCBSizeSeekBar = (SeekBar) lp.findViewById(R.id.colorBorderSizeSeekBar);
104 mCBSizeValue = (TextView) lp.findViewById(R.id.colorBorderSizeValue);
105 setupClearButton(lp);
106 setupCBSizeSeekBar(lp);
107 setupCBCornerSizeSeekBar(lp);
111 private void setupClearButton(LinearLayout lp) {
112 Button clearButton = (Button) lp.findViewById(R.id.clearButton);
113 clearButton.setOnClickListener(new View.OnClickListener() {
115 public void onClick(View view) {
116 mEditorDraw.clearFrame();
121 private void setupCBSizeSeekBar(LinearLayout lp) {
122 mCBSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
124 public void onStopTrackingTouch(SeekBar seekBar) {
127 public void onStartTrackingTouch(SeekBar seekBar) {
130 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
131 int type = FilterColorBorderRepresentation.PARAM_SIZE;
132 BasicParameterInt size = (BasicParameterInt) mRep.getParam(type);
133 size.setValue(progress + size.getMinimum());
134 mCBSizeValue.setText(Integer.toString(size.getValue()));
135 mEditorDraw.commitLocalRepresentation();
141 private void setupCBCornerSizeSeekBar(LinearLayout lp) {
142 mCBCornerSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
144 public void onStopTrackingTouch(SeekBar seekBar) {
147 public void onStartTrackingTouch(SeekBar seekBar) {
150 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
151 int type = FilterColorBorderRepresentation.PARAM_RADIUS;
152 BasicParameterInt size = (BasicParameterInt) mRep.getParam(type);
153 size.setValue(progress + size.getMinimum());
154 mCBCornerSizeValue.setText(size.getValue() + "");
155 mEditorDraw.commitLocalRepresentation();
161 private void setupColor(LinearLayout lp, Resources res) {
162 final LinearLayout ctls = (LinearLayout) lp.findViewById(R.id.controls);
163 final LinearLayout pick = (LinearLayout) lp.findViewById(R.id.colorPicker);
164 Button b = (Button) lp.findViewById(R.id.draw_color_popupbutton);
165 b.setOnClickListener(new View.OnClickListener() {
168 public void onClick(View view) {
169 boolean b = ctls.getVisibility() == View.VISIBLE;
170 ctls.setVisibility((b) ? View.GONE : View.VISIBLE);
171 pick.setVisibility((!b) ? View.GONE : View.VISIBLE);
176 mTransparent = res.getColor(R.color.color_chooser_unslected_border);
177 mSelected = res.getColor(R.color.color_chooser_slected_border);
179 mColorButton = new Button[ids.length];
180 for (int i = 0; i < ids.length; i++) {
181 mColorButton[i] = (Button) lp.findViewById(ids[i]);
182 float[] hsvo = new float[4];
183 Color.colorToHSV(mBasColors[i], hsvo);
184 hsvo[3] = (0xFF & (mBasColors[i] >> 24)) / (float) 255;
185 mColorButton[i].setTag(hsvo);
186 GradientDrawable sd = ((GradientDrawable) mColorButton[i].getBackground());
187 sd.setColor(mBasColors[i]);
188 sd.setStroke(3, (0 == i) ? mSelected : mTransparent);
189 final int buttonNo = i;
190 mColorButton[i].setOnClickListener(new View.OnClickListener() {
192 public void onClick(View arg0) {
193 mSelectedColorButton = buttonNo;
194 float[] hsvo = Arrays.copyOf((float[]) mColorButton[buttonNo].getTag(), 4);
199 int type = FilterColorBorderRepresentation.PARAM_COLOR;
200 ParameterColor pram = (ParameterColor) mRep.getParam(type);
201 pram.setValue(mBasColors[mSelectedColorButton]);
202 mEditorDraw.commitLocalRepresentation();
203 mHueView.setColor(hsvo);
204 mSatValView.setColor(hsvo);
205 mOpacityView.setColor(hsvo);
206 mColorCompareView.setOrigColor(hsvo);
211 mHueView = (ColorHueView) lp.findViewById(R.id.ColorHueView);
212 mSatValView = (ColorSVRectView) lp.findViewById(R.id.colorRectView);
213 mOpacityView = (ColorOpacityView) lp.findViewById(R.id.colorOpacityView);
214 mColorCompareView = (ColorCompareView) lp.findViewById(R.id.btnSelect);
216 float[] hsvo = new float[4];
217 Color.colorToHSV(mBasColors[0], hsvo);
218 hsvo[3] = (0xFF & (mBasColors[0] >> 24)) / (float) 255;
219 mColorCompareView.setOrigColor(hsvo);
221 ColorListener[] colorViews = {mHueView, mSatValView, mOpacityView, mColorCompareView};
222 for (int i = 0; i < colorViews.length; i++) {
223 colorViews[i].setColor(hsvo);
224 for (int j = 0; j < colorViews.length; j++) {
228 colorViews[i].addColorListener(colorViews[j]);
232 ColorListener colorListener = new ColorListener() {
234 public void setColor(float[] hsvo) {
235 int color = Color.HSVToColor((int) (hsvo[3] * 255), hsvo);
236 Button b = mColorButton[mSelectedColorButton];
237 float[] f = (float[]) b.getTag();
238 System.arraycopy(hsvo, 0, f, 0, 4);
239 mBasColors[mSelectedColorButton] = color;
240 GradientDrawable sd = ((GradientDrawable) b.getBackground());
244 pram = (ParameterColor) mRep.getParam(FilterColorBorderRepresentation.PARAM_COLOR);
245 pram.setValue(color);
246 mEditorDraw.commitLocalRepresentation();
249 public void addColorListener(ColorListener l) {
253 for (int i = 0; i < colorViews.length; i++) {
254 colorViews[i].addColorListener(colorListener);
258 private void resetBorders() {
259 for (int i = 0; i < ids.length; i++) {
260 final Button button = mColorButton[i];
261 GradientDrawable sd = ((GradientDrawable) button.getBackground());
262 sd.setColor(mBasColors[i]);
263 sd.setStroke(3, (mSelectedColorButton == i) ? mSelected : mTransparent);