Merge "[Bouncer] Add entry animation" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-09-08 17:43:37 +00:00
committed by Android (Google) Code Review
9 changed files with 113 additions and 47 deletions

View File

@@ -17,23 +17,24 @@
*/ */
--> -->
<com.android.keyguard.KeyguardPINView <com.android.keyguard.KeyguardPINView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/res-auto" xmlns:androidprv="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/keyguard_pin_view" android:id="@+id/keyguard_pin_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
androidprv:layout_maxWidth="@dimen/keyguard_security_width"
android:layout_gravity="center_horizontal|bottom" android:layout_gravity="center_horizontal|bottom"
android:clipChildren="false"
android:clipToPadding="false"
android:orientation="vertical" android:orientation="vertical"
> androidprv:layout_maxWidth="@dimen/keyguard_security_width">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/pin_container" android:id="@+id/pin_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:clipChildren="false"
android:clipToPadding="false"
android:layout_weight="1" android:layout_weight="1"
android:layoutDirection="ltr" android:layoutDirection="ltr"
android:orientation="vertical"> android:orientation="vertical">
@@ -79,6 +80,8 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="0dp" android:layout_height="0dp"
android:orientation="horizontal" android:orientation="horizontal"
android:clipChildren="false"
android:clipToPadding="false"
androidprv:constraint_referenced_ids="key1,key2,key3,key4,key5,key6,key7,key8,key9,delete_button,key0,key_enter" androidprv:constraint_referenced_ids="key1,key2,key3,key4,key5,key6,key7,key8,key9,delete_button,key0,key_enter"

View File

@@ -50,7 +50,7 @@
<item name="android:background">@null</item> <item name="android:background">@null</item>
<item name="android:textSize">32sp</item> <item name="android:textSize">32sp</item>
<item name="android:textColor">?android:attr/textColorPrimary</item> <item name="android:textColor">?android:attr/textColorPrimary</item>
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item> <item name="android:fontFamily">@*android:string/config_bodyFontFamily</item>
<item name="android:paddingBottom">-16dp</item> <item name="android:paddingBottom">-16dp</item>
</style> </style>
<style name="Widget.TextView.Password" parent="@android:style/Widget.TextView"> <style name="Widget.TextView.Password" parent="@android:style/Widget.TextView">

View File

@@ -45,7 +45,6 @@ public abstract class KeyguardInputViewController<T extends KeyguardInputView>
private final EmergencyButtonController mEmergencyButtonController; private final EmergencyButtonController mEmergencyButtonController;
private boolean mPaused; private boolean mPaused;
// The following is used to ignore callbacks from SecurityViews that are no longer current // The following is used to ignore callbacks from SecurityViews that are no longer current
// (e.g. face unlock). This avoids unwanted asynchronous events from messing with the // (e.g. face unlock). This avoids unwanted asynchronous events from messing with the
// state for the current security method. // state for the current security method.

View File

