1
0
Fork 0

reorganized the Debug screen and moved the log messages to a separate screen

This commit is contained in:
sspanak 2024-09-04 18:04:27 +03:00 committed by Dimo Karaivanov
parent 3ecdd7020e
commit 1300f8b517
7 changed files with 129 additions and 112 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:tools="http://schemas.android.com/tools" <manifest xmlns:tools="http://schemas.android.com/tools"
android:versionCode="659" android:versionCode="672"
android:versionName="37.16" android:versionName="37.29"
xmlns:android="http://schemas.android.com/apk/res/android"> xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <!-- allows displaying notifications on Android >= 13 --> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <!-- allows displaying notifications on Android >= 13 -->
@ -54,6 +54,16 @@
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:label="Log Messages"
android:name="io.github.sspanak.tt9.preferences.LogsActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity <activity
android:excludeFromRecents="true" android:excludeFromRecents="true"
android:label="" android:label=""

View file

@ -1,62 +1,23 @@
package io.github.sspanak.tt9.preferences; package io.github.sspanak.tt9.preferences;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.os.Bundle;
import android.util.Base64;
import android.webkit.WebView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import io.github.sspanak.tt9.ui.WebViewActivity;
import io.github.sspanak.tt9.util.Logger; import io.github.sspanak.tt9.util.Logger;
public class HelpActivity extends AppCompatActivity { public class HelpActivity extends WebViewActivity {
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected String getMimeType() {
super.onCreate(savedInstanceState); return "text/html";
buildLayout();
} }
@Override @Override
public boolean onSupportNavigateUp() { protected String getText() {
finish();
return true;
}
private void buildLayout() {
enableBackButton();
setContent();
}
private void enableBackButton() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
private void setContent() {
WebView container = new WebView(this);
// On API > 30 the WebView does not load the entire String with .loadData(),
// so we need to do this weird shit.
// The "app:" prefix is mandatory, otherwise the anchor links do not work.
// Reference: https://developer.android.com/develop/ui/views/layout/webapps/webview
String html = getHelpHtml();
String encodedHtml = "app:" + Base64.encodeToString(html.getBytes(), Base64.NO_PADDING);
container.loadDataWithBaseURL(encodedHtml, html, "text/html", "UTF-8", null);
setContentView(container);
}
private String getHelpHtml() {
AssetManager assets = getAssets(); AssetManager assets = getAssets();
try { try {
InputStream stream = assets.open("help.html"); InputStream stream = assets.open("help.html");

View file

@ -0,0 +1,19 @@
package io.github.sspanak.tt9.preferences;
import io.github.sspanak.tt9.db.customWords.LogcatExporter;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
import io.github.sspanak.tt9.ui.WebViewActivity;
public class LogsActivity extends WebViewActivity {
@Override
protected String getMimeType() {
return "text/plain";
}
@Override
protected String getText() {
boolean includeSystemLogs = new SettingsStore(this).getSystemLogs();
String logs = LogcatExporter.getLogs(includeSystemLogs).replace("\n", "\n\n");
return logs.isEmpty() ? "No Logs" : logs;
}
}

View file

@ -1,9 +1,6 @@
package io.github.sspanak.tt9.preferences.screens.debug; package io.github.sspanak.tt9.preferences.screens.debug;
import androidx.preference.SwitchPreferenceCompat;
import io.github.sspanak.tt9.R; import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.db.customWords.LogcatExporter;
import io.github.sspanak.tt9.hacks.DeviceInfo; import io.github.sspanak.tt9.hacks.DeviceInfo;
import io.github.sspanak.tt9.preferences.PreferencesActivity; import io.github.sspanak.tt9.preferences.PreferencesActivity;
import io.github.sspanak.tt9.preferences.items.ItemText; import io.github.sspanak.tt9.preferences.items.ItemText;
@ -13,10 +10,6 @@ public class DebugScreen extends BaseScreenFragment {
public static final String NAME = "Debug"; public static final String NAME = "Debug";
private static final String DEVICE_INFO_CONTAINER = "pref_device_info"; private static final String DEVICE_INFO_CONTAINER = "pref_device_info";
private static final String SYSTEM_LOGS_SWITCH = "pref_enable_system_logs";
private ItemText logsContainer;
public DebugScreen() { init(); } public DebugScreen() { init(); }
public DebugScreen(PreferencesActivity activity) { init(activity); } public DebugScreen(PreferencesActivity activity) { init(activity); }
@ -32,35 +25,7 @@ public class DebugScreen extends BaseScreenFragment {
(new ItemText(activity, findPreference(DEVICE_INFO_CONTAINER))).populate(new DeviceInfo().toString()).enableClickHandler(); (new ItemText(activity, findPreference(DEVICE_INFO_CONTAINER))).populate(new DeviceInfo().toString()).enableClickHandler();
(new ItemExportLogcat(findPreference(ItemExportLogcat.NAME), activity)).enableClickHandler(); (new ItemExportLogcat(findPreference(ItemExportLogcat.NAME), activity)).enableClickHandler();
(new ItemDemoMode(findPreference(ItemDemoMode.NAME), activity)).populate().enableClickHandler(); (new ItemDemoMode(findPreference(ItemDemoMode.NAME), activity)).populate().enableClickHandler();
initSystemLogsSwitch();
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
boolean includeSystemLogs = systemLogs != null && systemLogs.isChecked();
printLogs(includeSystemLogs);
resetFontSize(false); resetFontSize(false);
} }
private void initSystemLogsSwitch() {
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
if (systemLogs != null) {
systemLogs.setOnPreferenceChangeListener((p, newValue) -> {
printLogs((boolean) newValue);
return true;
});
}
}
private void printLogs(boolean includeSystemLogs) {
if (logsContainer == null) {
logsContainer = new ItemText(activity, findPreference("debug_logs_container"));
logsContainer.enableClickHandler();
}
String logs = LogcatExporter.getLogs(includeSystemLogs).replace("\n", "\n\n");
if (logs.isEmpty()) {
logs = "No Logs";
}
logsContainer.populate(logs);
}
} }

View file

@ -62,4 +62,8 @@ class SettingsHacks extends BaseSettings {
defaultTime = DeviceInfo.isQinF21() ? 20 : defaultTime; defaultTime = DeviceInfo.isQinF21() ? 20 : defaultTime;
return getStringifiedInt("pref_key_pad_debounce_time", defaultTime); return getStringifiedInt("pref_key_pad_debounce_time", defaultTime);
} }
public boolean getSystemLogs() {
return prefs.getBoolean("pref_enable_system_logs", false);
}
} }

