package com.hanju.video.app.ui.dialog;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.TextView;
|
|
import com.hanju.lib.library.util.common.StringUtils;
|
import com.hanju.video.app.R;
|
|
|
/**
|
* 用户协议弹框
|
*/
|
public class LoadingDialogUtil {
|
|
private static Dialog pd;
|
|
public static void show(Context context) {
|
show(context, "", false);
|
}
|
|
public static void show(Context context, String msg, boolean cancelable) {
|
try {
|
dismiss();
|
//拿到dialog
|
pd = getLoadingDialog(context, msg);
|
//设置点击外围是否消失
|
pd.setCancelable(cancelable);
|
pd.show();
|
} catch (Exception e) {
|
}
|
}
|
|
//这里的加载效果自己随意定义
|
public static Dialog getLoadingDialog(Context context, String msg) {
|
Dialog loading_dialog = new Dialog(context, R.style.Dialog);
|
View view = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
|
TextView tv_msg = view.findViewById(R.id.tv_msg);
|
if (StringUtils.isEmpty(msg)) {
|
tv_msg.setVisibility(View.GONE);
|
} else {
|
tv_msg.setText(msg);
|
tv_msg.setVisibility(View.VISIBLE);
|
}
|
loading_dialog.setContentView(view);
|
loading_dialog.getWindow().setBackgroundDrawableResource(R.color.transparent);
|
loading_dialog.setCancelable(false);
|
return loading_dialog;
|
}
|
|
|
//在这里直接做了判断,大胆的放心的使用,保证不会出现空指针
|
public static void dismiss() {
|
try {
|
if (pd != null && pd.isShowing()) {
|
pd.dismiss();
|
}
|
pd = null;
|
} catch (Exception e) {
|
// TODO: handle exception
|
} finally {
|
pd = null;
|
}
|
}
|
|
|
public static boolean isShowing() {
|
try {
|
if (pd != null) {
|
return pd.isShowing();
|
}
|
} catch (Exception e) {
|
// TODO: handle exception
|
}
|
return false;
|
}
|
|
/**
|
* 设置dialog点击外部是否可以消失
|
*/
|
public static void setCanceledOnTouchOutside(boolean b) {
|
try {
|
if (pd != null && pd.isShowing()) {
|
pd.setCanceledOnTouchOutside(b);
|
}
|
} catch (Exception e) {
|
// TODO: handle exception
|
}
|
|
}
|
|
|
}
|