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