SquaringDrawable.java revision e7319b67364bd0ac6306bc7470a43d4a31600c1a
1package com.bumptech.glide.request.target;
2
3import android.annotation.TargetApi;
4import android.graphics.Canvas;
5import android.graphics.ColorFilter;
6import android.graphics.PorterDuff;
7import android.graphics.Rect;
8import android.graphics.drawable.Drawable;
9import android.os.Build;
10
11import com.bumptech.glide.load.resource.drawable.GlideDrawable;
12
13/**
14 * A wrapper drawable to square the wrapped drawable so that it expands to fill a square with exactly the given side
15 * length. The goal of this drawable is to ensure that square thumbnail drawables always match the size of the view
16 * they will be displayed in to avoid a costly requestLayout call. This class should not be used with views or drawables
17 * that are not square.
18 */
19public class SquaringDrawable extends GlideDrawable {
20    private final GlideDrawable wrapped;
21    private final int side;
22
23    public SquaringDrawable(GlideDrawable wrapped, int side) {
24        this.wrapped = wrapped;
25        this.side = side;
26    }
27
28    @Override
29    public void setBounds(int left, int top, int right, int bottom) {
30        super.setBounds(left, top, right, bottom);
31        wrapped.setBounds(left, top, right, bottom);
32    }
33
34    @Override
35    public void setBounds(Rect bounds) {
36        super.setBounds(bounds);
37        wrapped.setBounds(bounds);
38    }
39    public void setChangingConfigurations(int configs) {
40        wrapped.setChangingConfigurations(configs);
41    }
42
43    @Override
44    public int getChangingConfigurations() {
45        return wrapped.getChangingConfigurations();
46    }
47
48    @Override
49    public void setDither(boolean dither) {
50        wrapped.setDither(dither);
51    }
52
53    @Override
54    public void setFilterBitmap(boolean filter) {
55        wrapped.setFilterBitmap(filter);
56    }
57
58    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
59    @Override
60    public Callback getCallback() {
61        return wrapped.getCallback();
62    }
63
64    @TargetApi(Build.VERSION_CODES.KITKAT)
65    @Override
66    public int getAlpha() {
67        return wrapped.getAlpha();
68    }
69
70    @Override
71    public void setColorFilter(int color, PorterDuff.Mode mode) {
72        wrapped.setColorFilter(color, mode);
73    }
74
75    @Override
76    public void clearColorFilter() {
77        wrapped.clearColorFilter();
78    }
79
80    @Override
81    public Drawable getCurrent() {
82        return wrapped.getCurrent();
83    }
84
85    @Override
86    public boolean setVisible(boolean visible, boolean restart) {
87        return wrapped.setVisible(visible, restart);
88    }
89
90    @Override
91    public int getIntrinsicWidth() {
92        return side;
93    }
94
95    @Override
96    public int getIntrinsicHeight() {
97        return side;
98    }
99
100    @Override
101    public int getMinimumWidth() {
102        return wrapped.getMinimumWidth();
103    }
104
105    @Override
106    public int getMinimumHeight() {
107        return wrapped.getMinimumHeight();
108    }
109
110    @Override
111    public boolean getPadding(Rect padding) {
112        return wrapped.getPadding(padding);
113    }
114
115    @Override
116    public void invalidateSelf() {
117        super.invalidateSelf();
118        wrapped.invalidateSelf();
119    }
120
121    @Override
122    public void unscheduleSelf(Runnable what) {
123        super.unscheduleSelf(what);
124        wrapped.unscheduleSelf(what);
125    }
126
127    @Override
128    public void scheduleSelf(Runnable what, long when) {
129        super.scheduleSelf(what, when);
130        wrapped.scheduleSelf(what, when);
131    }
132
133    @Override
134    public void draw(Canvas canvas) {
135        wrapped.draw(canvas);
136    }
137
138    @Override
139    public void setAlpha(int i) {
140        wrapped.setAlpha(i);
141    }
142
143    @Override
144    public void setColorFilter(ColorFilter colorFilter) {
145        wrapped.setColorFilter(colorFilter);
146    }
147
148    @Override
149    public int getOpacity() {
150        return wrapped.getOpacity();
151    }
152
153    @Override
154    public boolean isAnimated() {
155        return wrapped.isAnimated();
156    }
157
158    @Override
159    public void setLoopCount(int loopCount) {
160        wrapped.setLoopCount(loopCount);
161    }
162
163    @Override
164    public void start() {
165        wrapped.start();
166    }
167
168    @Override
169    public void stop() {
170        wrapped.stop();
171    }
172
173    @Override
174    public boolean isRunning() {
175        return wrapped.isRunning();
176    }
177}
178