• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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.car.ui.uxr;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.widget.Button;
21 
22 import androidx.annotation.Nullable;
23 
24 /**
25  * A {@link Button} that implements {@link DrawableStateView}, for allowing additional states
26  * such as ux restriction.
27  */
28 public class DrawableStateButton extends Button implements DrawableStateView {
29     private DrawableStateUtil mUtil;
30 
DrawableStateButton(Context context)31     public DrawableStateButton(Context context) {
32         super(context);
33     }
34 
DrawableStateButton(Context context, @Nullable AttributeSet attrs)35     public DrawableStateButton(Context context, @Nullable AttributeSet attrs) {
36         super(context, attrs);
37     }
38 
DrawableStateButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr)39     public DrawableStateButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
40         super(context, attrs, defStyleAttr);
41     }
42 
43     @Override
setExtraDrawableState(@ullable int[] stateToAdd, @Nullable int[] stateToRemove)44     public void setExtraDrawableState(@Nullable int[] stateToAdd, @Nullable int[] stateToRemove) {
45         if (mUtil == null) {
46             mUtil = new DrawableStateUtil(this);
47         }
48         mUtil.setExtraDrawableState(stateToAdd, stateToRemove);
49     }
50 
51     @Override
onCreateDrawableState(int extraSpace)52     public int[] onCreateDrawableState(int extraSpace) {
53         if (mUtil == null) {
54             mUtil = new DrawableStateUtil(this);
55         }
56         return mUtil.onCreateDrawableState(extraSpace, space -> super.onCreateDrawableState(space));
57     }
58 }
59