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