1 /* 2 * Copyright (C) 2022 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.decor 18 19 import android.content.Context 20 import android.view.DisplayCutout 21 import android.view.Surface 22 import android.view.View 23 import android.view.ViewGroup 24 import com.android.systemui.R 25 import com.android.systemui.ScreenDecorations.DisplayCutoutView 26 27 class CutoutDecorProviderImpl( 28 @DisplayCutout.BoundsPosition override val alignedBound: Int 29 ) : BoundDecorProvider() { 30 31 override val viewId: Int = when (alignedBound) { 32 DisplayCutout.BOUNDS_POSITION_TOP -> R.id.display_cutout 33 DisplayCutout.BOUNDS_POSITION_LEFT -> R.id.display_cutout_left 34 DisplayCutout.BOUNDS_POSITION_RIGHT -> R.id.display_cutout_right 35 else -> R.id.display_cutout_bottom 36 } 37 38 override fun inflateView( 39 context: Context, 40 parent: ViewGroup, 41 @Surface.Rotation rotation: Int, 42 tintColor: Int 43 ): View { 44 return DisplayCutoutView(context, alignedBound).also { view -> 45 view.id = viewId 46 view.setColor(tintColor) 47 parent.addView(view) 48 view.updateRotation(rotation) 49 } 50 } 51 52 override fun onReloadResAndMeasure( 53 view: View, 54 reloadToken: Int, 55 @Surface.Rotation rotation: Int, 56 tintColor: Int, 57 displayUniqueId: String? 58 ) { 59 (view as? DisplayCutoutView)?.let { cutoutView -> 60 cutoutView.setColor(tintColor) 61 cutoutView.updateRotation(rotation) 62 cutoutView.updateConfiguration(displayUniqueId) 63 } 64 } 65 } 66