blob: 2362a1ad74a0b6566e1e5d5614128a53e805dc10 [file] [log] [blame]
/*
* 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);
}
}