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