Home | History | Annotate | Download | only in drawable
      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 
     37     public DrawableWrapper(Drawable drawable) {
     38         mDrawable = Preconditions.checkNotNull(drawable);
     39         mDrawable.setCallback(this);
     40     }
     41 
     42     @Override
     43     public void draw(Canvas canvas) {
     44         mDrawable.draw(canvas);
     45     }
     46 
     47     @Override
     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
     54     public void setChangingConfigurations(int configs) {
     55         mDrawable.setChangingConfigurations(configs);
     56     }
     57 
     58     @Override
     59     public int getChangingConfigurations() {
     60         return mDrawable.getChangingConfigurations();
     61     }
     62 
     63     @Override
     64     public void setDither(boolean dither) {
     65         mDrawable.setDither(dither);
     66     }
     67 
     68     @Override
     69     public void setFilterBitmap(boolean filter) {
     70         mDrawable.setFilterBitmap(filter);
     71     }
     72 
     73     @Override
     74     public void setAlpha(int alpha) {
     75         mDrawable.setAlpha(alpha);
     76     }
     77 
     78     @Override
     79     public void setColorFilter(ColorFilter cf) {
     80         mDrawable.setColorFilter(cf);
     81     }
     82 
     83     @Override
     84     public boolean isStateful() {
     85         return mDrawable.isStateful();
     86     }
     87 
     88     @Override
     89     public boolean setState(final int[] stateSet) {
     90         return mDrawable.setState(stateSet);
     91     }
     92 
     93     @Override
     94     public int[] getState() {
     95         return mDrawable.getState();
     96     }
     97 
     98     @Override
     99     public void jumpToCurrentState() {
    100         mDrawable.jumpToCurrentState();
    101     }
    102 
    103     @Override
    104     public Drawable getCurrent() {
    105         return mDrawable.getCurrent();
    106     }
    107 
    108     @Override
    109     public boolean setVisible(boolean visible, boolean restart) {
    110         return super.setVisible(visible, restart) || mDrawable.setVisible(visible, restart);
    111     }
    112 
    113     @Override
    114     public int getOpacity() {
    115         return mDrawable.getOpacity();
    116     }
    117 
    118     @Override
    119     public Region getTransparentRegion() {
    120         return mDrawable.getTransparentRegion();
    121     }
    122 
    123     @Override
    124     public int getIntrinsicWidth() {
    125         return mDrawable.getIntrinsicWidth();
    126     }
    127 
    128     @Override
    129     public int getIntrinsicHeight() {
    130         return mDrawable.getIntrinsicHeight();
    131     }
    132 
    133     @Override
    134     public int getMinimumWidth() {
    135         return mDrawable.getMinimumWidth();
    136     }
    137 
    138     @Override
    139     public int getMinimumHeight() {
    140         return mDrawable.getMinimumHeight();
    141     }
    142 
    143     @Override
    144     public boolean getPadding(Rect padding) {
    145         return mDrawable.getPadding(padding);
    146     }
    147 
    148     /** {@inheritDoc} */
    149     public void invalidateDrawable(Drawable who) {
    150         invalidateSelf();
    151     }
    152 
    153     /** {@inheritDoc} */
    154     public void scheduleDrawable(Drawable who, Runnable what, long when) {
    155         scheduleSelf(what, when);
    156     }
    157 
    158     /** {@inheritDoc} */
    159     public void unscheduleDrawable(Drawable who, Runnable what) {
    160         unscheduleSelf(what);
    161     }
    162 }
    163