aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java
diff options
context:
space:
mode:
authorsteckbrief <steckbrief@chefmail.de>2015-04-11 23:00:10 +0200
committersteckbrief <steckbrief@chefmail.de>2015-04-11 23:00:10 +0200
commit17779e77002e99dabb73f4fa8f9596e9d220319b (patch)
tree7604484b69948e299c95a58f2f6be8fd78056fd7 /src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java
parent94a669fcb861d9cff4414d98abb289d1452c9300 (diff)
Color choose dialog
Diffstat (limited to 'src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java')
-rw-r--r--src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java b/src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java
new file mode 100644
index 00000000..9fb854df
--- /dev/null
+++ b/src/main/java/yuku/ambilwarna/AmbilWarnaSquare.java
@@ -0,0 +1,46 @@
+package yuku.ambilwarna;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ComposeShader;
+import android.graphics.LinearGradient;
+import android.graphics.Paint;
+import android.graphics.PorterDuff;
+import android.graphics.Shader;
+import android.graphics.Shader.TileMode;
+import android.util.AttributeSet;
+import android.view.View;
+
+public class AmbilWarnaSquare extends View {
+ Paint paint;
+ Shader luar;
+ final float[] color = { 1.f, 1.f, 1.f };
+
+ public AmbilWarnaSquare(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public AmbilWarnaSquare(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ }
+
+ @SuppressLint("DrawAllocation") @Override protected void onDraw(Canvas canvas) {
+ super.onDraw(canvas);
+ if (paint == null) {
+ paint = new Paint();
+ luar = new LinearGradient(0.f, 0.f, 0.f, this.getMeasuredHeight(), 0xffffffff, 0xff000000, TileMode.CLAMP);
+ }
+ int rgb = Color.HSVToColor(color);
+ Shader dalam = new LinearGradient(0.f, 0.f, this.getMeasuredWidth(), 0.f, 0xffffffff, rgb, TileMode.CLAMP);
+ ComposeShader shader = new ComposeShader(luar, dalam, PorterDuff.Mode.MULTIPLY);
+ paint.setShader(shader);
+ canvas.drawRect(0.f, 0.f, this.getMeasuredWidth(), this.getMeasuredHeight(), paint);
+ }
+
+ void setHue(float hue) {
+ color[0] = hue;
+ invalidate();
+ }
+} \ No newline at end of file