From d5ffb116b83d625cad9047397117a642554c74b2 Mon Sep 17 00:00:00 2001 From: agnostic-apollo Date: Sat, 4 Sep 2021 08:08:51 +0500 Subject: [PATCH] Added: Add constants and functions for termux-widget in TermuxConstants and TermuxPreferenceConstants --- .../TermuxPreferenceConstants.java | 10 ++- .../TermuxWidgetAppSharedPreferences.java | 19 +++++ .../termux/shared/termux/TermuxConstants.java | 73 ++++++++++++++++--- 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java index 5cf2ff7a..492ff619 100644 --- a/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxPreferenceConstants.java @@ -1,7 +1,7 @@ package com.termux.shared.settings.preferences; /* - * Version: v0.13.0 + * Version: v0.14.0 * * Changelog * @@ -58,6 +58,9 @@ package com.termux.shared.settings.preferences; * - Added following to `TERMUX_FLOAT_APP`: * `KEY_WINDOW_X`, `KEY_WINDOW_Y`, `KEY_WINDOW_WIDTH`, `KEY_WINDOW_HEIGHT`, `KEY_FONTSIZE`, * `KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED`. + * + * - 0.14.0 (2021-09-04) + * - Added `TERMUX_WIDGET_APP.KEY_TOKEN`. */ /** @@ -270,6 +273,11 @@ public final class TermuxPreferenceConstants { */ public static final String KEY_LOG_LEVEL = "log_level"; + /** + * Defines the key for current token for shortcuts. + */ + public static final String KEY_TOKEN = "token"; + } } diff --git a/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxWidgetAppSharedPreferences.java b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxWidgetAppSharedPreferences.java index 5356e94c..717ed135 100644 --- a/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxWidgetAppSharedPreferences.java +++ b/termux-shared/src/main/java/com/termux/shared/settings/preferences/TermuxWidgetAppSharedPreferences.java @@ -11,6 +11,8 @@ import com.termux.shared.packages.PackageUtils; import com.termux.shared.settings.preferences.TermuxPreferenceConstants.TERMUX_WIDGET_APP; import com.termux.shared.termux.TermuxConstants; +import java.util.UUID; + import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -74,6 +76,23 @@ public class TermuxWidgetAppSharedPreferences { + public static String getGeneratedToken(@NonNull Context context) { + TermuxWidgetAppSharedPreferences preferences = TermuxWidgetAppSharedPreferences.build(context, true); + if (preferences == null) return null; + return preferences.getGeneratedToken(); + } + + public String getGeneratedToken() { + String token = SharedPreferenceUtils.getString(mSharedPreferences, TERMUX_WIDGET_APP.KEY_TOKEN, null, true); + if (token == null) { + token = UUID.randomUUID().toString(); + SharedPreferenceUtils.setString(mSharedPreferences, TERMUX_WIDGET_APP.KEY_TOKEN, token, false); + } + return token; + } + + + public int getLogLevel(boolean readFromFile) { if (readFromFile) return SharedPreferenceUtils.getInt(mMultiProcessSharedPreferences, TERMUX_WIDGET_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL); diff --git a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java index c0a80593..ca7a73a6 100644 --- a/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/TermuxConstants.java @@ -12,7 +12,7 @@ import java.util.IllegalFormatException; import java.util.List; /* - * Version: v0.28.0 + * Version: v0.29.0 * * Changelog * @@ -190,6 +190,14 @@ import java.util.List; * * - 0.28.0 (2021-09-02) * - Added `TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE*` and `TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE*`. + * + * - 0.29.0 (2021-09-04) + * - Added `TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR_BASENAME`, `TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_BASENAME`, + * `TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_PATH`, `TERMUX_SHORTCUT_SCRIPT_ICONS_DIR`. + * - Added following to `TERMUX_WIDGET.TERMUX_WIDGET_PROVIDER`: + * `ACTION_WIDGET_ITEM_CLICKED`, `ACTION_REFRESH_WIDGET`, `EXTRA_FILE_CLICKED`. + * - Changed naming convention of `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE.ACTION_*`. + * - Fixed wrong path set for `TERMUX_SHORTCUT_SCRIPTS_DIR_PATH`. */ /** @@ -687,18 +695,32 @@ public final class TermuxConstants { /** Termux app directory path to store foreground scripts that can be run by the termux launcher * widget provided by Termux:Widget */ - public static final String TERMUX_SHORTCUT_SCRIPTS_DIR_PATH = TERMUX_DATA_HOME_DIR_PATH + "/shortcuts"; // Default: "/data/data/com.termux/files/home/.termux/shortcuts" + public static final String TERMUX_SHORTCUT_SCRIPTS_DIR_PATH = TERMUX_HOME_DIR_PATH + "/.shortcuts"; // Default: "/data/data/com.termux/files/home/.shortcuts" /** Termux app directory to store foreground scripts that can be run by the termux launcher widget provided by Termux:Widget */ public static final File TERMUX_SHORTCUT_SCRIPTS_DIR = new File(TERMUX_SHORTCUT_SCRIPTS_DIR_PATH); + /** Termux app directory basename that stores background scripts that can be run by the termux + * launcher widget provided by Termux:Widget */ + public static final String TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR_BASENAME = "tasks"; // Default: "tasks" /** Termux app directory path to store background scripts that can be run by the termux launcher * widget provided by Termux:Widget */ - public static final String TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR_PATH = TERMUX_DATA_HOME_DIR_PATH + "/shortcuts/tasks"; // Default: "/data/data/com.termux/files/home/.termux/shortcuts/tasks" + public static final String TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR_PATH = TERMUX_SHORTCUT_SCRIPTS_DIR_PATH + "/" + TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR_BASENAME; // Default: "/data/data/com.termux/files/home/.shortcuts/tasks" /** Termux app directory to store background scripts that can be run by the termux launcher widget provided by Termux:Widget */ public static final File TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR = new File(TERMUX_SHORTCUT_TASKS_SCRIPTS_DIR_PATH); + /** Termux app directory basename that stores icons for the foreground and background scripts + * that can be run by the termux launcher widget provided by Termux:Widget */ + public static final String TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_BASENAME = "icons"; // Default: "icons" + /** Termux app directory path to store icons for the foreground and background scripts that can + * be run by the termux launcher widget provided by Termux:Widget */ + public static final String TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_PATH = TERMUX_SHORTCUT_SCRIPTS_DIR_PATH + "/" + TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_BASENAME; // Default: "/data/data/com.termux/files/home/.shortcuts/icons" + /** Termux app directory to store icons for the foreground and background scripts that can be + * run by the termux launcher widget provided by Termux:Widget */ + public static final File TERMUX_SHORTCUT_SCRIPT_ICONS_DIR = new File(TERMUX_SHORTCUT_SCRIPT_ICONS_DIR_PATH); + + /** Termux app directory path to store scripts to be run by 3rd party twofortyfouram locale plugin * host apps like Tasker app via the Termux:Tasker plugin client */ public static final String TERMUX_TASKER_SCRIPTS_DIR_PATH = TERMUX_DATA_HOME_DIR_PATH + "/tasker"; // Default: "/data/data/com.termux/files/home/.termux/tasker" @@ -1100,14 +1122,14 @@ public final class TermuxConstants { */ public static final class TERMUX_FLOAT_SERVICE { - /** Intent action to stop TERMUX_FLOAT_SERVICE */ - public static final String ACTION_STOP_SERVICE = TERMUX_FLOAT_PACKAGE_NAME + ".stop_service"; // Default: "com.termux.window.stop_service" + /** Intent action to stop TERMUX_FLOAT_SERVICE. */ + public static final String ACTION_STOP_SERVICE = TERMUX_FLOAT_PACKAGE_NAME + ".ACTION_STOP_SERVICE"; // Default: "com.termux.float.ACTION_STOP_SERVICE" - /** Intent action to show float window */ - public static final String ACTION_SHOW = TERMUX_FLOAT_PACKAGE_NAME + ".show"; // Default: "com.termux.window.show" + /** Intent action to show float window. */ + public static final String ACTION_SHOW = TERMUX_FLOAT_PACKAGE_NAME + ".ACTION_SHOW"; // Default: "com.termux.float.ACTION_SHOW" - /** Intent action to hide float window */ - public static final String ACTION_HIDE = TERMUX_FLOAT_PACKAGE_NAME + ".hide"; // Default: "com.termux.window.hide" + /** Intent action to hide float window. */ + public static final String ACTION_HIDE = TERMUX_FLOAT_PACKAGE_NAME + ".ACTION_HIDE"; // Default: "com.termux.float.ACTION_HIDE" } @@ -1127,4 +1149,37 @@ public final class TermuxConstants { } + + + + + /** + * Termux Widget app constants. + */ + public static final class TERMUX_WIDGET { + + /** Intent {@code String} extra for the token of the Termux Widget app shortcuts. */ + public static final String EXTRA_TOKEN_NAME = TERMUX_PACKAGE_NAME + ".shortcut.token"; // Default: "com.termux.shortcut.token" + + /** + * Termux Widget app {@link android.appwidget.AppWidgetProvider} class. + */ + public static final class TERMUX_WIDGET_PROVIDER { + + /** Intent action for if an item is clicked in the widget. */ + public static final String ACTION_WIDGET_ITEM_CLICKED = TERMUX_WIDGET_PACKAGE_NAME + ".ACTION_WIDGET_ITEM_CLICKED"; // Default: "com.termux.widget.ACTION_WIDGET_ITEM_CLICKED" + + + /** Intent action to refresh files in the widget. */ + public static final String ACTION_REFRESH_WIDGET = TERMUX_WIDGET_PACKAGE_NAME + ".ACTION_REFRESH_WIDGET"; // Default: "com.termux.widget.ACTION_REFRESH_WIDGET" + + + /** Intent {@code String} extra for the file clicked for the TERMUX_WIDGET_PROVIDER.ACTION_WIDGET_ITEM_CLICKED intent. */ + public static final String EXTRA_FILE_CLICKED = TERMUX_WIDGET_PACKAGE_NAME + ".EXTRA_FILE_CLICKED"; // Default: "com.termux.widget.EXTRA_FILE_CLICKED" + + } + + } + + }