package com.lsjwzh.loadingeverywhere;

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

/**
 * Created by panwenye on 14-8-11.
 */
public class ProgressLayout extends LoadingLayout {
    /**
     * create a ProgressLayout 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 ProgressLayout wrap(final View targetView){
        if(targetView==null){
            throw new IllegalArgumentException();
        }

        final ProgressLayout progressLayout = new ProgressLayout(targetView.getContext());
        progressLayout.attachTo(targetView);
        return progressLayout;
    }
    protected ProgressBar mProgressBar;
    protected int mProgress = -1;
    protected int mMax = -1;



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

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

    public ProgressLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    
    public void setMax(int max){
        mMax = max;
        if(mProgressBar!=null){
            mProgressBar.setMax(max);
        }
    }
    public void setProgress(int progress){
        mProgress = progress;
        if(mProgressBar!=null){
            mProgressBar.setProgress(progress);
        }
    }

    /**
     * create progressbar
     * @return
     */
    @Override
    protected View createProgressBar() {
        mProgressBar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleHorizontal);
        if(mProgress>=0){
            mProgressBar.setProgress(mProgress);
        }
        if(mMax>=0){
            mProgressBar.setMax(mMax);
        }
        return mProgressBar;
    }

}

@@ -907,24 +907,784 @@
 yout;%0A    %7D%0A
+    public static ProgressLayout wrap(final View targetView, final int defStyle)%7B%0A        if(targetView==null)%7B%0A            throw new IllegalArgumentException();%0A        %7D%0A%0A        final ProgressLayout progressLayout = new ProgressLayout(targetView.getContext())%7B%0A            @Override%0A            protected View createProgressBar() %7B%0A                mProgressBar = new ProgressBar(getContext(), null, defStyle);%0A                if(mProgress%3E=0)%7B%0A                    mProgressBar.setProgress(mProgress);%0A                %7D%0A                if(mMax%3E=0)%7B%0A                    mProgressBar.setMax(mMax);%0A                %7D%0A                return mProgressBar;%0A            %7D%0A        %7D;%0A        progressLayout.attachTo(targetView);%0A        return progressLayout;%0A    %7D%0A
     protecte

enable to specify progressBarStyle for ProgressLayout