Replace KeyButtonView's custom glow with Quantum Ripple

Bug: 15212514
Change-Id: Ia66bccd627c123f637d67076f78ab418c3f9e835
This commit is contained in:
Adrian Roos
2014-05-26 22:21:46 +02:00
parent 236da706b9
commit cde52d77eb
23 changed files with 82 additions and 147 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

View File

@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2014 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="?android:attr/colorControlHighlight"
android:tintMode="src_over"
android:pinned="true" />

View File

@@ -55,7 +55,7 @@
systemui:keyCode="4"
android:layout_weight="0"
android:scaleType="center"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_back"
/>
<View
@@ -71,7 +71,7 @@
systemui:keyCode="3"
systemui:keyRepeat="false"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_home"
/>
<View
@@ -85,7 +85,7 @@
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_recent"
/>
<FrameLayout
@@ -99,7 +99,7 @@
android:contentDescription="@string/accessibility_menu"
android:src="@drawable/ic_sysbar_menu"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
systemui:keyCode="82" />
<com.android.systemui.statusbar.policy.KeyButtonView
android:id="@+id/ime_switcher"
@@ -109,7 +109,7 @@
android:scaleType="centerInside"
android:src="@drawable/ic_ime_switcher_default"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight" />
android:background="@drawable/ripple_drawable" />
</FrameLayout>
</LinearLayout>
@@ -212,7 +212,7 @@
android:layout_weight="0"
android:visibility="invisible"
android:contentDescription="@string/accessibility_menu"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land" />
android:background="@drawable/ripple_drawable" />
<com.android.systemui.statusbar.policy.KeyButtonView
android:id="@+id/ime_switcher"
android:layout_height="@dimen/navigation_extra_key_width"
@@ -221,7 +221,7 @@
android:scaleType="centerInside"
android:src="@drawable/ic_ime_switcher_default"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight" />
android:background="@drawable/ripple_drawable" />
</FrameLayout>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/back"
android:layout_height="80dp"
@@ -231,7 +231,7 @@
systemui:keyCode="4"
android:layout_weight="0"
android:contentDescription="@string/accessibility_back"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
/>
<View
android:layout_height="match_parent"
@@ -247,7 +247,7 @@
systemui:keyRepeat="false"
android:layout_weight="0"
android:contentDescription="@string/accessibility_home"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
/>
<View
android:layout_height="match_parent"
@@ -261,7 +261,7 @@
android:src="@drawable/ic_sysbar_recent_land"
android:layout_weight="0"
android:contentDescription="@string/accessibility_recent"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
/>
<View
android:layout_height="40dp"

View File

@@ -59,7 +59,7 @@
android:src="@drawable/ic_sysbar_back"
systemui:keyCode="4"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_back"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
@@ -69,7 +69,7 @@
systemui:keyCode="3"
systemui:keyRepeat="true"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_home"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
@@ -77,7 +77,7 @@
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_recent"
/>
<Space
@@ -98,7 +98,7 @@
systemui:keyCode="82"
android:visibility="invisible"
android:contentDescription="@string/accessibility_menu"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
/>
<com.android.systemui.statusbar.policy.KeyButtonView
android:id="@+id/ime_switcher"
@@ -109,7 +109,7 @@
android:src="@drawable/ic_ime_switcher_default"
android:visibility="invisible"
android:contentDescription="@string/accessibility_ime_switch_button"
systemui:glowBackground="@drawable/ic_sysbar_highlight" />
android:background="@drawable/ripple_drawable" />
</FrameLayout>
</LinearLayout>
@@ -216,7 +216,7 @@
android:src="@drawable/ic_sysbar_back"
systemui:keyCode="4"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_back"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/home"
@@ -226,7 +226,7 @@
systemui:keyCode="3"
systemui:keyRepeat="true"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_home"
/>
<com.android.systemui.statusbar.policy.KeyButtonView android:id="@+id/recent_apps"
@@ -234,7 +234,7 @@
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_recent"
/>
<Space
@@ -255,7 +255,7 @@
systemui:keyCode="82"
android:visibility="invisible"
android:contentDescription="@string/accessibility_menu"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
/>
<com.android.systemui.statusbar.policy.KeyButtonView
android:id="@+id/ime_switcher"
@@ -266,7 +266,7 @@
android:visibility="invisible"
android:contentDescription="@string/accessibility_ime_switch_button"
android:scaleType="centerInside"
systemui:glowBackground="@drawable/ic_sysbar_highlight" />
android:background="@drawable/ripple_drawable" />
</FrameLayout>
</LinearLayout>

