|
@@ -292,7 +292,8 @@ public class ViewUtil {
|
|
|
return showMsgDialog(context, new DialogConfig().setMsg(msg).setTitle(title).setFinish(isFinish).setBtnLeftText("知道了"));
|
|
return showMsgDialog(context, new DialogConfig().setMsg(msg).setTitle(title).setFinish(isFinish).setBtnLeftText("知道了"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static AlertDialog showMsgDialog(final Context context, final DialogConfig dialogConfig) {
|
|
|
|
|
|
|
+ public static AlertDialog showMsgDialog(Context context, final DialogConfig dialogConfig) {
|
|
|
|
|
+ final Context mContext = context == null ? ActivityManager.getInstance().currentActivity() : context;
|
|
|
String title = dialogConfig.getTitle();
|
|
String title = dialogConfig.getTitle();
|
|
|
String msg = dialogConfig.getMsg();
|
|
String msg = dialogConfig.getMsg();
|
|
|
String msgMore = dialogConfig.getMsgMore();
|
|
String msgMore = dialogConfig.getMsgMore();
|
|
@@ -301,85 +302,107 @@ public class ViewUtil {
|
|
|
final View.OnClickListener btnLeftOnClickListener = dialogConfig.getBtnLeftOnClickListener();
|
|
final View.OnClickListener btnLeftOnClickListener = dialogConfig.getBtnLeftOnClickListener();
|
|
|
String btnRightText = dialogConfig.getBtnRightText();
|
|
String btnRightText = dialogConfig.getBtnRightText();
|
|
|
final View.OnClickListener btnRightOnClickListener = dialogConfig.getBtnRightOnClickListener();
|
|
final View.OnClickListener btnRightOnClickListener = dialogConfig.getBtnRightOnClickListener();
|
|
|
- View dialog_parent = View.inflate(context, R.layout.dialog_parent, null);
|
|
|
|
|
- final AlertDialog dialog = new AlertDialog.Builder(context, context instanceof Activity ? R.style.MyDialogActivityTheme : R.style.AppTheme_Dialog_Alert).setView(dialog_parent).create();
|
|
|
|
|
|
|
+ View dialog_parent = View.inflate(mContext, R.layout.dialog_parent, null);
|
|
|
|
|
+ final AlertDialog dialog = new AlertDialog.Builder(mContext, mContext instanceof Activity ? R.style.MyDialogActivityTheme : R.style.AppTheme_Dialog_Alert).setView(dialog_parent).create();
|
|
|
TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
|
|
TextView dialog_title = dialog_parent.findViewById(R.id.dialog_title);
|
|
|
View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
|
|
View dialog_close = dialog_parent.findViewById(R.id.dialog_close);
|
|
|
LinearLayout dialog_center_ll = dialog_parent.findViewById(R.id.dialog_center_ll);
|
|
LinearLayout dialog_center_ll = dialog_parent.findViewById(R.id.dialog_center_ll);
|
|
|
- View view = LayoutInflater.from(context).inflate(R.layout.x_msg_dialog, dialog_center_ll, true);
|
|
|
|
|
|
|
+ View view = LayoutInflater.from(mContext).inflate(dialogConfig.getLayoutId(), dialog_center_ll, true);
|
|
|
if (!TextUtils.isEmpty(title))
|
|
if (!TextUtils.isEmpty(title))
|
|
|
dialog_title.setText(title);
|
|
dialog_title.setText(title);
|
|
|
|
|
|
|
|
final TextView dialog_msg = view.findViewById(R.id.dialog_msg);
|
|
final TextView dialog_msg = view.findViewById(R.id.dialog_msg);
|
|
|
- dialog_msg.setText(msg);
|
|
|
|
|
- int msgGravity = dialogConfig.getMsgGravity();
|
|
|
|
|
- if(msgGravity != Gravity.NO_GRAVITY)
|
|
|
|
|
- dialog_msg.setGravity(msgGravity);
|
|
|
|
|
|
|
+ if(dialog_msg != null) {
|
|
|
|
|
+ dialog_msg.setText(msg);
|
|
|
|
|
+ int msgGravity = dialogConfig.getMsgGravity();
|
|
|
|
|
+ if (msgGravity != Gravity.NO_GRAVITY)
|
|
|
|
|
+ dialog_msg.setGravity(msgGravity);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ final WebView dialog_msg_wv = view.findViewById(R.id.dialog_msg_wv);
|
|
|
|
|
+ if(dialog_msg_wv != null) {
|
|
|
|
|
+ ViewUtil.loadDataWithBaseURL(dialog_msg_wv, msg);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
TextView dialog_msg_more = view.findViewById(R.id.dialog_msg_more);
|
|
TextView dialog_msg_more = view.findViewById(R.id.dialog_msg_more);
|
|
|
- if(TextUtils.isEmpty(msgMore)){
|
|
|
|
|
- dialog_msg_more.setVisibility(View.GONE);
|
|
|
|
|
- } else {
|
|
|
|
|
- dialog_msg_more.setVisibility(View.VISIBLE);
|
|
|
|
|
- dialog_msg_more.setText(msgMore);
|
|
|
|
|
|
|
+ if(dialog_msg_more != null) {
|
|
|
|
|
+ if (TextUtils.isEmpty(msgMore)) {
|
|
|
|
|
+ dialog_msg_more.setVisibility(View.GONE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dialog_msg_more.setVisibility(View.VISIBLE);
|
|
|
|
|
+ dialog_msg_more.setText(msgMore);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TextView dialog_tip = view.findViewById(R.id.dialog_tip);
|
|
TextView dialog_tip = view.findViewById(R.id.dialog_tip);
|
|
|
- if(TextUtils.isEmpty(tip)){
|
|
|
|
|
- dialog_tip.setVisibility(View.GONE);
|
|
|
|
|
- } else {
|
|
|
|
|
- dialog_tip.setVisibility(View.VISIBLE);
|
|
|
|
|
- dialog_tip.setText(tip);
|
|
|
|
|
|
|
+ if(dialog_tip != null) {
|
|
|
|
|
+ if (TextUtils.isEmpty(tip)) {
|
|
|
|
|
+ dialog_tip.setVisibility(View.GONE);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ dialog_tip.setVisibility(View.VISIBLE);
|
|
|
|
|
+ dialog_tip.setText(tip);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
TextView dialog_btn_left = view.findViewById(R.id.dialog_btn_left);
|
|
TextView dialog_btn_left = view.findViewById(R.id.dialog_btn_left);
|
|
|
boolean isLeftBtnShow = btnLeftText != null || btnLeftOnClickListener != null;
|
|
boolean isLeftBtnShow = btnLeftText != null || btnLeftOnClickListener != null;
|
|
|
- dialog_btn_left.setVisibility(isLeftBtnShow ? View.VISIBLE : View.GONE);
|
|
|
|
|
- if (!TextUtils.isEmpty(btnLeftText))
|
|
|
|
|
- dialog_btn_left.setText(btnLeftText);
|
|
|
|
|
- dialog_btn_left.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View v) {
|
|
|
|
|
- if (btnLeftOnClickListener != null) {
|
|
|
|
|
- btnLeftOnClickListener.onClick(v);
|
|
|
|
|
|
|
+ if(dialog_btn_left != null) {
|
|
|
|
|
+ dialog_btn_left.setVisibility(isLeftBtnShow ? View.VISIBLE : View.GONE);
|
|
|
|
|
+ if (!TextUtils.isEmpty(btnLeftText))
|
|
|
|
|
+ dialog_btn_left.setText(btnLeftText);
|
|
|
|
|
+ dialog_btn_left.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ if (btnLeftOnClickListener != null) {
|
|
|
|
|
+ btnLeftOnClickListener.onClick(v);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!dialogConfig.isBtnLeftNotDissDialog())
|
|
|
|
|
+ dialog.dismiss();
|
|
|
}
|
|
}
|
|
|
- dialog.dismiss();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
TextView dialog_btn_right = view.findViewById(R.id.dialog_btn_right);
|
|
TextView dialog_btn_right = view.findViewById(R.id.dialog_btn_right);
|
|
|
boolean isRigthBtnShow = btnRightText != null || btnRightOnClickListener != null;
|
|
boolean isRigthBtnShow = btnRightText != null || btnRightOnClickListener != null;
|
|
|
- dialog_btn_right.setVisibility(isRigthBtnShow ? View.VISIBLE : View.GONE);
|
|
|
|
|
- if (!TextUtils.isEmpty(btnRightText))
|
|
|
|
|
- dialog_btn_right.setText(btnRightText);
|
|
|
|
|
- dialog_btn_right.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onClick(View v) {
|
|
|
|
|
- if (btnRightOnClickListener != null) {
|
|
|
|
|
- btnRightOnClickListener.onClick(v);
|
|
|
|
|
- }
|
|
|
|
|
- dialog.dismiss();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- View dialog_btn_center = view.findViewById(R.id.dialog_btn_center);
|
|
|
|
|
- dialog_btn_center.setVisibility(isLeftBtnShow && isRigthBtnShow ? View.VISIBLE : View.GONE);
|
|
|
|
|
-
|
|
|
|
|
- if(dialogConfig.isCancelable())//
|
|
|
|
|
- dialog_close.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
|
|
+ if(dialog_btn_right != null) {
|
|
|
|
|
+ dialog_btn_right.setVisibility(isRigthBtnShow ? View.VISIBLE : View.GONE);
|
|
|
|
|
+ if (!TextUtils.isEmpty(btnRightText))
|
|
|
|
|
+ dialog_btn_right.setText(btnRightText);
|
|
|
|
|
+ dialog_btn_right.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
|
|
|
+ if (btnRightOnClickListener != null) {
|
|
|
|
|
+ btnRightOnClickListener.onClick(v);
|
|
|
|
|
+ }
|
|
|
dialog.dismiss();
|
|
dialog.dismiss();
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
- else
|
|
|
|
|
- dialog_close.setVisibility(View.GONE);
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ View dialog_btn_center = view.findViewById(R.id.dialog_btn_center);
|
|
|
|
|
+ if(dialog_btn_center != null) {
|
|
|
|
|
+ dialog_btn_center.setVisibility(isLeftBtnShow && isRigthBtnShow ? View.VISIBLE : View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(dialog_close != null) {
|
|
|
|
|
+ if (dialogConfig.isCancelable())//
|
|
|
|
|
+ dialog_close.setOnClickListener(new View.OnClickListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onClick(View v) {
|
|
|
|
|
+ dialog.dismiss();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ else
|
|
|
|
|
+ dialog_close.setVisibility(View.GONE);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
if(dialogConfig.isFinish()) {
|
|
if(dialogConfig.isFinish()) {
|
|
|
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onDismiss(DialogInterface dialog) {
|
|
public void onDismiss(DialogInterface dialog) {
|
|
|
try {
|
|
try {
|
|
|
- if (context instanceof Activity) {
|
|
|
|
|
- ((Activity) context).finish();
|
|
|
|
|
|
|
+ if (mContext instanceof Activity) {
|
|
|
|
|
+ ((Activity) mContext).finish();
|
|
|
}
|
|
}
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -387,7 +410,7 @@ public class ViewUtil {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- if(!(context instanceof Activity) && dialog.getWindow() != null) {
|
|
|
|
|
|
|
+ if(!(mContext instanceof Activity) && dialog.getWindow() != null) {
|
|
|
dialog.getWindow().setType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_TOAST);
|
|
dialog.getWindow().setType(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_TOAST);
|
|
|
}
|
|
}
|
|
|
if(!dialogConfig.isCancelable())
|
|
if(!dialogConfig.isCancelable())
|