View file

@ -0,0 +1,53 @@
package io.github.sspanak.tt9.ui;
import android.os.Bundle;
import android.util.Base64;
import android.webkit.WebView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
abstract public class WebViewActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
buildLayout();
}
@Override
public boolean onSupportNavigateUp() {
finish();
return true;
}
private void buildLayout() {
enableBackButton();
setContent();
}
private void enableBackButton() {
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
private void setContent() {
WebView container = new WebView(this);
// On API > 30 the WebView does not load the entire String with .loadData(),
// so we need to do this weird shit.
// The "app:" prefix is mandatory, otherwise the anchor links do not work.
// Reference: https://developer.android.com/develop/ui/views/layout/webapps/webview
String text = getText();
String encodedHtml = "app:" + Base64.encodeToString(text.getBytes(), Base64.NO_PADDING);
container.loadDataWithBaseURL(encodedHtml, text, getMimeType(), "UTF-8", null);
setContentView(container);
}
abstract protected String getText();
abstract protected String getMimeType();
}

View file

@ -1,43 +1,48 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto" app:orderingFromXml="true"> <PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:orderingFromXml="true">
<Preference
android:key="pref_device_info"
android:title="Device Info" />
<Preference <Preference
app:key="pref_device_info" android:fragment="io.github.sspanak.tt9.preferences.screens.UsageStatsScreen"
app:title="Device Info" /> android:key="pref_slow_queries"
android:title="@string/pref_category_usage_stats" />
<DropDownPreference <PreferenceCategory android:title="Hacks" android:singleLineTitle="true">
app:key="pref_input_handling_mode" <SwitchPreferenceCompat
app:title="Keypad Handling Mode" /> android:key="pref_demo_mode"
android:title="Demo Mode" />
<SwitchPreferenceCompat <DropDownPreference
app:key="pref_demo_mode" android:key="pref_input_handling_mode"
app:title="Demo Mode" /> android:title="Keypad Handling Mode" />
</PreferenceCategory>
<Preference <PreferenceCategory android:title="Logging" android:singleLineTitle="true">
app:fragment="io.github.sspanak.tt9.preferences.UsageStatsScreen" <DropDownPreference
app:key="pref_slow_queries" android:key="pref_log_level"
app:title="@string/pref_category_usage_stats" /> android:title="Log Level" />
<DropDownPreference <SwitchPreferenceCompat
app:key="pref_log_level" android:defaultValue="false"
app:title="Log Level" /> android:key="pref_enable_system_logs"
android:title="System Logs" />
<SwitchPreferenceCompat <Preference
app:defaultValue="false" android:key="pref_export_logcat"
app:key="pref_enable_system_logs" android:title="Export Logs" />
app:title="System Logs" />
<Preference <Preference
app:key="pref_export_logcat" android:key="screen_logs"
app:title="Export Logs" /> android:title="Recent Log Messages...">
<intent
<PreferenceCategory android:action="android.intent.action.VIEW"
app:title="Recent Log Messages" android:targetPackage="io.github.sspanak.tt9"
app:singleLineTitle="true"> android:targetClass="io.github.sspanak.tt9.preferences.LogsActivity" />
<io.github.sspanak.tt9.preferences.custom.PreferencePlainText </Preference>
app:key="debug_logs_container"
app:summary="--">
</io.github.sspanak.tt9.preferences.custom.PreferencePlainText>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>