• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  package com.android.systemui.keyguard.ui.view.layout.sections
18  
19  import android.content.Context
20  import android.view.View
21  import android.view.ViewTreeObserver.OnPreDrawListener
22  import androidx.constraintlayout.helper.widget.Layer
23  
24  class AodBurnInLayer(
25      context: Context,
26  ) : Layer(context) {
27      // For setScale in Layer class, it stores it in mScaleX/Y and directly apply scale to
28      // referenceViews instead of keeping the value in fields of View class
29      // when we try to clone ConstraintSet, it will call getScaleX from View class and return 1.0
30      // and when we clone and apply, it will reset everything in the layer
31      // which cause the flicker from AOD to LS
32      private var _scaleX = 1F
33      private var _scaleY = 1F
34  
35      // As described for _scaleX and _scaleY, we have similar issue with translation
36      private var _translationX = 0F
37      private var _translationY = 0F
38  
<lambda>null39      private val _predrawListener = OnPreDrawListener {
40          super.setScaleX(_scaleX)
41          super.setScaleY(_scaleY)
42          super.setTranslationX(_translationX)
43          super.setTranslationY(_translationY)
44          true
45      }
46  
47      // avoid adding views with same ids
addViewnull48      override fun addView(view: View?) {
49          view?.let { if (it.id !in referencedIds) super.addView(view) }
50      }
51  
registerListenernull52      fun registerListener(rootView: View) {
53          rootView.viewTreeObserver.addOnPreDrawListener(_predrawListener)
54      }
55  
unregisterListenernull56      fun unregisterListener(rootView: View) {
57          rootView.viewTreeObserver.removeOnPreDrawListener(_predrawListener)
58      }
59  
setScaleXnull60      override fun setScaleX(scaleX: Float) {
61          _scaleX = scaleX
62          super.setScaleX(scaleX)
63      }
64  
getScaleXnull65      override fun getScaleX(): Float {
66          return _scaleX
67      }
68  
setScaleYnull69      override fun setScaleY(scaleY: Float) {
70          _scaleY = scaleY
71          super.setScaleY(scaleY)
72      }
73  
getScaleYnull74      override fun getScaleY(): Float {
75          return _scaleY
76      }
77  
setTranslationXnull78      override fun setTranslationX(dx: Float) {
79          _translationX = dx
80          super.setTranslationX(dx)
81      }
82  
getTranslationXnull83      override fun getTranslationX(): Float {
84          return _translationX
85      }
86  
setTranslationYnull87      override fun setTranslationY(dy: Float) {
88          _translationY = dy
89          super.setTranslationY(dy)
90      }
91  
getTranslationYnull92      override fun getTranslationY(): Float {
93          return _translationY
94      }
95  }
96