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.res.Resources 21 import androidx.constraintlayout.widget.ConstraintLayout 22 import androidx.constraintlayout.widget.ConstraintSet 23 import androidx.constraintlayout.widget.ConstraintSet.BOTTOM 24 import androidx.constraintlayout.widget.ConstraintSet.LEFT 25 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID 26 import androidx.constraintlayout.widget.ConstraintSet.RIGHT 27 import androidx.constraintlayout.widget.ConstraintSet.TOP 28 import com.android.systemui.dagger.qualifiers.Main 29 import com.android.systemui.deviceentry.shared.DeviceEntryUdfpsRefactor 30 import com.android.systemui.keyguard.KeyguardBottomAreaRefactor 31 import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder 32 import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModel 33 import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel 34 import com.android.systemui.plugins.FalsingManager 35 import com.android.systemui.res.R 36 import com.android.systemui.statusbar.KeyguardIndicationController 37 import com.android.systemui.statusbar.VibratorHelper 38 import javax.inject.Inject 39 40 class AlignShortcutsToUdfpsSection 41 @Inject 42 constructor( 43 @Main private val resources: Resources, 44 private val keyguardQuickAffordancesCombinedViewModel: 45 KeyguardQuickAffordancesCombinedViewModel, 46 private val keyguardRootViewModel: KeyguardRootViewModel, 47 private val falsingManager: FalsingManager, 48 private val indicationController: KeyguardIndicationController, 49 private val vibratorHelper: VibratorHelper, 50 ) : BaseShortcutSection() { addViewsnull51 override fun addViews(constraintLayout: ConstraintLayout) { 52 if (KeyguardBottomAreaRefactor.isEnabled) { 53 addLeftShortcut(constraintLayout) 54 addRightShortcut(constraintLayout) 55 } 56 } 57 bindDatanull58 override fun bindData(constraintLayout: ConstraintLayout) { 59 if (KeyguardBottomAreaRefactor.isEnabled) { 60 leftShortcutHandle = 61 KeyguardQuickAffordanceViewBinder.bind( 62 constraintLayout.requireViewById(R.id.start_button), 63 keyguardQuickAffordancesCombinedViewModel.startButton, 64 keyguardQuickAffordancesCombinedViewModel.transitionAlpha, 65 falsingManager, 66 vibratorHelper, 67 ) { 68 indicationController.showTransientIndication(it) 69 } 70 rightShortcutHandle = 71 KeyguardQuickAffordanceViewBinder.bind( 72 constraintLayout.requireViewById(R.id.end_button), 73 keyguardQuickAffordancesCombinedViewModel.endButton, 74 keyguardQuickAffordancesCombinedViewModel.transitionAlpha, 75 falsingManager, 76 vibratorHelper, 77 ) { 78 indicationController.showTransientIndication(it) 79 } 80 } 81 } 82 applyConstraintsnull83 override fun applyConstraints(constraintSet: ConstraintSet) { 84 val width = resources.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_width) 85 val height = resources.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height) 86 87 val lockIconViewId = 88 if (DeviceEntryUdfpsRefactor.isEnabled) { 89 R.id.device_entry_icon_view 90 } else { 91 R.id.lock_icon_view 92 } 93 94 constraintSet.apply { 95 constrainWidth(R.id.start_button, width) 96 constrainHeight(R.id.start_button, height) 97 connect(R.id.start_button, LEFT, PARENT_ID, LEFT) 98 connect(R.id.start_button, RIGHT, lockIconViewId, LEFT) 99 connect(R.id.start_button, TOP, lockIconViewId, TOP) 100 connect(R.id.start_button, BOTTOM, lockIconViewId, BOTTOM) 101 102 constrainWidth(R.id.end_button, width) 103 constrainHeight(R.id.end_button, height) 104 connect(R.id.end_button, RIGHT, PARENT_ID, RIGHT) 105 connect(R.id.end_button, LEFT, lockIconViewId, RIGHT) 106 connect(R.id.end_button, TOP, lockIconViewId, TOP) 107 connect(R.id.end_button, BOTTOM, lockIconViewId, BOTTOM) 108 } 109 } 110 } 111