1915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford/*
2915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * Copyright (C) 2013 The Android Open Source Project
3915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford *
4915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * Licensed under the Apache License, Version 2.0 (the "License");
5915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * you may not use this file except in compliance with the License.
6915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * You may obtain a copy of the License at
7915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford *
8915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford *      http://www.apache.org/licenses/LICENSE-2.0
9915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford *
10915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * Unless required by applicable law or agreed to in writing, software
11915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * distributed under the License is distributed on an "AS IS" BASIS,
12915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * See the License for the specific language governing permissions and
14915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford * limitations under the License.
15915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford */
16915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
17915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordpackage com.android.gallery3d.filtershow.colorpicker;
18915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
19915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.content.Context;
20915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.Canvas;
21915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.Color;
22915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.LinearGradient;
23915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.Paint;
24915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.RadialGradient;
25915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.RectF;
26915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.Shader;
27915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.SweepGradient;
28915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.util.AttributeSet;
29915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.util.DisplayMetrics;
30915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.view.MotionEvent;
31915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.view.View;
32915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
33915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport com.android.gallery3d.R;
34915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
35915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport java.util.ArrayList;
36915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
37915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordpublic class ColorRectView extends View implements ColorListener {
38915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mDpToPix;
39915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mRadius = 80;
40915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mCtrY = 100;
41915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private Paint mWheelPaint1;
42915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private Paint mWheelPaint2;
43915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private Paint mWheelPaint3;
44915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mCtrX = 100;
45915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private Paint mDotPaint;
46915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mDotRadus;
47915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mBorder;
48915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private int mBgcolor = 0;
49915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mDotX = Float.NaN;
50915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float mDotY;
51915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private int mSliderColor = 0xFF33B5E5;
52915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private float[] mHSVO = new float[4];
53915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private int[] mColors = new int[] {
54915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFFFF0000,// red
55915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFFFFFF00,// yellow
56915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFF00FF00,// green
57915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFF00FFFF,// cyan
58915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFF0000FF,// blue
59915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFFFF00FF,// magenta
60915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            0xFFFF0000,// red
61915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    };
62915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private int mWidth;
63915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private int mHeight;
64915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public final static float DOT_SIZE = 20;
65915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public final static float BORDER_SIZE = 10;
66915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
67915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public ColorRectView(Context ctx, AttributeSet attrs) {
68915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        super(ctx, attrs);
69915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
70915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
71915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDpToPix = metrics.density;
72915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotRadus = DOT_SIZE * mDpToPix;
73915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mBorder = BORDER_SIZE * mDpToPix;
74915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
75915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint1 = new Paint();
76915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint2 = new Paint();
77915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint3 = new Paint();
78915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotPaint = new Paint();
79915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
80915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotPaint.setStyle(Paint.Style.FILL);
81915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
82915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);
83915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint1.setStyle(Paint.Style.FILL);
84915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint2.setStyle(Paint.Style.FILL);
85915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint3.setStyle(Paint.Style.FILL);
86915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
87915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
88915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public boolean onDown(MotionEvent e) {
89915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        return true;
90915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
91915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
92915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    @Override
93915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public boolean onTouchEvent(MotionEvent event) {
94915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
95915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        invalidate((int) (mDotX - mDotRadus), (int) (mDotY - mDotRadus), (int) (mDotX + mDotRadus),
96915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                (int) (mDotY + mDotRadus));
97915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        float x = event.getX();
98915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        float y = event.getY();
99915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
100915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        x = Math.max(Math.min(x, mWidth - mBorder), mBorder);
101915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        y = Math.max(Math.min(y, mHeight - mBorder), mBorder);
102915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotX = x;
103915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotY = y;
104915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        float sat = 1 - (mDotY - mBorder) / (mHeight - 2 * mBorder);
105915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        if (sat > 1) {
106915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            sat = 1;
107915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
108915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
109915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        double hue = Math.PI * 2 * (mDotX - mBorder) / (mHeight - 2 * mBorder);
110915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mHSVO[0] = ((float) Math.toDegrees(hue) + 360) % 360;
111915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mHSVO[1] = sat;
112915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        notifyColorListeners(mHSVO);
113915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        updateDotPaint();
114915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        invalidate((int) (mDotX - mDotRadus), (int) (mDotY - mDotRadus), (int) (mDotX + mDotRadus),
115915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                (int) (mDotY + mDotRadus));
116915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
117915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        return true;
118915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
119915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
120915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    @Override
121915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
122915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWidth = w;
123915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mHeight = h;
124915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mCtrY = h / 2f;
125915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mCtrX = w / 2f;
126915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mRadius = Math.min(mCtrY, mCtrX) - 2 * mBorder;
127915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        setUpColorPanel();
128915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
129915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
130915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private void setUpColorPanel() {
131915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        float val = mHSVO[2];
132915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        int v = 0xFF000000 | 0x10101 * (int) (val * 0xFF);
133915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        int[] colors = new int[] {
134915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                0x0000000, v };
135915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        int[] colors2 = new int[] {
136915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                0x0000000, 0xFF000000 };
137915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        int[] wheelColor = new int[mColors.length];
138915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        float[] hsv = new float[3];
139915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (int i = 0; i < wheelColor.length; i++) {
140915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Color.colorToHSV(mColors[i], hsv);
141915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            hsv[2] = mHSVO[2];
142915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            wheelColor[i] = Color.HSVToColor(hsv);
143915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
144915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        updateDot();
145915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        updateDotPaint();
146915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        SweepGradient sg = new SweepGradient(mCtrX, mCtrY, wheelColor, null);
147915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        LinearGradient lg = new LinearGradient(
148915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mBorder, 0, mWidth - mBorder, 0, wheelColor, null, Shader.TileMode.CLAMP);
149915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
150915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint1.setShader(lg);
151915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        LinearGradient rg = new LinearGradient(
152915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                0, mBorder, 0, mHeight - mBorder, colors, null, Shader.TileMode.CLAMP);
153915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint2.setShader(rg);
154915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        LinearGradient rg2 = new LinearGradient(
155915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                0, mBorder, 0, mHeight - mBorder, colors2, null, Shader.TileMode.CLAMP);
156915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mWheelPaint3.setShader(rg2);
157915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
158915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
159915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    @Override
160915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    protected void onDraw(Canvas canvas) {
161915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        super.onDraw(canvas);
162915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        canvas.drawColor(mBgcolor);
163915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        RectF rect = new RectF();
164915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        rect.left = mBorder;
165915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        rect.right = mWidth - mBorder;
166915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        rect.top = mBorder;
167915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        rect.bottom = mHeight - mBorder;
168915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
169915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        canvas.drawRect(rect, mWheelPaint1);
170915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        canvas.drawRect(rect, mWheelPaint3);
171915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        canvas.drawRect(rect, mWheelPaint2);
172915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
173915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        if (mDotX != Float.NaN) {
174915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
175915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.drawCircle(mDotX, mDotY, mDotRadus, mDotPaint);
176915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
177915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
178915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
179915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private void updateDot() {
180915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
181915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        double hue = mHSVO[0];
182915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        double sat = mHSVO[1];
183915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
184915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotX = (float) (mBorder + (mHeight - 2 * mBorder) * Math.toRadians(hue) / (Math.PI * 2));
185915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotY = (float) ((1 - sat) * (mHeight - 2 * mBorder) + mBorder);
186915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
187915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
188915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
189915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    private void updateDotPaint() {
190915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        int[] colors3 = new int[] {
191915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mSliderColor, mSliderColor, 0x66000000, 0 };
192915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        RadialGradient g = new RadialGradient(mDotX, mDotY, mDotRadus, colors3, new float[] {
193915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                0, .3f, .31f, 1 }, Shader.TileMode.CLAMP);
194915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDotPaint.setShader(g);
195915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
196915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
197915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
198915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    @Override
199915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public void setColor(float[] hsvo) {
200915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        System.arraycopy(hsvo, 0, mHSVO, 0, mHSVO.length);
201915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
202915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        setUpColorPanel();
203915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        invalidate();
204915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
205915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        updateDot();
206915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        updateDotPaint();
207915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
208915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
209915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
210915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    ArrayList<ColorListener> mColorListeners = new ArrayList<ColorListener>();
211915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
212915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public void notifyColorListeners(float[] hsv) {
213915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (ColorListener l : mColorListeners) {
214915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            l.setColor(hsv);
215915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
216915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
217915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
218915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public void addColorListener(ColorListener l) {
219915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mColorListeners.add(l);
220915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
221915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
222915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public void removeColorListener(ColorListener l) {
223915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mColorListeners.remove(l);
224915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
225915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford}
226