448 lines
18 KiB
Java
448 lines
18 KiB
Java
package com.gh.common.util;
|
||
|
||
import android.app.Activity;
|
||
import android.app.Dialog;
|
||
import android.content.*;
|
||
import android.content.pm.ApplicationInfo;
|
||
import android.content.pm.PackageInfo;
|
||
import android.graphics.Bitmap;
|
||
import android.net.Uri;
|
||
import android.os.Handler;
|
||
import android.text.Html;
|
||
import android.text.Spanned;
|
||
import android.view.*;
|
||
import android.widget.*;
|
||
import com.gh.base.AppController;
|
||
import com.gh.gamecenter.R;
|
||
import com.gh.gamecenter.kuaichuan.WifiMgr;
|
||
|
||
import java.io.File;
|
||
import java.text.DecimalFormat;
|
||
import java.text.SimpleDateFormat;
|
||
import java.util.*;
|
||
|
||
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) {
|
||
|
||
AppController.remove("FileInfo");
|
||
|
||
List<Map<String, String>> mapList = (List<Map<String, String>>) AppController.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);
|
||
RelativeLayout content = (RelativeLayout) view.findViewById(R.id.kuaichuan_dialog);
|
||
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();
|
||
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 == 0) {
|
||
sendTime = 1;
|
||
}
|
||
|
||
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(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 file = new File(activity.getExternalCacheDir().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 showWarningDialog(Context context, String title, CharSequence msg, String cancel, String confirm,
|
||
final ConfiremListener cmListener, final CancelListener clListener) {
|
||
|
||
if (isShow) {
|
||
return;
|
||
}
|
||
isShow = true;
|
||
|
||
final Dialog dialog = new Dialog(context);
|
||
|
||
View view = View.inflate(context, R.layout.common_alertdialog, null);
|
||
|
||
// 标题
|
||
TextView alertdialog_title = (TextView) view.findViewById(R.id.alertdialog_title);
|
||
alertdialog_title.setText(title);
|
||
|
||
// 内容
|
||
TextView alertdialog_content = (TextView) view.findViewById(R.id.alertdialog_content);
|
||
alertdialog_content.setText(msg);
|
||
|
||
// 取消按钮
|
||
TextView alertdialog_cannel = (TextView) view.findViewById(R.id.alertdialog_cannel);
|
||
alertdialog_cannel.setText(cancel);
|
||
alertdialog_cannel.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
dialog.dismiss();
|
||
if (clListener != null) {
|
||
clListener.onCancel();
|
||
}
|
||
}
|
||
});
|
||
|
||
// 确定按钮
|
||
TextView alertdialog_confirm = (TextView) view.findViewById(R.id.alertdialog_confirm);
|
||
alertdialog_confirm.setText(confirm);
|
||
alertdialog_confirm.setOnClickListener(new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
dialog.dismiss();
|
||
if (cmListener != null) {
|
||
cmListener.onConfirem();
|
||
}
|
||
}
|
||
});
|
||
|
||
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 showInstallHintDialog(Context context, final ConfiremListener 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);
|
||
|
||
TextView installhint_cancel = (TextView) view.findViewById(R.id.installhint_cancel);
|
||
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.onConfirem();
|
||
}
|
||
}
|
||
}
|
||
});
|
||
|
||
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.hintdialog_title);
|
||
hintdialog_title.setText(title);
|
||
|
||
// 内容
|
||
TextView hintdialog_content = (TextView) view.findViewById(R.id.hintdialog_content);
|
||
hintdialog_content.setText(msg);
|
||
|
||
TextView hintdialog_confirm = (TextView) view.findViewById(R.id.hintdialog_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 ConfiremListener() {
|
||
@Override
|
||
public void onConfirem() {
|
||
// 跳转wifi管理界面
|
||
context.startActivity(new Intent("android.settings.WIFI_SETTINGS"));
|
||
}
|
||
});
|
||
}
|
||
|
||
// 网络劫持时 打开QQ客户端,创建临时会话
|
||
public static void showQqSessionDialog(final Context context, String qq) {
|
||
if (qq == null) {
|
||
qq = "2586716223";// 默认客服QQ
|
||
}
|
||
final String finalQq = qq;
|
||
showWarningDialog(context, "警告", "您当前网络环境异常,下载地址可能被运营商恶意替换(网络劫持)" +
|
||
",如多次下载失败,请联系客服获取正确的下载地址(客服QQ:" + qq + ")"
|
||
, "取消", "前往QQ", new ConfiremListener() {
|
||
@Override
|
||
public void onConfirem() {
|
||
if (ShareUtils.isQQClientAvailable(context)) {
|
||
//安装了QQ会直接调用QQ,打开手机QQ进行会话 QQ号:2586716223
|
||
String str = "mqqwpa://im/chat?chat_type=wpa&uin=" + finalQq + "&version=1&src_type=web&web_src=oicqzone.com";
|
||
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(str)));
|
||
} else {
|
||
//没有安装QQ 复制账号
|
||
ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||
cmb.setText(finalQq);
|
||
Utils.toast(context, "已复制" + finalQq);
|
||
}
|
||
}
|
||
}, null);
|
||
}
|
||
|
||
|
||
public static void showWarningDialog(Context context, String title, CharSequence msg, final ConfiremListener listener) {
|
||
showWarningDialog(context, title, msg, "取消", "确定", listener, null);
|
||
}
|
||
|
||
public static void showDownloadDialog(Context context, ConfiremListener listener) {
|
||
showWarningDialog(context, "下载提示", "您当前使用的网络为2G/3G/4G,开始下载将会消耗移动流量,确定下载?", listener);
|
||
}
|
||
|
||
public static void showCancelDialog(Context context, final ConfiremListener listener) {
|
||
Spanned content = Html.fromHtml("取消关注游戏后,您将无法及时收到游戏" +
|
||
"<font color=\"#ff0000\">攻略</font>、" +
|
||
"<font color=\"#ff0000\">资讯</font>等最新动态提醒。");
|
||
showWarningDialog(context, "取消关注", content, "暂不取消", "确定取消", listener, null);
|
||
}
|
||
|
||
public static void showPluginDialog(Context context, final ConfiremListener listener) {
|
||
Spanned spanned = Html.fromHtml("您将进行插件化安装以实现插件功能,此过程将"
|
||
+ "<font color=\"#ff0000\">卸载</font>" + "当前使用的版本并"
|
||
+ "<font color=\"#ff0000\">安装插件版本</font>");
|
||
showWarningDialog(context, "插件化安装", spanned, listener);
|
||
}
|
||
|
||
public static void showDisclaimerDialog(Context context, String content) {
|
||
final Dialog disclaimerDialog = new Dialog(context);
|
||
View view = View.inflate(context, R.layout.dialog_disclaimer, null);
|
||
|
||
// TextView title = (TextView) view.findViewById(R.id.disclaimer_title);
|
||
// title.setText("免责声明");
|
||
|
||
TextView message = (TextView) view.findViewById(R.id.disclaimer_message);
|
||
Spanned spanned = Html.fromHtml(content);
|
||
message.setText(spanned);
|
||
|
||
view.findViewById(R.id.disclaimer_confirm).setOnClickListener(
|
||
new View.OnClickListener() {
|
||
@Override
|
||
public void onClick(View v) {
|
||
disclaimerDialog.dismiss();
|
||
}
|
||
});
|
||
|
||
disclaimerDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||
disclaimerDialog.setContentView(view);
|
||
disclaimerDialog.show();
|
||
}
|
||
|
||
public interface ConfiremListener {
|
||
void onConfirem();
|
||
}
|
||
|
||
public interface CancelListener {
|
||
void onCancel();
|
||
}
|
||
|
||
}
|