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 package com.android.wm.shell.bubbles 17 18 import android.graphics.Color 19 import com.android.wm.shell.R 20 import com.android.wm.shell.common.bubbles.BubblePopupDrawable 21 import com.android.wm.shell.common.bubbles.BubblePopupView 22 23 /** 24 * A convenience method to setup the [BubblePopupView] with the correct config using local resources 25 */ 26 fun BubblePopupView.setup() { 27 val attrs = 28 context.obtainStyledAttributes( 29 intArrayOf( 30 com.android.internal.R.attr.materialColorSurface, 31 android.R.attr.dialogCornerRadius 32 ) 33 ) 34 35 val res = context.resources 36 val config = 37 BubblePopupDrawable.Config( 38 color = attrs.getColor(0, Color.WHITE), 39 cornerRadius = attrs.getDimension(1, 0f), 40 contentPadding = res.getDimensionPixelSize(R.dimen.bubble_popup_padding), 41 arrowWidth = res.getDimension(R.dimen.bubble_popup_arrow_width), 42 arrowHeight = res.getDimension(R.dimen.bubble_popup_arrow_height), 43 arrowRadius = res.getDimension(R.dimen.bubble_popup_arrow_corner_radius) 44 ) 45 attrs.recycle() 46 setupBackground(config) 47 } 48