197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford/*
297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * Copyright (C) 2013 The Android Open Source Project
397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford *
497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * Licensed under the Apache License, Version 2.0 (the "License");
597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * you may not use this file except in compliance with the License.
697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * You may obtain a copy of the License at
797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford *
897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford *      http://www.apache.org/licenses/LICENSE-2.0
997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford *
1097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * Unless required by applicable law or agreed to in writing, software
1197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * distributed under the License is distributed on an "AS IS" BASIS,
1297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * See the License for the specific language governing permissions and
1497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford * limitations under the License.
1597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford */
1697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
1797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordpackage com.android.gallery3d.filtershow.editors;
1897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
1997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.app.ActionBar;
2097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.content.Context;
2197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.content.res.Resources;
2297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.graphics.Bitmap;
2397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.graphics.BitmapFactory;
2497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.graphics.Color;
2597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.graphics.drawable.GradientDrawable;
2697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.view.View;
2797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.widget.Button;
2897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.widget.ImageButton;
2997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.widget.ImageView;
3097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.widget.LinearLayout;
3197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.widget.SeekBar;
3297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport android.widget.TextView;
3397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
3497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.R;
356125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorCompareView;
3697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorHueView;
3797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorListener;
3897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
3997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorSVRectView;
4097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.controller.BasicParameterInt;
4197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.controller.BasicParameterStyle;
4297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.controller.ParameterColor;
4397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport com.android.gallery3d.filtershow.filters.FilterDrawRepresentation;
4497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
4597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordimport java.util.Arrays;
4697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
4797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hofordpublic class EditorDrawTabletUI {
4897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private EditorDraw mEditorDraw;
4997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int[] mBrushIcons;
5097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private static int sIconDim = 120;
5197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int mSelectedColorButton;
5297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int mSelectedStyleButton;
5397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private FilterDrawRepresentation mRep;
5497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private Button[] mColorButton;
5597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private ImageButton[] mStyleButton;
5697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private ColorHueView mHueView;
5797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private ColorSVRectView mSatValView;
5897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private ColorOpacityView mOpacityView;
596125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford    private ColorCompareView mColorCompareView;
605921b53e411a1ee5de8daea34fda90c2ada31974John Hoford    private TextView mDrawSizeValue;
6197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
6297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int[] mBasColors;
6397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int mSelected;
6497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int mTransparent;
6597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private SeekBar mdrawSizeSeekBar;
6697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int[] ids = {
6797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button01,
6897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button02,
6997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button03,
7097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button04,
7197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button05,
7297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    };
7397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
7497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    public void setDrawRepresentation(FilterDrawRepresentation rep) {
7597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mRep = rep;
7697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        BasicParameterInt size;
7797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        size = (BasicParameterInt) mRep.getParam(FilterDrawRepresentation.PARAM_SIZE);
7897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mdrawSizeSeekBar.setMax(size.getMaximum() - size.getMinimum());
796125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mdrawSizeSeekBar.setProgress(size.getValue());
806125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
8197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        ParameterColor color;
8297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        color = (ParameterColor) mRep.getParam(FilterDrawRepresentation.PARAM_COLOR);
8397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        color.setValue(mBasColors[mSelectedColorButton]);
8497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        BasicParameterStyle style;
8597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        style = (BasicParameterStyle) mRep.getParam(FilterDrawRepresentation.PARAM_STYLE);
8697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        style.setSelected(mSelectedStyleButton);
8797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
8897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
8997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    public EditorDrawTabletUI(EditorDraw editorDraw, Context context, LinearLayout lp) {
9097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mEditorDraw = editorDraw;
9197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mBasColors = editorDraw.mBasColors;
9297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mBrushIcons = editorDraw.brushIcons;
9397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Resources res = context.getResources();
9497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        sIconDim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
9597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        LinearLayout buttonContainer = (LinearLayout) lp.findViewById(R.id.listStyles);
9697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
9797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mdrawSizeSeekBar = (SeekBar) lp.findViewById(R.id.drawSizeSeekBar);
985921b53e411a1ee5de8daea34fda90c2ada31974John Hoford        mDrawSizeValue = (TextView) lp.findViewById(R.id.drawSizeValue);
9997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
10097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Button clearButton = (Button) lp.findViewById(R.id.clearButton);
10197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        clearButton.setOnClickListener(new View.OnClickListener() {
10297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
10397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onClick(View view) {
10497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mEditorDraw.clearDrawing();
10597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
10697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        });
10797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
10897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mdrawSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
10997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
11097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
11197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onStopTrackingTouch(SeekBar seekBar) {
11297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
11397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
11497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
11597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onStartTrackingTouch(SeekBar seekBar) {
11697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
11797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
11897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
11997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
12097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                BasicParameterInt size;
12197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                size = (BasicParameterInt) mRep.getParam(FilterDrawRepresentation.PARAM_SIZE);
12297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                size.setValue(progress + size.getMinimum());
12397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mEditorDraw.commitLocalRepresentation();
1245921b53e411a1ee5de8daea34fda90c2ada31974John Hoford                int val  = progress + size.getMinimum();
1255921b53e411a1ee5de8daea34fda90c2ada31974John Hoford                mDrawSizeValue.setText(((val>0)?"+":"")+val);
12697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
12797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        });
12897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
12997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        ActionBar.LayoutParams params = new ActionBar.LayoutParams(sIconDim, sIconDim);
13097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mStyleButton = new ImageButton[mBrushIcons.length];
13197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < mBrushIcons.length; i++) {
13297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final ImageButton button = new ImageButton(context);
13397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mStyleButton[i] = button;
13497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setScaleType(ImageView.ScaleType.CENTER_CROP);
13597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setLayoutParams(params);
13697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), mBrushIcons[i]);
13797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setImageBitmap(bitmap);
13897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setBackgroundResource(android.R.color.transparent);
13997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            buttonContainer.addView(button);
14097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final int current = i;
14197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setOnClickListener(new View.OnClickListener() {
14297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                @Override
14397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                public void onClick(View view) {
14497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mSelectedStyleButton = current;
14597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    if (mRep == null) {
14697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                        return;
14797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    }
14897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    BasicParameterStyle style = (BasicParameterStyle)
14997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                            mRep.getParam(FilterDrawRepresentation.PARAM_STYLE);
15097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    style.setSelected(current);
15197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    resetStyle();
15297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mEditorDraw.commitLocalRepresentation();
15397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                }
15497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            });
15597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
15697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
15797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        final LinearLayout ctls = (LinearLayout) lp.findViewById(R.id.controls);
15897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        final LinearLayout pick = (LinearLayout) lp.findViewById(R.id.colorPicker);
15997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Button b = (Button) lp.findViewById(R.id.draw_color_popupbutton);
16097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        b.setOnClickListener(new View.OnClickListener() {
16197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
16297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onClick(View view) {
16397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                boolean b = ctls.getVisibility() == View.VISIBLE;
16497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                ctls.setVisibility((b) ? View.GONE : View.VISIBLE);
16597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                pick.setVisibility((!b) ? View.GONE : View.VISIBLE);
16697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
16797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
16897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        );
16997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
17097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mTransparent = res.getColor(R.color.color_chooser_unslected_border);
17197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mSelected = res.getColor(R.color.color_chooser_slected_border);
17297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
17397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mColorButton = new Button[ids.length];
17497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < ids.length; i++) {
17597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mColorButton[i] = (Button) lp.findViewById(ids[i]);
17697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
17797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            float[] hsvo = new float[4];
17897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            Color.colorToHSV(mBasColors[i], hsvo);
17997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            hsvo[3] = (0xFF & (mBasColors[i] >> 24)) / (float) 255;
18097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mColorButton[i].setTag(hsvo);
18197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            GradientDrawable sd = ((GradientDrawable) mColorButton[i].getBackground());
18297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
18397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setColor(mBasColors[i]);
18497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setStroke(3, (0 == i) ? mSelected : mTransparent);
18597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
18697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final int buttonNo = i;
18797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mColorButton[i].setOnClickListener(new View.OnClickListener() {
18897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                @Override
18997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                public void onClick(View arg0) {
19097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
19197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mSelectedColorButton = buttonNo;
1926125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    float[] hsvo = Arrays.copyOf((float[]) mColorButton[buttonNo].getTag(), 4);
19397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    resetBorders();
19497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    if (mRep == null) {
19597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                        return;
19697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    }
19797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    ParameterColor pram;
19897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    pram = (ParameterColor) mRep.getParam(FilterDrawRepresentation.PARAM_COLOR);
19997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    pram.setValue(mBasColors[mSelectedColorButton]);
20097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mEditorDraw.commitLocalRepresentation();
20197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mHueView.setColor(hsvo);
20297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mSatValView.setColor(hsvo);
20397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mOpacityView.setColor(hsvo);
2046125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    mColorCompareView.setColor(hsvo);
2056125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    mColorCompareView.setOrigColor(hsvo);
20697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                }
20797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            });
20897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
2096125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
21097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mHueView = (ColorHueView) lp.findViewById(R.id.ColorHueView);
21197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mSatValView = (ColorSVRectView) lp.findViewById(R.id.colorRectView);
21297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mOpacityView = (ColorOpacityView) lp.findViewById(R.id.colorOpacityView);
2136125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mColorCompareView = (ColorCompareView) lp.findViewById(R.id.btnSelect);
2146125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2156125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        float[] hsvo = new float[4];
2166125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        Color.colorToHSV(mBasColors[0], hsvo);
2176125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        hsvo[3] = (0xFF & (mBasColors[0] >> 24)) / (float) 255;
2186125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2196125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mColorCompareView.setOrigColor(hsvo);
2206125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        ColorListener[] colorViews = {mHueView, mSatValView, mOpacityView, mColorCompareView};
2216125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        for (int i = 0; i < colorViews.length; i++) {
2226125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            colorViews[i].setColor(hsvo);
2236125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2246125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            for (int j = 0; j < colorViews.length; j++) {
2256125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                if (i == j) {
2266125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    continue;
2276125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                }
2286125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                colorViews[i].addColorListener(colorViews[j]);
2296125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            }
2306125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        }
23197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        ColorListener colorListener = new ColorListener() {
23297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
23397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
23497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void setColor(float[] hsvo) {
23597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                int color = Color.HSVToColor((int) (hsvo[3] * 255), hsvo);
23697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                Button b = mColorButton[mSelectedColorButton];
23797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                float[] f = (float[]) b.getTag();
2386125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                System.arraycopy(hsvo, 0, f, 0, 4);
23997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mBasColors[mSelectedColorButton] = color;
24097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                GradientDrawable sd = ((GradientDrawable) b.getBackground());
24197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                sd.setColor(color);
24297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                resetBorders();
24397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                ParameterColor pram;
24497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                pram = (ParameterColor) mRep.getParam(FilterDrawRepresentation.PARAM_COLOR);
24597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                pram.setValue(color);
24697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mEditorDraw.commitLocalRepresentation();
24797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
2486125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2496125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            @Override
2506125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            public void addColorListener(ColorListener l) {
2516125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            }
25297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        };
2536125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2546125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        for (int i = 0; i < colorViews.length; i++) {
2556125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            colorViews[i].addColorListener(colorListener);
2566125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        }
2576125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
25897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
25997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
26097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    public void resetStyle() {
26197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < mStyleButton.length; i++) {
26297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            int rid = (i == mSelectedStyleButton) ? android.R.color.holo_blue_light :
26397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    android.R.color.transparent;
26497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mStyleButton[i].setBackgroundResource(rid);
26597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
26697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
26797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
26897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
26997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private void resetBorders() {
27097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < ids.length; i++) {
27197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final Button button = mColorButton[i];
27297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
27397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            GradientDrawable sd = ((GradientDrawable) button.getBackground());
27497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setColor(mBasColors[i]);
27597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setStroke(3, (mSelectedColorButton == i) ? mSelected : mTransparent);
27697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
27797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
27897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford}
279