reorganized the Debug screen and moved the log messages to a separate screen
This commit is contained in:
parent
3ecdd7020e
commit
1300f8b517
7 changed files with 129 additions and 112 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:tools="http://schemas.android.com/tools"
|
||||
android:versionCode="659"
|
||||
android:versionName="37.16"
|
||||
android:versionCode="672"
|
||||
android:versionName="37.29"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <!-- allows displaying notifications on Android >= 13 -->
|
||||
|
|
@ -54,6 +54,16 @@
|
|||
</intent-filter>
|
||||
</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
|
||||
android:excludeFromRecents="true"
|
||||
android:label=""
|
||||
|
|
|
|||
|
|
@ -1,62 +1,23 @@
|
|||
package io.github.sspanak.tt9.preferences;
|
||||
|
||||
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.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import io.github.sspanak.tt9.ui.WebViewActivity;
|
||||
import io.github.sspanak.tt9.util.Logger;
|
||||
|
||||
public class HelpActivity extends AppCompatActivity {
|
||||
public class HelpActivity extends WebViewActivity {
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
buildLayout();
|
||||
protected String getMimeType() {
|
||||
return "text/html";
|
||||
}
|
||||
|
||||
@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 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() {
|
||||
protected String getText() {
|
||||
AssetManager assets = getAssets();
|
||||
try {
|
||||
InputStream stream = assets.open("help.html");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
package io.github.sspanak.tt9.preferences.screens.debug;
|
||||
|
||||
import androidx.preference.SwitchPreferenceCompat;
|
||||
|
||||
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.preferences.PreferencesActivity;
|
||||
import io.github.sspanak.tt9.preferences.items.ItemText;
|
||||
|
|
@ -13,10 +10,6 @@ public class DebugScreen extends BaseScreenFragment {
|
|||
public static final String NAME = "Debug";
|
||||
|
||||
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(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 ItemExportLogcat(findPreference(ItemExportLogcat.NAME), activity)).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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,4 +62,8 @@ class SettingsHacks extends BaseSettings {
|
|||
defaultTime = DeviceInfo.isQinF21() ? 20 : defaultTime;
|
||||
return getStringifiedInt("pref_key_pad_debounce_time", defaultTime);
|
||||
}
|
||||
|
||||
public boolean getSystemLogs() {
|
||||
return prefs.getBoolean("pref_enable_system_logs", false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -1,43 +1,48 @@
|
|||
<?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
|
||||
app:key="pref_device_info"
|
||||
app:title="Device Info" />
|
||||
android:fragment="io.github.sspanak.tt9.preferences.screens.UsageStatsScreen"
|
||||
android:key="pref_slow_queries"
|
||||
android:title="@string/pref_category_usage_stats" />
|
||||
|
||||
<PreferenceCategory android:title="Hacks" android:singleLineTitle="true">
|
||||
<SwitchPreferenceCompat
|
||||
android:key="pref_demo_mode"
|
||||
android:title="Demo Mode" />
|
||||
|
||||
<DropDownPreference
|
||||
app:key="pref_input_handling_mode"
|
||||
app:title="Keypad Handling Mode" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:key="pref_demo_mode"
|
||||
app:title="Demo Mode" />
|
||||
|
||||
<Preference
|
||||
app:fragment="io.github.sspanak.tt9.preferences.UsageStatsScreen"
|
||||
app:key="pref_slow_queries"
|
||||
app:title="@string/pref_category_usage_stats" />
|
||||
android:key="pref_input_handling_mode"
|
||||
android:title="Keypad Handling Mode" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="Logging" android:singleLineTitle="true">
|
||||
<DropDownPreference
|
||||
app:key="pref_log_level"
|
||||
app:title="Log Level" />
|
||||
android:key="pref_log_level"
|
||||
android:title="Log Level" />
|
||||
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:key="pref_enable_system_logs"
|
||||
app:title="System Logs" />
|
||||
android:defaultValue="false"
|
||||
android:key="pref_enable_system_logs"
|
||||
android:title="System Logs" />
|
||||
|
||||
<Preference
|
||||
app:key="pref_export_logcat"
|
||||
app:title="Export Logs" />
|
||||
android:key="pref_export_logcat"
|
||||
android:title="Export Logs" />
|
||||
|
||||
<PreferenceCategory
|
||||
app:title="Recent Log Messages"
|
||||
app:singleLineTitle="true">
|
||||
<io.github.sspanak.tt9.preferences.custom.PreferencePlainText
|
||||
app:key="debug_logs_container"
|
||||
app:summary="--">
|
||||
</io.github.sspanak.tt9.preferences.custom.PreferencePlainText>
|
||||
<Preference
|
||||
android:key="screen_logs"
|
||||
android:title="Recent Log Messages...">
|
||||
<intent
|
||||
android:action="android.intent.action.VIEW"
|
||||
android:targetPackage="io.github.sspanak.tt9"
|
||||
android:targetClass="io.github.sspanak.tt9.preferences.LogsActivity" />
|
||||
</Preference>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue