1 /* 2 * Copyright (C) 2024 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.permissioncontroller.permission.ui.handheld.v35 18 19 import android.content.Context 20 import android.util.AttributeSet 21 import android.widget.LinearLayout 22 import androidx.annotation.AttrRes 23 import androidx.annotation.StyleRes 24 25 /** This is a simple wrapper for [LinearLayout] that allows setting an extra drawable state. */ 26 class DrawableStateLinearLayout : LinearLayout { 27 var extraDrawableState: IntArray? = null 28 set(value) { 29 if (field != value) { 30 field = value 31 refreshDrawableState() 32 } 33 } 34 35 constructor(context: Context) : super(context) 36 37 constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) 38 39 constructor( 40 context: Context, 41 attrs: AttributeSet?, 42 @AttrRes defStyleAttr: Int 43 ) : super(context, attrs, defStyleAttr) 44 45 constructor( 46 context: Context, 47 attrs: AttributeSet?, 48 @AttrRes defStyleAttr: Int, 49 @StyleRes defStyleRes: Int 50 ) : super(context, attrs, defStyleAttr, defStyleRes) 51 onCreateDrawableStatenull52 override fun onCreateDrawableState(extraSpace: Int): IntArray { 53 val extraDrawableState = 54 extraDrawableState ?: return super.onCreateDrawableState(extraSpace) 55 return mergeDrawableStates( 56 super.onCreateDrawableState(extraSpace + extraDrawableState.size), 57 extraDrawableState 58 ) 59 } 60 } 61