Color Picker: use oval preview
this code was in old light customization settings commit, no idea who made it
Signed-off-by: xyyx <xyyx@mail.ru>
Change-Id: I67d2f5362ab903a3e42fbbca89e51a049c7aac90
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 373d6bc..7046bfe 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -20,4 +20,6 @@
<dimen name="color_blend_preview_size">36dp</dimen>
<dimen name="alert_dialog_padding_material">20dp</dimen>
+ <dimen name="picker_circle_preview_size">26dp</dimen>
+
</resources>
diff --git a/src/com/bliss/support/colorpicker/ColorPickerPreference.java b/src/com/bliss/support/colorpicker/ColorPickerPreference.java
index b0f8e64..8315395 100644
--- a/src/com/bliss/support/colorpicker/ColorPickerPreference.java
+++ b/src/com/bliss/support/colorpicker/ColorPickerPreference.java
@@ -23,6 +23,8 @@
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Color;
+import android.graphics.drawable.ShapeDrawable;
+import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -202,8 +204,10 @@
}
widgetFrameView.addView(iView);
widgetFrameView.setMinimumWidth(0);
- iView.setBackgroundDrawable(new AlphaPatternDrawable((int) (5 * mDensity)));
- iView.setImageBitmap(getPreviewBitmap());
+ final int size = (int) getContext().getResources().getDimension(R.dimen.picker_circle_preview_size);
+ final int imageColor = ((mValue & 0xF0F0F0) == 0xF0F0F0) ?
+ (mValue - 0x101010) : mValue;
+ iView.setImageDrawable(createOvalShape(size, 0xFF000000 + imageColor));
iView.setTag("preview");
iView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -223,26 +227,6 @@
}
}
- private Bitmap getPreviewBitmap() {
- int d = (int) (mDensity * 31); // 30dip
- int color = mValue;
- Bitmap bm = Bitmap.createBitmap(d, d, Config.ARGB_8888);
- int w = bm.getWidth();
- int h = bm.getHeight();
- int c = color;
- for (int i = 0; i < w; i++) {
- for (int j = i; j < h; j++) {
- c = (i <= 1 || j <= 1 || i >= w - 2 || j >= h - 2) ? Color.GRAY : color;
- bm.setPixel(i, j, c);
- if (i != j) {
- bm.setPixel(j, i, c);
- }
- }
- }
-
- return bm;
- }
-
@Override
public void onColorChanged(int color) {
if (isPersistent()) {
@@ -416,4 +400,12 @@
}
};
}
+
+ private static ShapeDrawable createOvalShape(int size, int color) {
+ ShapeDrawable shape = new ShapeDrawable(new OvalShape());
+ shape.setIntrinsicHeight(size);
+ shape.setIntrinsicWidth(size);
+ shape.getPaint().setColor(color);
+ return shape;
+ }
}