1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package androidx.vectordrawable.graphics.drawable; 16 17 import android.content.res.Resources; 18 import android.graphics.ColorFilter; 19 import android.graphics.PorterDuff; 20 import android.graphics.Rect; 21 import android.graphics.Region; 22 import android.graphics.drawable.Drawable; 23 24 import androidx.core.graphics.drawable.DrawableCompat; 25 import androidx.core.graphics.drawable.TintAwareDrawable; 26 27 /** 28 * Internal common delegation shared by VectorDrawableCompat and AnimatedVectorDrawableCompat 29 */ 30 abstract class VectorDrawableCommon extends Drawable implements TintAwareDrawable { 31 32 // Drawable delegation for supported API levels. 33 Drawable mDelegateDrawable; 34 35 @Override 36 public void setColorFilter(int color, PorterDuff.Mode mode) { 37 if (mDelegateDrawable != null) { 38 mDelegateDrawable.setColorFilter(color, mode); 39 return; 40 } 41 super.setColorFilter(color, mode); 42 } 43 44 @Override 45 public ColorFilter getColorFilter() { 46 if (mDelegateDrawable != null) { 47 return DrawableCompat.getColorFilter(mDelegateDrawable); 48 } 49 return null; 50 } 51 52 @Override 53 protected boolean onLevelChange(int level) { 54 if (mDelegateDrawable != null) { 55 return mDelegateDrawable.setLevel(level); 56 } 57 return super.onLevelChange(level); 58 } 59 60 @Override 61 protected void onBoundsChange(Rect bounds) { 62 if (mDelegateDrawable != null) { 63 mDelegateDrawable.setBounds(bounds); 64 return; 65 } 66 super.onBoundsChange(bounds); 67 } 68 69 @Override 70 public void setHotspot(float x, float y) { 71 if (mDelegateDrawable != null) { 72 DrawableCompat.setHotspot(mDelegateDrawable, x, y); 73 } 74 return; 75 } 76 77 @Override 78 public void setHotspotBounds(int left, int top, int right, int bottom) { 79 if (mDelegateDrawable != null) { 80 DrawableCompat.setHotspotBounds(mDelegateDrawable, left, top, right, bottom); 81 return; 82 } 83 } 84 85 @Override 86 public void setFilterBitmap(boolean filter) { 87 if (mDelegateDrawable != null) { 88 mDelegateDrawable.setFilterBitmap(filter); 89 return; 90 } 91 } 92 93 @Override 94 public void jumpToCurrentState() { 95 if (mDelegateDrawable != null) { 96 DrawableCompat.jumpToCurrentState(mDelegateDrawable); 97 return; 98 } 99 } 100 101 @Override 102 public void applyTheme(Resources.Theme t) { 103 // API >= 21 only. 104 if (mDelegateDrawable != null) { 105 DrawableCompat.applyTheme(mDelegateDrawable, t); 106 return; 107 } 108 } 109 110 @Override 111 public void clearColorFilter() { 112 if (mDelegateDrawable != null) { 113 mDelegateDrawable.clearColorFilter(); 114 return; 115 } 116 super.clearColorFilter(); 117 } 118 119 @Override 120 public Drawable getCurrent() { 121 if (mDelegateDrawable != null) { 122 return mDelegateDrawable.getCurrent(); 123 } 124 return super.getCurrent(); 125 } 126 127 @Override 128 public int getMinimumWidth() { 129 if (mDelegateDrawable != null) { 130 return mDelegateDrawable.getMinimumWidth(); 131 } 132 return super.getMinimumWidth(); 133 } 134 135 @Override 136 public int getMinimumHeight() { 137 if (mDelegateDrawable != null) { 138 return mDelegateDrawable.getMinimumHeight(); 139 } 140 return super.getMinimumHeight(); 141 } 142 143 @Override 144 public boolean getPadding(Rect padding) { 145 if (mDelegateDrawable != null) { 146 return mDelegateDrawable.getPadding(padding); 147 } 148 return super.getPadding(padding); 149 } 150 151 @Override 152 public int[] getState() { 153 if (mDelegateDrawable != null) { 154 return mDelegateDrawable.getState(); 155 } 156 return super.getState(); 157 } 158 159 160 @Override 161 public Region getTransparentRegion() { 162 if (mDelegateDrawable != null) { 163 return mDelegateDrawable.getTransparentRegion(); 164 } 165 return super.getTransparentRegion(); 166 } 167 168 @Override 169 public void setChangingConfigurations(int configs) { 170 if (mDelegateDrawable != null) { 171 mDelegateDrawable.setChangingConfigurations(configs); 172 return; 173 } 174 super.setChangingConfigurations(configs); 175 } 176 177 @Override 178 public boolean setState(int[] stateSet) { 179 if (mDelegateDrawable != null) { 180 return mDelegateDrawable.setState(stateSet); 181 } 182 return super.setState(stateSet); 183 } 184 } 185