Commit 3c94fdd8 authored by fallenstardust's avatar fallenstardust
parents 598d385c 9b1dbef3
......@@ -8,7 +8,7 @@ public class FullScreenUtils {
private boolean isFullscreen;
private Activity activity;
private static final int windowsFlags =
Build.VERSION.SDK_INT >= 19 ? (
Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT ? (
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
......
......@@ -22,6 +22,7 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-sdk
tools:overrideLibrary="com.toptoche.searchablespinnerlibrary"/>
......@@ -168,6 +169,7 @@
android:label="@string/app_name"/>
<activity
android:name="cn.garymb.ygomobile.ui.mycard.mcchat.SplashActivity"/>
<activity android:name="cn.garymb.ygomobile.ui.activities.FileLogActivity"/>
<service
android:name="cn.garymb.ygomobile.ui.plus.ServiceDuelAssistant"
android:priority="1000"/>
......
......@@ -5,6 +5,8 @@ import android.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatDelegate;
import cn.garymb.ygomobile.utils.CrashHandler;
public class App extends GameApplication {
@Override
......@@ -12,6 +14,9 @@ public class App extends GameApplication {
super.onCreate();
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
AppsSettings.init(this);
//初始化异常工具类
CrashHandler crashHandler = CrashHandler.getInstance();
crashHandler.init(getApplicationContext());
if (AppsSettings.get().isSoundEffect()) {
initSoundEffectPool();
setInitSoundEffectPool(true);
......
......@@ -12,6 +12,7 @@ import org.json.JSONArray;
import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -19,6 +20,7 @@ import java.util.List;
import java.util.Locale;
import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.FileLogUtil;
import cn.garymb.ygomobile.utils.ScreenUtil;
import cn.garymb.ygomobile.utils.SystemUtils;
......@@ -116,29 +118,66 @@ public class AppsSettings {
mDensity = context.getResources().getDisplayMetrics().density;
mScreenHeight = context.getResources().getDisplayMetrics().heightPixels;
mScreenWidth = context.getResources().getDisplayMetrics().widthPixels;
if (isImmerSiveMode() && context instanceof Activity) {
if (context instanceof Activity) {
DisplayMetrics dm = SystemUtils.getHasVirtualDisplayMetrics((Activity) context);
if (dm != null) {
int height = Math.max(dm.widthPixels, dm.heightPixels);
Log.i("机横屏height1", "横屏" + height);
// if(dm.widthPixels / dm.heightPixels !=9/16 ) {
// height = height - getStatusBarHeight(context);
// }
if (ScreenUtil.isNotchInScreen((Activity) context)&&ScreenUtil.getNotchHeight((Activity)context)!=0)
height = height - ScreenUtil.getNotchHeight((Activity)context);
if (mScreenHeight == Math.max(mScreenHeight, mScreenWidth)) {
try {
FileLogUtil.writeAndTime("原始长"+mScreenHeight);
FileLogUtil.writeAndTime("原始宽"+mScreenWidth);
FileLogUtil.writeAndTime("界面长"+dm.heightPixels);
FileLogUtil.writeAndTime("界面宽"+dm.widthPixels);
} catch (IOException e) {
e.printStackTrace();
}
if(isImmerSiveMode())
return;
ScreenUtil.findNotchInformation(((Activity) context), new ScreenUtil.FindNotchInformation() {
@Override
public void onNotchInformation(boolean isNotch, int notchHeight, int phoneType) {
int height = Math.max(dm.widthPixels, dm.heightPixels);
try {
FileLogUtil.writeAndTime("是否有刘海: "+isNotch);
FileLogUtil.writeAndTime("刘海高"+notchHeight);
FileLogUtil.writeAndTime("height值: "+height);
} catch (IOException e) {
e.printStackTrace();
}
if (isNotch) {
height-=notchHeight;
}
try {
FileLogUtil.writeAndTime("处理后height值: "+height);
} catch (IOException e) {
e.printStackTrace();
}
if (mScreenHeight> mScreenWidth) {
mScreenHeight = height;
} else {
mScreenWidth = height;
}
try {
FileLogUtil.writeAndTime("转换后长"+mScreenHeight);
FileLogUtil.writeAndTime("转换后宽"+mScreenWidth);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
}
Log.i("机屏幕高度", "" + mScreenHeight);
Log.i("机屏幕宽度", "" + mScreenWidth);
for(int i:getNotchSize(context))
Log.i("机刘海高度", "刘海高度" +i );
for (int i : getNotchSize(context))
Log.i("机刘海高度", "刘海高度" + i);
Log.i("机状态栏高度", "" + getStatusBarHeight(context));
Log.i("机是否存在刘海",""+ hasNotchInScreen(context));
Log.i("机是否存在刘海", "" + hasNotchInScreen(context));
}
public int getAppVersion() {
......@@ -356,6 +395,13 @@ public class AppsSettings {
return new File(getResourcePath(), Constants.CORE_IMAGE_PATH).getAbsolutePath();
}
/***
* log文件夹
*/
public String getMobileLogPath() {
return new File(getResourcePath(), Constants.MOBILE_LOG).getAbsolutePath();
}
/***
* 当前数据库文件夹
*/
......
......@@ -65,6 +65,7 @@ public interface Constants {
String CORE_EXPANSIONS = "expansions";
String CORE_SINGLE_PATH = "single";
String CORE_IMAGE_PATH = "pics";
String MOBILE_LOG="log";
String CORE_EXPANSIONS_IMAGE_PATH = "expansions/pics";
String CORE_IMAGE_FIELD_PATH = "field";
String CORE_SCRIPT_PATH = "script";
......
package cn.garymb.ygomobile.ui.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.TextView;
import java.io.IOException;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.utils.FileLogUtil;
public class FileLogActivity extends BaseActivity {
private TextView tv_log;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.file_log_activity);
Toolbar toolbar = findViewById(R.id.toolbar);
tv_log = $(R.id.tv_log);
setSupportActionBar(toolbar);
enableBackHome();
setTitle("本地Log输出");
read();
tv_log.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
read();
}
});
}
private void read() {
try {
tv_log.setText(FileLogUtil.read());
} catch (IOException e) {
tv_log.setText("读取日志失败,点击重新读取");
}
}
}
......@@ -28,6 +28,7 @@ import android.view.animation.AnimationUtils;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;
......@@ -57,6 +58,7 @@ import cn.garymb.ygomobile.bean.ServerInfo;
import cn.garymb.ygomobile.bean.events.ServerInfoEvent;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.activities.BaseActivity;
import cn.garymb.ygomobile.ui.activities.FileLogActivity;
import cn.garymb.ygomobile.ui.activities.WebActivity;
import cn.garymb.ygomobile.ui.adapters.ServerListAdapter;
import cn.garymb.ygomobile.ui.adapters.SimpleListAdapter;
......@@ -411,6 +413,7 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
doMenu(mMenuIds.get(index));
}
});
}
private void addMenuButton(SparseArray<Integer> mMenuIds, BoomMenuButton menuButton, int menuId, int stringId, int image) {
......@@ -530,11 +533,19 @@ public abstract class HomeActivity extends BaseActivity implements NavigationVie
}
public void StartMycard() {
$(R.id.btn_mycard).setOnClickListener((v) -> {
ImageView iv_mc = $(R.id.btn_mycard);
iv_mc.setOnClickListener((v) -> {
if (Constants.SHOW_MYCARD) {
startActivity(new Intent(this, MyCardActivity.class));
}
});
iv_mc.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
startActivity(new Intent(HomeActivity.this, FileLogActivity.class));
return true;
}
});
}
public boolean joinQQGroup(String key) {
......
......@@ -274,7 +274,8 @@ public class ResCheckTask extends AsyncTask<Void, Integer, Integer> {
Constants.CORE_DECK_PATH,
Constants.CORE_REPLAY_PATH,
Constants.FONT_DIRECTORY,
Constants.CORE_IMAGE_PATH
Constants.CORE_IMAGE_PATH,
Constants.MOBILE_LOG
};
File dirFile = null;
for (String dir : dirs) {
......
package cn.garymb.ygomobile.utils;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Environment;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import cn.garymb.ygomobile.AppsSettings;
public class CrashHandler implements Thread.UncaughtExceptionHandler {
public static final String TAG = "YGOMobile-Exception";
public static final CrashHandler INSTANCE = new CrashHandler();
private Map<String, String> infos = new HashMap<String, String>();
private DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH.mm.ss");
private Context context;
private Thread.UncaughtExceptionHandler defaultHandler;
private CrashHandler() {
}
public static CrashHandler getInstance() {
return INSTANCE;
}
public void init(Context context) {
this.context = context;
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(this);
}
@Override
public void uncaughtException(Thread thread, Throwable ex) {
if (!handleException(ex) && defaultHandler != null) {
defaultHandler.uncaughtException(thread, ex);
} else {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.e(TAG, "error : ", e);
}
System.exit(1);
android.os.Process.killProcess(android.os.Process.myPid());
}
}
private boolean handleException(Throwable ex) {
if (ex == null) {
return false;
}
//使用Toast来显示异常信息
new Thread() {
@Override
public void run() {
Looper.prepare();
Toast.makeText(context, "软件错误退出", Toast.LENGTH_LONG).show();
Looper.loop();
}
}.start();
collectDeviceInfo(context);
saveCrashInfo2File(ex);
return true;
}
public void collectDeviceInfo(Context ctx) {
try {
PackageManager pm = ctx.getPackageManager();
PackageInfo pi = pm.getPackageInfo(ctx.getPackageName(), PackageManager.GET_ACTIVITIES);
if (pi != null) {
String versionName = pi.versionName == null ? "null" : pi.versionName;
String versionCode = pi.versionCode + "";
infos.put("versionName", versionName);
infos.put("versionCode", versionCode);
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "an error occured when collect package info", e);
}
Field[] fields = Build.class.getDeclaredFields();
for (Field field : fields) {
try {
field.setAccessible(true);
infos.put(field.getName(), field.get(null).toString());
Log.d(TAG, field.getName() + " : " + field.get(null));
} catch (Exception e) {
Log.e(TAG, "an error occured when collect crash info", e);
}
}
}
private String saveCrashInfo2File(Throwable ex) {
StringBuffer sb = new StringBuffer();
for (Map.Entry<String, String> entry : infos.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
sb.append(key + "=" + value + "\n");
}
Writer writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
ex.printStackTrace(printWriter);
Throwable cause = ex.getCause();
while (cause != null) {
cause.printStackTrace(printWriter);
cause = cause.getCause();
}
printWriter.close();
String result = writer.toString();
sb.append(result);
Log.e(TAG,sb.toString());
try {
// long timestamp = System.currentTimeMillis();
String time = formatter.format(new Date());
String fileName ="【Demo】" + time+/* timestamp +*/ ".log";
String path = AppsSettings.get().getMobileLogPath() + "/";
FileOutputStream fos = new FileOutputStream(path + fileName);
fos.write(sb.toString().getBytes());
fos.close();
return fileName;
} catch (Exception e) {
Log.e(TAG, "an error occured while writing file...", e);
}
return null;
}
}
package cn.garymb.ygomobile.utils;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import cn.garymb.ygomobile.AppsSettings;
public class FileLogUtil {
private static int writeNum=0;
//获取配置文件路径
public static File getConfigFile() {
return new File(AppsSettings.get().getResourcePath(), "YGOMobile.log");
}
public static void writeAndTime(String message) throws IOException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM-dd HH:mm");// HH:mm:ss
// 获取当前时间
Date date = new Date(System.currentTimeMillis());
write(simpleDateFormat.format(date) + ": " + message);
}
public static void write(String message) throws IOException {
FileWriter fw = null;
//如果文件存在,则追加内容;如果文件不存在,则创建文件
File f = getConfigFile();
fw = new FileWriter(f, true);
PrintWriter pw = new PrintWriter(fw);
if (writeNum==0)
pw.println();
pw.println(message);
writeNum++;
pw.flush();
fw.flush();
pw.close();
fw.close();
}
public static String read() throws IOException {
String encoding = "UTF-8";
File file = getConfigFile();
Long filelength = file.length();
byte[] filecontent = new byte[filelength.intValue()];
FileInputStream in = new FileInputStream(file);
in.read(filecontent);
in.close();
return new String(filecontent, encoding);
}
}
......@@ -6,8 +6,8 @@ import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.util.Log;
import android.view.Display;
import android.view.DisplayCutout;
import android.view.View;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
......@@ -21,52 +21,75 @@ public class ScreenUtil {
public static final int VIVO_FILLET = 0x00000008;//是否有圆角
public static final int NOTCH_TYPE_PHONE_VIVO = 0;
public static final int NOTCH_TYPE_PHONE_OPPO = 1;
public static final int NOTCH_TYPE_PHONE_HUAWEI = 2;
public static final int NOTCH_TYPE_PHONE_XIAOMI = 3;
public static final int NOTCH_TYPE_PHONE_ANDROID_P = 4;
public static final int NOTCH_TYPE_PHONE_OTHER = 5;
public static interface FindNotchInformation {
void onNotchInformation(boolean isNotch, int notchHeight, int phoneType);
}
//是否是刘海屏
public static boolean isNotchInScreen(Activity activity) {
if (!(isNotchOPPO(activity) || isNotchVivo(activity) || isNotchHuawei(activity))||isNotchXiaomi(activity)) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
return isNotchP(activity);
else
return false;
}
return true;
}
//获取刘海高度
public static int getNotchHeight(Activity activity) {
int NotchHeight=0;
if ((NotchHeight=getNotchHeightOPPO(activity))!=0)
return NotchHeight;
if ((NotchHeight=getNotchHeightVivo(activity))!=0)
return NotchHeight;
if ((NotchHeight=getNotchHeightHuawei(activity))!=0)
return NotchHeight;
if ((NotchHeight=getNotchHeightXiaomi(activity))!=0)
return NotchHeight;
public static void findNotchInformation(Activity activity, FindNotchInformation findNotchInformation) {
if (isNotchVivo(activity)) {
findNotchInformation.onNotchInformation(true, getNotchHeightVivo(activity), NOTCH_TYPE_PHONE_VIVO);
} else if (isNotchOPPO(activity)) {
findNotchInformation.onNotchInformation(true, getNotchHeightOPPO(activity), NOTCH_TYPE_PHONE_OPPO);
} else if (isNotchHuawei(activity)) {
findNotchInformation.onNotchInformation(true, getNotchHeightHuawei(activity), NOTCH_TYPE_PHONE_HUAWEI);
} else if (isNotchXiaomi(activity)) {
findNotchInformation.onNotchInformation(true, getNotchHeightXiaomi(activity), NOTCH_TYPE_PHONE_XIAOMI);
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if ((NotchHeight=getNotchHeightP(activity))!=0)
return NotchHeight;
findNotchPInformation(activity, findNotchInformation);
} else {
findNotchInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_OTHER);
}
}
return 0;
}
@RequiresApi(api = Build.VERSION_CODES.P)
public static int getNotchHeightP(Activity activity) {
DisplayCutout displayCutout = getDisplayCutout(activity);
if (displayCutout == null)
return 0;
return displayCutout.getSafeInsetTop();
// Log.e("TAG", "安全区域距离屏幕左边的距离 SafeInsetLeft:" + displayCutout.getSafeInsetLeft());
// Log.e("TAG", "安全区域距离屏幕右部的距离 SafeInsetRight:" + displayCutout.getSafeInsetRight());
// Log.e("TAG", "安全区域距离屏幕顶部的距离 SafeInsetTop:" + displayCutout.getSafeInsetTop());
// Log.e("TAG", "安全区域距离屏幕底部的距离 SafeInsetBottom:" + displayCutout.getSafeInsetBottom());
public static void findNotchPInformation(Activity activity, final FindNotchInformation findNotchPInformation) {
final View decorView = activity.getWindow().getDecorView();
decorView.post(new Runnable() {
@Override
public void run() {
DisplayCutout cutout = decorView.getRootWindowInsets().getDisplayCutout();
if (cutout == null) {
findNotchPInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_ANDROID_P);
} else {
List<Rect> rects = cutout.getBoundingRects();
if (rects == null || rects.size() == 0) {
findNotchPInformation.onNotchInformation(false, 0, NOTCH_TYPE_PHONE_ANDROID_P);
} else {
findNotchPInformation.onNotchInformation(true, cutout.getSafeInsetTop(), NOTCH_TYPE_PHONE_ANDROID_P);
//刘海的数量可以是多个
// for (Rect rect : rects) {
// Log.e(TAG, "cutout.getSafeInsetTop():" + cutout.getSafeInsetTop()
// + ", cutout.getSafeInsetBottom():" + cutout.getSafeInsetBottom()
// + ", cutout.getSafeInsetLeft():" + cutout.getSafeInsetLeft()
// + ", cutout.getSafeInsetRight():" + cutout.getSafeInsetRight()
// + ", cutout.rects:" + rect
// );
// }
}
}
}
});
}
@RequiresApi(api = Build.VERSION_CODES.P)
public static DisplayCutout getDisplayCutout(Activity activity) {
return activity.getWindow().getDecorView().getRootWindowInsets().getDisplayCutout();
}
......@@ -74,8 +97,8 @@ public class ScreenUtil {
//小米的状态栏高度会略高于刘海屏的高度,因此可以通过获取状态栏的高度来间接避开刘海屏
public static int getNotchHeightXiaomi(Activity activity) {
if (isNotchXiaomi(activity))
return 0;
return getStatusBarHeight(activity);
return 0;
}
//获取状态栏高度
......@@ -132,23 +155,24 @@ public class ScreenUtil {
}
}
public static boolean isNotchXiaomi(Activity activity){
return getInt("ro.miui.notch",activity)==1;
public static boolean isNotchXiaomi(Activity activity) {
return getInt("ro.miui.notch", activity) == 1;
}
/**
* 小米刘海屏判断.
*
* @return 0 if it is not notch ; return 1 means notch
* @throws IllegalArgumentException if the key exceeds 32 characters
*/
public static int getInt(String key,Activity activity) {
public static int getInt(String key, Activity activity) {
int result = 0;
if (ROMUtil.isXiaomi()){
if (ROMUtil.isXiaomi()) {
try {
ClassLoader classLoader = activity.getClassLoader();
@SuppressWarnings("rawtypes")
Class SystemProperties = classLoader.loadClass("android.os.SystemProperties");
//参数类型
//参数类型
@SuppressWarnings("rawtypes")
Class[] paramTypes = new Class[2];
paramTypes[0] = String.class;
......@@ -175,23 +199,23 @@ public class ScreenUtil {
return result;
}
//其他安卓p的机子是否有刘海
@RequiresApi(api = Build.VERSION_CODES.P)
public static boolean isNotchP(Activity activity) {
DisplayCutout displayCutout = getDisplayCutout(activity);
if (displayCutout == null)
return false;
List<Rect> rects = displayCutout.getBoundingRects();
return rects == null || rects.size() == 0;
// if (rects == null || rects.size() == 0) {
// Log.e("TAG", "不是刘海屏");
// } else {
// Log.e("TAG", "刘海屏数量:" + rects.size());
// for (Rect rect : rects) {
// Log.e("TAG", "刘海屏区域:" + rect);
// //其他安卓p的机子是否有刘海
// @RequiresApi(api = Build.VERSION_CODES.P)
// public static boolean isNotchP(Activity activity) {
// DisplayCutout displayCutout = getDisplayCutout(activity);
// if (displayCutout == null)
// return false;
// List<Rect> rects = displayCutout.getBoundingRects();
// return rects == null || rects.size() == 0;
//// if (rects == null || rects.size() == 0) {
//// Log.e("TAG", "不是刘海屏");
//// } else {
//// Log.e("TAG", "刘海屏数量:" + rects.size());
//// for (Rect rect : rects) {
//// Log.e("TAG", "刘海屏区域:" + rect);
//// }
//// }
// }
// }
}
//获取oppo刘海高度
......@@ -221,7 +245,7 @@ public class ScreenUtil {
}
//获取华为刘海尺寸:width、height
//int[0]值为刘海宽度 int[1]值为刘海高度
//int[0]值为刘海宽度 int[1]值为刘海高度
public static int[] getNotchSizeAtHuawei(Context context) {
int[] ret = new int[]{0, 0};
try {
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<include
layout="@layout/content_toolbar"/>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textStyle="bold"
android:id="@+id/tv_log"
android:textColor="@color/white"
android:textSize="18sp"
android:padding="15dp"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment