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