Skip to content

Commit 3fd0e1a

Browse files
committed
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
1 parent af051b5 commit 3fd0e1a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class KeyButtonView extends ImageView {
5252
int mCode;
5353
int mTouchSlop;
5454
Drawable mGlowBG;
55+
int mGlowWidth, mGlowHeight;
5556
float mGlowAlpha = 0f, mGlowScale = 1f, mDrawingAlpha = 1f;
5657
boolean mSupportsLongpress = true;
5758
RectF mRect = new RectF(0f,0f,0f,0f);
@@ -89,6 +90,8 @@ public KeyButtonView(Context context, AttributeSet attrs, int defStyle) {
8990
mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground);
9091
if (mGlowBG != null) {
9192
setDrawingAlpha(BUTTON_QUIESCENT_ALPHA);
93+
mGlowWidth = mGlowBG.getIntrinsicWidth();
94+
mGlowHeight = mGlowBG.getIntrinsicHeight();
9295
}
9396

9497
a.recycle();
@@ -103,8 +106,12 @@ protected void onDraw(Canvas canvas) {
103106
canvas.save();
104107
final int w = getWidth();
105108
final int h = getHeight();
109+
final float aspect = (float)mGlowWidth / mGlowHeight;
110+
final int drawW = (int)(h*aspect);
111+
final int drawH = h;
112+
final int margin = (drawW-w)/2;
106113
canvas.scale(mGlowScale, mGlowScale, w*0.5f, h*0.5f);
107-
mGlowBG.setBounds(0, 0, w, h);
114+
mGlowBG.setBounds(-margin, 0, drawW-margin, drawH);
108115
mGlowBG.setAlpha((int)(mDrawingAlpha * mGlowAlpha * 255));
109116
mGlowBG.draw(canvas);
110117
canvas.restore();

0 commit comments

Comments
 (0)