• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.keyguard;
18 
19 import android.content.Context;
20 import android.content.res.ColorStateList;
21 import android.graphics.PointF;
22 import android.graphics.RectF;
23 import android.graphics.drawable.Drawable;
24 import android.util.AttributeSet;
25 import android.view.Gravity;
26 import android.view.View;
27 import android.widget.FrameLayout;
28 import android.widget.ImageView;
29 
30 import androidx.annotation.NonNull;
31 
32 import com.android.settingslib.Utils;
33 import com.android.systemui.Dumpable;
34 import com.android.systemui.R;
35 
36 import java.io.FileDescriptor;
37 import java.io.PrintWriter;
38 
39 /**
40  * A view positioned under the notification shade.
41  */
42 public class LockIconView extends FrameLayout implements Dumpable {
43     @NonNull private final RectF mSensorRect;
44     @NonNull private PointF mLockIconCenter = new PointF(0f, 0f);
45     private int mRadius;
46 
47     private ImageView mLockIcon;
48     private ImageView mUnlockBgView;
49 
50     private int mLockIconColor;
51 
LockIconView(Context context, AttributeSet attrs)52     public LockIconView(Context context, AttributeSet attrs) {
53         super(context, attrs);
54         mSensorRect = new RectF();
55     }
56 
57     @Override
onFinishInflate()58     public void onFinishInflate() {
59         super.onFinishInflate();
60         mLockIcon = findViewById(R.id.lock_icon);
61         mUnlockBgView = findViewById(R.id.lock_icon_bg);
62     }
63 
updateColorAndBackgroundVisibility(boolean useBackground)64     void updateColorAndBackgroundVisibility(boolean useBackground) {
65         if (useBackground) {
66             mLockIconColor = Utils.getColorAttrDefaultColor(getContext(),
67                     android.R.attr.textColorPrimary);
68             mUnlockBgView.setBackground(getContext().getDrawable(R.drawable.fingerprint_bg));
69             mUnlockBgView.setVisibility(View.VISIBLE);
70         } else {
71             mLockIconColor = Utils.getColorAttrDefaultColor(getContext(),
72                     R.attr.wallpaperTextColorAccent);
73             mUnlockBgView.setVisibility(View.GONE);
74         }
75 
76         mLockIcon.setImageTintList(ColorStateList.valueOf(mLockIconColor));
77     }
78 
setImageDrawable(Drawable drawable)79     void setImageDrawable(Drawable drawable) {
80         mLockIcon.setImageDrawable(drawable);
81     }
82 
setCenterLocation(@onNull PointF center, int radius)83     void setCenterLocation(@NonNull PointF center, int radius) {
84         mLockIconCenter = center;
85         mRadius = radius;
86 
87         // mSensorProps coordinates assume portrait mode which is OK b/c the keyguard is always in
88         // portrait.
89         mSensorRect.set(mLockIconCenter.x - mRadius,
90                 mLockIconCenter.y - mRadius,
91                 mLockIconCenter.x + mRadius,
92                 mLockIconCenter.y + mRadius);
93 
94         setX(mSensorRect.left);
95         setY(mSensorRect.top);
96 
97         final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
98                 (int) (mSensorRect.right - mSensorRect.left),
99                 (int) (mSensorRect.bottom - mSensorRect.top));
100         lp.gravity = Gravity.CENTER;
101         setLayoutParams(lp);
102     }
103 
104     @Override
hasOverlappingRendering()105     public boolean hasOverlappingRendering() {
106         return false;
107     }
108 
getLocationTop()109     float getLocationTop() {
110         return mLockIconCenter.y - mRadius;
111     }
112 
113     @Override
dump(@onNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args)114     public void dump(@NonNull FileDescriptor fd, @NonNull PrintWriter pw, @NonNull String[] args) {
115         pw.println("Center in px (x, y)= (" + mLockIconCenter.x + ", " + mLockIconCenter.y + ")");
116         pw.println("Radius in pixels: " + mRadius);
117     }
118 }
119