diff options
author | Adrian Roos <roosa@google.com> | 2014-05-26 20:54:12 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-26 20:54:13 +0000 |
commit | 41b170d6066cb52bb3e396c608b01f2981b95e5d (patch) | |
tree | becbc8ba0aa1008b3ab0fd37abc91bdfbe5cc15b /packages/SystemUI/src/com/android | |
parent | 7c1d454da1f052c634c6a95ed3805be34d322765 (diff) | |
parent | cde52d77ebfee9229fa39cc0d8a0e6ad0c839212 (diff) | |
download | frameworks_base-41b170d6066cb52bb3e396c608b01f2981b95e5d.zip frameworks_base-41b170d6066cb52bb3e396c608b01f2981b95e5d.tar.gz frameworks_base-41b170d6066cb52bb3e396c608b01f2981b95e5d.tar.bz2 |
Merge "Replace KeyButtonView's custom glow with Quantum Ripple" into lmp-preview-dev
Diffstat (limited to 'packages/SystemUI/src/com/android')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java | 144 |
1 files changed, 31 insertions, 113 deletions
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 718acc3..330b599 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyButtonView.java @@ -17,12 +17,9 @@ package com.android.systemui.statusbar.policy; import android.animation.Animator; -import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.Context; import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.hardware.input.InputManager; import android.os.SystemClock; @@ -34,9 +31,7 @@ import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.SoundEffectConstants; -import android.view.View; import android.view.ViewConfiguration; -import android.view.ViewDebug; import android.view.accessibility.AccessibilityEvent; import android.widget.ImageView; @@ -46,25 +41,18 @@ public class KeyButtonView extends ImageView { private static final String TAG = "StatusBar.KeyButtonView"; private static final boolean DEBUG = false; - final float GLOW_MAX_SCALE_FACTOR = 1.8f; public static final float DEFAULT_QUIESCENT_ALPHA = 0.70f; - long mDownTime; - int mCode; - int mTouchSlop; - Drawable mGlowBG; - int mGlowWidth, mGlowHeight; - float mGlowAlpha = 0f, mGlowScale = 1f; - @ViewDebug.ExportedProperty(category = "drawing") - float mDrawingAlpha = 1f; - @ViewDebug.ExportedProperty(category = "drawing") - float mQuiescentAlpha = DEFAULT_QUIESCENT_ALPHA; - boolean mSupportsLongpress = true; - RectF mRect = new RectF(); - AnimatorSet mPressedAnim; - Animator mAnimateToQuiescent = new ObjectAnimator(); + private long mDownTime; + private int mCode; + private int mTouchSlop; + private float mDrawingAlpha = 1f; + private float mQuiescentAlpha = DEFAULT_QUIESCENT_ALPHA; + private boolean mSupportsLongpress = true; + private Animator mAnimateToQuiescent = new ObjectAnimator(); + private Drawable mBackground; - Runnable mCheckLongPress = new Runnable() { + private final Runnable mCheckLongPress = new Runnable() { public void run() { if (isPressed()) { // Log.d("KeyButtonView", "longpressed: " + this); @@ -93,47 +81,27 @@ public class KeyButtonView extends ImageView { mSupportsLongpress = a.getBoolean(R.styleable.KeyButtonView_keyRepeat, true); - mGlowBG = a.getDrawable(R.styleable.KeyButtonView_glowBackground); - setDrawingAlpha(mQuiescentAlpha); - if (mGlowBG != null) { - mGlowWidth = mGlowBG.getIntrinsicWidth(); - mGlowHeight = mGlowBG.getIntrinsicHeight(); + Drawable d = getBackground(); + if (d != null) { + mBackground = d.mutate(); + setBackground(mBackground); } + setDrawingAlpha(mQuiescentAlpha); + a.recycle(); setClickable(true); mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); } - @Override - protected void onDraw(Canvas canvas) { - if (mGlowBG != null) { - 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(-margin, 0, drawW-margin, drawH); - mGlowBG.setAlpha((int)(mDrawingAlpha * mGlowAlpha * 255)); - mGlowBG.draw(canvas); - canvas.restore(); - mRect.right = w; - mRect.bottom = h; - } - super.onDraw(canvas); - } - public void setQuiescentAlpha(float alpha, boolean animate) { mAnimateToQuiescent.cancel(); alpha = Math.min(Math.max(alpha, 0), 1); if (alpha == mQuiescentAlpha && alpha == mDrawingAlpha) return; mQuiescentAlpha = alpha; if (DEBUG) Log.d(TAG, "New quiescent alpha = " + mQuiescentAlpha); - if (mGlowBG != null && animate) { + if (mBackground != null && animate) { mAnimateToQuiescent = animateToQuiescent(); mAnimateToQuiescent.start(); } else { @@ -154,87 +122,35 @@ public class KeyButtonView extends ImageView { } public void setDrawingAlpha(float x) { - // Calling setAlpha(int), which is an ImageView-specific - // method that's different from setAlpha(float). This sets - // the alpha on this ImageView's drawable directly - setAlpha((int) (x * 255)); - mDrawingAlpha = x; - } - - public float getGlowAlpha() { - if (mGlowBG == null) return 0; - return mGlowAlpha; - } - - public void setGlowAlpha(float x) { - if (mGlowBG == null) return; - mGlowAlpha = x; - invalidate(); - } - - public float getGlowScale() { - if (mGlowBG == null) return 0; - return mGlowScale; - } - - public void setGlowScale(float x) { - if (mGlowBG == null) return; - mGlowScale = x; - final float w = getWidth(); - final float h = getHeight(); - if (GLOW_MAX_SCALE_FACTOR <= 1.0f) { - // this only works if we know the glow will never leave our bounds - invalidate(); - } else { - final float rx = (w * (GLOW_MAX_SCALE_FACTOR - 1.0f)) / 2.0f + 1.0f; - final float ry = (h * (GLOW_MAX_SCALE_FACTOR - 1.0f)) / 2.0f + 1.0f; - com.android.systemui.SwipeHelper.invalidateGlobalRegion( - this, - new RectF(getLeft() - rx, - getTop() - ry, - getRight() + rx, - getBottom() + ry)); - - // also invalidate our immediate parent to help avoid situations where nearby glows - // interfere - ((View)getParent()).invalidate(); + setImageAlpha((int) (x * 255)); + if (mBackground != null) { + mBackground.setAlpha((int)(x * 255)); } + mDrawingAlpha = x; } public void setPressed(boolean pressed) { - if (mGlowBG != null) { + if (mBackground != null) { if (pressed != isPressed()) { - if (mPressedAnim != null && mPressedAnim.isRunning()) { - mPressedAnim.cancel(); - } - final AnimatorSet as = mPressedAnim = new AnimatorSet(); if (pressed) { - if (mGlowScale < GLOW_MAX_SCALE_FACTOR) - mGlowScale = GLOW_MAX_SCALE_FACTOR; - if (mGlowAlpha < mQuiescentAlpha) - mGlowAlpha = mQuiescentAlpha; setDrawingAlpha(1f); - as.playTogether( - ObjectAnimator.ofFloat(this, "glowAlpha", 1f), - ObjectAnimator.ofFloat(this, "glowScale", GLOW_MAX_SCALE_FACTOR) - ); - as.setDuration(50); } else { mAnimateToQuiescent.cancel(); mAnimateToQuiescent = animateToQuiescent(); - as.playTogether( - ObjectAnimator.ofFloat(this, "glowAlpha", 0f), - ObjectAnimator.ofFloat(this, "glowScale", 1f), - mAnimateToQuiescent - ); - as.setDuration(500); + mAnimateToQuiescent.setDuration(500); + mAnimateToQuiescent.start(); } - as.start(); } } super.setPressed(pressed); } + private void setHotspot(float x, float y) { + if (mBackground != null) { + mBackground.setHotspot(x, y); + } + } + public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); int x, y; @@ -254,6 +170,7 @@ public class KeyButtonView extends ImageView { removeCallbacks(mCheckLongPress); postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout()); } + setHotspot(ev.getX(), ev.getY()); break; case MotionEvent.ACTION_MOVE: x = (int)ev.getX(); @@ -262,6 +179,7 @@ public class KeyButtonView extends ImageView { && x < getWidth() + mTouchSlop && y >= -mTouchSlop && y < getHeight() + mTouchSlop); + setHotspot(ev.getX(), ev.getY()); break; case MotionEvent.ACTION_CANCEL: setPressed(false); |