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>
This commit is contained in:
20
res/values/cherish_dimens.xml
Normal file
20
res/values/cherish_dimens.xml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2017 The ABC rom
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<resources>
|
||||||
|
<dimen name="picker_circle_preview_size">26dp</dimen>
|
||||||
|
</resources>
|
||||||
@@ -23,6 +23,8 @@ import android.content.res.TypedArray;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Bitmap.Config;
|
import android.graphics.Bitmap.Config;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ShapeDrawable;
|
||||||
|
import android.graphics.drawable.shapes.OvalShape;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
@@ -200,8 +202,10 @@ public class ColorPickerPreference extends Preference implements
|
|||||||
}
|
}
|
||||||
widgetFrameView.addView(iView);
|
widgetFrameView.addView(iView);
|
||||||
widgetFrameView.setMinimumWidth(0);
|
widgetFrameView.setMinimumWidth(0);
|
||||||
iView.setBackgroundDrawable(new AlphaPatternDrawable((int) (5 * mDensity)));
|
final int size = (int) getContext().getResources().getDimension(R.dimen.picker_circle_preview_size);
|
||||||
iView.setImageBitmap(getPreviewBitmap());
|
final int imageColor = ((mValue & 0xF0F0F0) == 0xF0F0F0) ?
|
||||||
|
(mValue - 0x101010) : mValue;
|
||||||
|
iView.setImageDrawable(createOvalShape(size, 0xFF000000 + imageColor));
|
||||||
iView.setTag("preview");
|
iView.setTag("preview");
|
||||||
iView.setOnClickListener(new View.OnClickListener() {
|
iView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -221,26 +225,6 @@ public class ColorPickerPreference extends Preference implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public void onColorChanged(int color) {
|
public void onColorChanged(int color) {
|
||||||
if (isPersistent()) {
|
if (isPersistent()) {
|
||||||
@@ -414,4 +398,12 @@ public class ColorPickerPreference extends Preference implements
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user