@@ -16,23 +16,25 @@
package com.android.keyguard; package com.android.keyguard;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_PIN_APPEAR;
import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_PIN_DISAPPEAR; import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_PIN_DISAPPEAR;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED; import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_HALF_OPENED;
import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN; import static com.android.systemui.statusbar.policy.DevicePostureController.DEVICE_POSTURE_UNKNOWN;
import android.animation.ValueAnimator;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.MathUtils;
import android.view.View; import android.view.View;
import android.view.animation.AnimationUtils; import android.view.animation.AnimationUtils;
import android.view.animation.Interpolator;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet; import androidx.constraintlayout.widget.ConstraintSet;
import com.android.settingslib.animation.AppearAnimationUtils;
import com.android.settingslib.animation.DisappearAnimationUtils; import com.android.settingslib.animation.DisappearAnimationUtils;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt; import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostureInt;
/** /**
@@ -40,7 +42,7 @@ import com.android.systemui.statusbar.policy.DevicePostureController.DevicePostu
*/ */
public class KeyguardPINView extends KeyguardPinBasedInputView { public class KeyguardPINView extends KeyguardPinBasedInputView {
private final AppearAnimationUtils mAppearAnimationUtils; ValueAnimator mAppearAnimator = ValueAnimator.ofFloat(0f, 1f);
private final DisappearAnimationUtils mDisappearAnimationUtils; private final DisappearAnimationUtils mDisappearAnimationUtils;
private final DisappearAnimationUtils mDisappearAnimationUtilsLocked; private final DisappearAnimationUtils mDisappearAnimationUtilsLocked;
private ConstraintLayout mContainer; private ConstraintLayout mContainer;
@@ -54,7 +56,6 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
public KeyguardPINView(Context context, AttributeSet attrs) { public KeyguardPINView(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
mAppearAnimationUtils = new AppearAnimationUtils(context);
mDisappearAnimationUtils = new DisappearAnimationUtils(context, mDisappearAnimationUtils = new DisappearAnimationUtils(context,
125, 0.6f /* translationScale */, 125, 0.6f /* translationScale */,
0.45f /* delayScale */, AnimationUtils.loadInterpolator( 0.45f /* delayScale */, AnimationUtils.loadInterpolator(
@@ -169,25 +170,20 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
@Override @Override
public void startAppearAnimation() { public void startAppearAnimation() {
enableClipping(false); if (mAppearAnimator.isRunning()) {
setAlpha(1f); mAppearAnimator.cancel();
setTranslationY(mAppearAnimationUtils.getStartTranslation());
AppearAnimationUtils.startTranslationYAnimation(this, 0 /* delay */, 500 /* duration */,
0, mAppearAnimationUtils.getInterpolator(),
getAnimationListener(CUJ_LOCKSCREEN_PIN_APPEAR));
mAppearAnimationUtils.startAnimation2d(mViews,
new Runnable() {
@Override
public void run() {
enableClipping(true);
} }
}); mAppearAnimator.setDuration(650);
mAppearAnimator.addUpdateListener(animation -> animate(animation.getAnimatedFraction()));
mAppearAnimator.start();
} }
public boolean startDisappearAnimation(boolean needsSlowUnlockTransition, public boolean startDisappearAnimation(boolean needsSlowUnlockTransition,
final Runnable finishRunnable) { final Runnable finishRunnable) {
if (mAppearAnimator.isRunning()) {
mAppearAnimator.cancel();
}
enableClipping(false);
setTranslationY(0); setTranslationY(0);
DisappearAnimationUtils disappearAnimationUtils = needsSlowUnlockTransition DisappearAnimationUtils disappearAnimationUtils = needsSlowUnlockTransition
? mDisappearAnimationUtilsLocked ? mDisappearAnimationUtilsLocked
@@ -195,7 +191,6 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
disappearAnimationUtils.createAnimation( disappearAnimationUtils.createAnimation(
this, 0, 200, mDisappearYTranslation, false, this, 0, 200, mDisappearYTranslation, false,
mDisappearAnimationUtils.getInterpolator(), () -> { mDisappearAnimationUtils.getInterpolator(), () -> {
enableClipping(true);
if (finishRunnable != null) { if (finishRunnable != null) {
finishRunnable.run(); finishRunnable.run();
} }
@@ -204,14 +199,32 @@ public class KeyguardPINView extends KeyguardPinBasedInputView {
return true; return true;
} }
private void enableClipping(boolean enable) {
mContainer.setClipToPadding(enable);
mContainer.setClipChildren(enable);
setClipChildren(enable);
}
@Override @Override
public boolean hasOverlappingRendering() { public boolean hasOverlappingRendering() {
return false; return false;
} }
/** Animate subviews according to expansion or time. */
private void animate(float progress) {
for (int i = 0; i < mViews.length; i++) {
View[] row = mViews[i];
for (View view : row) {
if (view == null) {
continue;
}
float scaledProgress = MathUtils.constrain(
(progress - 0.075f * i) / (1f - 0.075f * mViews.length),
0f,
1f
);
view.setAlpha(scaledProgress);
Interpolator interpolator = Interpolators.STANDARD_ACCELERATE;
view.setTranslationY(40 - (40 * interpolator.getInterpolation(scaledProgress)));
if (view instanceof NumPadAnimationListener) {
((NumPadAnimationListener) view).setProgress(scaledProgress);
}
}
}
}
} }

View File

@@ -156,7 +156,6 @@ public class KeyguardSecurityViewFlipperController
@Override @Override
public void onStartingToHide() { public void onStartingToHide() {
} }
} }
} }

View File

@@ -0,0 +1,23 @@
/*
* Copyright (C) 2022 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.
*/
package com.android.keyguard
/** Interface for classes to track animation progress. */
interface NumPadAnimationListener {
/** Track the progress of the animation. */
fun setProgress(progress: Float)
}

View File

@@ -48,6 +48,10 @@ class NumPadAnimator {
private int mTextColorPrimary; private int mTextColorPrimary;
private int mTextColorPressed; private int mTextColorPressed;
private int mStyle; private int mStyle;
private float mStartRadius;
private float mEndRadius;
private int mHeight;
private static final int EXPAND_ANIMATION_MS = 100; private static final int EXPAND_ANIMATION_MS = 100;
private static final int EXPAND_COLOR_ANIMATION_MS = 50; private static final int EXPAND_COLOR_ANIMATION_MS = 50;
private static final int CONTRACT_ANIMATION_DELAY_MS = 33; private static final int CONTRACT_ANIMATION_DELAY_MS = 33;
@@ -80,12 +84,20 @@ class NumPadAnimator {
mContractAnimatorSet.start(); mContractAnimatorSet.start();
} }
public void setProgress(float progress) {
mBackground.setCornerRadius(mEndRadius + (mStartRadius - mEndRadius) * progress);
int height = (int) (mHeight * 0.8f + mHeight * 0.2 * progress);
int difference = mHeight - height;
mBackground.setBounds(0, difference / 2, mHeight, mHeight - difference / 2);
}
void onLayout(int height) { void onLayout(int height) {
float startRadius = height / 2f; mHeight = height;
float endRadius = height / 4f; mStartRadius = height / 2f;
mBackground.setCornerRadius(startRadius); mEndRadius = height / 4f;
mExpandAnimator.setFloatValues(startRadius, endRadius); mBackground.setCornerRadius(mStartRadius);
mContractAnimator.setFloatValues(endRadius, startRadius); mExpandAnimator.setFloatValues(mStartRadius, mEndRadius);
mContractAnimator.setFloatValues(mEndRadius, mStartRadius);
} }
/** /**

View File

@@ -30,7 +30,7 @@ import androidx.annotation.Nullable;
/** /**
* Similar to the {@link NumPadKey}, but displays an image. * Similar to the {@link NumPadKey}, but displays an image.
*/ */
public class NumPadButton extends AlphaOptimizedImageButton { public class NumPadButton extends AlphaOptimizedImageButton implements NumPadAnimationListener {
@Nullable @Nullable
private NumPadAnimator mAnimator; private NumPadAnimator mAnimator;
@@ -104,4 +104,11 @@ public class NumPadButton extends AlphaOptimizedImageButton {
a.recycle(); a.recycle();
((VectorDrawable) getDrawable()).setTintList(ColorStateList.valueOf(imageColor)); ((VectorDrawable) getDrawable()).setTintList(ColorStateList.valueOf(imageColor));
} }
@Override
public void setProgress(float progress) {
if (mAnimator != null) {
mAnimator.setProgress(progress);
}
}
} }

View File

@@ -37,7 +37,10 @@ import com.android.internal.widget.LockPatternUtils;
import com.android.settingslib.Utils; import com.android.settingslib.Utils;
import com.android.systemui.R; import com.android.systemui.R;
public class NumPadKey extends ViewGroup { /**
* Viewgroup for the bouncer numpad button, specifically for digits.
*/
public class NumPadKey extends ViewGroup implements NumPadAnimationListener {
// list of "ABC", etc per digit, starting with '0' // list of "ABC", etc per digit, starting with '0'
static String sKlondike[]; static String sKlondike[];
@@ -221,4 +224,11 @@ public class NumPadKey extends ViewGroup {
performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY, performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY,
HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
} }
@Override
public void setProgress(float progress) {
if (mAnimator != null) {
mAnimator.setProgress(progress);
}
}
} }