Home | History | Annotate | Download | only in target
      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 
     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 
     40     @Override
     41     public void setChangingConfigurations(int configs) {
     42         wrapped.setChangingConfigurations(configs);
     43     }
     44 
     45     @Override
     46     public int getChangingConfigurations() {
     47         return wrapped.getChangingConfigurations();
     48     }
     49 
     50     @Override
     51     public void setDither(boolean dither) {
     52         wrapped.setDither(dither);
     53     }
     54 
     55     @Override
     56     public void setFilterBitmap(boolean filter) {
     57         wrapped.setFilterBitmap(filter);
     58     }
     59 
     60     @TargetApi(Build.VERSION_CODES.HONEYCOMB)
     61     @Override
     62     public Callback getCallback() {
     63         return wrapped.getCallback();
     64     }
     65 
     66     @TargetApi(Build.VERSION_CODES.KITKAT)
     67     @Override
     68     public int getAlpha() {
     69         return wrapped.getAlpha();
     70     }
     71 
     72     @Override
     73     public void setColorFilter(int color, PorterDuff.Mode mode) {
     74         wrapped.setColorFilter(color, mode);
     75     }
     76 
     77     @Override
     78     public void clearColorFilter() {
     79         wrapped.clearColorFilter();
     80     }
     81 
     82     @Override
     83     public Drawable getCurrent() {
     84         return wrapped.getCurrent();
     85     }
     86 
     87     @Override
     88     public boolean setVisible(boolean visible, boolean restart) {
     89         return wrapped.setVisible(visible, restart);
     90     }
     91 
     92     @Override
     93     public int getIntrinsicWidth() {
     94         return side;
     95     }
     96 
     97     @Override
     98     public int getIntrinsicHeight() {
     99         return side;
    100     }
    101 
    102     @Override
    103     public int getMinimumWidth() {
    104         return wrapped.getMinimumWidth();
    105     }
    106 
    107     @Override
    108     public int getMinimumHeight() {
    109         return wrapped.getMinimumHeight();
    110     }
    111 
    112     @Override
    113     public boolean getPadding(Rect padding) {
    114         return wrapped.getPadding(padding);
    115     }
    116 
    117     @Override
    118     public void invalidateSelf() {
    119         super.invalidateSelf();
    120         wrapped.invalidateSelf();
    121     }
    122 
    123     @Override
    124     public void unscheduleSelf(Runnable what) {
    125         super.unscheduleSelf(what);
    126         wrapped.unscheduleSelf(what);
    127     }
    128 
    129     @Override
    130     public void scheduleSelf(Runnable what, long when) {
    131         super.scheduleSelf(what, when);
    132         wrapped.scheduleSelf(what, when);
    133     }
    134 
    135     @Override
    136     public void draw(Canvas canvas) {
    137         wrapped.draw(canvas);
    138     }
    139 
    140     @Override
    141     public void setAlpha(int i) {
    142         wrapped.setAlpha(i);
    143     }
    144 
    145     @Override
    146     public void setColorFilter(ColorFilter colorFilter) {
    147         wrapped.setColorFilter(colorFilter);
    148     }
    149 
    150     @Override
    151     public int getOpacity() {
    152         return wrapped.getOpacity();
    153     }
    154 
    155     @Override
    156     public boolean isAnimated() {
    157         return wrapped.isAnimated();
    158     }
    159 
    160     @Override
    161     public void setLoopCount(int loopCount) {
    162         wrapped.setLoopCount(loopCount);
    163     }
    164 
    165     @Override
    166     public void start() {
    167         wrapped.start();
    168     }
    169 
    170     @Override
    171     public void stop() {
    172         wrapped.stop();
    173     }
    174 
    175     @Override
    176     public boolean isRunning() {
    177         return wrapped.isRunning();
    178     }
    179 }
    180