1 /* 2 * Copyright (C) 2011 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 com.android.settings.drawable; 18 19 import android.graphics.Canvas; 20 import android.graphics.ColorFilter; 21 import android.graphics.Rect; 22 import android.graphics.Region; 23 import android.graphics.drawable.Drawable; 24 import android.view.View; 25 26 import com.android.internal.util.Preconditions; 27 28 /** 29 * Base wrapper that delegates all calls to another {@link Drawable}. The 30 * wrapped {@link Drawable} <em>must</em> be fully released from any 31 * {@link View} before wrapping, otherwise internal {@link Drawable.Callback} 32 * may be dropped. 33 */ 34 public class DrawableWrapper extends Drawable implements Drawable.Callback { 35 private final Drawable mDrawable; 36 DrawableWrapper(Drawable drawable)37 public DrawableWrapper(Drawable drawable) { 38 mDrawable = Preconditions.checkNotNull(drawable); 39 mDrawable.setCallback(this); 40 } 41 42 @Override draw(Canvas canvas)43 public void draw(Canvas canvas) { 44 mDrawable.draw(canvas); 45 } 46 47 @Override setBounds(int left, int top, int right, int bottom)48 public void setBounds(int left, int top, int right, int bottom) { 49 super.setBounds(left, top, right, bottom); 50 mDrawable.setBounds(left, top, right, bottom); 51 } 52 53 @Override setChangingConfigurations(int configs)54 public void setChangingConfigurations(int configs) { 55 mDrawable.setChangingConfigurations(configs); 56 } 57 58 @Override getChangingConfigurations()59 public int getChangingConfigurations() { 60 return mDrawable.getChangingConfigurations(); 61 } 62 63 @Override setDither(boolean dither)64 public void setDither(boolean dither) { 65 mDrawable.setDither(dither); 66 } 67 68 @Override setFilterBitmap(boolean filter)69 public void setFilterBitmap(boolean filter) { 70 mDrawable.setFilterBitmap(filter); 71 } 72 73 @Override setAlpha(int alpha)74 public void setAlpha(int alpha) { 75 mDrawable.setAlpha(alpha); 76 } 77 78 @Override setColorFilter(ColorFilter cf)79 public void setColorFilter(ColorFilter cf) { 80 mDrawable.setColorFilter(cf); 81 } 82 83 @Override isStateful()84 public boolean isStateful() { 85 return mDrawable.isStateful(); 86 } 87 88 @Override setState(final int[] stateSet)89 public boolean setState(final int[] stateSet) { 90 return mDrawable.setState(stateSet); 91 } 92 93 @Override getState()94 public int[] getState() { 95 return mDrawable.getState(); 96 } 97 98 @Override jumpToCurrentState()99 public void jumpToCurrentState() { 100 mDrawable.jumpToCurrentState(); 101 } 102 103 @Override getCurrent()104 public Drawable getCurrent() { 105 return mDrawable.getCurrent(); 106 } 107 108 @Override setVisible(boolean visible, boolean restart)109 public boolean setVisible(boolean visible, boolean restart) { 110 return super.setVisible(visible, restart) || mDrawable.setVisible(visible, restart); 111 } 112 113 @Override getOpacity()114 public int getOpacity() { 115 return mDrawable.getOpacity(); 116 } 117 118 @Override getTransparentRegion()119 public Region getTransparentRegion() { 120 return mDrawable.getTransparentRegion(); 121 } 122 123 @Override getIntrinsicWidth()124 public int getIntrinsicWidth() { 125 return mDrawable.getIntrinsicWidth(); 126 } 127 128 @Override getIntrinsicHeight()129 public int getIntrinsicHeight() { 130 return mDrawable.getIntrinsicHeight(); 131 } 132 133 @Override getMinimumWidth()134 public int getMinimumWidth() { 135 return mDrawable.getMinimumWidth(); 136 } 137 138 @Override getMinimumHeight()139 public int getMinimumHeight() { 140 return mDrawable.getMinimumHeight(); 141 } 142 143 @Override getPadding(Rect padding)144 public boolean getPadding(Rect padding) { 145 return mDrawable.getPadding(padding); 146 } 147 148 /** {@inheritDoc} */ invalidateDrawable(Drawable who)149 public void invalidateDrawable(Drawable who) { 150 invalidateSelf(); 151 } 152 153 /** {@inheritDoc} */ scheduleDrawable(Drawable who, Runnable what, long when)154 public void scheduleDrawable(Drawable who, Runnable what, long when) { 155 scheduleSelf(what, when); 156 } 157 158 /** {@inheritDoc} */ unscheduleDrawable(Drawable who, Runnable what)159 public void unscheduleDrawable(Drawable who, Runnable what) { 160 unscheduleSelf(what); 161 } 162 } 163