Properly center and scale the navkey glow.
The overall scale of the glow is currently based on the
height of the navigation bar. That is, the glow asset will
be scaled so its height fits perfectly in the bar when at
rest (i.e. not enlarged by active touch).
Bug: 6399510
Change-Id: I95139787a435bcf69d5fda0003c84e4fe55c330d
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
index a00fab3..bb0ce16 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java
@@ -52,6 +52,7 @@
int mCode;
int mTouchSlop;
Drawable mGlowBG;
+ int mGlowWidth, mGlowHeight;
float mGlowAlpha = 0f, mGlowScale = 1f, mDrawingAlpha = 1f;
boolean mSupportsLongpress = true;
RectF mRect = new RectF(0f,0f,0f,0f);
@@ -89,6 +90,8 @@
mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground);
if (mGlowBG != null) {
setDrawingAlpha(BUTTON_QUIESCENT_ALPHA);
+ mGlowWidth = mGlowBG.getIntrinsicWidth();
+ mGlowHeight = mGlowBG.getIntrinsicHeight();
}
a.recycle();
@@ -103,8 +106,12 @@
canvas.save();
final int w = getWidth();
final int h = getHeight();
+ final float aspect = (float)mGlowWidth / mGlowHeight;
+ final int drawW = (int)(h*aspect);
+ final int drawH = h;
+ final int margin = (drawW-w)/2;
canvas.scale(mGlowScale, mGlowScale, w*0.5f, h*0.5f);
- mGlowBG.setBounds(0, 0, w, h);
+ mGlowBG.setBounds(-margin, 0, drawW-margin, drawH);
mGlowBG.setAlpha((int)(mDrawingAlpha * mGlowAlpha * 255));
mGlowBG.draw(canvas);
canvas.restore();