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; 9 10/** 11 * A wrapper drawable to square the wrapped drawable so that it expands to fill a square with exactly the given side 12 * length. The goal of this drawable is to ensure that square thumbnail drawables always match the size of the view 13 * they will be displayed in to avoid a costly requestLayout call. This class should not be used with views or drawables 14 * that are not square. 15 */ 16public class SquaringDrawable extends Drawable { 17 private final Drawable wrapped; 18 private int side; 19 20 public SquaringDrawable(Drawable wrapped, int side) { 21 this.wrapped = wrapped; 22 this.side = side; 23 } 24 25 @Override 26 public void setBounds(int left, int top, int right, int bottom) { 27 super.setBounds(left, top, right, bottom); 28 wrapped.setBounds(left, top, right, bottom); 29 } 30 31 @Override 32 public void setBounds(Rect bounds) { 33 super.setBounds(bounds); 34 wrapped.setBounds(bounds); 35 } 36 public void setChangingConfigurations(int configs) { 37 wrapped.setChangingConfigurations(configs); 38 } 39 40 @Override 41 public int getChangingConfigurations() { 42 return wrapped.getChangingConfigurations(); 43 } 44 45 @Override 46 public void setDither(boolean dither) { 47 wrapped.setDither(dither); 48 } 49 50 @Override 51 public void setFilterBitmap(boolean filter) { 52 wrapped.setFilterBitmap(filter); 53 } 54 55 @TargetApi(11) 56 @Override 57 public Callback getCallback() { 58 return wrapped.getCallback(); 59 } 60 61 @TargetApi(19) 62 @Override 63 public int getAlpha() { 64 return wrapped.getAlpha(); 65 } 66 67 @Override 68 public void setColorFilter(int color, PorterDuff.Mode mode) { 69 wrapped.setColorFilter(color, mode); 70 } 71 72 @Override 73 public void clearColorFilter() { 74 wrapped.clearColorFilter(); 75 } 76 77 @Override 78 public Drawable getCurrent() { 79 return wrapped.getCurrent(); 80 } 81 82 @Override 83 public boolean setVisible(boolean visible, boolean restart) { 84 return wrapped.setVisible(visible, restart); 85 } 86 87 @Override 88 public int getIntrinsicWidth() { 89 return side; 90 } 91 92 @Override 93 public int getIntrinsicHeight() { 94 return side; 95 } 96 97 @Override 98 public int getMinimumWidth() { 99 return wrapped.getMinimumWidth(); 100 } 101 102 @Override 103 public int getMinimumHeight() { 104 return wrapped.getMinimumHeight(); 105 } 106 107 @Override 108 public boolean getPadding(Rect padding) { 109 return wrapped.getPadding(padding); 110 } 111 112 @Override 113 public void invalidateSelf() { 114 super.invalidateSelf(); //To change body of overridden methods use File | Settings | File Templates. 115 wrapped.invalidateSelf(); 116 } 117 118 @Override 119 public void unscheduleSelf(Runnable what) { 120 super.unscheduleSelf(what); //To change body of overridden methods use File | Settings | File Templates. 121 wrapped.unscheduleSelf(what); 122 } 123 124 @Override 125 public void scheduleSelf(Runnable what, long when) { 126 super.scheduleSelf(what, when); //To change body of overridden methods use File | Settings | File Templates. 127 wrapped.scheduleSelf(what, when); 128 } 129 130 @Override 131 public void draw(Canvas canvas) { 132 wrapped.draw(canvas); 133 } 134 135 @Override 136 public void setAlpha(int i) { 137 wrapped.setAlpha(i); 138 } 139 140 @Override 141 public void setColorFilter(ColorFilter colorFilter) { 142 wrapped.setColorFilter(colorFilter); 143 } 144 145 @Override 146 public int getOpacity() { 147 return wrapped.getOpacity(); 148 } 149} 150