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.layout.sections 19 20 import android.content.Context 21 import androidx.constraintlayout.widget.ConstraintLayout 22 import androidx.constraintlayout.widget.ConstraintSet 23 import com.android.systemui.deviceentry.ui.binder.UdfpsAccessibilityOverlayBinder 24 import com.android.systemui.deviceentry.ui.view.UdfpsAccessibilityOverlay 25 import com.android.systemui.deviceentry.ui.viewmodel.DeviceEntryUdfpsAccessibilityOverlayViewModel 26 import com.android.systemui.keyguard.KeyguardBottomAreaRefactor 27 import com.android.systemui.keyguard.shared.model.KeyguardSection 28 import com.android.systemui.res.R 29 import javax.inject.Inject 30 import kotlinx.coroutines.ExperimentalCoroutinesApi 31 32 /** Positions the UDFPS accessibility overlay on the bottom half of the keyguard. */ 33 @ExperimentalCoroutinesApi 34 class DefaultUdfpsAccessibilityOverlaySection 35 @Inject 36 constructor( 37 private val context: Context, 38 private val viewModel: DeviceEntryUdfpsAccessibilityOverlayViewModel, 39 ) : KeyguardSection() { 40 private val viewId = R.id.udfps_accessibility_overlay 41 private var cachedConstraintLayout: ConstraintLayout? = null 42 addViewsnull43 override fun addViews(constraintLayout: ConstraintLayout) { 44 cachedConstraintLayout = constraintLayout 45 constraintLayout.addView(UdfpsAccessibilityOverlay(context).apply { id = viewId }) 46 } 47 bindDatanull48 override fun bindData(constraintLayout: ConstraintLayout) { 49 UdfpsAccessibilityOverlayBinder.bind( 50 constraintLayout.findViewById(viewId)!!, 51 viewModel, 52 ) 53 } 54 applyConstraintsnull55 override fun applyConstraints(constraintSet: ConstraintSet) { 56 constraintSet.apply { 57 connect(viewId, ConstraintSet.START, ConstraintSet.PARENT_ID, ConstraintSet.START) 58 connect(viewId, ConstraintSet.END, ConstraintSet.PARENT_ID, ConstraintSet.END) 59 60 create(R.id.udfps_accessibility_overlay_top_guideline, ConstraintSet.HORIZONTAL) 61 setGuidelinePercent(R.id.udfps_accessibility_overlay_top_guideline, .5f) 62 connect( 63 viewId, 64 ConstraintSet.TOP, 65 R.id.udfps_accessibility_overlay_top_guideline, 66 ConstraintSet.BOTTOM, 67 ) 68 69 if (KeyguardBottomAreaRefactor.isEnabled) { 70 connect( 71 viewId, 72 ConstraintSet.BOTTOM, 73 R.id.keyguard_indication_area, 74 ConstraintSet.TOP, 75 ) 76 } else { 77 connect(viewId, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM) 78 } 79 } 80 } 81 removeViewsnull82 override fun removeViews(constraintLayout: ConstraintLayout) { 83 constraintLayout.removeView(viewId) 84 } 85 } 86