package cc.cubone.turbo.widget;

import android.content.Context;
import android.graphics.Matrix;
import android.util.AttributeSet;

import pl.droidsonroids.gif.GifImageView;

/**
 * @see <a href="https://gist.github.com/arriolac/3843346">TopCropImageView.java</a>
 */
public class TopCropGifImageView extends GifImageView {

    public TopCropGifImageView(Context context) {
        super(context);
    }

    public TopCropGifImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TopCropGifImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public TopCropGifImageView(Context context, AttributeSet attrs, int defStyle, int defStyleRes) {
        super(context, attrs, defStyle, defStyleRes);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        recomputeImgMatrix();
    }

    @Override
    protected boolean setFrame(int l, int t, int r, int b) {
        recomputeImgMatrix();
        return super.setFrame(l, t, r, b);
    }

    private void recomputeImgMatrix() {
        final Matrix matrix = getImageMatrix();

        float scale;
        final int viewWidth = getWidth() - getPaddingLeft() - getPaddingRight();
        final int viewHeight = getHeight() - getPaddingTop() - getPaddingBottom();
        final int drawableWidth = getDrawable().getIntrinsicWidth();
        final int drawableHeight = getDrawable().getIntrinsicHeight();

        if (drawableWidth * viewHeight > drawableHeight * viewWidth) {
            scale = (float) viewHeight / (float) drawableHeight;
        } else {
            scale = (float) viewWidth / (float) drawableWidth;
        }

        matrix.setScale(scale, scale);
        setImageMatrix(matrix);
    }

}

@@ -22,24 +22,61 @@
 bo.widget;%0A%0A
+import android.annotation.TargetApi;%0A
 import andro
@@ -127,16 +127,41 @@
 Matrix;%0A
+import android.os.Build;%0A
 import a
@@ -454,16 +454,56 @@
 ntext);%0A
+        setScaleType(ScaleType.MATRIX);%0A
     %7D%0A%0A 
@@ -598,24 +598,64 @@
 xt, attrs);%0A
+        setScaleType(ScaleType.MATRIX);%0A
     %7D%0A%0A    p
@@ -774,26 +774,111 @@
 Style);%0A    
-%7D%0A
+    setScaleType(ScaleType.MATRIX);%0A    %7D%0A%0A    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
 %0A    public 
@@ -1017,24 +1017,64 @@
 fStyleRes);%0A
+        setScaleType(ScaleType.MATRIX);%0A
     %7D%0A%0A    @
@@ -1458,24 +1458,68 @@
 gMatrix() %7B%0A
+        if (getDrawable() == null) return;%0A%0A
         fina

fix null drawable