149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford/*
249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * Copyright (C) 2013 The Android Open Source Project
349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford *
449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * Licensed under the Apache License, Version 2.0 (the "License");
549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * you may not use this file except in compliance with the License.
649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * You may obtain a copy of the License at
749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford *
849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford *      http://www.apache.org/licenses/LICENSE-2.0
949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford *
1049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * Unless required by applicable law or agreed to in writing, software
1149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * distributed under the License is distributed on an "AS IS" BASIS,
1249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * See the License for the specific language governing permissions and
1449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford * limitations under the License.
1549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford */
1649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
1749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordpackage com.android.gallery3d.filtershow.editors;
1849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
1949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.content.Context;
2049798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.content.res.Resources;
2149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.graphics.Color;
2249798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.graphics.drawable.GradientDrawable;
2349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.LayoutInflater;
2449798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.View;
2549798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.view.ViewGroup;
2649798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.Button;
2749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.LinearLayout;
2849798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.SeekBar;
2949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport android.widget.TextView;
3049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
3149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.R;
326125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorCompareView;
3349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorHueView;
3449798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorListener;
3549798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorOpacityView;
3649798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.colorpicker.ColorSVRectView;
3749798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.BasicParameterInt;
3849798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.controller.ParameterColor;
3949798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport com.android.gallery3d.filtershow.filters.FilterColorBorderRepresentation;
4049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
4149798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordimport java.util.Arrays;
4249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
4349798939f1bc58eaf5842bbc8bc5424284ab7930John Hofordpublic class EditorColorBorderTabletUI {
4449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private EditorColorBorder mEditorDraw;
4549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private static int sIconDim = 120;
4649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private int mSelectedColorButton;
4749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private FilterColorBorderRepresentation mRep;
4849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private Button[] mColorButton;
4949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private ColorHueView mHueView;
5049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private ColorSVRectView mSatValView;
5149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private ColorOpacityView mOpacityView;
526125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford    private ColorCompareView mColorCompareView;
5349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
5449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private int[] mBasColors;
5549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private int mSelected;
5649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private int mTransparent;
5749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private SeekBar mCBSizeSeekBar;
5849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private SeekBar mCBCornerSizeSeekBar;
5949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    TextView mCBCornerSizeValue;
6049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    TextView mCBSizeValue;
6149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
6249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private int[] ids = {
6349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            R.id.draw_color_button01,
6449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            R.id.draw_color_button02,
6549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            R.id.draw_color_button03,
6649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            R.id.draw_color_button04,
6749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            R.id.draw_color_button05,
6849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    };
6949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
7049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    public void setColorBorderRepresentation(FilterColorBorderRepresentation rep) {
7149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mRep = rep;
7249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        BasicParameterInt size;
7349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        size = (BasicParameterInt) mRep.getParam(FilterColorBorderRepresentation.PARAM_SIZE);
7449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBSizeSeekBar.setMax(size.getMaximum() - size.getMinimum());
7549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBSizeSeekBar.setProgress(size.getValue());
7649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
7749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        BasicParameterInt radius;
7849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        radius = (BasicParameterInt) mRep.getParam(FilterColorBorderRepresentation.PARAM_RADIUS);
7949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBCornerSizeSeekBar.setMax(radius.getMaximum() - radius.getMinimum());
8049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBCornerSizeSeekBar.setProgress(radius.getValue());
8149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
8249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        ParameterColor color;
8349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        color = (ParameterColor) mRep.getParam(FilterColorBorderRepresentation.PARAM_COLOR);
84ae068f80895d7d075064a5ded59069425b72271fJohn Hoford        mBasColors = color.getColorPalette();
8549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        color.setValue(mBasColors[mSelectedColorButton]);
8649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    }
8749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
8849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    public EditorColorBorderTabletUI(EditorColorBorder editorDraw, Context context, View base) {
8949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mEditorDraw = editorDraw;
9049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mBasColors = editorDraw.mBasColors;
9149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        LayoutInflater inflater =
9249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
9349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        LinearLayout lp = (LinearLayout) inflater.inflate(
9449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                R.layout.filtershow_color_border_ui, (ViewGroup) base, true);
9549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
9649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        Resources res = context.getResources();
9749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        sIconDim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim);
9849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        LinearLayout buttonContainer = (LinearLayout) lp.findViewById(R.id.listStyles);
9949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
10049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBCornerSizeSeekBar = (SeekBar) lp.findViewById(R.id.colorBorderCornerSizeSeekBar);
10149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBCornerSizeValue = (TextView) lp.findViewById(R.id.colorBorderCornerValue);
10249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBSizeSeekBar = (SeekBar) lp.findViewById(R.id.colorBorderSizeSeekBar);
1036125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
10449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBSizeValue = (TextView) lp.findViewById(R.id.colorBorderSizeValue);
10549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        setupCBSizeSeekBar(lp);
10649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        setupCBCornerSizeSeekBar(lp);
10749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        setupColor(lp, res);
10849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    }
10949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
11049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private void setupCBSizeSeekBar(LinearLayout lp) {
11149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
11249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
11349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onStopTrackingTouch(SeekBar seekBar) {
11449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
11549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
11649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onStartTrackingTouch(SeekBar seekBar) {
11749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
11849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
11949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
12049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                int type = FilterColorBorderRepresentation.PARAM_SIZE;
12149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                BasicParameterInt size = (BasicParameterInt) mRep.getParam(type);
12249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                size.setValue(progress + size.getMinimum());
12349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                mCBSizeValue.setText(Integer.toString(size.getValue()));
12449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                mEditorDraw.commitLocalRepresentation();
12549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
12649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        });
12749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
12849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    }
12949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
13049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private void setupCBCornerSizeSeekBar(LinearLayout lp) {
13149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mCBCornerSizeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
13249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
13349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onStopTrackingTouch(SeekBar seekBar) {
13449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
13549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
13649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onStartTrackingTouch(SeekBar seekBar) {
13749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
13849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
13949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
14049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                int type = FilterColorBorderRepresentation.PARAM_RADIUS;
14149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                BasicParameterInt size = (BasicParameterInt) mRep.getParam(type);
14249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                size.setValue(progress + size.getMinimum());
14349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                mCBCornerSizeValue.setText(size.getValue() + "");
14449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                mEditorDraw.commitLocalRepresentation();
14549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
14649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        });
14749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
14849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    }
14949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
15049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private void setupColor(LinearLayout lp, Resources res) {
15149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        final LinearLayout ctls = (LinearLayout) lp.findViewById(R.id.controls);
15249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        final LinearLayout pick = (LinearLayout) lp.findViewById(R.id.colorPicker);
15349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        Button b = (Button) lp.findViewById(R.id.draw_color_popupbutton);
15449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        b.setOnClickListener(new View.OnClickListener() {
15549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
15649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
15749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void onClick(View view) {
15849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                boolean b = ctls.getVisibility() == View.VISIBLE;
15949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                ctls.setVisibility((b) ? View.GONE : View.VISIBLE);
16049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                pick.setVisibility((!b) ? View.GONE : View.VISIBLE);
16149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
16249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        }
16349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        );
16449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
16549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mTransparent = res.getColor(R.color.color_chooser_unslected_border);
16649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mSelected = res.getColor(R.color.color_chooser_slected_border);
16749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
16849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mColorButton = new Button[ids.length];
16949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        for (int i = 0; i < ids.length; i++) {
17049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            mColorButton[i] = (Button) lp.findViewById(ids[i]);
17149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            float[] hsvo = new float[4];
17249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            Color.colorToHSV(mBasColors[i], hsvo);
17349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            hsvo[3] = (0xFF & (mBasColors[i] >> 24)) / (float) 255;
17449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            mColorButton[i].setTag(hsvo);
17549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            GradientDrawable sd = ((GradientDrawable) mColorButton[i].getBackground());
17649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            sd.setColor(mBasColors[i]);
17749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            sd.setStroke(3, (0 == i) ? mSelected : mTransparent);
17849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            final int buttonNo = i;
17949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            mColorButton[i].setOnClickListener(new View.OnClickListener() {
18049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                @Override
18149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                public void onClick(View arg0) {
18249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    mSelectedColorButton = buttonNo;
18349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    float[] hsvo = Arrays.copyOf((float[]) mColorButton[buttonNo].getTag(), 4);
18449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    resetBorders();
18549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    if (mRep == null) {
18649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                        return;
18749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    }
18849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    int type = FilterColorBorderRepresentation.PARAM_COLOR;
18949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    ParameterColor pram = (ParameterColor) mRep.getParam(type);
19049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    pram.setValue(mBasColors[mSelectedColorButton]);
19149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    mEditorDraw.commitLocalRepresentation();
19249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    mHueView.setColor(hsvo);
19349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    mSatValView.setColor(hsvo);
19449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                    mOpacityView.setColor(hsvo);
1956125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    mColorCompareView.setOrigColor(hsvo);
1966125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
19749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                }
19849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            });
19949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        }
20049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mHueView = (ColorHueView) lp.findViewById(R.id.ColorHueView);
20149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mSatValView = (ColorSVRectView) lp.findViewById(R.id.colorRectView);
20249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        mOpacityView = (ColorOpacityView) lp.findViewById(R.id.colorOpacityView);
2036125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mColorCompareView = (ColorCompareView) lp.findViewById(R.id.btnSelect);
2046125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2056125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        float[] hsvo = new float[4];
2066125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        Color.colorToHSV(mBasColors[0], hsvo);
2076125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        hsvo[3] = (0xFF & (mBasColors[0] >> 24)) / (float) 255;
2086125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        mColorCompareView.setOrigColor(hsvo);
2096125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2106125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        ColorListener[] colorViews = {mHueView, mSatValView, mOpacityView, mColorCompareView};
2116125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        for (int i = 0; i < colorViews.length; i++) {
2126125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            colorViews[i].setColor(hsvo);
2136125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            for (int j = 0; j < colorViews.length; j++) {
2146125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                if (i == j) {
2156125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                    continue;
2166125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                }
2176125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford                colorViews[i].addColorListener(colorViews[j]);
2186125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            }
2196125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        }
2206125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
22149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        ColorListener colorListener = new ColorListener() {
22249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            @Override
22349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            public void setColor(float[] hsvo) {
22449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                int color = Color.HSVToColor((int) (hsvo[3] * 255), hsvo);
22549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                Button b = mColorButton[mSelectedColorButton];
22649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                float[] f = (float[]) b.getTag();
22749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                System.arraycopy(hsvo, 0, f, 0, 4);
22849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                mBasColors[mSelectedColorButton] = color;
22949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                GradientDrawable sd = ((GradientDrawable) b.getBackground());
23049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                sd.setColor(color);
23149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                resetBorders();
23249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                ParameterColor pram;
23349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                pram = (ParameterColor) mRep.getParam(FilterColorBorderRepresentation.PARAM_COLOR);
23449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                pram.setValue(color);
23549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford                mEditorDraw.commitLocalRepresentation();
23649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            }
2376125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            @Override
2386125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            public void addColorListener(ColorListener l) {
2396125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            }
24049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        };
2416125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford
2426125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        for (int i = 0; i < colorViews.length; i++) {
2436125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford            colorViews[i].addColorListener(colorListener);
2446125a082a2b5ddc0d34a5198c5a7e826bd77e202John Hoford        }
24549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    }
24649798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford
24749798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    private void resetBorders() {
24849798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        for (int i = 0; i < ids.length; i++) {
24949798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            final Button button = mColorButton[i];
25049798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            GradientDrawable sd = ((GradientDrawable) button.getBackground());
25149798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            sd.setColor(mBasColors[i]);
25249798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford            sd.setStroke(3, (mSelectedColorButton == i) ? mSelected : mTransparent);
25349798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford        }
25449798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford    }
25549798939f1bc58eaf5842bbc8bc5424284ab7930John Hoford}
256