添加调试模式设置功能
This commit is contained in:
		| @@ -29,7 +29,7 @@ android { | ||||
|         // versionName 更新后需要手动设置  | ||||
|         // .winboll/winbollBuildProps.properties 文件的 stageCount=0 | ||||
|         // Gradle编译环境下合起来的 versionName 就是 "${versionName}.0" | ||||
|         versionName "1.1"  | ||||
|         versionName "1.2"  | ||||
|         if(true) { | ||||
|             versionName = genVersionName("${versionName}") | ||||
|         } | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Tue Feb 04 08:46:51 HKT 2025 | ||||
| stageCount=4 | ||||
| #Wed Feb 05 23:09:41 GMT 2025 | ||||
| stageCount=0 | ||||
| libraryProject=libappbase | ||||
| baseVersion=1.1 | ||||
| publishVersion=1.1.3 | ||||
| buildCount=0 | ||||
| baseBetaVersion=1.1.4 | ||||
| baseVersion=1.2 | ||||
| publishVersion=1.2.0 | ||||
| buildCount=3 | ||||
| baseBetaVersion=1.2.1 | ||||
|   | ||||
| @@ -1,15 +1,23 @@ | ||||
| package cc.winboll.studio.appbase; | ||||
|   | ||||
| import android.app.Activity; | ||||
| import android.os.Bundle; | ||||
|  | ||||
| public class MainActivity extends Activity { | ||||
|       | ||||
|     @Override | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         setContentView(R.layout.activity_main); | ||||
|          | ||||
|     } | ||||
| 	 | ||||
| } | ||||
| package cc.winboll.studio.appbase; | ||||
|  | ||||
| import android.app.Activity; | ||||
| import android.os.Bundle; | ||||
| import android.view.View; | ||||
| import android.widget.CheckBox; | ||||
| import cc.winboll.studio.libappbase.GlobalApplication; | ||||
|  | ||||
| public class MainActivity extends Activity { | ||||
|  | ||||
|     @Override | ||||
|     protected void onCreate(Bundle savedInstanceState) { | ||||
|         super.onCreate(savedInstanceState); | ||||
|         setContentView(R.layout.activity_main); | ||||
|  | ||||
|         CheckBox cbIsDebugMode = findViewById(R.id.activitymainCheckBox1); | ||||
|         cbIsDebugMode.setChecked(GlobalApplication.isDebuging()); | ||||
|     } | ||||
|  | ||||
| 	public void onSwitchDebugMode(View view) { | ||||
|         GlobalApplication.setIsDebuging(this, ((CheckBox)view).isChecked()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -4,13 +4,36 @@ | ||||
| 	xmlns:app="http://schemas.android.com/apk/res-auto" | ||||
| 	android:layout_width="match_parent" | ||||
| 	android:layout_height="match_parent" | ||||
| 	android:orientation="vertical" | ||||
| 	android:gravity="center"> | ||||
|  | ||||
| 	<TextView | ||||
| 		android:layout_width="wrap_content" | ||||
| 		android:layout_height="wrap_content" | ||||
| 		android:text="Hello, WinBoll!" | ||||
| 		android:onClick="onHello"/> | ||||
| 		android:text="Hello, WinBoll!"/> | ||||
|  | ||||
| 	<LinearLayout | ||||
| 		android:orientation="horizontal" | ||||
| 		android:layout_width="match_parent" | ||||
| 		android:layout_height="wrap_content" | ||||
| 		android:gravity="right|center_vertical"> | ||||
|  | ||||
| 		<CheckBox | ||||
| 			android:layout_width="wrap_content" | ||||
| 			android:layout_height="wrap_content" | ||||
| 			android:text="Debug Mode" | ||||
| 			android:layout_weight="1.0" | ||||
| 			android:onClick="onSwitchDebugMode" | ||||
| 			android:id="@+id/activitymainCheckBox1"/> | ||||
|  | ||||
| 		<Button | ||||
| 			android:layout_width="wrap_content" | ||||
| 			android:layout_height="wrap_content" | ||||
| 			android:text="Test Application CrashReport" | ||||
| 			android:textAllCaps="false" | ||||
| 			android:onClick="onTestApplicationCrashReport"/> | ||||
|  | ||||
| 	</LinearLayout> | ||||
|  | ||||
| </LinearLayout> | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| #Created by .winboll/winboll_app_build.gradle | ||||
| #Tue Feb 04 08:46:36 HKT 2025 | ||||
| stageCount=4 | ||||
| #Wed Feb 05 23:09:41 GMT 2025 | ||||
| stageCount=0 | ||||
| libraryProject=libappbase | ||||
| baseVersion=1.1 | ||||
| publishVersion=1.1.3 | ||||
| buildCount=0 | ||||
| baseBetaVersion=1.1.4 | ||||
| baseVersion=1.2 | ||||
| publishVersion=1.2.0 | ||||
| buildCount=3 | ||||
| baseBetaVersion=1.2.1 | ||||
|   | ||||
| @@ -82,13 +82,14 @@ public final class CrashHandler { | ||||
|  | ||||
|                     StringBuilder sb = new StringBuilder(); | ||||
|                     sb.append("************* Crash Head ****************\n"); | ||||
|                     sb.append("Time Of Crash      : ").append(time).append("\n"); | ||||
|                     sb.append("Device Manufacturer: ").append(Build.MANUFACTURER).append("\n"); | ||||
|                     sb.append("Device Model       : ").append(Build.MODEL).append("\n"); | ||||
|                     sb.append("Android Version    : ").append(Build.VERSION.RELEASE).append("\n"); | ||||
|                     sb.append("Android SDK        : ").append(Build.VERSION.SDK_INT).append("\n"); | ||||
|                     sb.append("App VersionName    : ").append(versionName).append("\n"); | ||||
|                     sb.append("App VersionCode    : ").append(versionCode).append("\n"); | ||||
|                     sb.append("Time Of Crash                        : ").append(time).append("\n"); | ||||
|                     sb.append("Device Manufacturer                  : ").append(Build.MANUFACTURER).append("\n"); | ||||
|                     sb.append("Device Model                         : ").append(Build.MODEL).append("\n"); | ||||
|                     sb.append("Android Version                      : ").append(Build.VERSION.RELEASE).append("\n"); | ||||
|                     sb.append("Android SDK                          : ").append(Build.VERSION.SDK_INT).append("\n"); | ||||
|                     sb.append("App VersionName                      : ").append(versionName).append("\n"); | ||||
|                     sb.append("App VersionCode                      : ").append(versionCode).append("\n"); | ||||
|                     sb.append("AppBase GlobalApplication Debug Mode : ").append(GlobalApplication.isDebuging).append("\n"); | ||||
|                     sb.append("************* Crash Head ****************\n"); | ||||
|                     sb.append("\n").append(fullStackTrace); | ||||
|  | ||||
| @@ -115,6 +116,7 @@ public final class CrashHandler { | ||||
|                                 DEFAULT_UNCAUGHT_EXCEPTION_HANDLER.uncaughtException(thread, throwable); | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                 } | ||||
|  | ||||
|                 private void writeFile(File file, String content) throws IOException { | ||||
|   | ||||
| @@ -5,51 +5,46 @@ package cc.winboll.studio.libappbase; | ||||
|  * @Date 2025/01/05 10:10:23 | ||||
|  * @Describe 全局应用类 | ||||
|  */ | ||||
| import android.app.Activity; | ||||
| import android.app.Application; | ||||
| import android.content.ClipData; | ||||
| import android.content.ClipboardManager; | ||||
| import android.content.Context; | ||||
| import android.content.Intent; | ||||
| import android.content.pm.PackageInfo; | ||||
| import android.content.res.Resources; | ||||
| import android.graphics.Typeface; | ||||
| import android.os.Build; | ||||
| import android.os.Bundle; | ||||
| import android.content.SharedPreferences; | ||||
| import android.os.Handler; | ||||
| import android.os.Looper; | ||||
| import android.text.TextUtils; | ||||
| import android.util.Log; | ||||
| import android.view.Menu; | ||||
| import android.view.MenuItem; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.HorizontalScrollView; | ||||
| import android.widget.ScrollView; | ||||
| import android.widget.TextView; | ||||
| import android.widget.Toast; | ||||
| import java.io.ByteArrayInputStream; | ||||
| import java.io.ByteArrayOutputStream; | ||||
| import java.io.Closeable; | ||||
| import java.io.File; | ||||
| import java.io.FileInputStream; | ||||
| import java.io.FileOutputStream; | ||||
| import java.io.IOException; | ||||
| import java.io.InputStream; | ||||
| import java.io.OutputStream; | ||||
| import java.lang.Thread.UncaughtExceptionHandler; | ||||
| import java.text.DateFormat; | ||||
| import java.text.SimpleDateFormat; | ||||
| import java.util.Arrays; | ||||
| import java.util.Date; | ||||
| import java.util.LinkedHashMap; | ||||
| import java.util.concurrent.atomic.AtomicBoolean; | ||||
| import android.content.pm.ApplicationInfo; | ||||
| import android.content.res.AssetManager; | ||||
|  | ||||
| public class GlobalApplication extends Application { | ||||
|  | ||||
|     final static String PREFS = GlobalApplication.class.getName() + "PREFS"; | ||||
|     final static String PREFS_ISDEBUGING = "PREFS_ISDEBUGING"; | ||||
|  | ||||
|     private static Handler MAIN_HANDLER = new Handler(Looper.getMainLooper()); | ||||
|  | ||||
|     // 是否处于调试状态 | ||||
|     volatile static boolean isDebuging = false; | ||||
|  | ||||
|     public static void setIsDebuging(Context context, boolean isDebuging) { | ||||
|         GlobalApplication.isDebuging = isDebuging; | ||||
|         // 获取SharedPreferences实例 | ||||
|         SharedPreferences sharedPreferences = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE); | ||||
|         // 获取编辑器 | ||||
|         SharedPreferences.Editor editor = sharedPreferences.edit(); | ||||
|         // 保存数据 | ||||
|         editor.putBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging); | ||||
|         // 提交更改 | ||||
|         editor.apply(); | ||||
|     } | ||||
|  | ||||
|     public static boolean isDebuging() { | ||||
|         return isDebuging; | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public Context getApplicationContext() { | ||||
|         return super.getApplicationContext(); | ||||
| @@ -62,7 +57,13 @@ public class GlobalApplication extends Application { | ||||
|     @Override | ||||
|     public void onCreate() { | ||||
|         super.onCreate(); | ||||
|  | ||||
|         // 设置应用异常处理窗口 | ||||
|         CrashHandler.init(this); | ||||
|  | ||||
|         // 设置应用调试状态 | ||||
|         SharedPreferences sharedPreferences = getSharedPreferences(PREFS, Context.MODE_PRIVATE); | ||||
|         GlobalApplication.isDebuging = sharedPreferences.getBoolean(PREFS_ISDEBUGING, GlobalApplication.isDebuging); | ||||
|     } | ||||
|  | ||||
|     public static void write(InputStream input, OutputStream output) throws IOException { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 ZhanGSKen
					ZhanGSKen