EditorDrawTabletUI.java revision 6125a082a2b5ddc0d34a5198c5a7e826bd77e202
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;
6097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
6197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int[] mBasColors;
6297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int mSelected;
6397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int mTransparent;
6497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private SeekBar mdrawSizeSeekBar;
6597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private int[] ids = {
6697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button01,
6797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button02,
6897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button03,
6997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button04,
7097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            R.id.draw_color_button05,
7197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    };
7297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
7397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    public void setDrawRepresentation(FilterDrawRepresentation rep) {
7497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mRep = rep;
7597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        BasicParameterInt size;
7697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        size = (BasicParameterInt) mRep.getParam(FilterDrawRepresentation.PARAM_SIZE);
7797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mdrawSizeSeekBar.setMax(size.getMaximum() - size.getMinimum());
786125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mdrawSizeSeekBar.setProgress(size.getValue());
796125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
8097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        ParameterColor color;
8197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        color = (ParameterColor) mRep.getParam(FilterDrawRepresentation.PARAM_COLOR);
8297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        color.setValue(mBasColors[mSelectedColorButton]);
8397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        BasicParameterStyle style;
8497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        style = (BasicParameterStyle) mRep.getParam(FilterDrawRepresentation.PARAM_STYLE);
8597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        style.setSelected(mSelectedStyleButton);
8697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
8797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
8897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    public EditorDrawTabletUI(EditorDraw editorDraw, Context context, LinearLayout lp) {
8997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mEditorDraw = editorDraw;
9097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mBasColors = editorDraw.mBasColors;
9197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mBrushIcons = editorDraw.brushIcons;
9297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Resources res = context.getResources();
9397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        sIconDim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
9497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        LinearLayout buttonContainer = (LinearLayout) lp.findViewById(R.id.listStyles);
9597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
9697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mdrawSizeSeekBar = (SeekBar) lp.findViewById(R.id.drawSizeSeekBar);
9797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        TextView drawSizeValue = (TextView) lp.findViewById(R.id.drawSizeValue);
9897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
9997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Button clearButton = (Button) lp.findViewById(R.id.clearButton);
10097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        clearButton.setOnClickListener(new View.OnClickListener() {
10197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
10297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onClick(View view) {
10397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mEditorDraw.clearDrawing();
10497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
10597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        });
10697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
10797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mdrawSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
10897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
10997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
11097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onStopTrackingTouch(SeekBar seekBar) {
11197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
11297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
11397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
11497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onStartTrackingTouch(SeekBar seekBar) {
11597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
11697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
11797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
11897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
11997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                BasicParameterInt size;
12097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                size = (BasicParameterInt) mRep.getParam(FilterDrawRepresentation.PARAM_SIZE);
12197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                size.setValue(progress + size.getMinimum());
12297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mEditorDraw.commitLocalRepresentation();
12397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
12497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        });
12597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
12697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        ActionBar.LayoutParams params = new ActionBar.LayoutParams(sIconDim, sIconDim);
12797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mStyleButton = new ImageButton[mBrushIcons.length];
12897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < mBrushIcons.length; i++) {
12997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final ImageButton button = new ImageButton(context);
13097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mStyleButton[i] = button;
13197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setScaleType(ImageView.ScaleType.CENTER_CROP);
13297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setLayoutParams(params);
13397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), mBrushIcons[i]);
13497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setImageBitmap(bitmap);
13597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setBackgroundResource(android.R.color.transparent);
13697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            buttonContainer.addView(button);
13797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final int current = i;
13897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            button.setOnClickListener(new View.OnClickListener() {
13997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                @Override
14097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                public void onClick(View view) {
14197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mSelectedStyleButton = current;
14297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    if (mRep == null) {
14397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                        return;
14497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    }
14597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    BasicParameterStyle style = (BasicParameterStyle)
14697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                            mRep.getParam(FilterDrawRepresentation.PARAM_STYLE);
14797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    style.setSelected(current);
14897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    resetStyle();
14997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mEditorDraw.commitLocalRepresentation();
15097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                }
15197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            });
15297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
15397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
15497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        final LinearLayout ctls = (LinearLayout) lp.findViewById(R.id.controls);
15597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        final LinearLayout pick = (LinearLayout) lp.findViewById(R.id.colorPicker);
15697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        Button b = (Button) lp.findViewById(R.id.draw_color_popupbutton);
15797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        b.setOnClickListener(new View.OnClickListener() {
15897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
15997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void onClick(View view) {
16097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                boolean b = ctls.getVisibility() == View.VISIBLE;
16197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                ctls.setVisibility((b) ? View.GONE : View.VISIBLE);
16297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                pick.setVisibility((!b) ? View.GONE : View.VISIBLE);
16397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
16497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
16597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        );
16697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
16797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mTransparent = res.getColor(R.color.color_chooser_unslected_border);
16897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mSelected = res.getColor(R.color.color_chooser_slected_border);
16997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
17097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mColorButton = new Button[ids.length];
17197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < ids.length; i++) {
17297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mColorButton[i] = (Button) lp.findViewById(ids[i]);
17397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
17497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            float[] hsvo = new float[4];
17597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            Color.colorToHSV(mBasColors[i], hsvo);
17697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            hsvo[3] = (0xFF & (mBasColors[i] >> 24)) / (float) 255;
17797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mColorButton[i].setTag(hsvo);
17897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            GradientDrawable sd = ((GradientDrawable) mColorButton[i].getBackground());
17997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
18097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setColor(mBasColors[i]);
18197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setStroke(3, (0 == i) ? mSelected : mTransparent);
18297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
18397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final int buttonNo = i;
18497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mColorButton[i].setOnClickListener(new View.OnClickListener() {
18597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                @Override
18697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                public void onClick(View arg0) {
18797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
18897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mSelectedColorButton = buttonNo;
1896125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    float[] hsvo = Arrays.copyOf((float[]) mColorButton[buttonNo].getTag(), 4);
19097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    resetBorders();
19197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    if (mRep == null) {
19297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                        return;
19397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    }
19497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    ParameterColor pram;
19597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    pram = (ParameterColor) mRep.getParam(FilterDrawRepresentation.PARAM_COLOR);
19697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    pram.setValue(mBasColors[mSelectedColorButton]);
19797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mEditorDraw.commitLocalRepresentation();
19897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mHueView.setColor(hsvo);
19997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mSatValView.setColor(hsvo);
20097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    mOpacityView.setColor(hsvo);
2016125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    mColorCompareView.setColor(hsvo);
2026125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    mColorCompareView.setOrigColor(hsvo);
20397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                }
20497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            });
20597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
2066125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
20797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mHueView = (ColorHueView) lp.findViewById(R.id.ColorHueView);
20897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mSatValView = (ColorSVRectView) lp.findViewById(R.id.colorRectView);
20997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        mOpacityView = (ColorOpacityView) lp.findViewById(R.id.colorOpacityView);
2106125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mColorCompareView = (ColorCompareView) lp.findViewById(R.id.btnSelect);
2116125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2126125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        float[] hsvo = new float[4];
2136125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        Color.colorToHSV(mBasColors[0], hsvo);
2146125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        hsvo[3] = (0xFF & (mBasColors[0] >> 24)) / (float) 255;
2156125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2166125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mColorCompareView.setOrigColor(hsvo);
2176125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        ColorListener[] colorViews = {mHueView, mSatValView, mOpacityView, mColorCompareView};
2186125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        for (int i = 0; i < colorViews.length; i++) {
2196125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            colorViews[i].setColor(hsvo);
2206125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2216125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            for (int j = 0; j < colorViews.length; j++) {
2226125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                if (i == j) {
2236125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    continue;
2246125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                }
2256125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                colorViews[i].addColorListener(colorViews[j]);
2266125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            }
2276125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        }
22897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        ColorListener colorListener = new ColorListener() {
22997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
23097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            @Override
23197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            public void setColor(float[] hsvo) {
23297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                int color = Color.HSVToColor((int) (hsvo[3] * 255), hsvo);
23397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                Button b = mColorButton[mSelectedColorButton];
23497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                float[] f = (float[]) b.getTag();
2356125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                System.arraycopy(hsvo, 0, f, 0, 4);
23697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mBasColors[mSelectedColorButton] = color;
23797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                GradientDrawable sd = ((GradientDrawable) b.getBackground());
23897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                sd.setColor(color);
23997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                resetBorders();
24097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                ParameterColor pram;
24197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                pram = (ParameterColor) mRep.getParam(FilterDrawRepresentation.PARAM_COLOR);
24297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                pram.setValue(color);
24397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                mEditorDraw.commitLocalRepresentation();
24497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            }
2456125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2466125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            @Override
2476125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            public void addColorListener(ColorListener l) {
2486125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            }
24997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        };
2506125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2516125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        for (int i = 0; i < colorViews.length; i++) {
2526125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            colorViews[i].addColorListener(colorListener);
2536125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        }
2546125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
25597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
25697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
25797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    public void resetStyle() {
25897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < mStyleButton.length; i++) {
25997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            int rid = (i == mSelectedStyleButton) ? android.R.color.holo_blue_light :
26097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford                    android.R.color.transparent;
26197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            mStyleButton[i].setBackgroundResource(rid);
26297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
26397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
26497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
26597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
26697d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    private void resetBorders() {
26797d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        for (int i = 0; i < ids.length; i++) {
26897d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            final Button button = mColorButton[i];
26997d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford
27097d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            GradientDrawable sd = ((GradientDrawable) button.getBackground());
27197d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setColor(mBasColors[i]);
27297d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford            sd.setStroke(3, (mSelectedColorButton == i) ? mSelected : mTransparent);
27397d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford        }
27497d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford    }
27597d76abecd25656bcd622c56d9cf4e2c9b236ea3John Hoford}
276