Merge "Bouncer: Improve push animations." into tm-dev
This commit is contained in:
@@ -16,14 +16,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
-->
|
-->
|
||||||
<ripple
|
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
<solid android:color="?android:attr/colorControlNormal" />
|
||||||
android:color="?android:attr/colorControlHighlight">
|
<corners android:radius="10dp" />
|
||||||
<item android:id="@+id/background">
|
</shape>
|
||||||
<shape>
|
|
||||||
<solid android:color="?android:attr/colorControlNormal" />
|
|
||||||
<corners android:radius="10dp" />
|
|
||||||
</shape>
|
|
||||||
</item>
|
|
||||||
</ripple>
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,17 +16,18 @@
|
|||||||
package com.android.keyguard;
|
package com.android.keyguard;
|
||||||
|
|
||||||
import android.animation.AnimatorSet;
|
import android.animation.AnimatorSet;
|
||||||
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
|
import android.annotation.Nullable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.ColorStateList;
|
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
import android.graphics.drawable.RippleDrawable;
|
|
||||||
import android.view.ContextThemeWrapper;
|
import android.view.ContextThemeWrapper;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.StyleRes;
|
import androidx.annotation.StyleRes;
|
||||||
|
|
||||||
import com.android.systemui.R;
|
|
||||||
import com.android.systemui.animation.Interpolators;
|
import com.android.systemui.animation.Interpolators;
|
||||||
import com.android.systemui.util.Utils;
|
import com.android.systemui.util.Utils;
|
||||||
|
|
||||||
@@ -34,45 +35,100 @@ import com.android.systemui.util.Utils;
|
|||||||
* Provides background color and radius animations for key pad buttons.
|
* Provides background color and radius animations for key pad buttons.
|
||||||
*/
|
*/
|
||||||
class NumPadAnimator {
|
class NumPadAnimator {
|
||||||
private AnimatorSet mAnimator;
|
|
||||||
private ValueAnimator mExpandAnimator;
|
private ValueAnimator mExpandAnimator;
|
||||||
|
private AnimatorSet mExpandAnimatorSet;
|
||||||
private ValueAnimator mContractAnimator;
|
private ValueAnimator mContractAnimator;
|
||||||
|
private AnimatorSet mContractAnimatorSet;
|
||||||
private GradientDrawable mBackground;
|
private GradientDrawable mBackground;
|
||||||
private RippleDrawable mRipple;
|
|
||||||
private int mNormalColor;
|
private int mNormalColor;
|
||||||
private int mHighlightColor;
|
private int mHighlightColor;
|
||||||
private int mStyle;
|
private int mStyle;
|
||||||
|
private static final int EXPAND_ANIMATION_MS = 100;
|
||||||
|
private static final int EXPAND_COLOR_ANIMATION_MS = 50;
|
||||||
|
private static final int CONTRACT_ANIMATION_DELAY_MS = 33;
|
||||||
|
private static final int CONTRACT_ANIMATION_MS = 417;
|
||||||
|
|
||||||
NumPadAnimator(Context context, final RippleDrawable drawable, @StyleRes int style) {
|
NumPadAnimator(Context context, final Drawable drawable, @StyleRes int style) {
|
||||||
|
this(context, drawable, style, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
NumPadAnimator(Context context, final Drawable drawable, @StyleRes int style,
|
||||||
|
@Nullable TextView digitTextView) {
|
||||||
mStyle = style;
|
mStyle = style;
|
||||||
mRipple = (RippleDrawable) drawable.mutate();
|
mBackground = (GradientDrawable) drawable;
|
||||||
mBackground = (GradientDrawable) mRipple.findDrawableByLayerId(R.id.background);
|
|
||||||
|
|
||||||
reloadColors(context);
|
reloadColors(context);
|
||||||
|
int textColorPrimary = com.android.settingslib.Utils
|
||||||
|
.getColorAttrDefaultColor(context, android.R.attr.textColorPrimary);
|
||||||
|
int textColorPrimaryInverse = com.android.settingslib.Utils
|
||||||
|
.getColorAttrDefaultColor(context, android.R.attr.textColorPrimaryInverse);
|
||||||
|
|
||||||
// Actual values will be updated later, usually during an onLayout() call
|
// Actual values will be updated later, usually during an onLayout() call
|
||||||
mAnimator = new AnimatorSet();
|
|
||||||
mExpandAnimator = ValueAnimator.ofFloat(0f, 1f);
|
mExpandAnimator = ValueAnimator.ofFloat(0f, 1f);
|
||||||
mExpandAnimator.setDuration(50);
|
mExpandAnimator.setDuration(EXPAND_ANIMATION_MS);
|
||||||
mExpandAnimator.setInterpolator(Interpolators.LINEAR);
|
mExpandAnimator.setInterpolator(Interpolators.LINEAR);
|
||||||
mExpandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
mExpandAnimator.addUpdateListener(
|
||||||
public void onAnimationUpdate(ValueAnimator anim) {
|
anim -> mBackground.setCornerRadius((float) anim.getAnimatedValue()));
|
||||||
mBackground.setCornerRadius((float) anim.getAnimatedValue());
|
|
||||||
mRipple.invalidateSelf();
|
ValueAnimator expandBackgroundColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||||
}
|
mNormalColor, mHighlightColor);
|
||||||
|
expandBackgroundColorAnimator.setDuration(EXPAND_COLOR_ANIMATION_MS);
|
||||||
|
expandBackgroundColorAnimator.addUpdateListener(
|
||||||
|
animator -> mBackground.setColor((int) animator.getAnimatedValue()));
|
||||||
|
|
||||||
|
ValueAnimator expandTextColorAnimator =
|
||||||
|
ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||||
|
textColorPrimary, textColorPrimaryInverse);
|
||||||
|
expandTextColorAnimator.setDuration(EXPAND_COLOR_ANIMATION_MS);
|
||||||
|
expandTextColorAnimator.addUpdateListener(valueAnimator -> {
|
||||||
|
if (digitTextView != null) {
|
||||||
|
digitTextView.setTextColor((int) valueAnimator.getAnimatedValue());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mExpandAnimatorSet = new AnimatorSet();
|
||||||
|
mExpandAnimatorSet.playTogether(mExpandAnimator,
|
||||||
|
expandBackgroundColorAnimator, expandTextColorAnimator);
|
||||||
|
|
||||||
mContractAnimator = ValueAnimator.ofFloat(1f, 0f);
|
mContractAnimator = ValueAnimator.ofFloat(1f, 0f);
|
||||||
mContractAnimator.setStartDelay(33);
|
mContractAnimator.setStartDelay(CONTRACT_ANIMATION_DELAY_MS);
|
||||||
mContractAnimator.setDuration(417);
|
mContractAnimator.setDuration(CONTRACT_ANIMATION_MS);
|
||||||
mContractAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
|
mContractAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
|
||||||
mContractAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
mContractAnimator.addUpdateListener(
|
||||||
public void onAnimationUpdate(ValueAnimator anim) {
|
anim -> mBackground.setCornerRadius((float) anim.getAnimatedValue()));
|
||||||
mBackground.setCornerRadius((float) anim.getAnimatedValue());
|
ValueAnimator contractBackgroundColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(),
|
||||||
mRipple.invalidateSelf();
|
mHighlightColor, mNormalColor);
|
||||||
}
|
contractBackgroundColorAnimator.setStartDelay(CONTRACT_ANIMATION_DELAY_MS);
|
||||||
|
contractBackgroundColorAnimator.setDuration(CONTRACT_ANIMATION_MS);
|
||||||
|
contractBackgroundColorAnimator.addUpdateListener(
|
||||||
|
animator -> mBackground.setColor((int) animator.getAnimatedValue()));
|
||||||
|
|
||||||
|
ValueAnimator contractTextColorAnimator =
|
||||||
|
ValueAnimator.ofObject(new ArgbEvaluator(), textColorPrimaryInverse,
|
||||||
|
textColorPrimary);
|
||||||
|
contractTextColorAnimator.setStartDelay(CONTRACT_ANIMATION_DELAY_MS);
|
||||||
|
contractTextColorAnimator.setDuration(CONTRACT_ANIMATION_MS);
|
||||||
|
contractTextColorAnimator.addUpdateListener(valueAnimator -> {
|
||||||
|
if (digitTextView != null) {
|
||||||
|
digitTextView.setTextColor((int) valueAnimator.getAnimatedValue());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
mAnimator.playSequentially(mExpandAnimator, mContractAnimator);
|
|
||||||
|
mContractAnimatorSet = new AnimatorSet();
|
||||||
|
mContractAnimatorSet.playTogether(mContractAnimator,
|
||||||
|
contractBackgroundColorAnimator, contractTextColorAnimator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void expand() {
|
||||||
|
mExpandAnimatorSet.cancel();
|
||||||
|
mContractAnimatorSet.cancel();
|
||||||
|
mExpandAnimatorSet.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void contract() {
|
||||||
|
mExpandAnimatorSet.cancel();
|
||||||
|
mContractAnimatorSet.cancel();
|
||||||
|
mContractAnimatorSet.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onLayout(int height) {
|
void onLayout(int height) {
|
||||||
@@ -83,11 +139,6 @@ class NumPadAnimator {
|
|||||||
mContractAnimator.setFloatValues(endRadius, startRadius);
|
mContractAnimator.setFloatValues(endRadius, startRadius);
|
||||||
}
|
}
|
||||||
|
|
||||||
void start() {
|
|
||||||
mAnimator.cancel();
|
|
||||||
mAnimator.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reload colors from resources.
|
* Reload colors from resources.
|
||||||
**/
|
**/
|
||||||
@@ -103,7 +154,6 @@ class NumPadAnimator {
|
|||||||
a.recycle();
|
a.recycle();
|
||||||
|
|
||||||
mBackground.setColor(mNormalColor);
|
mBackground.setColor(mNormalColor);
|
||||||
mRipple.setColor(ColorStateList.valueOf(mHighlightColor));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ import android.content.Context;
|
|||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.graphics.drawable.RippleDrawable;
|
|
||||||
import android.graphics.drawable.VectorDrawable;
|
import android.graphics.drawable.VectorDrawable;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -39,13 +37,8 @@ public class NumPadButton extends AlphaOptimizedImageButton {
|
|||||||
public NumPadButton(Context context, AttributeSet attrs) {
|
public NumPadButton(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
|
|
||||||
Drawable background = getBackground();
|
mAnimator = new NumPadAnimator(context, getBackground().mutate(),
|
||||||
if (background instanceof RippleDrawable) {
|
attrs.getStyleAttribute());
|
||||||
mAnimator = new NumPadAnimator(context, (RippleDrawable) getBackground(),
|
|
||||||
attrs.getStyleAttribute());
|
|
||||||
} else {
|
|
||||||
mAnimator = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -79,8 +72,14 @@ public class NumPadButton extends AlphaOptimizedImageButton {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && mAnimator != null) {
|
switch(event.getActionMasked()) {
|
||||||
mAnimator.start();
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
if (mAnimator != null) mAnimator.expand();
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
if (mAnimator != null) mAnimator.contract();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ package com.android.keyguard;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.graphics.drawable.RippleDrawable;
|
|
||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -131,13 +129,8 @@ public class NumPadKey extends ViewGroup {
|
|||||||
|
|
||||||
setContentDescription(mDigitText.getText().toString());
|
setContentDescription(mDigitText.getText().toString());
|
||||||
|
|
||||||
Drawable background = getBackground();
|
mAnimator = new NumPadAnimator(context, getBackground().mutate(),
|
||||||
if (background instanceof RippleDrawable) {
|
R.style.NumPadKey, mDigitText);
|
||||||
mAnimator = new NumPadAnimator(context, (RippleDrawable) background,
|
|
||||||
R.style.NumPadKey);
|
|
||||||
} else {
|
|
||||||
mAnimator = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -161,11 +154,16 @@ public class NumPadKey extends ViewGroup {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
|
switch(event.getActionMasked()) {
|
||||||
doHapticKeyClick();
|
case MotionEvent.ACTION_DOWN:
|
||||||
if (mAnimator != null) mAnimator.start();
|
doHapticKeyClick();
|
||||||
|
if (mAnimator != null) mAnimator.expand();
|
||||||
|
break;
|
||||||
|
case MotionEvent.ACTION_UP:
|
||||||
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
if (mAnimator != null) mAnimator.contract();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user