• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.bumptech.glide.request.target;
2 
3 import android.annotation.TargetApi;
4 import android.graphics.Canvas;
5 import android.graphics.ColorFilter;
6 import android.graphics.PorterDuff;
7 import android.graphics.Rect;
8 import android.graphics.drawable.Drawable;
9 import android.os.Build;
10 
11 import 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  */
19 public class SquaringDrawable extends GlideDrawable {
20     private final GlideDrawable wrapped;
21     private final int side;
22 
SquaringDrawable(GlideDrawable wrapped, int side)23     public SquaringDrawable(GlideDrawable wrapped, int side) {
24         this.wrapped = wrapped;
25         this.side = side;
26     }
27 
28     @Override
setBounds(int left, int top, int right, int bottom)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
setBounds(Rect bounds)35     public void setBounds(Rect bounds) {
36         super.setBounds(bounds);
37         wrapped.setBounds(bounds);
38     }
39 
40     @Override
setChangingConfigurations(int configs)41     public void setChangingConfigurations(int configs) {
42         wrapped.setChangingConfigurations(configs);
43     }
44 
45     @Override
getChangingConfigurations()46     public int getChangingConfigurations() {
47         return wrapped.getChangingConfigurations();
48     }
49 
50     @Override
setDither(boolean dither)51     public void setDither(boolean dither) {
52         wrapped.setDither(dither);
53     }
54 
55     @Override
setFilterBitmap(boolean filter)56     public void setFilterBitmap(boolean filter) {
57         wrapped.setFilterBitmap(filter);
58     }
59 
60     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
61     @Override
getCallback()62     public Callback getCallback() {
63         return wrapped.getCallback();
64     }
65 
66     @TargetApi(Build.VERSION_CODES.KITKAT)
67     @Override
getAlpha()68     public int getAlpha() {
69         return wrapped.getAlpha();
70     }
71 
72     @Override
setColorFilter(int color, PorterDuff.Mode mode)73     public void setColorFilter(int color, PorterDuff.Mode mode) {
74         wrapped.setColorFilter(color, mode);
75     }
76 
77     @Override
clearColorFilter()78     public void clearColorFilter() {
79         wrapped.clearColorFilter();
80     }
81 
82     @Override
getCurrent()83     public Drawable getCurrent() {
84         return wrapped.getCurrent();
85     }
86 
87     @Override
setVisible(boolean visible, boolean restart)88     public boolean setVisible(boolean visible, boolean restart) {
89         return wrapped.setVisible(visible, restart);
90     }
91 
92     @Override
getIntrinsicWidth()93     public int getIntrinsicWidth() {
94         return side;
95     }
96 
97     @Override
getIntrinsicHeight()98     public int getIntrinsicHeight() {
99         return side;
100     }
101 
102     @Override
getMinimumWidth()103     public int getMinimumWidth() {
104         return wrapped.getMinimumWidth();
105     }
106 
107     @Override
getMinimumHeight()108     public int getMinimumHeight() {
109         return wrapped.getMinimumHeight();
110     }
111 
112     @Override
getPadding(Rect padding)113     public boolean getPadding(Rect padding) {
114         return wrapped.getPadding(padding);
115     }
116 
117     @Override
invalidateSelf()118     public void invalidateSelf() {
119         super.invalidateSelf();
120         wrapped.invalidateSelf();
121     }
122 
123     @Override
unscheduleSelf(Runnable what)124     public void unscheduleSelf(Runnable what) {
125         super.unscheduleSelf(what);
126         wrapped.unscheduleSelf(what);
127     }
128 
129     @Override
scheduleSelf(Runnable what, long when)130     public void scheduleSelf(Runnable what, long when) {
131         super.scheduleSelf(what, when);
132         wrapped.scheduleSelf(what, when);
133     }
134 
135     @Override
draw(Canvas canvas)136     public void draw(Canvas canvas) {
137         wrapped.draw(canvas);
138     }
139 
140     @Override
setAlpha(int i)141     public void setAlpha(int i) {
142         wrapped.setAlpha(i);
143     }
144 
145     @Override
setColorFilter(ColorFilter colorFilter)146     public void setColorFilter(ColorFilter colorFilter) {
147         wrapped.setColorFilter(colorFilter);
148     }
149 
150     @Override
getOpacity()151     public int getOpacity() {
152         return wrapped.getOpacity();
153     }
154 
155     @Override
isAnimated()156     public boolean isAnimated() {
157         return wrapped.isAnimated();
158     }
159 
160     @Override
setLoopCount(int loopCount)161     public void setLoopCount(int loopCount) {
162         wrapped.setLoopCount(loopCount);
163     }
164 
165     @Override
start()166     public void start() {
167         wrapped.start();
168     }
169 
170     @Override
stop()171     public void stop() {
172         wrapped.stop();
173     }
174 
175     @Override
isRunning()176     public boolean isRunning() {
177         return wrapped.isRunning();
178     }
179 }
180