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 android.view.LayoutInflater 22 import android.view.View 23 import androidx.constraintlayout.widget.ConstraintLayout 24 import androidx.constraintlayout.widget.ConstraintSet 25 import androidx.constraintlayout.widget.ConstraintSet.BOTTOM 26 import androidx.constraintlayout.widget.ConstraintSet.END 27 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID 28 import androidx.constraintlayout.widget.ConstraintSet.START 29 import androidx.constraintlayout.widget.ConstraintSet.VISIBILITY_MODE_IGNORE 30 import androidx.constraintlayout.widget.ConstraintSet.WRAP_CONTENT 31 import androidx.core.view.isVisible 32 import com.android.systemui.animation.view.LaunchableLinearLayout 33 import com.android.systemui.dagger.qualifiers.Main 34 import com.android.systemui.keyguard.KeyguardBottomAreaRefactor 35 import com.android.systemui.keyguard.shared.model.KeyguardSection 36 import com.android.systemui.keyguard.ui.binder.KeyguardSettingsViewBinder 37 import com.android.systemui.keyguard.ui.viewmodel.KeyguardLongPressViewModel 38 import com.android.systemui.keyguard.ui.viewmodel.KeyguardRootViewModel 39 import com.android.systemui.keyguard.ui.viewmodel.KeyguardSettingsMenuViewModel 40 import com.android.systemui.plugins.ActivityStarter 41 import com.android.systemui.res.R 42 import com.android.systemui.statusbar.VibratorHelper 43 import javax.inject.Inject 44 import kotlinx.coroutines.DisposableHandle 45 46 class DefaultSettingsPopupMenuSection 47 @Inject 48 constructor( 49 @Main private val resources: Resources, 50 private val keyguardSettingsMenuViewModel: KeyguardSettingsMenuViewModel, 51 private val keyguardLongPressViewModel: KeyguardLongPressViewModel, 52 private val keyguardRootViewModel: KeyguardRootViewModel, 53 private val vibratorHelper: VibratorHelper, 54 private val activityStarter: ActivityStarter, 55 ) : KeyguardSection() { 56 private var settingsPopupMenuHandle: DisposableHandle? = null 57 addViewsnull58 override fun addViews(constraintLayout: ConstraintLayout) { 59 if (!KeyguardBottomAreaRefactor.isEnabled) { 60 return 61 } 62 val view = 63 LayoutInflater.from(constraintLayout.context) 64 .inflate(R.layout.keyguard_settings_popup_menu, constraintLayout, false) 65 .apply { 66 id = R.id.keyguard_settings_button 67 isVisible = false 68 alpha = 0f 69 } as LaunchableLinearLayout 70 constraintLayout.addView(view) 71 } 72 bindDatanull73 override fun bindData(constraintLayout: ConstraintLayout) { 74 if (KeyguardBottomAreaRefactor.isEnabled) { 75 settingsPopupMenuHandle = 76 KeyguardSettingsViewBinder.bind( 77 constraintLayout.requireViewById<View>(R.id.keyguard_settings_button), 78 keyguardSettingsMenuViewModel, 79 keyguardLongPressViewModel, 80 keyguardRootViewModel, 81 vibratorHelper, 82 activityStarter, 83 ) 84 } 85 } 86 applyConstraintsnull87 override fun applyConstraints(constraintSet: ConstraintSet) { 88 val horizontalOffsetMargin = 89 resources.getDimensionPixelSize(R.dimen.keyguard_affordance_horizontal_offset) 90 91 constraintSet.apply { 92 constrainWidth(R.id.keyguard_settings_button, WRAP_CONTENT) 93 constrainHeight(R.id.keyguard_settings_button, WRAP_CONTENT) 94 constrainMinHeight( 95 R.id.keyguard_settings_button, 96 resources.getDimensionPixelSize(R.dimen.keyguard_affordance_fixed_height) 97 ) 98 connect(R.id.keyguard_settings_button, START, PARENT_ID, START, horizontalOffsetMargin) 99 connect(R.id.keyguard_settings_button, END, PARENT_ID, END, horizontalOffsetMargin) 100 connect( 101 R.id.keyguard_settings_button, 102 BOTTOM, 103 PARENT_ID, 104 BOTTOM, 105 resources.getDimensionPixelSize(R.dimen.keyguard_affordance_vertical_offset) 106 ) 107 // Ignore ConstrainSet's default visibility, and let the view choose 108 setVisibilityMode(R.id.keyguard_settings_button, VISIBILITY_MODE_IGNORE) 109 } 110 } 111 removeViewsnull112 override fun removeViews(constraintLayout: ConstraintLayout) { 113 settingsPopupMenuHandle?.dispose() 114 constraintLayout.removeView(R.id.keyguard_settings_button) 115 } 116 } 117