mirror of
https://gitea.winboll.cc/ZhanGSKen/MyWinBoLL.git
synced 2026-08-14 13:37:11 +08:00
refactor: 精简调试工具按钮组
移除冗余按钮,仅保留测试崩溃和布局草稿两个功能: - 移除:清除数据、查看SP、查看日志、重启服务、应用信息 - 测试崩溃改为getString循环触发崩溃
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Sat Jul 18 20:10:18 CST 2026
|
||||
#Sun Jul 19 04:13:23 CST 2026
|
||||
stageCount=11
|
||||
libraryProject=
|
||||
baseVersion=15.20
|
||||
publishVersion=15.20.10
|
||||
buildCount=7
|
||||
buildCount=12
|
||||
baseBetaVersion=15.20.11
|
||||
|
||||
@@ -1,23 +1,14 @@
|
||||
package cc.winboll.studio.contacts.views;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Toast;
|
||||
import cc.winboll.studio.contacts.R;
|
||||
import cc.winboll.studio.contacts.services.MainService;
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.ToastUtils;
|
||||
import cc.winboll.studio.libappbase.utils.CrashHandleNotifyUtils;
|
||||
import cc.winboll.studio.libappbase.CrashActivity;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@qq.com>
|
||||
@@ -55,28 +46,9 @@ public class DebugToolButtonsView extends LinearLayout {
|
||||
}
|
||||
|
||||
private void initButtons() {
|
||||
Button btnClearData = (Button) findViewById(R.id.btn_debug_clear_data);
|
||||
Button btnShowSp = (Button) findViewById(R.id.btn_debug_show_sp);
|
||||
Button btnCrash = (Button) findViewById(R.id.btn_debug_crash);
|
||||
Button btnShowLog = (Button) findViewById(R.id.btn_debug_show_log);
|
||||
Button btnRestartService = (Button) findViewById(R.id.btn_debug_restart_service);
|
||||
Button btnAppInfo = (Button) findViewById(R.id.btn_debug_app_info);
|
||||
Button btnLayoutPreview = (Button) findViewById(R.id.btn_debug_layout_preview);
|
||||
|
||||
btnClearData.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onClearData();
|
||||
}
|
||||
});
|
||||
|
||||
btnShowSp.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onShowSp();
|
||||
}
|
||||
});
|
||||
|
||||
btnCrash.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -84,27 +56,6 @@ public class DebugToolButtonsView extends LinearLayout {
|
||||
}
|
||||
});
|
||||
|
||||
btnShowLog.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onShowLog();
|
||||
}
|
||||
});
|
||||
|
||||
btnRestartService.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onRestartService();
|
||||
}
|
||||
});
|
||||
|
||||
btnAppInfo.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onShowAppInfo();
|
||||
}
|
||||
});
|
||||
|
||||
btnLayoutPreview.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
@@ -113,97 +64,10 @@ public class DebugToolButtonsView extends LinearLayout {
|
||||
});
|
||||
}
|
||||
|
||||
private void onClearData() {
|
||||
LogUtils.d(TAG, "onClearData: 清除应用数据");
|
||||
try {
|
||||
mContext.deleteDatabase("contacts.db");
|
||||
SharedPreferences sp = mContext.getSharedPreferences("WinBoLL_SP_CONFIG", Context.MODE_PRIVATE);
|
||||
sp.edit().clear().apply();
|
||||
ToastUtils.show("应用数据已清除");
|
||||
LogUtils.d(TAG, "onClearData: 数据清除完成");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onClearData: 清除数据失败", e);
|
||||
ToastUtils.show("清除失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void onShowSp() {
|
||||
LogUtils.d(TAG, "onShowSp: 查看SharedPreferences");
|
||||
try {
|
||||
SharedPreferences sp = mContext.getSharedPreferences("WinBoLL_SP_CONFIG", Context.MODE_PRIVATE);
|
||||
java.util.Map<String, ?> allEntries = sp.getAll();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("WinBoLL_SP_CONFIG:\n");
|
||||
for (java.util.Map.Entry<String, ?> entry : allEntries.entrySet()) {
|
||||
sb.append(entry.getKey()).append(" = ").append(entry.getValue()).append("\n");
|
||||
}
|
||||
if (allEntries.isEmpty()) {
|
||||
sb.append("(空)");
|
||||
}
|
||||
ToastUtils.show(sb.toString());
|
||||
LogUtils.d(TAG, "onShowSp: SP内容已显示,共" + allEntries.size() + "条");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onShowSp: 读取SP失败", e);
|
||||
ToastUtils.show("读取失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void onTestCrash() {
|
||||
LogUtils.d(TAG, "onTestCrash: 触发测试崩溃");
|
||||
try {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
pw.close();
|
||||
String stackTraceStr = sw.toString();
|
||||
CrashHandleNotifyUtils.handleUncaughtException(
|
||||
(Application) mContext.getApplicationContext(),
|
||||
mContext.getPackageName(),
|
||||
"DebugToolButtonsView - 手动触发测试崩溃\n" + stackTraceStr,
|
||||
CrashActivity.class
|
||||
);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onTestCrash: 触发崩溃失败", e);
|
||||
throw new RuntimeException("DebugToolButtonsView 测试崩溃");
|
||||
}
|
||||
}
|
||||
|
||||
private void onShowLog() {
|
||||
LogUtils.d(TAG, "onShowLog: 跳转日志页面");
|
||||
try {
|
||||
Intent intent = new Intent();
|
||||
intent.setClassName(mContext, "cc.winboll.studio.libappbase.LogActivity");
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onShowLog: 跳转日志页面失败", e);
|
||||
ToastUtils.show("跳转失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void onRestartService() {
|
||||
LogUtils.d(TAG, "onRestartService: 重启主服务");
|
||||
try {
|
||||
MainService.restartMainService(mContext);
|
||||
ToastUtils.show("主服务已重启");
|
||||
LogUtils.d(TAG, "onRestartService: 主服务重启完成");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onRestartService: 重启服务失败", e);
|
||||
ToastUtils.show("重启失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void onShowAppInfo() {
|
||||
LogUtils.d(TAG, "onShowAppInfo: 显示应用信息");
|
||||
try {
|
||||
String pkgName = mContext.getPackageName();
|
||||
int versionCode = mContext.getPackageManager().getPackageInfo(pkgName, 0).versionCode;
|
||||
String versionName = mContext.getPackageManager().getPackageInfo(pkgName, 0).versionName;
|
||||
String info = "包名: " + pkgName + "\n版本: " + versionName + " (" + versionCode + ")";
|
||||
ToastUtils.show(info);
|
||||
LogUtils.d(TAG, "onShowAppInfo: " + info);
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onShowAppInfo: 获取应用信息失败", e);
|
||||
ToastUtils.show("获取信息失败: " + e.getMessage());
|
||||
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i++) {
|
||||
((android.app.Activity) mContext).getString(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +81,6 @@ public class DebugToolButtonsView extends LinearLayout {
|
||||
LogUtils.d(TAG, "onOpenLayoutPreview: 跳转成功");
|
||||
} catch (Exception e) {
|
||||
LogUtils.e(TAG, "onOpenLayoutPreview: 跳转失败", e);
|
||||
ToastUtils.show("跳转失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,22 +24,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_clear_data"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="清除数据"
|
||||
android:textSize="12sp"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_show_sp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="查看SP"
|
||||
android:textSize="12sp"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_crash"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -48,46 +32,6 @@
|
||||
android:textSize="12sp"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_show_log"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="查看日志"
|
||||
android:textSize="12sp"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_restart_service"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="重启服务"
|
||||
android:textSize="12sp"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_app_info"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="应用信息"
|
||||
android:textSize="12sp"
|
||||
android:layout_margin="2dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:id="@+id/btn_debug_layout_preview"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user