857 lines
34 KiB
Java
857 lines
34 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.pm.ApplicationInfo;
|
||
import android.content.pm.PackageInfo;
|
||
import android.graphics.Bitmap;
|
||
import android.graphics.Color;
|
||
import android.os.Handler;
|
||
import android.support.v4.content.ContextCompat;
|
||
import android.support.v7.app.AlertDialog;
|
||
import android.text.Html;
|
||
import android.text.Spanned;
|
||
import android.text.TextPaint;
|
||
import android.text.TextUtils;
|
||
import android.view.Display;
|
||
import android.view.Gravity;
|
||
import android.view.LayoutInflater;
|
||
import android.view.View;
|
||
import android.view.Window;
|
||
import android.view.WindowManager;
|
||
import android.widget.Button;
|
||
import android.widget.ImageView;
|
||
import android.widget.LinearLayout;
|
||
import android.widget.TextView;
|
||
|
||
import com.gh.gamecenter.AboutActivity;
|
||
import com.gh.gamecenter.KcSelectGameActivity;
|
||
import com.gh.gamecenter.R;
|
||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||
import com.halo.assistant.HaloApp;
|
||
import com.lightgame.utils.Utils;
|
||
|
||
import java.io.File;
|
||
import java.text.DecimalFormat;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.Date;
|
||
import java.util.List;
|
||
import java.util.Locale;
|
||
import java.util.Map;
|
||
|
||
public class DialogUtils {
|
||
|
||
private static boolean isShow = false;
|
||
|
||
public static Dialog showWaitDialog(Context context, String msg) {
|
||
Dialog dialog = new Dialog(context);
|
||
View view = View.inflate(context, R.layout.set_wait_dialog, null);
|
||
TextView message = (TextView) 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 showKuaiChuanResult(final Activity activity, Handler handler, int requestCode, final String picName) {
|
||
|
||
HaloApp.remove(KcSelectGameActivity.KEY_FILE_INFO);
|
||
|
||
List<Map<String, String>> mapList = (List<Map<String, String>>) HaloApp.get("sendData", true);
|
||
if (mapList == null || mapList.size() == 0) return;
|
||
|
||
WifiMgr.getInstance(activity).disconnectCurrentNetwork(); // 断开当前WiFi
|
||
|
||
// int heightPixels = getContext().getResources().getDisplayMetrics().heightPixels;
|
||
// int widthPixels = getContext().getResources().getDisplayMetrics().widthPixels;
|
||
|
||
int filesCount = mapList.size();
|
||
int filesSize = 0;
|
||
int sendTime = 0;
|
||
|
||
View view = View.inflate(activity, R.layout.dialog_kuaichuan, null);
|
||
final LinearLayout mShareLl = (LinearLayout) view.findViewById(R.id.kuaichuan_dialog_ll);
|
||
final LinearLayout mShareBottomLl = (LinearLayout) view.findViewById(R.id.kuaichuan_dialog_share_rl);
|
||
LinearLayout shareIconLl = (LinearLayout) view.findViewById(R.id.kuaichuan_icon_ll);
|
||
ImageView qrCode = (ImageView) view.findViewById(R.id.kuaichuan_qrcode);
|
||
TextView dateTv = (TextView) view.findViewById(R.id.kuaichuan_dialog_date);
|
||
TextView countTv = (TextView) view.findViewById(R.id.kuaichuan_send_count);
|
||
TextView sizeTv = (TextView) view.findViewById(R.id.kuaichuan_send_size);
|
||
TextView speedTv = (TextView) view.findViewById(R.id.kuaichuan_send_speed);
|
||
TextView timeCount = (TextView) view.findViewById(R.id.kuaichuan_time_count);
|
||
TextView timeTv = (TextView) view.findViewById(R.id.kuaichuan_time_tv);
|
||
TextView sendCountTv = (TextView) view.findViewById(R.id.dialog_send_tv);
|
||
ImageView closeIv = (ImageView) view.findViewById(R.id.kuaichuan_dialog_colse);
|
||
// content.setLayoutParams(new LinearLayout.LayoutParams((int)(((float)heightPixels)*0.85), (int)((float)widthPixels*0.81)));
|
||
|
||
final Dialog dialog = new Dialog(activity);
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setCanceledOnTouchOutside(false);
|
||
dialog.setContentView(view);
|
||
dialog.show();
|
||
|
||
Window dialogWindow = dialog.getWindow();
|
||
WindowManager m = activity.getWindowManager();
|
||
Display d = m.getDefaultDisplay();
|
||
if (dialogWindow != null) {
|
||
WindowManager.LayoutParams p = dialogWindow.getAttributes();
|
||
p.height = (int) (d.getHeight() * 0.82);
|
||
p.width = (int) (d.getWidth() * 0.80);
|
||
dialogWindow.setAttributes(p);
|
||
}
|
||
|
||
SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日", Locale.getDefault());
|
||
dateTv.setText(format.format(new Date().getTime()));
|
||
|
||
for (Map<String, String> map : mapList) {
|
||
int size = Integer.parseInt(map.get("apkSize"));
|
||
int time = 10;
|
||
try {
|
||
time = Integer.parseInt(map.get("sendTime"));
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
|
||
String apkPath = map.get("apkPath");
|
||
filesSize = filesSize + size;
|
||
sendTime = sendTime + time;
|
||
|
||
if (shareIconLl.getChildCount() >= 5) continue;
|
||
|
||
android.content.pm.PackageManager pm = activity.getPackageManager();
|
||
PackageInfo info = pm.getPackageArchiveInfo(apkPath,
|
||
android.content.pm.PackageManager.GET_ACTIVITIES);
|
||
if (info != null) {
|
||
ApplicationInfo appInfo = info.applicationInfo;
|
||
appInfo.sourceDir = apkPath;
|
||
appInfo.publicSourceDir = apkPath;
|
||
Bitmap bitmap = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
|
||
|
||
ImageView imageView = new ImageView(activity);
|
||
imageView.setLayoutParams(new LinearLayout.LayoutParams(DisplayUtils.dip2px(activity, 25)
|
||
, DisplayUtils.dip2px(activity, 24)));
|
||
imageView.setImageBitmap(bitmap);
|
||
shareIconLl.addView(imageView);
|
||
}
|
||
}
|
||
|
||
if (requestCode == 0x170) { // 发送
|
||
qrCode.setImageResource(R.drawable.kc_qrcode_120);
|
||
sendCountTv.setText("成功传送游戏");
|
||
} else {
|
||
qrCode.setImageResource(R.drawable.kc_qrcode_110);
|
||
sendCountTv.setText("成功接收游戏");
|
||
}
|
||
|
||
double size = (((float) filesSize / 1024) / 1024);
|
||
String sizeName;
|
||
if (size > 1024) {
|
||
DecimalFormat df = new DecimalFormat("#.0");
|
||
sizeName = df.format(size / 1024) + "GB";
|
||
} else {
|
||
DecimalFormat df = new DecimalFormat("#.0");
|
||
sizeName = df.format(size) + "MB";
|
||
}
|
||
|
||
if (sendTime < 1000) { // 最少设置发送时间为1s(为了简易计算)
|
||
sendTime = 1000;
|
||
}
|
||
|
||
int i = (filesSize / 1024) / (sendTime / 1000);
|
||
String speed;
|
||
if (i >= 1000) {
|
||
float mSpeed = i / 1024f;
|
||
DecimalFormat df = new DecimalFormat("#.0");
|
||
String str = df.format(mSpeed);
|
||
if (str.length() > 4) {
|
||
str = str.substring(0, 4);
|
||
}
|
||
speed = str + "MB/s";
|
||
} else {
|
||
speed = i + "KB/s";
|
||
}
|
||
|
||
if (sendTime > 60000) {
|
||
timeCount.setText(String.valueOf(sendTime / 1000 / 60));
|
||
timeTv.setText("分钟传送完成");
|
||
} else {
|
||
timeCount.setText(String.valueOf(sendTime / 1000));
|
||
timeTv.setText("秒传送完成");
|
||
}
|
||
|
||
sizeTv.setText(sizeName);
|
||
speedTv.setText(speed);
|
||
countTv.setText(filesCount + "个");
|
||
|
||
// 延迟操作,等待截图部分绘制完成
|
||
handler.postDelayed(new Runnable() {
|
||
@Override
|
||
public void run() {
|
||
mShareLl.setDrawingCacheEnabled(true);
|
||
mShareLl.buildDrawingCache();
|
||
Bitmap drawingCache = mShareLl.getDrawingCache();
|
||
saveBitmap(drawingCache, activity, picName);
|
||
MessageShareUtils.getInstance(activity).showShareWindows(activity, mShareBottomLl, drawingCache, picName, 2);
|
||
mShareBottomLl.setVisibility(View.VISIBLE);
|
||
}
|
||
}, 200);
|
||
|
||
closeIv.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
dialog.cancel();
|
||
}
|
||
});
|
||
}
|
||
|
||
public static void saveBitmap(Bitmap bm, Activity activity, String picName) {
|
||
File externalCacheDir = activity.getExternalCacheDir();
|
||
if (externalCacheDir == null) return;
|
||
|
||
File file = new File(externalCacheDir.getPath() + "/ShareImg");
|
||
if (!file.isDirectory()) {
|
||
file.delete();
|
||
file.mkdirs();
|
||
}
|
||
if (!file.exists()) {
|
||
file.mkdirs();
|
||
}
|
||
MessageShareUtils.getInstance(activity).writeBitmap(file.getPath(), picName, bm, false);
|
||
|
||
}
|
||
|
||
public static void showInstallHintDialog(Context context, final ConfirmListener cmListener) {
|
||
|
||
|
||
final Dialog dialog = new Dialog(context);
|
||
|
||
View view = View.inflate(context, R.layout.dialog_install_hint, null);
|
||
|
||
// 标题
|
||
TextView alertdialog_title = (TextView) 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 = (TextView) view.findViewById(R.id.installhint_content);
|
||
alertdialog_content.setText(content);
|
||
|
||
// 确定按钮
|
||
TextView installhint_confirm = (TextView) view.findViewById(R.id.installhint_confirm);
|
||
installhint_confirm.setText("知道了");
|
||
|
||
final ImageView installhint_unselect = (ImageView) view.findViewById(R.id.installhint_unselect);
|
||
final ImageView installhint_select = (ImageView) view.findViewById(R.id.installhint_select);
|
||
|
||
LinearLayout installhint_unselect_ll = (LinearLayout) view.findViewById(R.id.installhint_unselect_ll);
|
||
|
||
installhint_unselect_ll.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View 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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
dialog.dismiss();
|
||
if (installhint_select.getVisibility() == View.VISIBLE) {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
dialog.setOnDismissListener(new Dialog.OnDismissListener() {
|
||
@Override
|
||
public void onDismiss(DialogInterface dialog) {
|
||
isShow = false;
|
||
}
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(view);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showHintDialog(Context context, String title, CharSequence msg, String confirm) {
|
||
final Dialog dialog = new Dialog(context);
|
||
|
||
View view = View.inflate(context, R.layout.common_hintdialog, null);
|
||
|
||
TextView hintdialog_title = (TextView) view.findViewById(R.id.tv_dialog_hint_title);
|
||
hintdialog_title.setText(title);
|
||
|
||
// 内容
|
||
TextView hintdialog_content = (TextView) view.findViewById(R.id.tv_dialog_hint_content);
|
||
hintdialog_content.setText(msg);
|
||
|
||
TextView hintdialog_confirm = (TextView) view.findViewById(R.id.tv_dialog_hint_confirm);
|
||
|
||
hintdialog_confirm.setText(confirm);
|
||
|
||
hintdialog_confirm.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
dialog.cancel();
|
||
}
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(view);
|
||
dialog.show();
|
||
}
|
||
|
||
public static void showHijackDialog(final Context context) {
|
||
showWarningDialog(context, "警告", "您当前网络环境异常,下载地址已被替换(网络劫持),请更换网络环境进行下载。",
|
||
new ConfirmListener() {
|
||
@Override
|
||
public void onConfirm() {
|
||
// 跳转wifi管理界面
|
||
context.startActivity(IntentUtils.getWifiIntent());
|
||
}
|
||
});
|
||
}
|
||
|
||
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", new ConfirmListener() {
|
||
@Override
|
||
public void onConfirm() {
|
||
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 {
|
||
showDownloadDialog(context,
|
||
() -> callBack.onResponse(false),
|
||
() -> callBack.onResponse(true));
|
||
}
|
||
}
|
||
|
||
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.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) {
|
||
|
||
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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
}
|
||
});
|
||
|
||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View 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) {
|
||
|
||
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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View 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) {
|
||
|
||
|
||
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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
if (cmListener != null) {
|
||
cmListener.onConfirm();
|
||
}
|
||
dialog.dismiss();
|
||
}
|
||
});
|
||
|
||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
dialog.setContentView(contentView);
|
||
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
|
||
@Override
|
||
public void onCancel(DialogInterface 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) {
|
||
|
||
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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View 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) {
|
||
|
||
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(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View view) {
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
dialog.dismiss();
|
||
}
|
||
});
|
||
|
||
positiveTv.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View 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("确认", new DialogInterface.OnClickListener() {
|
||
@Override
|
||
public void onClick(DialogInterface dialog, int 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) {
|
||
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 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("链接超出范围,请检查升级至最新版本的光环助手");
|
||
titleTv.setText("提示");
|
||
negativeTv.setText("关闭");
|
||
positiveTv.setText("检查升级");
|
||
|
||
negativeTv.setOnClickListener(view -> dialog.dismiss());
|
||
|
||
positiveTv.setOnClickListener(view -> {
|
||
context.startActivity(AboutActivity.getIntent(context, true));
|
||
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) {
|
||
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 interface ConfirmListener {
|
||
void onConfirm();
|
||
}
|
||
|
||
public interface CancelListener {
|
||
void onCancel();
|
||
}
|
||
|
||
public interface OptionCallback {
|
||
void onClicked(String text);
|
||
}
|
||
|
||
public interface CheckDownloadCallBack {
|
||
void onResponse(boolean isSubscribe);
|
||
}
|
||
|
||
}
|