Animate in a background for kg unlock icon

- to indicate it is tappable
- update background drawable on color change to update
color

Test: manual
Fixes: 192403524
Change-Id: I34255e3f7cc7b1dfc246c4e2441822129abdf819
This commit is contained in:
Beverly
2021-07-14 16:01:50 -04:00
committed by Beverly Tai
parent 51c13dcc6c
commit 09923d5eca
5 changed files with 124 additions and 12 deletions

View File

@@ -14,10 +14,11 @@
-->
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
android:shape="oval">
<solid
android:color="?android:attr/colorBackground"/>
android:color="?androidprv:attr/colorSurface"/>
<size
android:width="64dp"

View File

@@ -55,9 +55,23 @@
android:id="@+id/lock_icon_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="48px"
android:layout_gravity="center"
android:scaleType="centerCrop"/>
android:layout_gravity="center">
<!-- Background protection -->
<ImageView
android:id="@+id/lock_icon_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fingerprint_bg"
android:visibility="invisible"/>
<ImageView
android:id="@+id/lock_icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="48px"
android:layout_gravity="center"
android:scaleType="centerCrop"/>
</com.android.keyguard.LockIconView>
<com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer
android:layout_width="match_parent"

View File

@@ -16,16 +16,29 @@
package com.android.keyguard;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Interpolator;
import android.view.animation.PathInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import com.android.settingslib.Utils;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -33,16 +46,96 @@ import java.io.PrintWriter;
/**
* A view positioned under the notification shade.
*/
public class LockIconView extends ImageView implements Dumpable {
public class LockIconView extends FrameLayout implements Dumpable {
@NonNull private final RectF mSensorRect;
@NonNull private PointF mLockIconCenter = new PointF(0f, 0f);
private int mRadius;
private ImageView mLockIcon;
private ImageView mUnlockBgView;
private AnimatorSet mBgAnimator;
private int mLockIconColor;
private int mUnlockStartColor;
private int mUnlockEndColor;
public LockIconView(Context context, AttributeSet attrs) {
super(context, attrs);
mSensorRect = new RectF();
}
@Override
public void onFinishInflate() {
super.onFinishInflate();
mLockIcon = findViewById(R.id.lock_icon);
mUnlockBgView = findViewById(R.id.lock_icon_bg);
}
void updateColor() {
mLockIconColor = Utils.getColorAttrDefaultColor(getContext(),
R.attr.wallpaperTextColorAccent);
mUnlockStartColor = mLockIconColor;
mUnlockEndColor = Utils.getColorAttrDefaultColor(getContext(),
android.R.attr.textColorPrimary);
mUnlockBgView.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg));
}
void setImageDrawable(Drawable drawable) {
mLockIcon.setImageDrawable(drawable);
}
void hideBg() {
mUnlockBgView.setVisibility(View.INVISIBLE);
mLockIcon.setImageTintList(ColorStateList.valueOf(mLockIconColor));
}
void animateBg() {
ValueAnimator bgAlphaAnimator = ObjectAnimator.ofFloat(mUnlockBgView, View.ALPHA, 0f, 1f);
bgAlphaAnimator.setDuration(133);
Interpolator interpolator = new PathInterpolator(0f, 0f, 0f, 1f);
Animator scaleXAnimator = ObjectAnimator.ofFloat(mUnlockBgView, View.SCALE_X, .9f, 1f);
scaleXAnimator.setInterpolator(interpolator);
scaleXAnimator.setDuration(300);
Animator scaleYAnimator = ObjectAnimator.ofFloat(mUnlockBgView, View.SCALE_Y, .9f, 1f);
scaleYAnimator.setDuration(300);
scaleYAnimator.setInterpolator(interpolator);
ValueAnimator lockIconColorAnimator =
ValueAnimator.ofObject(new ArgbEvaluator(), mUnlockStartColor, mUnlockEndColor);
lockIconColorAnimator.addUpdateListener(
animation -> mLockIcon.setImageTintList(
ColorStateList.valueOf((int) animation.getAnimatedValue())));
lockIconColorAnimator.setDuration(150);
if (mBgAnimator != null) {
if (mBgAnimator.isRunning()) {
return;
}
mBgAnimator.cancel();
}
mBgAnimator = new AnimatorSet();
mBgAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mBgAnimator = null;
}
});
mBgAnimator.playTogether(
bgAlphaAnimator,
scaleYAnimator,
scaleXAnimator,
lockIconColorAnimator);
mBgAnimator.setStartDelay(167);
mUnlockBgView.setAlpha(0f);
mUnlockBgView.setScaleX(0);
mUnlockBgView.setScaleY(0);
mUnlockBgView.setVisibility(View.VISIBLE);
mBgAnimator.start();
}
void setCenterLocation(@NonNull PointF center, int radius) {
mLockIconCenter = center;
mRadius = radius;
@@ -70,7 +163,6 @@ public class LockIconView extends ImageView implements Dumpable {
return mLockIconCenter.y - mRadius;
}
@Override
public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
pw.println("Center in px (x, y)= (" + mLockIconCenter.x + ", " + mLockIconCenter.y + ")");

View File

@@ -40,7 +40,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
import com.android.settingslib.Utils;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
import com.android.systemui.biometrics.AuthController;
@@ -145,6 +144,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
mUnlockedLabel = context.getResources().getString(R.string.accessibility_unlock_button);
mLockedLabel = context.getResources().getString(R.string.accessibility_lock_icon);
dumpManager.registerDumpable("LockIconViewController", this);
}
@Override
@@ -224,6 +224,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
mView.setImageDrawable(mLockIcon);
mView.setVisibility(View.VISIBLE);
mView.setContentDescription(mLockedLabel);
mView.hideBg();
} else if (mShowUnlockIcon) {
if (wasShowingFpIcon) {
mView.setImageDrawable(mFpToUnlockIcon);
@@ -234,9 +235,11 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
mLockToUnlockIcon.forceAnimationOnUI();
mLockToUnlockIcon.start();
}
mView.animateBg();
mView.setVisibility(View.VISIBLE);
mView.setContentDescription(mUnlockedLabel);
} else {
mView.hideBg();
mView.setVisibility(View.INVISIBLE);
mView.setContentDescription(null);
}
@@ -281,11 +284,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
}
private void updateColors() {
final int color = Utils.getColorAttrDefaultColor(mView.getContext(),
R.attr.wallpaperTextColorAccent);
mFpToUnlockIcon.setTint(color);
mLockToUnlockIcon.setTint(color);
mLockIcon.setTint(color);
mView.updateColor();
}
private void updateConfiguration() {
@@ -445,6 +444,7 @@ public class LockIconViewController extends ViewController<LockIconView> impleme
@Override
public void onConfigChanged(Configuration newConfig) {
updateConfiguration();
updateColors();
}
};

View File

@@ -162,7 +162,12 @@ public class UdfpsKeyguardView extends UdfpsAnimationView {
}
void updateColor() {
mWallpaperTextColor = Utils.getColorAttrDefaultColor(mContext,
R.attr.wallpaperTextColorAccent);
mTextColorPrimary = Utils.getColorAttrDefaultColor(mContext,
android.R.attr.textColorPrimary);
mLockScreenFp.invalidate();
mBgProtection.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg));
}
private boolean showingUdfpsBouncer() {