1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/*
* Copyright (C) 2012 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;
import android.app.ActivityManager;
import android.app.IActivityManager;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridLayout;
import androidx.core.graphics.ColorUtils;
import com.android.internal.widget.LockPatternUtils;
import com.android.systemui.R;
import com.android.systemui.statusbar.CrossFadeHelper;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Set;
/**
* View consisting of:
* - keyguard clock
* - media player (split shade mode only)
*/
public class KeyguardStatusView extends GridLayout {
private static final boolean DEBUG = KeyguardConstants.DEBUG;
private static final String TAG = "KeyguardStatusView";
private final LockPatternUtils mLockPatternUtils;
private final IActivityManager mIActivityManager;
private ViewGroup mStatusViewContainer;
private KeyguardClockSwitch mClockView;
private KeyguardSliceView mKeyguardSlice;
private View mMediaHostContainer;
private float mDarkAmount = 0;
private int mTextColor;
private float mChildrenAlphaExcludingSmartSpace = 1f;
/**
* Bottom margin that defines the margin between bottom of smart space and top of notification
* icons on AOD.
*/
private int mIconTopMargin;
private int mIconTopMarginWithHeader;
private boolean mShowingHeader;
public KeyguardStatusView(Context context) {
this(context, null, 0);
}
public KeyguardStatusView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public KeyguardStatusView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mIActivityManager = ActivityManager.getService();
mLockPatternUtils = new LockPatternUtils(getContext());
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mStatusViewContainer = findViewById(R.id.status_view_container);
mClockView = findViewById(R.id.keyguard_clock_container);
if (KeyguardClockAccessibilityDelegate.isNeeded(mContext)) {
mClockView.setAccessibilityDelegate(new KeyguardClockAccessibilityDelegate(mContext));
}
mKeyguardSlice = findViewById(R.id.keyguard_status_area);
mTextColor = mClockView.getCurrentTextColor();
mKeyguardSlice.setContentChangeListener(this::onSliceContentChanged);
onSliceContentChanged();
mMediaHostContainer = findViewById(R.id.status_view_media_container);
updateDark();
}
/**
* Moves clock, adjusting margins when slice content changes.
*/
private void onSliceContentChanged() {
final boolean hasHeader = mKeyguardSlice.hasHeader();
if (mShowingHeader == hasHeader) {
return;
}
mShowingHeader = hasHeader;
}
void setDarkAmount(float darkAmount) {
if (mDarkAmount == darkAmount) {
return;
}
mDarkAmount = darkAmount;
mClockView.setDarkAmount(darkAmount);
CrossFadeHelper.fadeOut(mMediaHostContainer, darkAmount);
updateDark();
}
void updateDark() {
final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, mDarkAmount);
mKeyguardSlice.setDarkAmount(mDarkAmount);
mClockView.setTextColor(blendedTextColor);
}
public void setChildrenAlphaExcludingClockView(float alpha) {
setChildrenAlphaExcluding(alpha, Set.of(mClockView));
}
/** Sets an alpha value on every view except for the views in the provided set. */
public void setChildrenAlphaExcluding(float alpha, Set<View> excludedViews) {
mChildrenAlphaExcludingSmartSpace = alpha;
for (int i = 0; i < mStatusViewContainer.getChildCount(); i++) {
final View child = mStatusViewContainer.getChildAt(i);
if (!excludedViews.contains(child)) {
child.setAlpha(alpha);
}
}
}
public float getChildrenAlphaExcludingSmartSpace() {
return mChildrenAlphaExcludingSmartSpace;
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("KeyguardStatusView:");
pw.println(" mDarkAmount: " + mDarkAmount);
pw.println(" mTextColor: " + Integer.toHexString(mTextColor));
if (mClockView != null) {
mClockView.dump(fd, pw, args);
}
if (mKeyguardSlice != null) {
mKeyguardSlice.dump(fd, pw, args);
}
}
private void loadBottomMargin() {
mIconTopMargin = getResources().getDimensionPixelSize(R.dimen.widget_vertical_padding);
mIconTopMarginWithHeader = getResources().getDimensionPixelSize(
R.dimen.widget_vertical_padding_with_header);
}
}
|