From fa4dd2637c9b29b962fe0bed2e1e2c0b1d3618c4 Mon Sep 17 00:00:00 2001 From: Ishan Bhargava Date: Wed, 29 Nov 2023 11:59:59 +0530 Subject: [PATCH] Add setting to disable open-from-highlight alias --- .../net/gsantner/markor/activity/SettingsActivity.java | 3 +++ .../net/gsantner/markor/util/MarkorContextUtils.java | 5 +++++ .../main/java/net/gsantner/opoc/util/GsContextUtils.java | 9 +++++++++ app/src/main/res/values/string-not_translatable.xml | 1 + app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/preferences_master.xml | 6 ++++++ 6 files changed, 26 insertions(+) diff --git a/app/src/main/java/net/gsantner/markor/activity/SettingsActivity.java b/app/src/main/java/net/gsantner/markor/activity/SettingsActivity.java index ee729fdaf6..dee8850b4f 100644 --- a/app/src/main/java/net/gsantner/markor/activity/SettingsActivity.java +++ b/app/src/main/java/net/gsantner/markor/activity/SettingsActivity.java @@ -214,6 +214,9 @@ protected void onPreferenceChanged(final SharedPreferences prefs, final String k } else if (eq(key, R.string.pref_key__is_launcher_for_special_files_enabled)) { boolean extraLaunchersEnabled = prefs.getBoolean(key, false); new MarkorContextUtils(getActivity()).applySpecialLaunchersVisibility(getActivity(), extraLaunchersEnabled); + } else if (eq(key, R.string.pref_key__is_open_from_highlight_enabled)) { + boolean openFromHighlightEnabled = prefs.getBoolean(key, true); + new MarkorContextUtils(getActivity()).applyOpenFromHighlightVisibility(getActivity(), openFromHighlightEnabled); } else if (eq(key, R.string.pref_key__file_description_format)) { try { new SimpleDateFormat(prefs.getString(key, ""), Locale.getDefault()); diff --git a/app/src/main/java/net/gsantner/markor/util/MarkorContextUtils.java b/app/src/main/java/net/gsantner/markor/util/MarkorContextUtils.java index f7386f52a1..0f082e1db9 100644 --- a/app/src/main/java/net/gsantner/markor/util/MarkorContextUtils.java +++ b/app/src/main/java/net/gsantner/markor/util/MarkorContextUtils.java @@ -45,6 +45,11 @@ public T applySpecialLaunchersVisibility(final Contex return thisp(); } + public T applyOpenFromHighlightVisibility(final Context context, boolean openFromHighlightEnabled) { + setLauncherActivityEnabledFromString(context, "net.gsantner.markor.AliasDocumentProcessText", openFromHighlightEnabled); + return thisp(); + } + public T createLauncherDesktopShortcut(final Context context, final File file) { // This is only allowed to call when direct file access is possible!! // So basically only for java.io.File Objects. Virtual files, or content:// diff --git a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java index 57b2255193..134bbc84ce 100644 --- a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java +++ b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java @@ -1148,6 +1148,15 @@ public T setLauncherActivityEnabled(final Context con return thisp(); } + public T setLauncherActivityEnabledFromString(final Context context, String activityClass, boolean enable) { + try { + ComponentName component = new ComponentName(context, activityClass); + context.getPackageManager().setComponentEnabledSetting(component, enable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); + } catch (Exception ignored) { + } + return thisp(); + } + /** * Try to create a new desktop shortcut on the launcher. Add permissions: * diff --git a/app/src/main/res/values/string-not_translatable.xml b/app/src/main/res/values/string-not_translatable.xml index 9adcd8d422..3b552980b1 100644 --- a/app/src/main/res/values/string-not_translatable.xml +++ b/app/src/main/res/values/string-not_translatable.xml @@ -192,6 +192,7 @@ work. If not, see . pref_key__markdown_newline_newparagraph pref_key__markdown_table_of_contents_enabled_levels pref_key__is_launcher_for_special_files_enabled + pref_key__is_open_from_highlight_enabled pref_key__basic_color_scheme__bg_light pref_key__basic_color_scheme__fg_light pref_key__basic_color_scheme__bg_dark diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47e825e369..abe73157e3 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -147,6 +147,8 @@ work. If not, see . Remember last directory Syntax highlighting Dynamic highlighting + Open from text highlight + Show an option in the highlighted text menu to open text in a new document Highlighting delay Delay in milliseconds for highlighting refresh. A lower value will start highlighting earlier, but it will drain your battery and may slow down the app on older devices. Control whether entered text should be highlighted or not diff --git a/app/src/main/res/xml/preferences_master.xml b/app/src/main/res/xml/preferences_master.xml index 473e99f52b..20777e3cef 100644 --- a/app/src/main/res/xml/preferences_master.xml +++ b/app/src/main/res/xml/preferences_master.xml @@ -107,6 +107,12 @@ android:icon="@drawable/ic_widgets_black_24dp" android:key="@string/pref_key__is_launcher_for_special_files_enabled" android:title="@string/special_documents" /> +