it is now possible to copy the debug logs by clicking them
This commit is contained in:
parent
312a6734d5
commit
bd675be3a2
1 changed files with 36 additions and 6 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
package io.github.sspanak.tt9.preferences.screens;
|
package io.github.sspanak.tt9.preferences.screens;
|
||||||
|
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.ClipboardManager;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
import androidx.preference.SwitchPreferenceCompat;
|
||||||
|
|
||||||
|
|
@ -10,11 +15,13 @@ import java.io.InputStreamReader;
|
||||||
import io.github.sspanak.tt9.Logger;
|
import io.github.sspanak.tt9.Logger;
|
||||||
import io.github.sspanak.tt9.R;
|
import io.github.sspanak.tt9.R;
|
||||||
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
import io.github.sspanak.tt9.preferences.PreferencesActivity;
|
||||||
|
import io.github.sspanak.tt9.ui.UI;
|
||||||
|
|
||||||
public class DebugScreen extends BaseScreenFragment {
|
public class DebugScreen extends BaseScreenFragment {
|
||||||
private static final String DEBUG_LOGS_SWITCH = "pref_enable_debug_logs";
|
private final static String LOG_TAG = "DebugScreen";
|
||||||
private static final String SYSTEM_LOGS_SWITCH = "pref_enable_system_logs";
|
private final static String DEBUG_LOGS_SWITCH = "pref_enable_debug_logs";
|
||||||
private static final String LOGS_CONTAINER = "debug_logs_container";
|
private final static String SYSTEM_LOGS_SWITCH = "pref_enable_system_logs";
|
||||||
|
private final static String LOGS_CONTAINER = "debug_logs_container";
|
||||||
|
|
||||||
public DebugScreen() { init(); }
|
public DebugScreen() { init(); }
|
||||||
public DebugScreen(PreferencesActivity activity) { init(activity); }
|
public DebugScreen(PreferencesActivity activity) { init(activity); }
|
||||||
|
|
@ -26,6 +33,7 @@ public class DebugScreen extends BaseScreenFragment {
|
||||||
protected void onCreate() {
|
protected void onCreate() {
|
||||||
initLogMessagesSwitch();
|
initLogMessagesSwitch();
|
||||||
initSystemLogsSwitch();
|
initSystemLogsSwitch();
|
||||||
|
enableLogsCopy();
|
||||||
|
|
||||||
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
|
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
|
||||||
boolean includeSystemLogs = systemLogs != null && systemLogs.isChecked();
|
boolean includeSystemLogs = systemLogs != null && systemLogs.isChecked();
|
||||||
|
|
@ -35,7 +43,7 @@ public class DebugScreen extends BaseScreenFragment {
|
||||||
private void initLogMessagesSwitch() {
|
private void initLogMessagesSwitch() {
|
||||||
SwitchPreferenceCompat msgSwitch = findPreference(DEBUG_LOGS_SWITCH);
|
SwitchPreferenceCompat msgSwitch = findPreference(DEBUG_LOGS_SWITCH);
|
||||||
if (msgSwitch == null) {
|
if (msgSwitch == null) {
|
||||||
Logger.w("DebugScreen", "Debug logs switch not found.");
|
Logger.w(LOG_TAG, "Debug logs switch not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,7 +57,7 @@ public class DebugScreen extends BaseScreenFragment {
|
||||||
private void initSystemLogsSwitch() {
|
private void initSystemLogsSwitch() {
|
||||||
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
|
SwitchPreferenceCompat systemLogs = findPreference(SYSTEM_LOGS_SWITCH);
|
||||||
if (systemLogs == null) {
|
if (systemLogs == null) {
|
||||||
Logger.w("DebugScreen", "System logs switch not found.");
|
Logger.w(LOG_TAG, "System logs switch not found.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,7 +70,7 @@ public class DebugScreen extends BaseScreenFragment {
|
||||||
private void printLogs(boolean includeSystemLogs) {
|
private void printLogs(boolean includeSystemLogs) {
|
||||||
Preference logsContainer = findPreference(LOGS_CONTAINER);
|
Preference logsContainer = findPreference(LOGS_CONTAINER);
|
||||||
if (logsContainer == null) {
|
if (logsContainer == null) {
|
||||||
Logger.w("DebugScreen", "Logs container not found. Cannot print logs");
|
Logger.w(LOG_TAG, "Logs container not found. Cannot print logs");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,4 +96,26 @@ public class DebugScreen extends BaseScreenFragment {
|
||||||
|
|
||||||
logsContainer.setSummary(log.toString());
|
logsContainer.setSummary(log.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void enableLogsCopy() {
|
||||||
|
if (activity == null) {
|
||||||
|
Logger.w(LOG_TAG, "Activity is missing. Copying the logs will not be possible.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Preference logsContainer = findPreference(LOGS_CONTAINER);
|
||||||
|
if (logsContainer == null) {
|
||||||
|
Logger.w(LOG_TAG, "Logs container not found. Copying the logs will not be possible.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ClipboardManager clipboard = (ClipboardManager) activity.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
logsContainer.setOnPreferenceClickListener((Preference p) -> {
|
||||||
|
clipboard.setPrimaryClip(ClipData.newPlainText("TT9 debug log", p.getSummary()));
|
||||||
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) {
|
||||||
|
UI.toast(activity, "Logs copied.");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue