package com.dayu.qiheonlinelibrary.net.progress;
|
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.os.Handler;
|
import android.os.Message;
|
|
|
/**
|
* Created by qwy on 16/3/10.
|
* 展示进度对话框
|
*/
|
public class ProgressDialogHandler extends Handler {
|
|
public static final int SHOW_PROGRESS_DIALOG = 1;
|
public static final int DISMISS_PROGRESS_DIALOG = 2;
|
|
private NetLoadingDialog pd;
|
|
private Context context;
|
private boolean cancelable;
|
private ProgressCancelListener mProgressCancelListener;
|
|
|
public ProgressDialogHandler(Context context, ProgressCancelListener mProgressCancelListener,
|
boolean cancelable) {
|
super();
|
this.context = context;
|
this.mProgressCancelListener = mProgressCancelListener;
|
this.cancelable = cancelable;
|
}
|
|
private void initProgressDialog() {
|
try {
|
if (pd == null) {
|
pd = new NetLoadingDialog(context);
|
pd.setCancelable(cancelable);
|
|
if (cancelable) {
|
pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
@Override
|
public void onCancel(DialogInterface dialogInterface) {
|
if (mProgressCancelListener != null)
|
mProgressCancelListener.onCancelProgress();
|
}
|
});
|
}
|
|
if (!pd.isShowing()) {
|
pd.startAnim();
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
private void dismissProgressDialog() {
|
if (pd != null) {
|
try {
|
if (pd.isShowing()) {
|
pd.dismiss();
|
}
|
pd.stopAnim();
|
pd = null;
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
@Override
|
public void handleMessage(Message msg) {
|
switch (msg.what) {
|
case SHOW_PROGRESS_DIALOG:
|
initProgressDialog();
|
break;
|
case DISMISS_PROGRESS_DIALOG:
|
dismissProgressDialog();
|
break;
|
}
|
}
|
|
}
|