959 lines
38 KiB
Java
959 lines
38 KiB
Java
package com.gh.common.util;
|
||
|
||
import android.app.Activity;
|
||
import android.app.Dialog;
|
||
import android.content.Context;
|
||
import android.content.DialogInterface;
|
||
import android.content.Intent;
|
||
import android.graphics.Color;
|
||
import android.text.Html;
|
||
import android.text.SpannableStringBuilder;
|
||
import android.text.Spanned;
|
||
import android.text.TextPaint;
|
||
import android.text.TextUtils;
|
||
import android.text.method.LinkMovementMethod;
|
||
import android.text.style.ClickableSpan;
|
||
import android.view.Gravity;
|
||
import android.view.KeyEvent;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.view.Window;
|
||
import android.widget.Button;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.TextView;
|
||
|
||
import com.gh.common.view.DrawableView;
|
||
import com.gh.gamecenter.AboutActivity;
|
||
import com.gh.gamecenter.R;
|
||
import com.gh.gamecenter.WebActivity;
|
||
import com.lightgame.utils.AppManager;
|
||
import com.lightgame.utils.Utils;
|
||
|
||
import java.util.List;
|
||
import java.util.concurrent.atomic.AtomicBoolean;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.appcompat.app.AlertDialog;
|
||
import androidx.core.content.ContextCompat;
|
||
|
||
public class DialogUtils {
|
||
|
||
public static Dialog showWaitDialog(Context context, String msg) {
|
||
context = checkDialogContext(context);
|
||
|
||
Dialog dialog = new Dialog(context);
|
||
View view = View.inflate(context, R.layout.set_wait_dialog, null);
|
||
TextView message = view.findViewById(R.id.set_wait_message);
|
||
message.setText(msg);
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(view);
|
||
dialog.setCanceledOnTouchOutside(false);
|
||
dialog.show();
|
||
return dialog;
|
||
}
|
||
|
||
|
||
public static void showInstallHintDialog(Context context, final ConfirmListener cmListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context);
|
||
|
||
View view = View.inflate(context, R.layout.dialog_install_hint, null);
|
||
|
||
// 标题
|
||
TextView alertdialog_title = view.findViewById(R.id.installhint_title);
|
||
alertdialog_title.setText("重要提示");
|
||
Spanned content = Html.fromHtml("如果您使用的是" + "<font color=\"#ff0000\">华为</font>" + "或" +
|
||
"<font color=\"#ff0000\">OPPO</font>" + "手机,安装游戏时请选择“" +
|
||
"<font color=\"#ff0000\">继续安装</font>" +
|
||
"”(记住不要选择“官方推荐”或“软件商店安装”)");
|
||
// 内容
|
||
TextView alertdialog_content = view.findViewById(R.id.installhint_content);
|
||
alertdialog_content.setText(content);
|
||
|
||
// 确定按钮
|
||
TextView installhint_confirm = view.findViewById(R.id.installhint_confirm);
|
||
installhint_confirm.setText("知道了");
|
||
|
||
final ImageView installhint_unselect = view.findViewById(R.id.installhint_unselect);
|
||
final ImageView installhint_select = view.findViewById(R.id.installhint_select);
|
||
|
||
LinearLayout installhint_unselect_ll = view.findViewById(R.id.installhint_unselect_ll);
|
||
|
||
installhint_unselect_ll.setOnClickListener(v -> {
|
||
if (installhint_unselect.getVisibility() == View.GONE) {
|
||
installhint_unselect.setVisibility(View.VISIBLE);
|
||
installhint_select.setVisibility(View.GONE);
|
||
} else {
|
||
installhint_unselect.setVisibility(View.GONE);
|
||
installhint_select.setVisibility(View.VISIBLE);
|
||
}
|
||
});
|
||
|
||
installhint_confirm.setOnClickListener(v -> {
|
||
dialog.dismiss();
|
||
if (installhint_select.getVisibility() == View.VISIBLE) {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
}
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(view);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showHintDialog(Context context, String title, CharSequence msg, String confirm) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context);
|
||
|
||
View view = View.inflate(context, R.layout.common_hintdialog, null);
|
||
|
||
TextView hintdialog_title = view.findViewById(R.id.tv_dialog_hint_title);
|
||
hintdialog_title.setText(title);
|
||
|
||
// 内容
|
||
TextView hintdialog_content = view.findViewById(R.id.tv_dialog_hint_content);
|
||
hintdialog_content.setText(msg);
|
||
|
||
TextView hintdialog_confirm = view.findViewById(R.id.tv_dialog_hint_confirm);
|
||
|
||
hintdialog_confirm.setText(confirm);
|
||
|
||
hintdialog_confirm.setOnClickListener(v -> dialog.cancel());
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(view);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showWarningDialog(Context context, String title, CharSequence msg, final ConfirmListener listener) {
|
||
if (!(context instanceof Activity)) {
|
||
return;
|
||
}
|
||
showWarningDialog(context, title, msg, "取消", "确定", listener, null);
|
||
}
|
||
|
||
public static void showWarningDialog(Context context, String title, CharSequence msg, String cancel, String confirm,
|
||
final ConfirmListener cmListener, final CancelListener clListener) {
|
||
|
||
showAlertDialog(context, title, msg, confirm, cancel, cmListener, clListener);
|
||
}
|
||
|
||
// 网络劫持时 打开QQ客户端,创建临时会话
|
||
public static void showQqSessionDialog(final Context context, final String qq) {
|
||
showWarningDialog(context, "警告", "您当前网络环境异常,下载地址可能被运营商恶意替换(网络劫持)" +
|
||
",如多次下载失败,请联系客服获取正确的下载地址(客服QQ:" + qq + ")"
|
||
, "取消", "前往QQ", () -> DirectUtils.directToQqConversation(context, qq), null);
|
||
}
|
||
|
||
public static void checkDownload(Context context, String size, CheckDownloadCallBack callBack) {
|
||
if (!NetworkUtils.isNetworkConnected(context)) {
|
||
showNoConnectionDownloadDialog(context, null,
|
||
() -> callBack.onResponse(true));
|
||
} else if (NetworkUtils.isWifiConnected(context) || filter4GorSize(context, size)) {
|
||
callBack.onResponse(false);
|
||
} else {
|
||
MtaHelper.onEvent("移动网络下载", NetworkUtils.getMobileNetworkType(context), "出现弹窗提示");
|
||
showDownloadDialog(context,
|
||
() -> {
|
||
callBack.onResponse(false);
|
||
MtaHelper.onEvent("移动网络下载", NetworkUtils.getMobileNetworkType(context), "立即下载");
|
||
},
|
||
() -> {
|
||
callBack.onResponse(true);
|
||
MtaHelper.onEvent("移动网络下载", NetworkUtils.getMobileNetworkType(context), "连上WiFi后自动下载");
|
||
});
|
||
}
|
||
}
|
||
|
||
private static boolean filter4GorSize(Context context, String size) {
|
||
try {
|
||
if (TextUtils.isEmpty(size)) {
|
||
return false;
|
||
}
|
||
String mb = size.toUpperCase().replaceAll("MB", "").trim();
|
||
Float i = Float.valueOf(mb);
|
||
if (NetworkUtils.isWifiOr4GConnected(context) && i <= 50) {
|
||
Utils.toast(context, "当前使用移动流量下载");
|
||
return true;
|
||
}
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
return false;
|
||
}
|
||
|
||
public static void checkResumeDownload(Context context, CheckDownloadCallBack callBack) {
|
||
if (!NetworkUtils.isNetworkConnected(context)) {
|
||
showNoConnectionDownloadDialog(context, null, () -> callBack.onResponse(true));
|
||
} else if (NetworkUtils.isWifiConnected(context)) {
|
||
callBack.onResponse(false);
|
||
} else {
|
||
showResumeDownloadDialog(context, () -> {
|
||
callBack.onResponse(false);
|
||
}, () -> {
|
||
callBack.onResponse(true);
|
||
});
|
||
}
|
||
}
|
||
|
||
public static void showNoConnectionDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||
showWarningDialog(context, "下载提示", "网络异常,请检查手机网络状态", "连上WiFi后自动下载", "关闭", listener, cancelListener);
|
||
}
|
||
|
||
public static void showDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||
showWarningDialog(context, "下载提示", "当前正在使用移动网络,立即下载会消耗手机流量", "连上WiFi后自动下载", "立即下载", listener, cancelListener);
|
||
}
|
||
|
||
public static void showResumeDownloadDialog(Context context, ConfirmListener listener, CancelListener cancelListener) {
|
||
showWarningDialog(context, "下载提示", "当前正在使用移动网络,继续下载会消耗手机流量", "连上WiFi后自动下载", "继续下载", listener, cancelListener);
|
||
}
|
||
|
||
|
||
public static void showDownloadDialog(Context context, ConfirmListener listener) {
|
||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", listener);
|
||
}
|
||
|
||
public static void showCancelDialog(Context context, final ConfirmListener listener, CancelListener cancelListener) {
|
||
Spanned content = Html.fromHtml(context.getString(R.string.cancel_concern_dialog));
|
||
showCancelListenerDialog(context, "取消关注", content, "确定取消", "暂不取消", listener, cancelListener);
|
||
}
|
||
|
||
public static void showPluginDialog(Context context, final ConfirmListener listener) {
|
||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||
+ "<font color=\"#ff0000\">安装插件版本</font>");
|
||
showWarningDialog(context, "插件化安装", spanned, listener);
|
||
}
|
||
|
||
/**
|
||
* Material Design 风格弹窗
|
||
*
|
||
* @param context
|
||
* @param title 标题
|
||
* @param message 内容
|
||
* @param positive 确认按钮文本
|
||
* @param negative 取消按钮文本
|
||
* @param cmListener 确认按钮监听
|
||
* @param clListener 取消按钮监听
|
||
*/
|
||
public static Dialog showAlertDialog(Context context, String title, CharSequence message
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
if (message.toString().contains("红包奖励")) {//将红包奖励四个字标红
|
||
String str = message.toString().substring(0, message.toString().indexOf("红包奖励")) + "<font color='#FF0000'>红包奖励</font>";
|
||
contentTv.setText(Html.fromHtml(str));
|
||
} else {
|
||
contentTv.setText(message);
|
||
}
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
return dialog;
|
||
}
|
||
|
||
public static Dialog showAlertDialog(Context context, String title, Spanned message
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
contentTv.setText(message);
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
return dialog;
|
||
}
|
||
|
||
public static Dialog showDialogWithHtmlContent(Context context, String title, String content
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
contentTv.setText(Html.fromHtml(content));
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
return dialog;
|
||
}
|
||
|
||
/**
|
||
* 取消按钮灰色
|
||
*
|
||
* @param context
|
||
* @param title
|
||
* @param message
|
||
* @param positive
|
||
* @param negative
|
||
* @param cmListener
|
||
*/
|
||
|
||
public static void showCancelAlertDialog(Context context, String title, CharSequence message
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
|
||
contentTv.setText(message);
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
negativeTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
}
|
||
|
||
/**
|
||
* 点击外部退出和取消监听绑定
|
||
*/
|
||
public static void showCancelListenerDialog(Context context, String title, CharSequence message
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
|
||
contentTv.setText(message);
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
//negativeTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
}
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.setOnCancelListener(dialogInterface -> {
|
||
if (clListener != null)
|
||
clListener.onCancel();
|
||
});
|
||
dialog.show();
|
||
|
||
|
||
}
|
||
|
||
|
||
/**
|
||
* 权限弹窗
|
||
* 只能在弹窗内取消
|
||
*/
|
||
public static void showPermissionDialog(Context context, String title, CharSequence message
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
|
||
contentTv.setText(message);
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
negativeTv.setTextColor(ContextCompat.getColor(context, R.color.hint));
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.setCancelable(false);
|
||
dialog.show();
|
||
|
||
}
|
||
|
||
/**
|
||
* 只能在弹窗内取消
|
||
*/
|
||
public static void showForceDialog(Context context, String title, CharSequence message
|
||
, String positive, String negative, final ConfirmListener cmListener, final CancelListener clListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
|
||
contentTv.setText(message);
|
||
titleTv.setText(title);
|
||
negativeTv.setText(negative);
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.setCancelable(false);
|
||
dialog.show();
|
||
}
|
||
|
||
/**
|
||
* 特殊:验证手机号码
|
||
*/
|
||
|
||
public static void checkPhoneNumDialog(Context context, CharSequence message, final ConfirmListener cmListener) {
|
||
String s = message.toString();
|
||
String sub1 = s.substring(0, 3);
|
||
String sub2 = s.substring(3, 7);
|
||
String sub3 = s.substring(7, 11);
|
||
String phoneNum = StringUtils.buildString(sub1, " - ", sub2, " - ", sub3);
|
||
|
||
AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.GhAlertDialog)
|
||
.setTitle("请确定手机号:")
|
||
.setMessage(phoneNum)
|
||
.setPositiveButton("确认", (dialog, which) -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
})
|
||
.setNegativeButton("取消", null)
|
||
.create();
|
||
alertDialog.show();
|
||
|
||
TextView mesage = (TextView) alertDialog.findViewById(android.R.id.message);
|
||
Button positiveBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_POSITIVE);
|
||
Button negativeBtn = alertDialog.getButton(android.app.AlertDialog.BUTTON_NEGATIVE);
|
||
|
||
positiveBtn.setTextSize(13);
|
||
positiveBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||
negativeBtn.setTextSize(13);
|
||
negativeBtn.setTextColor(ContextCompat.getColor(context, R.color.theme));
|
||
if (mesage != null) {
|
||
mesage.setGravity(Gravity.CENTER);
|
||
mesage.setTextSize(24);
|
||
mesage.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||
TextPaint tp = mesage.getPaint();
|
||
tp.setFakeBoldText(true);
|
||
}
|
||
|
||
}
|
||
|
||
public static void showSignDialog(Context context, String title, CharSequence message, CharSequence message2
|
||
, String positive, final ConfirmListener cmListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_sign, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
TextView content2Tv = contentView.findViewById(R.id.dialog_content2);
|
||
|
||
contentTv.setText(Html.fromHtml(message.toString()));
|
||
content2Tv.setText(Html.fromHtml(message2.toString()));
|
||
titleTv.setText(title);
|
||
positiveTv.setText(positive);
|
||
|
||
negativeTv.setOnClickListener(view -> dialog.dismiss());
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showLowVersionDialog(Context context) {
|
||
final Context activityContext = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(activityContext, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(activityContext).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView negativeTv = contentView.findViewById(R.id.dialog_negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
|
||
contentTv.setText("链接超出范围,请检查升级至最新版本的光环助手");
|
||
titleTv.setText("提示");
|
||
negativeTv.setText("关闭");
|
||
positiveTv.setText("检查升级");
|
||
|
||
negativeTv.setOnClickListener(view -> dialog.dismiss());
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
activityContext.startActivity(AboutActivity.getIntent(activityContext, true));
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showLowSystemVersionDialog(Context context) {
|
||
final Context activityContext = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(activityContext, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(activityContext).inflate(R.layout.dialog_alert, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
|
||
titleTv.setText("提示");
|
||
contentTv.setText("抱歉,您当前系统版本过低,暂不支持视频功能");
|
||
positiveTv.setText("我知道了");
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showListDialog(Context context,
|
||
List<String> selectionList,
|
||
DialogInterface.OnClickListener onClickListener) {
|
||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||
|
||
String[] selectionArray = new String[selectionList.size()];
|
||
selectionArray = selectionList.toArray(selectionArray);
|
||
builder.setItems(selectionArray, onClickListener);
|
||
AlertDialog dialog = builder.create();
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.show();
|
||
}
|
||
|
||
/**
|
||
* @param options 供以显示的选项
|
||
* @param disabledOptions 显示为灰色的选项(是 options 的子集)
|
||
*/
|
||
public static void showListDialog(Context context,
|
||
List<String> options,
|
||
List<String> disabledOptions,
|
||
OptionCallback callback) {
|
||
context = checkDialogContext(context);
|
||
|
||
Dialog dialog = new Dialog(context);
|
||
|
||
LinearLayout container = new LinearLayout(context);
|
||
container.setOrientation(LinearLayout.VERTICAL);
|
||
container.setBackgroundColor(Color.WHITE);
|
||
container.setPadding(0, DisplayUtils.dip2px(context, 12f), 0, DisplayUtils.dip2px(context, 12f));
|
||
|
||
for (String option : options) {
|
||
TextView reportTv = new TextView(context);
|
||
reportTv.setText(option);
|
||
reportTv.setTextSize(17f);
|
||
if (disabledOptions != null && disabledOptions.contains(option)) {
|
||
reportTv.setTextColor(ContextCompat.getColor(context, R.color.btn_gray));
|
||
} else {
|
||
reportTv.setTextColor(ContextCompat.getColor(context, R.color.title));
|
||
reportTv.setBackgroundResource(R.drawable.textview_white_style);
|
||
}
|
||
int widthPixels = context.getResources().getDisplayMetrics().widthPixels;
|
||
reportTv.setLayoutParams(new LinearLayout.LayoutParams(widthPixels * 9 / 10,
|
||
LinearLayout.LayoutParams.WRAP_CONTENT));
|
||
reportTv.setPadding(DisplayUtils.dip2px(context, 20f), DisplayUtils.dip2px(context, 12f),
|
||
0, DisplayUtils.dip2px(context, 12f));
|
||
container.addView(reportTv);
|
||
|
||
reportTv.setOnClickListener(v -> {
|
||
dialog.cancel();
|
||
callback.onClicked(reportTv.getText().toString());
|
||
});
|
||
}
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(container);
|
||
dialog.show();
|
||
}
|
||
|
||
|
||
/**
|
||
* 特殊:目前只在提交问题错误返回时弹出
|
||
*/
|
||
public static Dialog showCommunityDialog(Context context,
|
||
String title,
|
||
String contentTitle,
|
||
String contentDes,
|
||
String negative,
|
||
String positive,
|
||
final CancelListener clListener,
|
||
final ConfirmListener cmListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_community, null);
|
||
View contentContainer = contentView.findViewById(R.id.content_container);
|
||
TextView titleTv = contentView.findViewById(R.id.title);
|
||
TextView contentTitleTv = contentView.findViewById(R.id.content_title);
|
||
TextView contentDesTv = contentView.findViewById(R.id.content_des);
|
||
TextView negativeTv = contentView.findViewById(R.id.negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.positive);
|
||
|
||
titleTv.setText(title);
|
||
contentTitleTv.setText(contentTitle);
|
||
contentDesTv.setText(contentDes);
|
||
|
||
if (TextUtils.isEmpty(negative)) {
|
||
negativeTv.setVisibility(View.GONE);
|
||
} else {
|
||
negativeTv.setVisibility(View.VISIBLE);
|
||
negativeTv.setText(negative);
|
||
}
|
||
|
||
if (TextUtils.isEmpty(positive)) {
|
||
positiveTv.setVisibility(View.GONE);
|
||
} else {
|
||
positiveTv.setText(positive);
|
||
positiveTv.setVisibility(View.VISIBLE);
|
||
}
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
contentContainer.setOnClickListener(v -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
return dialog;
|
||
}
|
||
|
||
public static void showPrivacyPolicyDialog(Context context, String title, String content, EmptyCallback callback) {
|
||
final Context activityContext = checkDialogContext(context);
|
||
|
||
// 区分此 dialog 是点击 dialog 外部取消的还是点击返回取消的
|
||
AtomicBoolean isCanceledByClickOutsideOfDialog = new AtomicBoolean(true);
|
||
|
||
String privacyPolicyContent;
|
||
String privacyPolicyTitle = (TextUtils.isEmpty(title)) ? "个人信息保护指引" : title;
|
||
if (TextUtils.isEmpty(content)) {
|
||
privacyPolicyContent = "光环助手致力于为每位用户提供更安全的互联网环境,我们将依据相关法律法规和技术规范来收集和使用你的个人信息。" +
|
||
"<br/>1.为帮助你浏览内容、互动交流、注册认证等,我们需要获取一些必要的信息,以实现完整的功能;" +
|
||
"<br/>2.日常使用中,我们可能需要开启 IMEI号码、IMSI号码、定位、相册 等信息的读取权限;" +
|
||
"<br/>3.以上信息的读取权限均不会默认开启,只有在运行相关功能或服务时才会明确提示授权,光环助手不会在未经你同意的情况下收集相关信息。";
|
||
} else {
|
||
privacyPolicyContent = content;
|
||
}
|
||
|
||
final Dialog dialog = new Dialog(activityContext, R.style.GhAlertDialog);
|
||
|
||
dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
||
View contentView = LayoutInflater.from(activityContext).inflate(R.layout.dialog_privacy_policy, null);
|
||
TextView contentTv = contentView.findViewById(R.id.dialog_content);
|
||
TextView titleTv = contentView.findViewById(R.id.dialog_title);
|
||
TextView positiveTv = contentView.findViewById(R.id.dialog_positive);
|
||
TextView skipTv = contentView.findViewById(R.id.dialog_skip);
|
||
|
||
SpannableStringBuilder skipText = new SpannableStringBuilder("你可以查看完整版的 隐私政策");
|
||
skipText.setSpan(new ClickableSpan() {
|
||
@Override
|
||
public void updateDrawState(@NonNull TextPaint ds) {
|
||
super.updateDrawState(ds);
|
||
ds.setColor(ContextCompat.getColor(activityContext, R.color.text_1383EB));
|
||
ds.setUnderlineText(false);
|
||
}
|
||
|
||
@Override
|
||
public void onClick(@NonNull View widget) {
|
||
MtaHelper.onEvent("隐私政策弹窗", "隐私政策弹窗", "点击隐私政策");
|
||
Intent intent = WebActivity.getPrivacyPolicyIntent(activityContext);
|
||
activityContext.startActivity(intent);
|
||
}
|
||
}, skipText.length() - 4, skipText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||
|
||
|
||
skipTv.setText(skipText);
|
||
skipTv.setMovementMethod(new LinkMovementMethod());
|
||
contentTv.setText(Html.fromHtml(privacyPolicyContent));
|
||
titleTv.setText(privacyPolicyTitle);
|
||
positiveTv.setText("我知道了");
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
dialog.dismiss();
|
||
MtaHelper.onEvent("隐私政策弹窗", "隐私政策弹窗", "点击我知道了");
|
||
});
|
||
|
||
dialog.setOnDismissListener(d -> {
|
||
callback.onCallback();
|
||
});
|
||
|
||
dialog.setOnCancelListener(cd -> {
|
||
if (isCanceledByClickOutsideOfDialog.get()) {
|
||
MtaHelper.onEvent("隐私政策弹窗", "隐私政策弹窗", "点击空白");
|
||
}
|
||
});
|
||
|
||
dialog.setOnKeyListener((dialog1, keyCode, event) -> {
|
||
if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP) {
|
||
isCanceledByClickOutsideOfDialog.set(false);
|
||
MtaHelper.onEvent("隐私政策弹窗", "隐私政策弹窗", "点击返回");
|
||
}
|
||
return false;
|
||
});
|
||
|
||
MtaHelper.onEvent("隐私政策弹窗", "隐私政策弹窗", "出现弹窗");
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
try {
|
||
dialog.show();
|
||
} catch (Exception ignored) {
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 特殊:目前只在提交问题错误返回时弹出
|
||
*/
|
||
public static Dialog showUploadDraftDialog(Context context,
|
||
final CancelListener clListener,
|
||
final ConfirmListener cmListener) {
|
||
context = checkDialogContext(context);
|
||
|
||
final Dialog dialog = new Dialog(context, R.style.GhAlertDialog);
|
||
|
||
View contentView = LayoutInflater.from(context).inflate(R.layout.dialog_video_upload_draft, null);
|
||
TextView negativeTv = contentView.findViewById(R.id.negative);
|
||
TextView positiveTv = contentView.findViewById(R.id.positive);
|
||
TextView content = contentView.findViewById(R.id.content);
|
||
positiveTv.setBackground(DrawableView.getOvalDrawable(R.color.text_f5f5f5, 999));
|
||
negativeTv.setBackground(DrawableView.getOvalDrawable(R.color.theme, 999));
|
||
content.setText(Html.fromHtml(context.getString(R.string.video_upload_draft_dialog_content)));
|
||
|
||
negativeTv.setOnClickListener(view -> {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
});
|
||
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.show();
|
||
return dialog;
|
||
}
|
||
|
||
public static Dialog fixWebViewKeyboardNotWorking(Activity activity) {
|
||
final Dialog dialog = new Dialog(activity, R.style.TransparentDialog);
|
||
View view = new View(activity);
|
||
view.setOnClickListener(v -> dialog.dismiss());
|
||
view.postDelayed(() -> {
|
||
if (!activity.isFinishing()) {
|
||
dialog.show();
|
||
dialog.dismiss();
|
||
}
|
||
}, 500);
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(view);
|
||
return dialog;
|
||
}
|
||
|
||
/**
|
||
* @param context may be is application context
|
||
* @return activity context
|
||
*/
|
||
public static Context checkDialogContext(Context context) {
|
||
if (context == null) {
|
||
throw new NullPointerException("dialog context is null");
|
||
}
|
||
|
||
if (context instanceof Activity) {
|
||
return context;
|
||
}
|
||
|
||
return AppManager.getInstance().currentActivity();
|
||
}
|
||
|
||
public interface ConfirmListener {
|
||
void onConfirm();
|
||
}
|
||
|
||
public interface CancelListener {
|
||
void onCancel();
|
||
}
|
||
|
||
public interface OptionCallback {
|
||
void onClicked(String text);
|
||
}
|
||
|
||
public interface CheckDownloadCallBack {
|
||
void onResponse(boolean isSubscribe);
|
||
}
|
||
|
||
}
|