2010-11-07 21:21:32 -05:00
|
|
|
/* Sourced from http://code.google.com/p/android-color-picker/source/browse/trunk/AmbilWarna/src/yuku/ambilwarna/AmbilWarnaBox.java?r=1
|
2010-11-12 20:47:08 -05:00
|
|
|
* On 2010-11-07
|
2010-11-07 21:21:32 -05:00
|
|
|
* Translated to English, Ported to use the same (inferior) API as the more standard "ColorPickerDialog" and imported into the K-9 namespace by Jesse Vincent
|
|
|
|
* In an ideal world, we should move to using AmbilWarna as an Android Library Project in the future
|
2010-11-12 20:47:08 -05:00
|
|
|
* License: Apache 2.0
|
2010-11-07 21:21:32 -05:00
|
|
|
* Author: yukuku@code.google.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-12 19:18:00 -05:00
|
|
|
package com.fsck.k9.view;
|
2010-11-07 21:21:32 -05:00
|
|
|
import com.fsck.k9.R;
|
|
|
|
import android.content.*;
|
|
|
|
import android.graphics.*;
|
|
|
|
import android.graphics.Shader.*;
|
|
|
|
import android.util.*;
|
|
|
|
import android.view.*;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class ColorPickerBox extends View {
|
2010-11-07 21:21:32 -05:00
|
|
|
|
|
|
|
Paint paint;
|
|
|
|
Shader dalam;
|
|
|
|
Shader luar;
|
|
|
|
float hue;
|
|
|
|
float onedp;
|
|
|
|
float sizeUiDp = 240.f;
|
|
|
|
float sizeUiPx; // diset di constructor
|
|
|
|
float[] tmp00 = new float[3];
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public ColorPickerBox(Context context) {
|
2010-11-07 21:21:32 -05:00
|
|
|
this(context, null);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public ColorPickerBox(Context context, AttributeSet attrs) {
|
2010-11-07 21:21:32 -05:00
|
|
|
this(context, attrs, 0);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public ColorPickerBox(Context context, AttributeSet attrs, int defStyle) {
|
2010-11-07 21:21:32 -05:00
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
|
|
|
onedp = context.getResources().getDimension(R.dimen.colorpicker_onedp);
|
|
|
|
sizeUiPx = sizeUiDp * onedp;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
protected void onDraw(Canvas canvas) {
|
2010-11-07 21:21:32 -05:00
|
|
|
super.onDraw(canvas);
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (paint == null) {
|
2010-11-07 21:21:32 -05:00
|
|
|
paint = new Paint();
|
|
|
|
luar = new LinearGradient(0.f, 0.f, 0.f, sizeUiPx, 0xffffffff, 0xff000000, TileMode.CLAMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp00[1] = tmp00[2] = 1.f;
|
|
|
|
tmp00[0] = hue;
|
|
|
|
int rgb = Color.HSVToColor(tmp00);
|
|
|
|
|
|
|
|
dalam = new LinearGradient(0.f, 0.f, sizeUiPx, 0.f, 0xffffffff, rgb, TileMode.CLAMP);
|
|
|
|
ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
|
|
|
|
|
|
|
|
paint.setShader(shader);
|
|
|
|
|
|
|
|
canvas.drawRect(0.f, 0.f, sizeUiPx, sizeUiPx, paint);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void setHue(float hue) {
|
2010-11-07 21:21:32 -05:00
|
|
|
this.hue = hue;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|