Skip to content

Commit

Permalink
Merge pull request #14 from kadbbz/dev-1.14.2
Browse files Browse the repository at this point in the history
1.14.2
  • Loading branch information
kadbbz authored Jan 12, 2024
2 parents e223c03 + aa2340d commit 7b19351
Show file tree
Hide file tree
Showing 39 changed files with 880 additions and 706 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
//noinspection ExpiredTargetSdkVersion
targetSdk 29 // 超过29后,文件权限要大改
versionCode 4
versionName '1.14.1-release'
versionName '1.14.2-release'

manifestPlaceholders = [
JPUSH_PKGNAME : applicationId,
Expand Down Expand Up @@ -58,4 +58,5 @@ dependencies {
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1' // 预览PDF
implementation 'cn.jiguang.sdk:jpush:5.2.0' // 极光推送
implementation 'com.github.Jasonchenlijian:FastBle:2.4.0' // BLE设备
implementation 'com.elvishew:xlog:1.11.0' // 日志文件记录
}
2 changes: 1 addition & 1 deletion app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"filters": [],
"attributes": [],
"versionCode": 4,
"versionName": "1.14.0-release",
"versionName": "1.14.2-release",
"outputFile": "app-release.apk"
}
],
Expand Down
18 changes: 3 additions & 15 deletions app/src/main/java/com/huozige/lab/container/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
*/
public class BaseActivity extends AppCompatActivity {

private ConfigManager configManager;

public BaseActivity(){
super();

configManager = new ConfigManager(this);
}

/**
Expand All @@ -34,19 +30,19 @@ public void refreshActionBar(){
ActionBar actionBar = getSupportActionBar();

if(actionBar!=null){
if(!getConfigManager().getActionBarVisible()){
if(!ConfigManager.getInstance().getActionBarVisible()){
// 隐藏ActionBar
actionBar.hide();
}else{

// 设置ActionBar的颜色
actionBar.setBackgroundDrawable(new ColorDrawable(getConfigManager().getTCD()));
actionBar.setBackgroundDrawable(new ColorDrawable(ConfigManager.getInstance().getTCD()));

// 设置状态栏颜色,做沉浸式体验
Window window = this.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(getConfigManager().getTCD());
window.setStatusBarColor(ConfigManager.getInstance().getTCD());
}
}

Expand All @@ -63,12 +59,4 @@ public void onResume() {

refreshActionBar();
}

public ConfigManager getConfigManager() {
return configManager;
}

public void setConfigManager(ConfigManager configManager) {
this.configManager = configManager;
}
}
104 changes: 95 additions & 9 deletions app/src/main/java/com/huozige/lab/container/HACApplication.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
package com.huozige.lab.container;

import android.app.Application;
import android.util.Log;
import android.os.Build;
import android.os.Environment;

import com.elvishew.xlog.LogConfiguration;
import com.elvishew.xlog.LogLevel;
import com.elvishew.xlog.XLog;
import com.elvishew.xlog.flattener.ClassicFlattener;
import com.elvishew.xlog.printer.AndroidPrinter;
import com.elvishew.xlog.printer.Printer;
import com.elvishew.xlog.printer.file.FilePrinter;
import com.elvishew.xlog.printer.file.clean.FileLastModifiedCleanStrategy;
import com.elvishew.xlog.printer.file.naming.FileNameGenerator;
import com.elvishew.xlog.printer.file.writer.SimpleWriter;
import com.huozige.lab.container.utilities.ConfigManager;
import com.huozige.lab.container.utilities.MiscUtilities;

import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import cn.jpush.android.api.JPushInterface;
import io.realm.Realm;
Expand All @@ -12,19 +30,78 @@
*/
public class HACApplication extends Application {

final static String LOG_TAG="HACApplication";
static final long MAX_TIME = 1000 * 60 * 60 * 24 * 7; // 7 days
final static String LOG_TAG = "HAC_Application";

@Override
public void onCreate() {
super.onCreate();

Log.v(LOG_TAG,">>>>>>> 应用启动 <<<<<<<");
ConfigManager.init(this);

initLogger();

XLog.v(">>>>>>> 应用启动 <<<<<<<");

initCrashHandler();

XLog.v("全局异常处理挂载完成");

initReadlm();

XLog.v("Realm初始化完成");

JPushInterface.init(HACApplication.this);

XLog.v("JPush初始化完成");

}

private void initLogger() {
// 初始化日志记录器
LogConfiguration logConfig = new LogConfiguration.Builder()
.logLevel(BuildConfig.DEBUG ? LogLevel.ALL // Specify log level, logs below this level won't be printed, default: LogLevel.ALL
: ConfigManager.getInstance().getShouldLogAllEntry() ? LogLevel.ALL : LogLevel.ERROR)
.tag(LOG_TAG) // Specify TAG, default: "X-LOG"
.enableThreadInfo() // Enable thread info, disabled by default
.enableStackTrace(2) // Enable stack trace info with depth 2, disabled by default
.enableBorder() // Enable border, disabled by default
.build();
Printer androidPrinter = new AndroidPrinter(true); // Printer that print the log using android.util.Log
Printer filePrinter = new FilePrinter // Printer that print(save) the log to file
.Builder(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getPath())
.fileNameGenerator(new HACFileNameGenerator())
.cleanStrategy(new FileLastModifiedCleanStrategy(MAX_TIME))
.flattener(new ClassicFlattener())
.writer(new SimpleWriter() {
@Override
public void onNewFileCreated(File file) {
super.onNewFileCreated(file);
final String header = "\n>>>>>>>>>>>>>>>> File Header >>>>>>>>>>>>>>>>" +
"\nDevice Manufacturer: " + Build.MANUFACTURER +
"\nDevice Model : " + Build.MODEL +
"\nAndroid Version : " + Build.VERSION.RELEASE +
"\nAndroid SDK : " + Build.VERSION.SDK_INT +
"\nApp VersionName : " + MiscUtilities.getPackageVersionName(HACApplication.this) +
"\nWebView Version : " + MiscUtilities.getWebViewVersionName() +
"\n<<<<<<<<<<<<<<<< File Header <<<<<<<<<<<<<<<<\n\n";
appendLog(header);
}
})
.build();

XLog.init(
logConfig,
androidPrinter,
filePrinter);
}

private void initCrashHandler() {
HACCrashHandler handler = new HACCrashHandler(this);
Thread.setDefaultUncaughtExceptionHandler(handler);
}

Log.v(LOG_TAG,"全局异常处理挂载完成");

private void initReadlm() {
// 初始化Realm
Realm.init(this);

Expand All @@ -33,12 +110,21 @@ public void onCreate() {
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(config);
}

Log.v(LOG_TAG,"Realm初始化完成");

JPushInterface.init(this);
public static class HACFileNameGenerator implements FileNameGenerator {

Log.v(LOG_TAG,"JPush初始化完成");
@Override
public boolean isFileNameChangeable() {
return true;
}

/**
* Generate a file name which represent a specific log level.
*/
@Override
public String generateFileName(int logLevel, long timestamp) {
return "HAC_Log_" + LogLevel.getLevelName(logLevel) + "_"+ LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")) + ".txt";
}
}
}
19 changes: 10 additions & 9 deletions app/src/main/java/com/huozige/lab/container/HACCrashHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import android.app.Application;
import android.content.Intent;
import android.util.Log;

import com.elvishew.xlog.XLog;

import android.widget.Toast;

import androidx.annotation.NonNull;
Expand All @@ -12,26 +14,25 @@
*/
public class HACCrashHandler implements Thread.UncaughtExceptionHandler {

final static String LOG_TAG="HACCrashHandler";

Application _context;

public HACCrashHandler(Application context){
public HACCrashHandler(Application context) {
_context = context;
}

@Override
public void uncaughtException(@NonNull Thread thread, @NonNull Throwable throwable) {

Log.e(LOG_TAG,"出现未捕获的异常:"+ throwable);
XLog.e("出现未捕获的异常:" + throwable.getMessage(), throwable);

String message = "应用出现严重错误,请拍摄本界面或截屏后,与技术支持人员联系。";
message+="\r\n\n";
message+=throwable.getMessage();
message+="\r\n";
message+=throwable.toString();
message += "\r\n\n";
message += throwable.getMessage();
message += "\r\n";
message += throwable.toString();

Toast.makeText(this._context,message,Toast.LENGTH_LONG).show();
Toast.makeText(this._context, message, Toast.LENGTH_LONG).show();

Intent intent = new Intent(_context, ShowErrorActivity.class);
intent.putExtra(ShowErrorActivity.EXTRA_KEY_MESSAGE, message);
Expand Down
Loading

0 comments on commit 7b19351

Please sign in to comment.