1 /* 2 * Copyright (C) 2015 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 androidx.vectordrawable.graphics.drawable; 18 19 import android.content.res.Resources; 20 import android.graphics.PorterDuff; 21 import android.graphics.Rect; 22 import android.graphics.Region; 23 import android.graphics.drawable.Drawable; 24 25 import androidx.core.graphics.drawable.DrawableCompat; 26 import androidx.core.graphics.drawable.TintAwareDrawable; 27 28 import org.jspecify.annotations.NonNull; 29 30 /** 31 * Internal common delegation shared by VectorDrawableCompat and AnimatedVectorDrawableCompat 32 */ 33 abstract class VectorDrawableCommon extends Drawable implements TintAwareDrawable { 34 35 // Drawable delegation for supported API levels. 36 Drawable mDelegateDrawable; 37 38 @Override setColorFilter(int color, PorterDuff.Mode mode)39 public void setColorFilter(int color, PorterDuff.Mode mode) { 40 if (mDelegateDrawable != null) { 41 mDelegateDrawable.setColorFilter(color, mode); 42 return; 43 } 44 super.setColorFilter(color, mode); 45 } 46 47 @Override onLevelChange(int level)48 protected boolean onLevelChange(int level) { 49 if (mDelegateDrawable != null) { 50 return mDelegateDrawable.setLevel(level); 51 } 52 return super.onLevelChange(level); 53 } 54 55 @Override onBoundsChange(Rect bounds)56 protected void onBoundsChange(Rect bounds) { 57 if (mDelegateDrawable != null) { 58 mDelegateDrawable.setBounds(bounds); 59 return; 60 } 61 super.onBoundsChange(bounds); 62 } 63 64 @Override setHotspot(float x, float y)65 public void setHotspot(float x, float y) { 66 if (mDelegateDrawable != null) { 67 DrawableCompat.setHotspot(mDelegateDrawable, x, y); 68 } 69 } 70 71 @Override setHotspotBounds(int left, int top, int right, int bottom)72 public void setHotspotBounds(int left, int top, int right, int bottom) { 73 if (mDelegateDrawable != null) { 74 DrawableCompat.setHotspotBounds(mDelegateDrawable, left, top, right, bottom); 75 } 76 } 77 78 @Override setFilterBitmap(boolean filter)79 public void setFilterBitmap(boolean filter) { 80 if (mDelegateDrawable != null) { 81 mDelegateDrawable.setFilterBitmap(filter); 82 } 83 } 84 85 @SuppressWarnings("deprecation") 86 @Override jumpToCurrentState()87 public void jumpToCurrentState() { 88 if (mDelegateDrawable != null) { 89 DrawableCompat.jumpToCurrentState(mDelegateDrawable); 90 } 91 } 92 93 @Override applyTheme(Resources.@onNull Theme t)94 public void applyTheme(Resources.@NonNull Theme t) { 95 // API >= 21 only. 96 if (mDelegateDrawable != null) { 97 DrawableCompat.applyTheme(mDelegateDrawable, t); 98 } 99 } 100 101 @Override clearColorFilter()102 public void clearColorFilter() { 103 if (mDelegateDrawable != null) { 104 mDelegateDrawable.clearColorFilter(); 105 return; 106 } 107 super.clearColorFilter(); 108 } 109 110 @Override getCurrent()111 public Drawable getCurrent() { 112 if (mDelegateDrawable != null) { 113 return mDelegateDrawable.getCurrent(); 114 } 115 return super.getCurrent(); 116 } 117 118 @Override getMinimumWidth()119 public int getMinimumWidth() { 120 if (mDelegateDrawable != null) { 121 return mDelegateDrawable.getMinimumWidth(); 122 } 123 return super.getMinimumWidth(); 124 } 125 126 @Override getMinimumHeight()127 public int getMinimumHeight() { 128 if (mDelegateDrawable != null) { 129 return mDelegateDrawable.getMinimumHeight(); 130 } 131 return super.getMinimumHeight(); 132 } 133 134 @Override getPadding(Rect padding)135 public boolean getPadding(Rect padding) { 136 if (mDelegateDrawable != null) { 137 return mDelegateDrawable.getPadding(padding); 138 } 139 return super.getPadding(padding); 140 } 141 142 @Override getState()143 public int[] getState() { 144 if (mDelegateDrawable != null) { 145 return mDelegateDrawable.getState(); 146 } 147 return super.getState(); 148 } 149 150 151 @Override getTransparentRegion()152 public Region getTransparentRegion() { 153 if (mDelegateDrawable != null) { 154 return mDelegateDrawable.getTransparentRegion(); 155 } 156 return super.getTransparentRegion(); 157 } 158 159 @Override setChangingConfigurations(int configs)160 public void setChangingConfigurations(int configs) { 161 if (mDelegateDrawable != null) { 162 mDelegateDrawable.setChangingConfigurations(configs); 163 return; 164 } 165 super.setChangingConfigurations(configs); 166 } 167 168 @Override setState(int[] stateSet)169 public boolean setState(int[] stateSet) { 170 if (mDelegateDrawable != null) { 171 return mDelegateDrawable.setState(stateSet); 172 } 173 return super.setState(stateSet); 174 } 175 } 176