From f55e2c7961f41f3e2e661c2ca882ab2882285002 Mon Sep 17 00:00:00 2001 From: Dil3mm4 Date: Tue, 26 Jan 2021 23:28:26 +0000 Subject: [ArrowOS][11.0] SystemUI: Face Unlock animation Change-Id: I3b6addb91923ca703f9e73bfce9bcf0bf8f1fc85 --- packages/SystemUI/res/drawable/ic_lock_face.xml | 10 ++++ .../com/android/systemui/FaceLockUIAnimations.java | 68 ++++++++++++++++++++++ .../android/systemui/statusbar/phone/LockIcon.java | 19 ++++-- 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 packages/SystemUI/res/drawable/ic_lock_face.xml create mode 100644 packages/SystemUI/src/com/android/systemui/FaceLockUIAnimations.java diff --git a/packages/SystemUI/res/drawable/ic_lock_face.xml b/packages/SystemUI/res/drawable/ic_lock_face.xml new file mode 100644 index 000000000000..78e4896bfefa --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_lock_face.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/packages/SystemUI/src/com/android/systemui/FaceLockUIAnimations.java b/packages/SystemUI/src/com/android/systemui/FaceLockUIAnimations.java new file mode 100644 index 000000000000..5786c6dd9aba --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/FaceLockUIAnimations.java @@ -0,0 +1,68 @@ +package com.android.systemui; + +import android.animation.Animator; +import android.animation.ObjectAnimator; +import android.view.animation.Animation; +import android.view.animation.BounceInterpolator; +import android.view.animation.LinearInterpolator; +import android.view.View; + +import java.util.Random; + +public class FaceLockUIAnimations { + + private static boolean mAnimationStarted = false; + + public static void faceLockShake(View targetView, boolean isCancelling) { + if (!isCancelling) { + ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "translationY", -100, 0, 0); + ObjectAnimator animator2 = ObjectAnimator.ofFloat(targetView, "translationX", 0, 17, 0); + animator.setInterpolator(new BounceInterpolator()); + animator2.setInterpolator(new BounceInterpolator()); + animator.setDuration(500); + animator2.setStartDelay(500); + animator2.setDuration(500); + animator2.setRepeatCount(-1); + animator.setAutoCancel(true); + animator2.setAutoCancel(true); + animator.start(); + animator2.start(); + } else { + setNullAnim(targetView); + } + } + + public static void aodBackgroundRotation(View targetView, boolean isCancelling, boolean isPinwheel) { + if (!mAnimationStarted) { + if (!isCancelling) { + ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "rotation", 0f, 360f); + if (isPinwheel) { + animator.setDuration(getRandomNumberInRange(1000,3000)); + } else { + animator.setDuration(30000); + } + animator.setInterpolator(new LinearInterpolator()); + animator.setRepeatCount(ObjectAnimator.INFINITE); + animator.setRepeatMode(ObjectAnimator.INFINITE); + animator.start(); + } else { + setNullAnim(targetView); + } + } + } + + private static void setNullAnim(View targetView) { + ObjectAnimator animator = ObjectAnimator.ofFloat(targetView, "translationY", 0, 0, 0); + ObjectAnimator animator2 = ObjectAnimator.ofFloat(targetView, "translationX", 0, 0, 0); + mAnimationStarted = false; + animator.setDuration(0); + animator2.setDuration(0); + animator.start(); + animator2.start(); + } + + private static int getRandomNumberInRange(int min, int max) { + Random r = new Random(); + return r.nextInt((max - min) + 1) + min; + } +} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java index 40b329d39032..1bbc5e4caeb8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/LockIcon.java @@ -32,6 +32,7 @@ import android.util.SparseArray; import android.view.ViewTreeObserver.OnPreDrawListener; import com.android.internal.graphics.ColorUtils; +import com.android.systemui.FaceLockUIAnimations; import com.android.systemui.Interpolators; import com.android.systemui.R; import com.android.systemui.statusbar.KeyguardAffordanceView; @@ -55,6 +56,7 @@ public class LockIcon extends KeyguardAffordanceView { private boolean mPulsing; private boolean mDozing; private boolean mKeyguardJustShown; + private boolean mIsFaceUnlock; private boolean mPredrawRegistered; private Drawable mFaceScanningAnim; private final SparseArray mDrawableCache = new SparseArray<>(); @@ -67,13 +69,17 @@ public class LockIcon extends KeyguardAffordanceView { int newState = mState; Drawable icon = getIcon(newState); - setImageDrawable(icon, false); + mIsFaceUnlock = newState == STATE_SCANNING_FACE; - if (newState == STATE_SCANNING_FACE) { + if (mIsFaceUnlock) { + icon = mContext.getDrawable(getIconForState(newState)); announceForAccessibility(getResources().getString( R.string.accessibility_scanning_face)); } + setImageDrawable(icon, false); + shakeFace(); + if (icon instanceof AnimatedVectorDrawable) { final AnimatedVectorDrawable animation = (AnimatedVectorDrawable) icon; animation.forceAnimationOnUI(); @@ -186,11 +192,12 @@ public class LockIcon extends KeyguardAffordanceView { private static int getIconForState(int state) { int iconRes; switch (state) { + case STATE_SCANNING_FACE: + iconRes = com.android.systemui.R.drawable.ic_lock_face; + break; case STATE_LOCKED: // Scanning animation is a pulsing padlock. This means that the resting state is // just a padlock. - case STATE_SCANNING_FACE: - // Error animation also starts and ands on the padlock. case STATE_BIOMETRICS_ERROR: iconRes = com.android.internal.R.drawable.ic_lock; break; @@ -268,4 +275,8 @@ public class LockIcon extends KeyguardAffordanceView { } return LOCK_ANIM_RES_IDS[0][lockAnimIndex]; } + + public void shakeFace() { + FaceLockUIAnimations.faceLockShake(this, mIsFaceUnlock ? false :true); + } } -- cgit v1.2.3