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 android.view.View 22 import androidx.constraintlayout.widget.ConstraintLayout 23 import androidx.constraintlayout.widget.ConstraintSet 24 import androidx.constraintlayout.widget.ConstraintSet.BOTTOM 25 import androidx.constraintlayout.widget.ConstraintSet.PARENT_ID 26 import com.android.systemui.keyguard.MigrateClocksToBlueprint 27 import com.android.systemui.keyguard.shared.model.KeyguardSection 28 import com.android.systemui.keyguard.ui.view.KeyguardRootView 29 import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel 30 import com.android.systemui.res.R 31 import javax.inject.Inject 32 33 /** Adds a layer to group elements for translation for burn-in preventation */ 34 class AodBurnInSection 35 @Inject 36 constructor( 37 private val context: Context, 38 private val rootView: KeyguardRootView, 39 private val clockViewModel: KeyguardClockViewModel, 40 ) : KeyguardSection() { 41 private lateinit var burnInLayer: AodBurnInLayer 42 // The burn-in layer requires at least 1 view at all times <lambda>null43 private val emptyView: View by lazy { 44 View(context, null).apply { 45 id = R.id.burn_in_layer_empty_view 46 visibility = View.GONE 47 } 48 } addViewsnull49 override fun addViews(constraintLayout: ConstraintLayout) { 50 if (!MigrateClocksToBlueprint.isEnabled) { 51 return 52 } 53 54 constraintLayout.addView(emptyView) 55 burnInLayer = 56 AodBurnInLayer(context).apply { 57 id = R.id.burn_in_layer 58 registerListener(rootView) 59 addView(emptyView) 60 } 61 constraintLayout.addView(burnInLayer) 62 } 63 bindDatanull64 override fun bindData(constraintLayout: ConstraintLayout) { 65 if (!MigrateClocksToBlueprint.isEnabled) { 66 return 67 } 68 clockViewModel.burnInLayer = burnInLayer 69 } 70 applyConstraintsnull71 override fun applyConstraints(constraintSet: ConstraintSet) { 72 if (!MigrateClocksToBlueprint.isEnabled) { 73 return 74 } 75 76 constraintSet.apply { 77 // The empty view should not occupy any space 78 constrainHeight(R.id.burn_in_layer_empty_view, 1) 79 constrainWidth(R.id.burn_in_layer_empty_view, 0) 80 connect(R.id.burn_in_layer_empty_view, BOTTOM, PARENT_ID, BOTTOM) 81 } 82 } 83 removeViewsnull84 override fun removeViews(constraintLayout: ConstraintLayout) { 85 burnInLayer.unregisterListener(rootView) 86 constraintLayout.removeView(R.id.burn_in_layer) 87 } 88 } 89