Workaround for generating QSB icon press states. (Bug 7132477)
Change-Id: I7754bbb20572908cd428c12ba84a7b1160063bcb
This commit is contained in:
parent
061e9008b0
commit
4cc332ac43
|
@ -42,13 +42,15 @@ public class HolographicViewHelper {
|
||||||
void generatePressedFocusedStates(ImageView v) {
|
void generatePressedFocusedStates(ImageView v) {
|
||||||
if (!mStatesUpdated && v != null) {
|
if (!mStatesUpdated && v != null) {
|
||||||
mStatesUpdated = true;
|
mStatesUpdated = true;
|
||||||
|
Bitmap original = createOriginalImage(v, mTempCanvas);
|
||||||
Bitmap outline = createPressImage(v, mTempCanvas);
|
Bitmap outline = createPressImage(v, mTempCanvas);
|
||||||
FastBitmapDrawable d = new FastBitmapDrawable(outline);
|
FastBitmapDrawable originalD = new FastBitmapDrawable(original);
|
||||||
|
FastBitmapDrawable outlineD = new FastBitmapDrawable(outline);
|
||||||
|
|
||||||
StateListDrawable states = new StateListDrawable();
|
StateListDrawable states = new StateListDrawable();
|
||||||
states.addState(new int[] {android.R.attr.state_pressed}, d);
|
states.addState(new int[] {android.R.attr.state_pressed}, outlineD);
|
||||||
states.addState(new int[] {android.R.attr.state_focused}, d);
|
states.addState(new int[] {android.R.attr.state_focused}, outlineD);
|
||||||
states.addState(new int[] {}, v.getDrawable());
|
states.addState(new int[] {}, originalD);
|
||||||
v.setImageDrawable(states);
|
v.setImageDrawable(states);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,18 +65,33 @@ public class HolographicViewHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a copy of the original image.
|
||||||
|
*/
|
||||||
|
private Bitmap createOriginalImage(ImageView v, Canvas canvas) {
|
||||||
|
final Bitmap b = Bitmap.createBitmap(
|
||||||
|
v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
|
canvas.setBitmap(b);
|
||||||
|
canvas.save();
|
||||||
|
v.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
canvas.setBitmap(null);
|
||||||
|
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new press state image which is the old image with a blue overlay.
|
* Creates a new press state image which is the old image with a blue overlay.
|
||||||
* Responsibility for the bitmap is transferred to the caller.
|
* Responsibility for the bitmap is transferred to the caller.
|
||||||
*/
|
*/
|
||||||
private Bitmap createPressImage(ImageView v, Canvas canvas) {
|
private Bitmap createPressImage(ImageView v, Canvas canvas) {
|
||||||
final int padding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS;
|
|
||||||
final Bitmap b = Bitmap.createBitmap(
|
final Bitmap b = Bitmap.createBitmap(
|
||||||
v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888);
|
v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
canvas.setBitmap(b);
|
canvas.setBitmap(b);
|
||||||
canvas.save();
|
canvas.save();
|
||||||
v.getDrawable().draw(canvas);
|
v.draw(canvas);
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
canvas.drawColor(mHighlightColor, PorterDuff.Mode.SRC_IN);
|
canvas.drawColor(mHighlightColor, PorterDuff.Mode.SRC_IN);
|
||||||
canvas.setBitmap(null);
|
canvas.setBitmap(null);
|
||||||
|
|
Loading…
Reference in New Issue