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