Skip to content

Commit

Permalink
Add setting to disable open-from-highlight alias
Browse files Browse the repository at this point in the history
  • Loading branch information
ConcurrentCrab committed Nov 29, 2023
1 parent edd2fed commit fa4dd26
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public <T extends GsContextUtils> T applySpecialLaunchersVisibility(final Contex
return thisp();
}

public <T extends GsContextUtils> T applyOpenFromHighlightVisibility(final Context context, boolean openFromHighlightEnabled) {
setLauncherActivityEnabledFromString(context, "net.gsantner.markor.AliasDocumentProcessText", openFromHighlightEnabled);
return thisp();
}

public <T extends GsContextUtils> 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://
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,15 @@ public <T extends GsContextUtils> T setLauncherActivityEnabled(final Context con
return thisp();
}

public <T extends GsContextUtils> 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:
* <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="pref_key__markdown_newline_newparagraph" translatable="false">pref_key__markdown_newline_newparagraph</string>
<string name="pref_key__markdown_table_of_contents_enabled_levels" translatable="false">pref_key__markdown_table_of_contents_enabled_levels</string>
<string name="pref_key__is_launcher_for_special_files_enabled" translatable="false">pref_key__is_launcher_for_special_files_enabled</string>
<string name="pref_key__is_open_from_highlight_enabled">pref_key__is_open_from_highlight_enabled</string>
<string name="pref_key__basic_color_scheme__bg_light" translatable="false">pref_key__basic_color_scheme__bg_light</string>
<string name="pref_key__basic_color_scheme__fg_light" translatable="false">pref_key__basic_color_scheme__fg_light</string>
<string name="pref_key__basic_color_scheme__bg_dark" translatable="false">pref_key__basic_color_scheme__bg_dark</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="remember_last_directory">Remember last directory</string>
<string name="syntax_highlighting">Syntax highlighting</string>
<string name="dynamic_highlighting">Dynamic highlighting</string>
<string name="open_from_highlight">Open from text highlight</string>
<string name="open_from_highlight_effect">Show an option in the highlighted text menu to open text in a new document</string>
<string name="highlighting_delay">Highlighting delay</string>
<string name="highlighting_delay_lower_value_more_battery_drain_description__appspecific">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.</string>
<string name="highlighting_enabled_or_not__appspecific">Control whether entered text should be highlighted or not</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/preferences_master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
<CheckBoxPreference
android:defaultValue="true"
android:icon="@drawable/ic_widgets_black_24dp"
android:key="@string/pref_key__is_open_from_highlight_enabled"
android:title="@string/open_from_highlight"
android:summary="@string/open_from_highlight_effect" />
<CheckBoxPreference
android:defaultValue="true"
android:icon="@drawable/ic_border_outer_black_24dp"
Expand Down

0 comments on commit fa4dd26

Please sign in to comment.