package me.xiaopan.sketchsample.widget;

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

import me.xiaopan.sketch.SketchImageView;
import me.xiaopan.sketchsample.R;
import me.xiaopan.sketchsample.util.Settings;

public class MyImageView extends SketchImageView {
    private Settings settings;
    private boolean autoApplyGlobalAttr = true;

    public MyImageView(Context context) {
        super(context);
        onInit(context);
    }

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

    private void onInit(Context context){
        settings = Settings.with(context);
        if(!isInEditMode()){
            setShowGifFlag(R.drawable.ic_gif);
        }
    }

    @Override
    public void onDisplay() {
        super.onDisplay();

        if(autoApplyGlobalAttr){
            setShowPressedStatus(settings.isShowPressedStatus());
            setShowImageFrom(settings.isShowImageFromFlag());
            setShowDownloadProgress(settings.isShowImageDownloadProgress());
            setClickRetryOnPauseDownload(settings.isClickDisplayOnPauseDownload());
            setClickRetryOnFailed(settings.isClickDisplayOnFailed());
        }
    }

    public void setAutoApplyGlobalAttr(boolean autoApplyGlobalAttr){
        this.autoApplyGlobalAttr = autoApplyGlobalAttr;
    }
}

@@ -143,16 +143,60 @@
 geView;%0A
+import me.xiaopan.sketch.request.UriScheme;%0A
 import m
@@ -844,39 +844,30 @@
 lay(
-) %7B%0A        super.onDisplay();%0A
+UriScheme uriScheme) %7B
 %0A   
@@ -1256,32 +1256,69 @@
 ed());%0A        %7D
+%0A%0A        super.onDisplay(uriScheme);
 %0A    %7D%0A%0A    publ

update sample