DialogUtils

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;

import com.cheletong.ToolUtils.StringUtils;

/**
 *
 * @Description:窗口对应的工具类
 */
public class DialogUtils {

    private static LoadingOneDialog oneDialog = null;

    private static TwoBtnAlertDialog alertDialogue = null;

    private static TipAlertDialogue tipDialogue=null;

    /**
     * 加载对话框
     * @param message
     */
    public final static void loading(Context context,String message){
        closeLoading();
        oneDialog = LoadingOneDialog.makeLoading(context,message,false,new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {

            }
        });
        oneDialog.show();
    }

    /**
     * 关闭对话框
     */
    public final static void closeLoading(){
        if (oneDialog != null) {
            oneDialog.dismiss ();
            oneDialog = null;
        }
    }

    /**
     * @Description 显示弹出的alert框
     * @param msg
     * @param context
     * @param leftBtnMsg
     * @param rightBtnMsg
     * @param windowType
     * @param callback
     */
    public static void showAlertDialog(String msg,Context context,String leftBtnMsg,String rightBtnMsg,int windowType,final AlertDialogueCallBack callback){

        closeAlertDialog ();

        alertDialogue = new TwoBtnAlertDialog(context,new TwoBtnAlertDialogCallbackAdapter() {

            @Override
            public void onSureBtnClicked(TwoBtnAlertDialog dialog){
                if (callback != null) {
                    callback.doCallBack ();
                }
            }

            @Override
            public void onCancelBtnClicked(TwoBtnAlertDialog dialog){

                if(callback!=null)
                {
                    callback.onCancalBtnClicked ();
                }
            }
        },windowType);
        alertDialogue.setMessage (msg);
        alertDialogue.getDialog ().setCanceledOnTouchOutside (false);
        if(!StringUtils.isEmpty (rightBtnMsg))
        {
            alertDialogue.setPositiveButton (StringUtils.trimNull (rightBtnMsg));
        }
        if(!StringUtils.isEmpty (leftBtnMsg))
        {
            alertDialogue.setNegativeButton (StringUtils.trimNull (leftBtnMsg));
        }
    }


    /**
     * 提示对话框
     *
     */
    public static void showAlertDialog(String msg,Context context,String leftBtnMsg,String rightBtnMsg,final AlertDialogueCallBack callback){
        closeAlertDialog ();
        alertDialogue = new TwoBtnAlertDialog (context,new TwoBtnAlertDialogCallbackAdapter () {
            @Override
            public void onSureBtnClicked(TwoBtnAlertDialog dialog){
                if (callback != null) {
                    callback.doCallBack ();
                }
            }

            @Override
            public void onCancelBtnClicked(TwoBtnAlertDialog dialog){
                if(callback!=null)
                {
                    callback.onCancalBtnClicked ();
                }
            }
        });
        alertDialogue.setMessage (msg);
        alertDialogue.getDialog ().setCanceledOnTouchOutside (false);
        if(!StringUtils.isEmpty (rightBtnMsg))
        {
            alertDialogue.setPositiveButton (StringUtils.trimNull (rightBtnMsg));
        }
        if(!StringUtils.isEmpty (leftBtnMsg))
        {
            alertDialogue.setNegativeButton (StringUtils.trimNull (leftBtnMsg));
        }
    }


    /**
     *
     *@Description: 关闭弹出框
     */
    public static void closeAlertDialog()
    {
        if (alertDialogue != null) {
            try {
                alertDialogue.dismiss ();
            } catch (Exception e) {}
            alertDialogue = null;
        }
    }

    /**
     * 提示对话框
     *
     */
    public static void showTipAlertDialog(Context context,String tipmsg,String btnmsg){
        closeTipAlertDialog ();
        tipDialogue = new TipAlertDialogue (context, tipmsg, btnmsg);
        tipDialogue.getDialog ().setCanceledOnTouchOutside (false);

    }

    /**
    *
    *@Description: 关闭弹出框
    */
   public static void closeTipAlertDialog()
   {
       if (tipDialogue != null) {
           try {
               tipDialogue.dismiss ();
           } catch (Exception e) {}
           tipDialogue = null;
       }
   }
}

你可能感兴趣的:(手机端)