View File

@@ -31,7 +31,6 @@
android:src="@drawable/ic_camera_alt_24dp"
android:scaleType="center"
android:contentDescription="@string/accessibility_camera_button"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
systemui:swipeDirection="start"/>
<com.android.systemui.statusbar.phone.SwipeAffordanceView
@@ -43,7 +42,6 @@
android:src="@drawable/ic_phone_24dp"
android:scaleType="center"
android:contentDescription="@string/accessibility_phone_button"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
systemui:swipeDirection="end"/>
<com.android.systemui.statusbar.phone.KeyguardIndicationTextView

View File

@@ -55,7 +55,7 @@
systemui:keyCode="4"
android:layout_weight="0"
android:scaleType="center"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_back"
/>
<View
@@ -71,7 +71,7 @@
systemui:keyCode="3"
systemui:keyRepeat="false"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_home"
/>
<View
@@ -85,7 +85,7 @@
android:layout_height="match_parent"
android:src="@drawable/ic_sysbar_recent"
android:layout_weight="0"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
android:contentDescription="@string/accessibility_recent"
/>
<FrameLayout
@@ -99,7 +99,7 @@
android:contentDescription="@string/accessibility_menu"
android:src="@drawable/ic_sysbar_menu"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight"
android:background="@drawable/ripple_drawable"
systemui:keyCode="82" />
<com.android.systemui.statusbar.policy.KeyButtonView
@@ -110,7 +110,7 @@
android:scaleType="centerInside"
android:src="@drawable/ic_ime_switcher_default"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight" />
android:background="@drawable/ripple_drawable" />
</FrameLayout>
</LinearLayout>
@@ -219,7 +219,7 @@
android:scaleType="centerInside"
android:src="@drawable/ic_ime_switcher_default"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight" />
android:background="@drawable/ripple_drawable" />
<com.android.systemui.statusbar.policy.KeyButtonView
android:id="@+id/menu"
@@ -228,7 +228,7 @@
android:contentDescription="@string/accessibility_menu"
android:src="@drawable/ic_sysbar_menu_land"
android:visibility="invisible"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
systemui:keyCode="82" />
</FrameLayout>
@@ -238,7 +238,7 @@
android:src="@drawable/ic_sysbar_recent_land"
android:layout_weight="0"
android:contentDescription="@string/accessibility_recent"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
/>
<View
android:layout_height="match_parent"
@@ -254,7 +254,7 @@
systemui:keyRepeat="false"
android:layout_weight="0"
android:contentDescription="@string/accessibility_home"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
/>
<View
android:layout_height="match_parent"
@@ -270,7 +270,7 @@
systemui:keyCode="4"
android:layout_weight="0"
android:contentDescription="@string/accessibility_back"
systemui:glowBackground="@drawable/ic_sysbar_highlight_land"
android:background="@drawable/ripple_drawable"
/>
<View
android:layout_height="40dp"

View File

@@ -20,8 +20,6 @@
<attr name="keyCode" format="integer" />
<!-- does this button generate longpress / repeat events? -->
<attr name="keyRepeat" format="boolean" />
<!-- drawable to use for a swelling, glowing background on press -->
<attr name="glowBackground" format="reference" />
</declare-styleable>
<declare-styleable name="ToggleSlider">
<attr name="text" format="string" />

View File

@@ -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));
setImageAlpha((int) (x * 255));
if (mBackground != null) {
mBackground.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();
}
}
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);