summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/notificationlight
diff options
context:
space:
mode:
authorDvTonder <david.vantonder@gmail.com>2013-01-05 09:14:14 -0500
committerDvTonder <david.vantonder@gmail.com>2013-01-05 09:14:14 -0500
commit527f17f73f76feee76f50d022c7b7629d288e312 (patch)
tree73889017ffca6641f52f229bccff31b013c127ec /src/com/android/settings/notificationlight
parentf8c9fbcb214f6881ddb6ac02fa5ae45518828be7 (diff)
downloadpackages_apps_Settings-527f17f73f76feee76f50d022c7b7629d288e312.zip
packages_apps_Settings-527f17f73f76feee76f50d022c7b7629d288e312.tar.gz
packages_apps_Settings-527f17f73f76feee76f50d022c7b7629d288e312.tar.bz2
Settings: Fix color picker ComposeShader view
The shader was not showing the proper combined gradients. This is a limitation of the ComposeShader in Android 3+ and has to do with the hardware acceleration as described here: 'ComposeShader can only contain shaders of differenttypes (a BitmapShader and a LinearGradient for instance, but not two instances of BitmapShader)'. But, 'If your application is affected by any of these missing features or limitations, you can turn off hardware acceleration for just the affected portion of your application by calling: setLayerType(View.LAYER_TYPE_SOFTWARE, null).' Change-Id: I8d945e37ed97c409a0cc7e9ec5570019545f0f68
Diffstat (limited to 'src/com/android/settings/notificationlight')
-rw-r--r--src/com/android/settings/notificationlight/ApplicationLightPreference.java2
-rw-r--r--src/com/android/settings/notificationlight/ColorPickerView.java193
2 files changed, 37 insertions, 158 deletions
diff --git a/src/com/android/settings/notificationlight/ApplicationLightPreference.java b/src/com/android/settings/notificationlight/ApplicationLightPreference.java
index d88eaf9..f76b0fd 100644
--- a/src/com/android/settings/notificationlight/ApplicationLightPreference.java
+++ b/src/com/android/settings/notificationlight/ApplicationLightPreference.java
@@ -34,11 +34,9 @@ import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import com.android.settings.R;
-import com.android.settings.Utils;
public class ApplicationLightPreference extends Preference implements
View.OnClickListener {
diff --git a/src/com/android/settings/notificationlight/ColorPickerView.java b/src/com/android/settings/notificationlight/ColorPickerView.java
index 9a4d287..817e397 100644
--- a/src/com/android/settings/notificationlight/ColorPickerView.java
+++ b/src/com/android/settings/notificationlight/ColorPickerView.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 Daniel Nilsson
- * Copyright (C) 2012 THe CyanogenMod Project
+ * Copyright (C) 2012 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,12 +24,13 @@ import android.graphics.ComposeShader;
import android.graphics.LinearGradient;
import android.graphics.Paint;
import android.graphics.Point;
-import android.graphics.PorterDuff;
+import android.graphics.PorterDuff.Mode;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Shader.TileMode;
+import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
@@ -155,7 +156,6 @@ public class ColorPickerView extends View {
PANEL_SPACING = PANEL_SPACING * mDensity;
mDrawingOffset = calculateRequiredOffset();
-
initPaintTools();
// Needed for receiving track ball motion events.
@@ -164,7 +164,6 @@ public class ColorPickerView extends View {
}
private void initPaintTools() {
-
mSatValPaint = new Paint();
mSatValTrackerPaint = new Paint();
mHuePaint = new Paint();
@@ -187,7 +186,6 @@ public class ColorPickerView extends View {
mAlphaTextPaint.setAntiAlias(true);
mAlphaTextPaint.setTextAlign(Align.CENTER);
mAlphaTextPaint.setFakeBoldText(true);
-
}
private float calculateRequiredOffset() {
@@ -198,7 +196,6 @@ public class ColorPickerView extends View {
}
private int[] buildHueColorArray() {
-
int[] hue = new int[361];
int count = 0;
@@ -207,25 +204,24 @@ public class ColorPickerView extends View {
i, 1f, 1f
});
}
-
return hue;
}
@Override
protected void onDraw(Canvas canvas) {
-
- if (mDrawingRect.width() <= 0 || mDrawingRect.height() <= 0)
+ if (mDrawingRect.width() <= 0 || mDrawingRect.height() <= 0) {
return;
-
+ }
drawSatValPanel(canvas);
drawHuePanel(canvas);
drawAlphaPanel(canvas);
-
}
private void drawSatValPanel(Canvas canvas) {
-
final RectF rect = mSatValRect;
+ int rgb = Color.HSVToColor(new float[] {
+ mHue, 1f, 1f
+ });
if (BORDER_WIDTH_PX > 0) {
mBorderPaint.setColor(mBorderColor);
@@ -233,35 +229,32 @@ public class ColorPickerView extends View {
rect.bottom + BORDER_WIDTH_PX, mBorderPaint);
}
+ // On Honeycomb+ we need to use software rendering to create the shader properly
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
+ setLayerType(View.LAYER_TYPE_SOFTWARE, null);
+ }
+
+ // Get the overlaying gradients ready and create the ComposeShader
if (mValShader == null) {
mValShader = new LinearGradient(rect.left, rect.top, rect.left, rect.bottom,
0xffffffff, 0xff000000, TileMode.CLAMP);
}
-
- int rgb = Color.HSVToColor(new float[] {
- mHue, 1f, 1f
- });
-
mSatShader = new LinearGradient(rect.left, rect.top, rect.right, rect.top,
0xffffffff, rgb, TileMode.CLAMP);
- ComposeShader mShader = new ComposeShader(mValShader, mSatShader, PorterDuff.Mode.MULTIPLY);
+ ComposeShader mShader = new ComposeShader(mValShader, mSatShader, Mode.MULTIPLY);
mSatValPaint.setShader(mShader);
-
canvas.drawRect(rect, mSatValPaint);
Point p = satValToPoint(mSat, mVal);
-
mSatValTrackerPaint.setColor(0xff000000);
canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS - 1f * mDensity,
mSatValTrackerPaint);
mSatValTrackerPaint.setColor(0xffdddddd);
canvas.drawCircle(p.x, p.y, PALETTE_CIRCLE_TRACKER_RADIUS, mSatValTrackerPaint);
-
}
private void drawHuePanel(Canvas canvas) {
-
final RectF rect = mHueRect;
if (BORDER_WIDTH_PX > 0) {
@@ -296,9 +289,9 @@ public class ColorPickerView extends View {
}
private void drawAlphaPanel(Canvas canvas) {
-
- if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null)
+ if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) {
return;
+ }
final RectF rect = mAlphaRect;
@@ -332,7 +325,6 @@ public class ColorPickerView extends View {
}
float rectWidth = 4 * mDensity / 2;
-
Point p = alphaToPoint(mAlpha);
RectF r = new RectF();
@@ -342,19 +334,15 @@ public class ColorPickerView extends View {
r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;
canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
-
}
private Point hueToPoint(float hue) {
-
final RectF rect = mHueRect;
final float height = rect.height();
Point p = new Point();
-
p.y = (int) (height - (hue * height / 360f) + rect.top);
p.x = (int) rect.left;
-
return p;
}
@@ -373,229 +361,161 @@ public class ColorPickerView extends View {
}
private Point alphaToPoint(int alpha) {
-
final RectF rect = mAlphaRect;
final float width = rect.width();
Point p = new Point();
-
p.x = (int) (width - (alpha * width / 0xff) + rect.left);
p.y = (int) rect.top;
-
return p;
-
}
private float[] pointToSatVal(float x, float y) {
-
final RectF rect = mSatValRect;
float[] result = new float[2];
-
float width = rect.width();
float height = rect.height();
if (x < rect.left) {
x = 0f;
- }
- else if (x > rect.right) {
+ } else if (x > rect.right) {
x = width;
- }
- else {
+ } else {
x = x - rect.left;
}
if (y < rect.top) {
y = 0f;
- }
- else if (y > rect.bottom) {
+ } else if (y > rect.bottom) {
y = height;
- }
- else {
+ } else {
y = y - rect.top;
}
result[0] = 1.f / width * x;
result[1] = 1.f - (1.f / height * y);
-
return result;
}
private float pointToHue(float y) {
-
final RectF rect = mHueRect;
-
float height = rect.height();
if (y < rect.top) {
y = 0f;
- }
- else if (y > rect.bottom) {
+ } else if (y > rect.bottom) {
y = height;
- }
- else {
+ } else {
y = y - rect.top;
}
-
return 360f - (y * 360f / height);
}
private int pointToAlpha(int x) {
-
final RectF rect = mAlphaRect;
final int width = (int) rect.width();
if (x < rect.left) {
x = 0;
- }
- else if (x > rect.right) {
+ } else if (x > rect.right) {
x = width;
- }
- else {
+ } else {
x = x - (int) rect.left;
}
-
return 0xff - (x * 0xff / width);
-
}
@Override
public boolean onTrackballEvent(MotionEvent event) {
-
float x = event.getX();
float y = event.getY();
-
boolean update = false;
if (event.getAction() == MotionEvent.ACTION_MOVE) {
-
switch (mLastTouchedPanel) {
-
case PANEL_SAT_VAL:
-
float sat,
val;
-
sat = mSat + x / 50f;
val = mVal - y / 50f;
-
if (sat < 0f) {
sat = 0f;
- }
- else if (sat > 1f) {
+ } else if (sat > 1f) {
sat = 1f;
}
if (val < 0f) {
val = 0f;
- }
- else if (val > 1f) {
+ } else if (val > 1f) {
val = 1f;
}
-
mSat = sat;
mVal = val;
-
update = true;
-
break;
-
case PANEL_HUE:
-
float hue = mHue - y * 10f;
-
if (hue < 0f) {
hue = 0f;
- }
- else if (hue > 360f) {
+ } else if (hue > 360f) {
hue = 360f;
}
-
mHue = hue;
-
update = true;
-
break;
-
case PANEL_ALPHA:
-
if (!mShowAlphaPanel || mAlphaRect == null) {
update = false;
- }
- else {
-
+ } else {
int alpha = (int) (mAlpha - x * 10);
-
if (alpha < 0) {
alpha = 0;
- }
- else if (alpha > 0xff) {
+ } else if (alpha > 0xff) {
alpha = 0xff;
}
-
mAlpha = alpha;
-
update = true;
}
-
break;
}
-
}
if (update) {
-
if (mListener != null) {
mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[] {
mHue, mSat, mVal
}));
}
-
invalidate();
return true;
}
-
return super.onTrackballEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
-
boolean update = false;
switch (event.getAction()) {
-
case MotionEvent.ACTION_DOWN:
-
mStartTouchPoint = new Point((int) event.getX(), (int) event.getY());
-
update = moveTrackersIfNeeded(event);
-
break;
-
case MotionEvent.ACTION_MOVE:
-
update = moveTrackersIfNeeded(event);
-
break;
-
case MotionEvent.ACTION_UP:
-
mStartTouchPoint = null;
-
update = moveTrackersIfNeeded(event);
-
break;
-
}
if (update) {
-
if (mListener != null) {
mListener.onColorChanged(Color.HSVToColor(mAlpha, new float[] {
mHue, mSat, mVal
}));
}
-
invalidate();
return true;
}
@@ -609,34 +529,22 @@ public class ColorPickerView extends View {
return false;
boolean update = false;
-
int startX = mStartTouchPoint.x;
int startY = mStartTouchPoint.y;
if (mHueRect.contains(startX, startY)) {
mLastTouchedPanel = PANEL_HUE;
-
mHue = pointToHue(event.getY());
-
update = true;
- }
- else if (mSatValRect.contains(startX, startY)) {
-
+ } else if (mSatValRect.contains(startX, startY)) {
mLastTouchedPanel = PANEL_SAT_VAL;
-
float[] result = pointToSatVal(event.getX(), event.getY());
-
mSat = result[0];
mVal = result[1];
-
update = true;
- }
- else if (mAlphaRect != null && mAlphaRect.contains(startX, startY)) {
-
+ } else if (mAlphaRect != null && mAlphaRect.contains(startX, startY)) {
mLastTouchedPanel = PANEL_ALPHA;
-
mAlpha = pointToAlpha((int) event.getX());
-
update = true;
}
@@ -645,7 +553,6 @@ public class ColorPickerView extends View {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-
int width = 0;
int height = 0;
@@ -666,25 +573,20 @@ public class ColorPickerView extends View {
if (height > heightAllowed) {
height = heightAllowed;
width = (int) (height + PANEL_SPACING + HUE_PANEL_WIDTH);
- }
- else {
+ } else {
width = widthAllowed;
}
- }
- else {
+ } else {
width = (int) (heightAllowed - ALPHA_PANEL_HEIGHT + HUE_PANEL_WIDTH);
if (width > widthAllowed) {
width = widthAllowed;
height = (int) (widthAllowed - HUE_PANEL_WIDTH + ALPHA_PANEL_HEIGHT);
- }
- else {
+ } else {
height = heightAllowed;
}
-
}
-
setMeasuredDimension(width, height);
}
@@ -705,25 +607,18 @@ public class ColorPickerView extends View {
}
private int getPrefferedWidth() {
-
int width = getPrefferedHeight();
-
if (mShowAlphaPanel) {
width -= (PANEL_SPACING + ALPHA_PANEL_HEIGHT);
}
-
return (int) (width + HUE_PANEL_WIDTH + PANEL_SPACING);
-
}
private int getPrefferedHeight() {
-
int height = (int) (200 * mDensity);
-
if (mShowAlphaPanel) {
height += PANEL_SPACING + ALPHA_PANEL_HEIGHT;
}
-
return height;
}
@@ -743,7 +638,6 @@ public class ColorPickerView extends View {
}
private void setUpSatValRect() {
-
final RectF dRect = mDrawingRect;
float panelSide = dRect.height() - BORDER_WIDTH_PX * 2;
@@ -755,7 +649,6 @@ public class ColorPickerView extends View {
float top = dRect.top + BORDER_WIDTH_PX;
float bottom = top + panelSide;
float right = left + panelSide;
-
mSatValRect = new RectF(left, top, right, bottom);
}
@@ -772,24 +665,21 @@ public class ColorPickerView extends View {
}
private void setUpAlphaRect() {
-
- if (!mShowAlphaPanel)
+ if (!mShowAlphaPanel) {
return;
+ }
final RectF dRect = mDrawingRect;
-
float left = dRect.left + BORDER_WIDTH_PX;
float top = dRect.bottom - ALPHA_PANEL_HEIGHT + BORDER_WIDTH_PX;
float bottom = dRect.bottom - BORDER_WIDTH_PX;
float right = dRect.right - BORDER_WIDTH_PX;
mAlphaRect = new RectF(left, top, right, bottom);
-
mAlphaPattern = new AlphaPatternDrawable((int) (5 * mDensity));
mAlphaPattern.setBounds(Math.round(mAlphaRect.left), Math
.round(mAlphaRect.top), Math.round(mAlphaRect.right), Math
.round(mAlphaRect.bottom));
-
}
/**
@@ -847,16 +737,13 @@ public class ColorPickerView extends View {
* OnColorChangedListener.
*/
public void setColor(int color, boolean callback) {
-
int alpha = Color.alpha(color);
int red = Color.red(color);
int blue = Color.blue(color);
int green = Color.green(color);
-
float[] hsv = new float[3];
Color.RGBToHSV(red, green, blue, hsv);
-
mAlpha = alpha;
mHue = hsv[0];
mSat = hsv[1];
@@ -867,7 +754,6 @@ public class ColorPickerView extends View {
mHue, mSat, mVal
}));
}
-
invalidate();
}
@@ -890,7 +776,6 @@ public class ColorPickerView extends View {
* @param visible
*/
public void setAlphaSliderVisible(boolean visible) {
-
if (mShowAlphaPanel != visible) {
mShowAlphaPanel = visible;
@@ -902,8 +787,6 @@ public class ColorPickerView extends View {
mSatShader = null;
mHueShader = null;
mAlphaShader = null;
- ;
-
requestLayout();
}
@@ -911,9 +794,7 @@ public class ColorPickerView extends View {
public void setSliderTrackerColor(int color) {
mSliderTrackerColor = color;
-
mHueTrackerPaint.setColor(mSliderTrackerColor);
-
invalidate();
}