Home | History | Annotate | Download | only in graphics
      1 /*
      2  * Copyright (C) 2008 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.example.android.apis.graphics;
     18 
     19 import android.graphics.Canvas;
     20 import android.graphics.ColorFilter;
     21 import android.graphics.PixelFormat;
     22 import android.graphics.drawable.Drawable;
     23 
     24 public class ProxyDrawable extends Drawable {
     25 
     26     private Drawable mProxy;
     27     private boolean mMutated;
     28 
     29     public ProxyDrawable(Drawable target) {
     30         mProxy = target;
     31     }
     32 
     33     public Drawable getProxy() {
     34         return mProxy;
     35     }
     36 
     37     public void setProxy(Drawable proxy) {
     38         if (proxy != this) {
     39             mProxy = proxy;
     40         }
     41     }
     42 
     43     @Override
     44     public void draw(Canvas canvas) {
     45         if (mProxy != null) {
     46             mProxy.draw(canvas);
     47         }
     48     }
     49 
     50     @Override
     51     public int getIntrinsicWidth() {
     52         return mProxy != null ? mProxy.getIntrinsicWidth() : -1;
     53     }
     54 
     55     @Override
     56     public int getIntrinsicHeight() {
     57         return mProxy != null ? mProxy.getIntrinsicHeight() : -1;
     58     }
     59 
     60     @Override
     61     public int getOpacity() {
     62         return mProxy != null ? mProxy.getOpacity() : PixelFormat.TRANSPARENT;
     63     }
     64 
     65     @Override
     66     public void setFilterBitmap(boolean filter) {
     67         if (mProxy != null) {
     68             mProxy.setFilterBitmap(filter);
     69         }
     70     }
     71 
     72     @Override
     73     public void setDither(boolean dither) {
     74         if (mProxy != null) {
     75             mProxy.setDither(dither);
     76         }
     77     }
     78 
     79     @Override
     80     public void setColorFilter(ColorFilter colorFilter) {
     81         if (mProxy != null) {
     82             mProxy.setColorFilter(colorFilter);
     83         }
     84     }
     85 
     86     @Override
     87     public void setAlpha(int alpha) {
     88         if (mProxy != null) {
     89             mProxy.setAlpha(alpha);
     90         }
     91     }
     92 
     93     @Override
     94     public Drawable mutate() {
     95         if (mProxy != null && !mMutated && super.mutate() == this) {
     96             mProxy.mutate();
     97             mMutated = true;
     98         }
     99         return this;
    100     }
    101 }
    102 
    103