1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15 package com.android.systemui.statusbar 16 17 import android.annotation.SuppressLint 18 import android.content.Context 19 import android.content.res.Configuration 20 import android.util.AttributeSet 21 import android.widget.FrameLayout 22 import com.android.systemui.res.R 23 import com.android.systemui.statusbar.events.BackgroundAnimatableView 24 25 /** Chip that appears in the status bar when an external display is connected. */ 26 class ConnectedDisplayChip 27 @JvmOverloads 28 constructor(context: Context, attrs: AttributeSet? = null) : 29 FrameLayout(context, attrs), BackgroundAnimatableView { 30 31 private val iconContainer: FrameLayout 32 init { 33 inflate(context, R.layout.connected_display_chip, this) 34 iconContainer = requireViewById(R.id.icons_rounded_container) 35 } 36 37 /** 38 * When animating as a chip in the status bar, we want to animate the width for the rounded 39 * container. We have to subtract our own top and left offset because the bounds come to us as 40 * absolute on-screen bounds. 41 */ setBoundsForAnimationnull42 override fun setBoundsForAnimation(l: Int, t: Int, r: Int, b: Int) { 43 iconContainer.setLeftTopRightBottom(l - left, t - top, r - left, b - top) 44 } 45 onConfigurationChangednull46 override fun onConfigurationChanged(newConfig: Configuration) { 47 super.onConfigurationChanged(newConfig) 48 updateResources() 49 } 50 51 @SuppressLint("UseCompatLoadingForDrawables") updateResourcesnull52 private fun updateResources() { 53 iconContainer.background = context.getDrawable(R.drawable.statusbar_chip_bg) 54 } 55 } 56