package com.lsjwzh.loadingeverywhere;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ProgressBar;

/**
 * Layout with a loading mask.
 * Created by lsjwzh on 14-8-9.
 */
public class LoadingLayout extends OverlayLayout {

    /**
     * create a LoadingLayout to wrap and replace the targetView.
     * Note: if you attachTo targetView on 'onCreate' method,targetView may be not layout complete.
     *
     * @param targetView
     * @return
     */
    public static LoadingLayout wrap(final View targetView){
        if(targetView==null){
            throw new IllegalArgumentException();
        }

        final LoadingLayout loadingLayout = new LoadingLayout(targetView.getContext());
        loadingLayout.attachTo(targetView);
        return loadingLayout;
    }

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

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

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


    public void showLoading(){
        showOverlay();
    }

    public void hideLoading(){
        hideOverlay();
    }

    public void setIsHideTargetViewWhenLoading(boolean isHideTargetViewWhenLoading){
        setIsHideTargetViewWhenOverlayShown(isHideTargetViewWhenLoading);
    }

    public boolean isLoadingMaskShown(){
        return isOverlayShown();
    }

    public View getLoadingMask(){
        return super.mOverlay;
    }

    /**
     * create loading mask
     * @return
     */
    @Override
    View createOverlayView() {
        LinearLayout ll = new LinearLayout(getContext());
        ll.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
        ll.setGravity(Gravity.CENTER);
        View progressBar = createProgressBar();
        ll.addView(progressBar);
        return ll;
    }

    protected View createProgressBar() {
        return new ProgressBar(getContext(),null,android.R.attr.progressBarStyleLarge);
    }
}

@@ -742,16 +742,403 @@
 tView)%7B%0A
+         return wrap(targetView,android.R.attr.progressBarStyleLarge);%0A    %7D%0A    /**%0A     * create a LoadingLayout to wrap and replace the targetView.%0A     * Note: if you attachTo targetView on 'onCreate' method,targetView may be not layout complete.%0A     *%0A     * @param targetView%0A     * @return%0A     */%0A    public static LoadingLayout wrap(final View targetView, final int defStyle)%7B%0A
         
@@ -1298,32 +1298,196 @@
 ew.getContext())
+%7B%0A            @Override%0A            protected View createProgressBar() %7B%0A                return new ProgressBar(getContext(),null,defStyle);%0A            %7D%0A        %7D
 ;%0A        loadin

enable to specify progressBarStyle