summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/keyguard/LockIconView.java
diff options
context:
space:
mode:
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/LockIconView.java')
-rw-r--r--packages/SystemUI/src/com/android/keyguard/LockIconView.java107
1 files changed, 100 insertions, 7 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/LockIconView.java b/packages/SystemUI/src/com/android/keyguard/LockIconView.java
index ef4353b93179..0c1934cb977b 100644
--- a/packages/SystemUI/src/com/android/keyguard/LockIconView.java
+++ b/packages/SystemUI/src/com/android/keyguard/LockIconView.java
@@ -18,6 +18,7 @@ package com.android.keyguard;
import android.content.Context;
import android.content.res.ColorStateList;
+import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
@@ -26,9 +27,11 @@ import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
+import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
+import com.android.internal.graphics.ColorUtils;
import com.android.settingslib.Utils;
import com.android.systemui.Dumpable;
import com.android.systemui.R;
@@ -40,6 +43,17 @@ import java.io.PrintWriter;
* A view positioned under the notification shade.
*/
public class LockIconView extends FrameLayout implements Dumpable {
+ @IntDef({ICON_NONE, ICON_LOCK, ICON_FINGERPRINT, ICON_UNLOCK})
+ public @interface IconType {}
+
+ public static final int ICON_NONE = -1;
+ public static final int ICON_LOCK = 0;
+ public static final int ICON_FINGERPRINT = 1;
+ public static final int ICON_UNLOCK = 2;
+
+ private @IconType int mIconType;
+ private boolean mAod;
+
@NonNull private final RectF mSensorRect;
@NonNull private PointF mLockIconCenter = new PointF(0f, 0f);
private int mRadius;
@@ -49,6 +63,7 @@ public class LockIconView extends FrameLayout implements Dumpable {
private int mLockIconColor;
private boolean mUseBackground = false;
+ private float mDozeAmount = 0f;
public LockIconView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -62,15 +77,25 @@ public class LockIconView extends FrameLayout implements Dumpable {
mBgView = findViewById(R.id.lock_icon_bg);
}
+ void setDozeAmount(float dozeAmount) {
+ mDozeAmount = dozeAmount;
+ updateColorAndBackgroundVisibility();
+ }
+
void updateColorAndBackgroundVisibility() {
if (mUseBackground && mLockIcon.getDrawable() != null) {
- mLockIconColor = Utils.getColorAttrDefaultColor(getContext(),
- android.R.attr.textColorPrimary);
+ mLockIconColor = ColorUtils.blendARGB(
+ Utils.getColorAttrDefaultColor(getContext(), android.R.attr.textColorPrimary),
+ Color.WHITE,
+ mDozeAmount);
mBgView.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg));
+ mBgView.setAlpha(1f - mDozeAmount);
mBgView.setVisibility(View.VISIBLE);
} else {
- mLockIconColor = Utils.getColorAttrDefaultColor(getContext(),
- R.attr.wallpaperTextColorAccent);
+ mLockIconColor = ColorUtils.blendARGB(
+ Utils.getColorAttrDefaultColor(getContext(), R.attr.wallpaperTextColorAccent),
+ Color.WHITE,
+ mDozeAmount);
mBgView.setVisibility(View.GONE);
}
@@ -129,10 +154,78 @@ public class LockIconView extends FrameLayout implements Dumpable {
return mLockIconCenter.y - mRadius;
}
+ /**
+ * Updates the icon its default state where no visual is shown.
+ */
+ public void clearIcon() {
+ updateIcon(ICON_NONE, false);
+ }
+
+ /**
+ * Transition the current icon to a new state
+ * @param icon type (ie: lock icon, unlock icon, fingerprint icon)
+ * @param aod whether to use the aod icon variant (some icons don't have aod variants and will
+ * therefore show no icon)
+ */
+ public void updateIcon(@IconType int icon, boolean aod) {
+ mIconType = icon;
+ mAod = aod;
+
+ mLockIcon.setImageState(getLockIconState(mIconType, mAod), true);
+ }
+
+ private static int[] getLockIconState(@IconType int icon, boolean aod) {
+ if (icon == ICON_NONE) {
+ return new int[0];
+ }
+
+ int[] lockIconState = new int[2];
+ switch (icon) {
+ case ICON_LOCK:
+ lockIconState[0] = android.R.attr.state_first;
+ break;
+ case ICON_FINGERPRINT:
+ lockIconState[0] = android.R.attr.state_middle;
+ break;
+ case ICON_UNLOCK:
+ lockIconState[0] = android.R.attr.state_last;
+ break;
+ }
+
+ if (aod) {
+ lockIconState[1] = android.R.attr.state_single;
+ } else {
+ lockIconState[1] = -android.R.attr.state_single;
+ }
+
+ return lockIconState;
+ }
+
+ private String typeToString(@IconType int type) {
+ switch (type) {
+ case ICON_NONE:
+ return "none";
+ case ICON_LOCK:
+ return "lock";
+ case ICON_FINGERPRINT:
+ return "fingerprint";
+ case ICON_UNLOCK:
+ return "unlock";
+ }
+
+ return "invalid";
+ }
+
@Override
public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
- pw.println("Center in px (x, y)= (" + mLockIconCenter.x + ", " + mLockIconCenter.y + ")");
- pw.println("Radius in pixels: " + mRadius);
- pw.println("topLeft= (" + getX() + ", " + getY() + ")");
+ pw.println("Lock Icon View Parameters:");
+ pw.println(" Center in px (x, y)= ("
+ + mLockIconCenter.x + ", " + mLockIconCenter.y + ")");
+ pw.println(" Radius in pixels: " + mRadius);
+ pw.println(" mIconType=" + typeToString(mIconType));
+ pw.println(" mAod=" + mAod);
+ pw.println("Lock Icon View actual measurements:");
+ pw.println(" topLeft= (" + getX() + ", " + getY() + ")");
+ pw.println(" width=" + getWidth() + " height=" + getHeight());
}
}