Compare commits
6 Commits
appbase-v1
...
appbase-v1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5768881a47 | ||
|
|
6e02c130b2 | ||
|
|
fb9443bbc7 | ||
|
|
bfc1180822 | ||
|
|
ee52a6c28c | ||
|
|
2f72f1795e |
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Feb 09 11:40:48 HKT 2025
|
||||
stageCount=2
|
||||
#Sun Feb 09 15:09:34 HKT 2025
|
||||
stageCount=4
|
||||
libraryProject=libappbase
|
||||
baseVersion=1.2
|
||||
publishVersion=1.2.1
|
||||
publishVersion=1.2.3
|
||||
buildCount=0
|
||||
baseBetaVersion=1.2.2
|
||||
baseBetaVersion=1.2.4
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sun Feb 09 11:40:48 HKT 2025
|
||||
stageCount=2
|
||||
#Sun Feb 09 15:09:34 HKT 2025
|
||||
stageCount=4
|
||||
libraryProject=libappbase
|
||||
baseVersion=1.2
|
||||
publishVersion=1.2.1
|
||||
publishVersion=1.2.3
|
||||
buildCount=0
|
||||
baseBetaVersion=1.2.2
|
||||
baseBetaVersion=1.2.4
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
||||
|
||||
T beanTemp = clazz.newInstance();
|
||||
String szBeanSimpleName = beanTemp.getName();
|
||||
String szListJson = FileUtils.readStringFromFile(szFilePath);
|
||||
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
StringReader stringReader = new StringReader(szListJson);
|
||||
JsonReader jsonReader = new JsonReader(stringReader);
|
||||
jsonReader.beginArray();
|
||||
@@ -204,7 +204,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
||||
try {
|
||||
File fTemp = new File(szFilePath);
|
||||
if (fTemp.exists()) {
|
||||
T beanTemp = clazz.newInstance();String szJson = FileUtils.readStringFromFile(szFilePath);
|
||||
T beanTemp = clazz.newInstance();String szJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
return beanTemp.parseStringToBean(szJson, clazz);
|
||||
}
|
||||
} catch (InstantiationException e) {
|
||||
@@ -226,7 +226,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
||||
public static <T extends BaseBean> boolean saveBeanToFile(String szFilePath, T bean) {
|
||||
try {
|
||||
String szJson = bean.toString();
|
||||
FileUtils.writeStringToFile(szFilePath, szJson);
|
||||
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
@@ -248,7 +248,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
||||
try {
|
||||
File fTemp = new File(szFilePath);
|
||||
if (fTemp.exists()) {
|
||||
String szListJson = FileUtils.readStringFromFile(szFilePath);
|
||||
String szListJson = UTF8FileUtils.readStringFromFile(szFilePath);
|
||||
return parseStringToBeanList(szListJson, beanList, clazz);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@@ -272,7 +272,7 @@ public abstract class BaseBean<T extends BaseBean> {
|
||||
public static <T extends BaseBean> boolean saveBeanListToFile(String szFilePath, ArrayList<T> beanList) {
|
||||
try {
|
||||
String szJson = toStringByBeanList(beanList);
|
||||
FileUtils.writeStringToFile(szFilePath, szJson);
|
||||
UTF8FileUtils.writeStringToFile(szFilePath, szJson);
|
||||
//LogUtils.d(TAG, "FileUtil.writeFile beanList.size() is " + Integer.toString(beanList.size()));
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -50,11 +50,11 @@ import java.util.Locale;
|
||||
public final class CrashHandler {
|
||||
|
||||
public static final String TAG = "CrashHandler";
|
||||
|
||||
|
||||
public static final String TITTLE = "CrashReport";
|
||||
|
||||
private static final String EXTRA_CRASH_INFO = "crashInfo";
|
||||
|
||||
|
||||
final static String PREFS = CrashHandler.class.getName() + "PREFS";
|
||||
final static String PREFS_CRASHHANDLER_ISCRASHHAPPEN = "PREFS_CRASHHANDLER_ISCRASHHAPPEN";
|
||||
|
||||
@@ -130,7 +130,6 @@ public final class CrashHandler {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: ");
|
||||
if (AppCrashSafetyWire.getInstance().isAppCrashSafetyWireOK()) {
|
||||
LogUtils.d(TAG, "gotoCrashActiviy: isAppCrashSafetyWireOK");
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(app);
|
||||
intent.setClass(app, GlobalCrashActiviy.class);
|
||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
||||
// 如果发生了 CrashHandler 内部崩溃, 就调用基础的应用崩溃显示类
|
||||
@@ -141,10 +140,9 @@ public final class CrashHandler {
|
||||
// 正常状态调用进阶的应用崩溃显示页
|
||||
intent.setClass(app, CrashActiviy.class);
|
||||
intent.putExtra(EXTRA_CRASH_INFO, errorLog);
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// intent.setClass(app, CrashActiviy.class);
|
||||
// intent.putExtra(CrashActiviy.EXTRA_CRASH_INFO, errorLog);
|
||||
@@ -330,23 +328,19 @@ public final class CrashHandler {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
// 进程持续运行时,恢复保险丝熔断值
|
||||
//Resume to maximum
|
||||
resumeToMaximumImmediately();
|
||||
// LogUtils.d(TAG, "postCrashSafetyWire Resume to maximum");
|
||||
// while (resumeToMaximum(currentSafetyLevel + 1)) {
|
||||
// try {
|
||||
// Thread.sleep(1000);
|
||||
// } catch (InterruptedException e) {
|
||||
// LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
// }
|
||||
// }
|
||||
LogUtils.d(TAG, "Handler run()");
|
||||
if (!AppCrashSafetyWire.getInstance().isSafetyWireWorking(currentSafetyLevel - 1)) {
|
||||
// 如果下一次应用崩溃时,保险丝熔断,则先恢复保险丝满能状态
|
||||
// 进程持续运行时,恢复保险丝熔断值
|
||||
//Resume to maximum
|
||||
AppCrashSafetyWire.getInstance().resumeToMaximumImmediately();
|
||||
LogUtils.d(TAG, "postResumeCrashSafetyWireHandler");
|
||||
}
|
||||
}
|
||||
}, 1000);
|
||||
}, 500);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static String getAppName(Context context) {
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
try {
|
||||
@@ -368,7 +362,8 @@ public final class CrashHandler {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
||||
setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
|
||||
setContentView: {
|
||||
@@ -388,7 +383,7 @@ public final class CrashHandler {
|
||||
contentView.addView(hw, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
setContentView(contentView);
|
||||
getActionBar().setTitle(TITTLE);
|
||||
getActionBar().setSubtitle("GlobalCrashActiviy Error");
|
||||
getActionBar().setSubtitle(GlobalApplication.class.getSimpleName() + " Error");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,6 +452,8 @@ public final class CrashHandler {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
AppCrashSafetyWire.getInstance().postResumeCrashSafetyWireHandler(getApplicationContext());
|
||||
|
||||
mLog = getIntent().getStringExtra(EXTRA_CRASH_INFO);
|
||||
setTheme(android.R.style.Theme_DeviceDefault_NoActionBar);
|
||||
// TypedArray a = obtainStyledAttributes(attrs, R.styleable.ASupportToolbar, R.attr.aSupportToolbar, 0);
|
||||
@@ -466,7 +463,7 @@ public final class CrashHandler {
|
||||
// mEndColor = a.getColor(R.styleable.ASupportToolbar_attrASupportToolbarEndColor, Color.YELLOW);
|
||||
// // 返回一个绑定资源结束的信号给资源
|
||||
// a.recycle();
|
||||
|
||||
|
||||
setContentView: {
|
||||
// LinearLayout contentView = new LinearLayout(this);
|
||||
// contentView.setOrientation(LinearLayout.VERTICAL);
|
||||
@@ -518,7 +515,7 @@ public final class CrashHandler {
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
getActionBar().setTitle(TITTLE);
|
||||
getActionBar().setSubtitle(getAppName(getApplicationContext()));
|
||||
}
|
||||
|
||||
@@ -1,120 +0,0 @@
|
||||
package cc.winboll.studio.libappbase;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@QQ.COM
|
||||
* @Date 2024/07/19 14:30:57
|
||||
* @Describe 文件工具类
|
||||
*/
|
||||
import android.content.Context;
|
||||
import android.content.res.AssetManager;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
public static final String TAG = "FileUtils";
|
||||
|
||||
public static void copyAssetsToSD(Context context, String szSrcAssets, String szDstSD) {
|
||||
LogUtils.d(TAG, "copyAssetsToSD [" + szSrcAssets + "] to [" + szDstSD + "]");
|
||||
AssetManager assetManager = context.getAssets();
|
||||
InputStream inputStream = null;
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
inputStream = assetManager.open(szSrcAssets);
|
||||
File outputFile = new File(szDstSD);
|
||||
outputStream = new FileOutputStream(outputFile);
|
||||
byte[] buffer = new byte[1024];
|
||||
int length = 0;
|
||||
while ((length = inputStream.read(buffer)) > 0) {
|
||||
outputStream.write(buffer, 0, length);
|
||||
}
|
||||
outputStream.flush();
|
||||
LogUtils.d(TAG, "copyAssetsToSD done.");
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e.getMessage(), Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// 把字符串写入文件,指定 UTF-8 编码
|
||||
//
|
||||
public static void writeStringToFile(String szFilePath, String szContent) throws IOException {
|
||||
File file = new File(szFilePath);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
||||
writer.write(szContent);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
//
|
||||
// 读取文件到字符串,指定 UTF-8 编码
|
||||
//
|
||||
public static String readStringFromFile(String szFilePath) throws IOException {
|
||||
File file = new File(szFilePath);
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
StringBuilder content = new StringBuilder();
|
||||
int character;
|
||||
while ((character = reader.read()) != -1) {
|
||||
content.append((char) character);
|
||||
}
|
||||
reader.close();
|
||||
return content.toString();
|
||||
}
|
||||
|
||||
public static boolean copyFile(File srcFile, File dstFile) {
|
||||
if (!srcFile.exists()) {
|
||||
LogUtils.d(TAG, "The original file does not exist.");
|
||||
} else {
|
||||
try {
|
||||
// 源文件路径
|
||||
Path sourcePath = Paths.get(srcFile.getPath());
|
||||
// 目标文件路径
|
||||
Path destPath = Paths.get(dstFile.getPath());
|
||||
// 建立目标父级文件夹
|
||||
if (!dstFile.getParentFile().exists()) {
|
||||
dstFile.getParentFile().mkdirs();
|
||||
}
|
||||
// 删除旧的目标文件
|
||||
if (dstFile.exists()) {
|
||||
dstFile.delete();
|
||||
}
|
||||
// 拷贝文件
|
||||
Files.copy(sourcePath, destPath);
|
||||
LogUtils.d(TAG, "File copy successfully.");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -360,7 +360,7 @@ public class LogUtils {
|
||||
public static void cleanLog() {
|
||||
if (_mfLogCatchFile.exists()) {
|
||||
try {
|
||||
FileUtils.writeStringToFile(_mfLogCatchFile.getPath(), "");
|
||||
UTF8FileUtils.writeStringToFile(_mfLogCatchFile.getPath(), "");
|
||||
//LogUtils.d(TAG, "cleanLog");
|
||||
} catch (IOException e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package cc.winboll.studio.libappbase;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen@QQ.COM
|
||||
* @Date 2024/07/19 14:30:57
|
||||
* @Describe UTF-8编码文件工具类
|
||||
*/
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class UTF8FileUtils {
|
||||
|
||||
public static final String TAG = "FileUtils";
|
||||
|
||||
//
|
||||
// 把字符串写入文件,指定 UTF-8 编码
|
||||
//
|
||||
public static void writeStringToFile(String szFilePath, String szContent) throws IOException {
|
||||
File file = new File(szFilePath);
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
||||
writer.write(szContent);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
//
|
||||
// 读取文件到字符串,指定 UTF-8 编码
|
||||
//
|
||||
public static String readStringFromFile(String szFilePath) throws IOException {
|
||||
File file = new File(szFilePath);
|
||||
FileInputStream inputStream = new FileInputStream(file);
|
||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||
StringBuilder content = new StringBuilder();
|
||||
int character;
|
||||
while ((character = reader.read()) != -1) {
|
||||
content.append((char) character);
|
||||
}
|
||||
reader.close();
|
||||
return content.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user