package com.tofly.ghrq_route.common.ui.view;

import android.app.ProgressDialog;
import android.content.Context;

/**
 * 组合自定义控件：带进度条
 * Created by zombiexq on 2016/7/5.
 */
public class CustomView {

    private Context context;
    private static ProgressDialog percentProgress = null;

    public CustomView(Context context){
        this.context = context;
    }


    /**
     * 百分比进度条开始显示
     *
     * @param title
     * @param max
     */
    public void ProgressPercentStart(String title, int max) {
        if (percentProgress == null) {
            percentProgress = new ProgressDialog(context);
            // 设置进度条风格，风格为圆形，旋转的
            percentProgress.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            // 设置ProgressDialog 标题
            percentProgress.setTitle(title);
            // 设置ProgressDialog提示信息
            // percentProgress.setMessage(title);
            // 设置ProgressDialog 的进度条是否不明确 false 就是不设置为不明确
            percentProgress.setIndeterminate(false);

            percentProgress.setMax(max);
            // 设置ProgressDialog 进度条进度
            // progressDialog.setProgress(100);
            // 设置ProgressDialog是否可以按退回键取消
            percentProgress.setCancelable(false);
        }
        percentProgress.show();
    }

    /**
     * 百分比进度条位置设置
     *
     * @param percent

     */
    public void ProgressPercent(int percent) {
        if (percentProgress != null) {
            percentProgress.setProgress(percent);
        }
    }

    /**
     * 百分比进度条停止
     */
    public void ProgressPercentStop() {
        if (percentProgress != null) {
            percentProgress.cancel();
            percentProgress = null;
        }
    }
}
