From 6f6d11fbb84ea12675f8dcb2c73fe0a169389bd3 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Tue, 16 Mar 2021 19:06:17 +0500 Subject: [PATCH] Updated TermuxPreferenceConstants The `TermuxPreferenceConstants` classes has been updated to `v0.3.0`. Check its Changelog sections for info on changes. --- .../TermuxPreferenceConstants.java | 80 +++++++++++++------ .../preferences/TermuxSharedPreferences.java | 31 ++++--- 2 files changed, 68 insertions(+), 43 deletions(-) diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java b/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java index 1e9df39d..a760a1bf 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java +++ b/app/src/main/java/com/termux/app/settings/preferences/TermuxPreferenceConstants.java @@ -1,16 +1,22 @@ package com.termux.app.settings.preferences; -import com.termux.app.TermuxConstants; - /* - * Version: v0.2.0 + * Version: v0.3.0 * * Changelog * * - 0.1.0 (2021-03-12) * - Initial Release. + * * - 0.2.0 (2021-03-13) * - Added `KEY_LOG_LEVEL` and `KEY_TERMINAL_VIEW_LOGGING_ENABLED` + * + * - 0.3.0 (2021-03-16) + * - Changed to per app scoping of variables so that the same file can store all constants of + * Termux app and its plugins. This will allow {@link com.termux.app.TermuxSettings} to + * manage preferences of plugins as well if they don't have launcher activity themselves + * and also allow plugin apps to make changes to preferences from background. + * - Added `KEY_LOG_LEVEL` to `TERMUX_TASKER_APP` scope. */ /** @@ -19,42 +25,64 @@ import com.termux.app.TermuxConstants; * instead of copying constants to random classes. The 3rd party apps can also import it for * interacting with termux apps. If changes are made to this file, increment the version number * and add an entry in the Changelog section above. - * - * The properties are loaded from the first file found at - * {@link TermuxConstants#TERMUX_PROPERTIES_PRIMARY_FILE_PATH} or - * {@link TermuxConstants#TERMUX_PROPERTIES_SECONDARY_FILE_PATH} */ public final class TermuxPreferenceConstants { - /** Defines the key for whether to show terminal toolbar containing extra keys and text input field */ - public static final String KEY_SHOW_TERMINAL_TOOLBAR = "show_extra_keys"; - public static final boolean DEFAULT_VALUE_SHOW_TERMINAL_TOOLBAR = true; + /** + * Termux app constants. + */ + public static final class TERMUX_APP { + + /** + * Defines the key for whether to show terminal toolbar containing extra keys and text input field + */ + public static final String KEY_SHOW_TERMINAL_TOOLBAR = "show_extra_keys"; + public static final boolean DEFAULT_VALUE_SHOW_TERMINAL_TOOLBAR = true; - - /** Defines the key for whether to always keep screen on */ - public static final String KEY_KEEP_SCREEN_ON = "screen_always_on"; - public static final boolean DEFAULT_VALUE_KEEP_SCREEN_ON = true; + /** + * Defines the key for whether to always keep screen on + */ + public static final String KEY_KEEP_SCREEN_ON = "screen_always_on"; + public static final boolean DEFAULT_VALUE_KEEP_SCREEN_ON = true; - - /** Defines the key for font size of termux terminal view */ - public static final String KEY_FONTSIZE = "fontsize"; + /** + * Defines the key for font size of termux terminal view + */ + public static final String KEY_FONTSIZE = "fontsize"; - - /** Defines the key for current termux terminal session */ - public static final String KEY_CURRENT_SESSION = "current_session"; + /** + * Defines the key for current termux terminal session + */ + public static final String KEY_CURRENT_SESSION = "current_session"; - - /** Defines the key for current termux log level */ - public static final String KEY_LOG_LEVEL = "log_level"; + /** + * Defines the key for current termux log level + */ + public static final String KEY_LOG_LEVEL = "log_level"; + /** + * Defines the key for whether termux terminal view key logging is enabled or not + */ + public static final String KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED = "terminal_view_key_logging_enabled"; + public static final boolean DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED = false; - /** Defines the key for whether termux terminal view key logging is enabled or not */ - public static final String KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED = "terminal_view_key_logging_enabled"; - public static final boolean DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED = false; + } + + /** + * Termux Tasker app constants. + */ + public static final class TERMUX_TASKER_APP { + + /** + * Defines the key for current termux log level + */ + public static final String KEY_LOG_LEVEL = "log_level"; + + } } diff --git a/app/src/main/java/com/termux/app/settings/preferences/TermuxSharedPreferences.java b/app/src/main/java/com/termux/app/settings/preferences/TermuxSharedPreferences.java index c0e9ab0a..f1a7b0b1 100644 --- a/app/src/main/java/com/termux/app/settings/preferences/TermuxSharedPreferences.java +++ b/app/src/main/java/com/termux/app/settings/preferences/TermuxSharedPreferences.java @@ -8,6 +8,7 @@ import com.termux.app.TermuxConstants; import com.termux.app.utils.Logger; import com.termux.app.utils.TermuxUtils; import com.termux.app.utils.TextDataUtils; +import com.termux.app.settings.preferences.TermuxPreferenceConstants.TERMUX_APP; import javax.annotation.Nonnull; @@ -35,11 +36,11 @@ public class TermuxSharedPreferences { public boolean getShowTerminalToolbar() { - return mSharedPreferences.getBoolean(TermuxPreferenceConstants.KEY_SHOW_TERMINAL_TOOLBAR, TermuxPreferenceConstants.DEFAULT_VALUE_SHOW_TERMINAL_TOOLBAR); + return mSharedPreferences.getBoolean(TERMUX_APP.KEY_SHOW_TERMINAL_TOOLBAR, TERMUX_APP.DEFAULT_VALUE_SHOW_TERMINAL_TOOLBAR); } public void setShowTerminalToolbar(boolean value) { - mSharedPreferences.edit().putBoolean(TermuxPreferenceConstants.KEY_SHOW_TERMINAL_TOOLBAR, value).apply(); + mSharedPreferences.edit().putBoolean(TERMUX_APP.KEY_SHOW_TERMINAL_TOOLBAR, value).apply(); } public boolean toogleShowTerminalToolbar() { @@ -51,11 +52,11 @@ public class TermuxSharedPreferences { public boolean getKeepScreenOn() { - return mSharedPreferences.getBoolean(TermuxPreferenceConstants.KEY_KEEP_SCREEN_ON, TermuxPreferenceConstants.DEFAULT_VALUE_KEEP_SCREEN_ON); + return mSharedPreferences.getBoolean(TERMUX_APP.KEY_KEEP_SCREEN_ON, TERMUX_APP.DEFAULT_VALUE_KEEP_SCREEN_ON); } public void setKeepScreenOn(boolean value) { - mSharedPreferences.edit().putBoolean(TermuxPreferenceConstants.KEY_KEEP_SCREEN_ON, value).apply(); + mSharedPreferences.edit().putBoolean(TERMUX_APP.KEY_KEEP_SCREEN_ON, value).apply(); } @@ -82,7 +83,7 @@ public class TermuxSharedPreferences { String fontString; try { - fontString = mSharedPreferences.getString(TermuxPreferenceConstants.KEY_FONTSIZE, Integer.toString(DEFAULT_FONTSIZE)); + fontString = mSharedPreferences.getString(TERMUX_APP.KEY_FONTSIZE, Integer.toString(DEFAULT_FONTSIZE)); if(fontString != null) fontSize = Integer.parseInt(fontString); else @@ -96,7 +97,7 @@ public class TermuxSharedPreferences { } public void setFontSize(String value) { - mSharedPreferences.edit().putString(TermuxPreferenceConstants.KEY_FONTSIZE, value).apply(); + mSharedPreferences.edit().putString(TERMUX_APP.KEY_FONTSIZE, value).apply(); } public void changeFontSize(Context context, boolean increase) { @@ -112,42 +113,38 @@ public class TermuxSharedPreferences { public String getCurrentSession() { - return mSharedPreferences.getString(TermuxPreferenceConstants.KEY_CURRENT_SESSION, ""); + return mSharedPreferences.getString(TERMUX_APP.KEY_CURRENT_SESSION, ""); } public void setCurrentSession(String value) { - mSharedPreferences.edit().putString(TermuxPreferenceConstants.KEY_CURRENT_SESSION, value).apply(); + mSharedPreferences.edit().putString(TERMUX_APP.KEY_CURRENT_SESSION, value).apply(); } public int getLogLevel() { try { - return mSharedPreferences.getInt(TermuxPreferenceConstants.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL); + return mSharedPreferences.getInt(TERMUX_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL); } catch (Exception e) { - Logger.logStackTraceWithMessage("Error getting \"" + TermuxPreferenceConstants.KEY_LOG_LEVEL + "\" from shared preferences", e); + Logger.logStackTraceWithMessage("Error getting \"" + TERMUX_APP.KEY_LOG_LEVEL + "\" from shared preferences", e); return Logger.DEFAULT_LOG_LEVEL; } } public void setLogLevel(Context context, int logLevel) { logLevel = Logger.setLogLevel(context, logLevel); - mSharedPreferences.edit().putInt(TermuxPreferenceConstants.KEY_LOG_LEVEL, logLevel).apply(); + mSharedPreferences.edit().putInt(TERMUX_APP.KEY_LOG_LEVEL, logLevel).apply(); } public boolean getTerminalViewKeyLoggingEnabled() { - return mSharedPreferences.getBoolean(TermuxPreferenceConstants.KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED, TermuxPreferenceConstants.DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED); + return mSharedPreferences.getBoolean(TERMUX_APP.KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED, TERMUX_APP.DEFAULT_VALUE_TERMINAL_VIEW_KEY_LOGGING_ENABLED); } public void setTerminalViewKeyLoggingEnabled(boolean value) { - mSharedPreferences.edit().putBoolean(TermuxPreferenceConstants.KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED, value).apply(); + mSharedPreferences.edit().putBoolean(TERMUX_APP.KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED, value).apply(); } - - - - }