1 /* 2 * Copyright (C) 2023 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 18 package com.android.systemui.keyguard.ui.view 19 20 import android.content.Context 21 import android.util.AttributeSet 22 import android.view.LayoutInflater 23 import android.view.View 24 import android.widget.ImageView 25 import androidx.constraintlayout.widget.ConstraintLayout 26 import androidx.core.content.res.ResourcesCompat 27 import com.android.keyguard.KeyguardStatusView 28 import com.android.keyguard.LockIconView 29 import com.android.systemui.R 30 import com.android.systemui.animation.view.LaunchableImageView 31 32 /** Provides a container for all keyguard ui content. */ 33 class KeyguardRootView( 34 context: Context, 35 private val attrs: AttributeSet?, 36 ) : 37 ConstraintLayout( 38 context, 39 attrs, 40 ) { 41 42 private var statusView: KeyguardStatusView? = null 43 44 init { 45 addIndicationTextArea() 46 addLockIconView() 47 addAmbientIndicationArea() 48 addLeftShortcut() 49 addRightShortcut() 50 addSettingsPopupMenu() 51 addStatusView() 52 } 53 54 private fun addIndicationTextArea() { 55 val view = KeyguardIndicationArea(context, attrs) 56 addView(view) 57 } 58 59 private fun addLockIconView() { 60 val view = LockIconView(context, attrs).apply { id = R.id.lock_icon_view } 61 addView(view) 62 } 63 64 private fun addAmbientIndicationArea() { 65 LayoutInflater.from(context).inflate(R.layout.ambient_indication, this) 66 } 67 68 private fun addLeftShortcut() { 69 val padding = resources.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_padding) 70 val view = 71 LaunchableImageView(context, attrs).apply { 72 id = R.id.start_button 73 scaleType = ImageView.ScaleType.FIT_CENTER 74 background = 75 ResourcesCompat.getDrawable( 76 context.resources, 77 R.drawable.keyguard_bottom_affordance_bg, 78 context.theme 79 ) 80 foreground = 81 ResourcesCompat.getDrawable( 82 context.resources, 83 R.drawable.keyguard_bottom_affordance_selected_border, 84 context.theme 85 ) 86 visibility = View.INVISIBLE 87 setPadding(padding, padding, padding, padding) 88 } 89 addView(view) 90 } 91 92 private fun addRightShortcut() { 93 val padding = resources.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_padding) 94 val view = 95 LaunchableImageView(context, attrs).apply { 96 id = R.id.end_button 97 scaleType = ImageView.ScaleType.FIT_CENTER 98 background = 99 ResourcesCompat.getDrawable( 100 context.resources, 101 R.drawable.keyguard_bottom_affordance_bg, 102 context.theme 103 ) 104 foreground = 105 ResourcesCompat.getDrawable( 106 context.resources, 107 R.drawable.keyguard_bottom_affordance_selected_border, 108 context.theme 109 ) 110 visibility = View.INVISIBLE 111 setPadding(padding, padding, padding, padding) 112 } 113 addView(view) 114 } 115 116 private fun addSettingsPopupMenu() { 117 val view = 118 LayoutInflater.from(context) 119 .inflate(R.layout.keyguard_settings_popup_menu, this, false) 120 .apply { 121 id = R.id.keyguard_settings_button 122 visibility = GONE 123 } 124 addView(view) 125 } 126 127 fun addStatusView(): KeyguardStatusView { 128 // StatusView may need to be rebuilt on config changes. Remove and reinflate 129 statusView?.let { removeView(it) } 130 val view = 131 (LayoutInflater.from(context).inflate(R.layout.keyguard_status_view, this, false) 132 as KeyguardStatusView) 133 .apply { 134 setClipChildren(false) 135 statusView = this 136 } 137 138 addView(view) 139 return view 140 } 141 } 142