diff --git a/README.md b/README.md index 1d8f2cc00..391e590b5 100644 --- a/README.md +++ b/README.md @@ -66,13 +66,10 @@ Does not use internet permission, and thus is 100% offline. The app checks the SHA256 checksum of the library and warns the user if it doesn't match with known library versions. A mismatch indicates the library was modified, but may also occur if the user intentionally provides a different library than expected (e.g. a self-built variant). Note that if the the app is installed as a system app, both versions have access to the system glide typing library (if it is installed). * __App crashing when using as system app__: This happens if you do not install the app, but just copy the APK. Then the app's own library is not extracted from the APK, and not accessible to the app. You will need tp either install the app over itself, or provide a library. -* (_to be expanded_...) ## Hidden Functionality Features that may go unnoticed, and further potentially useful information -* Long-pressing pinned toolbar keys results in additional functionality - * clipboard -> paste, move left/right -> move full left/right, move up/down -> page up/down, copy -> copy all, select word -> select all, undo <-> redo, -* Long-pressing keys in the suggestion strip toolbar pins them to the suggestion strip. +* Long-pressing toolbar keys results in additional functionality: clipboard -> paste, move left/right -> move full left/right, move up/down -> page up/down, copy -> copy all, select word -> select all, undo <-> redo * Long-press the Comma-key to access Clipboard View, Emoji View, One-handed Mode, Settings, or Switch Language: * Emoji View and Language Switch will disappear if you have the corresponding key enabled; * For some layouts it\'s not the Comma-key, but the key at the same position (e.g. it\'s `q` for Dvorak layout). @@ -139,7 +136,6 @@ __Planned features and improvements:__ * Make use of the `.com` key in URL fields (currently only available for tablets) * With language-dependent TLDs * Internal cleanup (a lot of over-complicated and convoluted code) -* optionally move toolbar key pinning to a setting, so long press actions on unpinned toolbar keys are available * [Bug fixes](https://github.com/Helium314/HeliBoard/issues?q=is%3Aissue+is%3Aopen+label%3Abug) __What will _not_ be added:__ diff --git a/app/build.gradle b/app/build.gradle index 2830cacbb..c270024d9 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { applicationId "helium314.keyboard" minSdkVersion 21 targetSdkVersion 34 - versionCode 2000 + versionCode 2001 versionName '2.0-alpha1' ndk { abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64' diff --git a/app/src/main/java/helium314/keyboard/latin/App.kt b/app/src/main/java/helium314/keyboard/latin/App.kt index 7932ed2c0..cba11f306 100644 --- a/app/src/main/java/helium314/keyboard/latin/App.kt +++ b/app/src/main/java/helium314/keyboard/latin/App.kt @@ -11,6 +11,8 @@ import helium314.keyboard.latin.settings.USER_DICTIONARY_SUFFIX import helium314.keyboard.latin.utils.CUSTOM_LAYOUT_PREFIX import helium314.keyboard.latin.utils.DeviceProtectedUtils import helium314.keyboard.latin.utils.DictionaryInfoUtils +import helium314.keyboard.latin.utils.ToolbarKey +import helium314.keyboard.latin.utils.defaultPinnedToolbarPref import helium314.keyboard.latin.utils.getCustomLayoutFile import helium314.keyboard.latin.utils.onCustomLayoutFileListChanged import helium314.keyboard.latin.utils.upgradeToolbarPrefs @@ -39,7 +41,6 @@ fun checkVersionUpgrade(context: Context) { val oldVersion = prefs.getInt(Settings.PREF_VERSION_CODE, 0) if (oldVersion == BuildConfig.VERSION_CODE) return - upgradeToolbarPrefs(prefs) // clear extracted dictionaries, in case updated version contains newer ones DictionaryInfoUtils.getCachedDirectoryList(context)?.forEach { if (!it.isDirectory) return@forEach @@ -73,6 +74,22 @@ fun checkVersionUpgrade(context: Context) { putString(Settings.PREF_SELECTED_SUBTYPE, selectedSubtype) } } + if (oldVersion <= 2000) { + // upgrade pinned toolbar keys pref + val oldPinnedKeysPref = prefs.getString(Settings.PREF_PINNED_TOOLBAR_KEYS, "")!! + val pinnedKeys = oldPinnedKeysPref.split(";").mapNotNull { + try { + ToolbarKey.valueOf(it) + } catch (_: IllegalArgumentException) { + null + } + } + val newPinnedKeysPref = (pinnedKeys.map { "${it.name},true" } + defaultPinnedToolbarPref.split(";")) + .distinctBy { it.split(",").first() } + .joinToString(";") + prefs.edit { putString(Settings.PREF_PINNED_TOOLBAR_KEYS, newPinnedKeysPref) } + } + upgradeToolbarPrefs(prefs) onCustomLayoutFileListChanged() // just to be sure prefs.edit { putInt(Settings.PREF_VERSION_CODE, BuildConfig.VERSION_CODE) } } diff --git a/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java b/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java index 4ef8aa1c0..9379113f2 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/PreferencesSettingsFragment.java @@ -71,9 +71,14 @@ public final class PreferencesSettingsFragment extends SubScreenFragment { R.string.toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext())); return true; }); + findPreference(Settings.PREF_PINNED_TOOLBAR_KEYS).setOnPreferenceClickListener((pref) -> { + DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_PINNED_TOOLBAR_KEYS, ToolbarUtilsKt.getDefaultPinnedToolbarPref(), + R.string.pinned_toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext())); + return true; + }); findPreference(Settings.PREF_CLIPBOARD_TOOLBAR_KEYS).setOnPreferenceClickListener((pref) -> { DialogUtilsKt.reorderDialog(requireContext(), Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, ToolbarUtilsKt.getDefaultClipboardToolbarPref(), - R.string.toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext())); + R.string.clipboard_toolbar_keys, (name) -> ToolbarUtilsKt.getToolbarIconByName(name, requireContext())); return true; }); } @@ -89,7 +94,8 @@ public final class PreferencesSettingsFragment extends SubScreenFragment { if (key == null) return; switch (key) { case Settings.PREF_POPUP_KEYS_ORDER, Settings.PREF_SHOW_POPUP_HINTS, Settings.PREF_SHOW_NUMBER_ROW, - Settings.PREF_POPUP_KEYS_LABELS_ORDER, Settings.PREF_TOOLBAR_KEYS, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS + Settings.PREF_POPUP_KEYS_LABELS_ORDER, Settings.PREF_TOOLBAR_KEYS, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, + Settings.PREF_PINNED_TOOLBAR_KEYS, Settings.PREF_QUICK_PIN_TOOLBAR_KEYS -> mReloadKeyboard = true; case Settings.PREF_LOCALIZED_NUMBER_ROW -> KeyboardLayoutSet.onSystemLocaleChanged(); case Settings.PREF_SHOW_HINTS diff --git a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java index b9f3c84e9..9940127d7 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/Settings.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/Settings.java @@ -44,8 +44,6 @@ import helium314.keyboard.latin.utils.ResourceUtils; import helium314.keyboard.latin.utils.RunInLocaleKt; import helium314.keyboard.latin.utils.StatsUtils; import helium314.keyboard.latin.utils.SubtypeSettingsKt; -import helium314.keyboard.latin.utils.ToolbarKey; -import helium314.keyboard.latin.utils.ToolbarUtilsKt; import java.io.File; import java.util.ArrayList; @@ -148,6 +146,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang public static final String PREF_USE_SYSTEM_LOCALES = "use_system_locales"; public static final String PREF_URL_DETECTION = "url_detection"; public static final String PREF_DONT_SHOW_MISSING_DICTIONARY_DIALOG = "dont_show_missing_dict_dialog"; + public static final String PREF_QUICK_PIN_TOOLBAR_KEYS = "quick_pin_toolbar_keys"; public static final String PREF_PINNED_TOOLBAR_KEYS = "pinned_toolbar_keys"; public static final String PREF_TOOLBAR_KEYS = "toolbar_keys"; public static final String PREF_CLIPBOARD_TOOLBAR_KEYS = "clipboard_toolbar_keys"; @@ -486,29 +485,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang } } - public static ArrayList readPinnedKeys(final SharedPreferences prefs) { - final ArrayList list = new ArrayList<>(); - for (final String key : prefs.getString(Settings.PREF_PINNED_TOOLBAR_KEYS, "").split(";")) { - try { - list.add(ToolbarKey.valueOf(key)); - } catch (IllegalArgumentException ignored) { } // may happen if toolbar key is removed from app - } - return list; - } - - public static void addPinnedKey(final SharedPreferences prefs, final ToolbarKey key) { - final ArrayList keys = readPinnedKeys(prefs); - if (keys.contains(key)) return; - keys.add(key); - prefs.edit().putString(Settings.PREF_PINNED_TOOLBAR_KEYS, ToolbarUtilsKt.toToolbarKeyString(keys)).apply(); - } - - public static void removePinnedKey(final SharedPreferences prefs, final ToolbarKey key) { - final ArrayList keys = readPinnedKeys(prefs); - keys.remove(key); - prefs.edit().putString(Settings.PREF_PINNED_TOOLBAR_KEYS, ToolbarUtilsKt.toToolbarKeyString(keys)).apply(); - } - public static int readMorePopupKeysPref(final SharedPreferences prefs) { return switch (prefs.getString(Settings.PREF_MORE_POPUP_KEYS, "normal")) { case "all" -> LocaleKeyboardInfosKt.POPUP_KEYS_ALL; diff --git a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java index fbd14a256..d00c5b601 100644 --- a/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java +++ b/app/src/main/java/helium314/keyboard/latin/settings/SettingsValues.java @@ -99,6 +99,7 @@ public class SettingsValues { public final boolean mEnableEmojiAltPhysicalKey; public final boolean mIsSplitKeyboardEnabled; public final float mSplitKeyboardSpacerRelativeWidth; + public final boolean mQuickPinToolbarKeys; public final int mScreenMetrics; public final boolean mAddToPersonalDictionary; public final boolean mUseContactsDictionary; @@ -181,6 +182,7 @@ public class SettingsValues { mSplitKeyboardSpacerRelativeWidth = mIsSplitKeyboardEnabled ? Math.min(Math.max((displayWidthDp - 600) / 6000f + 0.15f, 0.15f), 0.25f) * prefs.getFloat(Settings.PREF_SPLIT_SPACER_SCALE, DEFAULT_SIZE_SCALE) : 0f; + mQuickPinToolbarKeys = prefs.getBoolean(Settings.PREF_QUICK_PIN_TOOLBAR_KEYS, false); mScreenMetrics = Settings.readScreenMetrics(res); // Compute other readable settings diff --git a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java index aea803001..af6699cba 100644 --- a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java +++ b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java @@ -217,13 +217,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick mToolbarExpandKey.getLayoutParams().height *= 0.82; // shrink the whole key a little (drawable not affected) mToolbarExpandKey.getLayoutParams().width *= 0.82; - for (final ToolbarKey pinnedKey : Settings.readPinnedKeys(prefs)) { + for (final ToolbarKey pinnedKey : ToolbarUtilsKt.getPinnedToolbarKeys(prefs)) { final ImageButton button = createToolbarKey(context, keyboardAttr, pinnedKey); button.setLayoutParams(toolbarKeyLayoutParams); setupKey(button, colors); mPinnedKeys.addView(button); final View pinnedKeyInToolbar = mToolbar.findViewWithTag(pinnedKey); - if (pinnedKeyInToolbar != null) + if (pinnedKeyInToolbar != null && Settings.getInstance().getCurrent().mQuickPinToolbarKeys) pinnedKeyInToolbar.setBackground(mEnabledToolKeyBackground); } @@ -374,7 +374,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick private void onLongClickToolKey(final View view) { if (!(view.getTag() instanceof ToolbarKey tag)) return; - if (view.getParent() == mPinnedKeys) { + if (view.getParent() == mPinnedKeys || !Settings.getInstance().getCurrent().mQuickPinToolbarKeys) { final int longClickCode = getCodeForToolbarKeyLongClick(tag); if (longClickCode != KeyCode.UNSPECIFIED) { mListener.onCodeInput(longClickCode, Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, false); @@ -384,9 +384,9 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick if (pinnedKeyView == null) { addKeyToPinnedKeys(tag); mToolbar.findViewWithTag(tag).setBackground(mEnabledToolKeyBackground); - Settings.addPinnedKey(DeviceProtectedUtils.getSharedPreferences(getContext()), tag); + ToolbarUtilsKt.addPinnedKey(DeviceProtectedUtils.getSharedPreferences(getContext()), tag); } else { - Settings.removePinnedKey(DeviceProtectedUtils.getSharedPreferences(getContext()), tag); + ToolbarUtilsKt.removePinnedKey(DeviceProtectedUtils.getSharedPreferences(getContext()), tag); mToolbar.findViewWithTag(tag).setBackground(mDefaultBackground.getConstantState().newDrawable(getResources())); mPinnedKeys.removeView(pinnedKeyView); } diff --git a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt index 8ab6b7da4..8c7ba0bec 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/ToolbarUtils.kt @@ -114,8 +114,6 @@ enum class ToolbarKey { val toolbarKeyStrings: Set = entries.mapTo(HashSet()) { it.toString().lowercase(Locale.US) } -fun toToolbarKeyString(keys: Collection) = keys.joinToString(";") { it.name } - val defaultToolbarPref = entries.filterNot { it == CLOSE_HISTORY }.joinToString(";") { when (it) { INCOGNITO, AUTOCORRECT, UP, DOWN, ONE_HANDED, FULL_LEFT, FULL_RIGHT, CUT, CLEAR_CLIPBOARD -> "${it.name},false" @@ -123,6 +121,10 @@ val defaultToolbarPref = entries.filterNot { it == CLOSE_HISTORY }.joinToString( } } +val defaultPinnedToolbarPref = entries.filterNot { it == CLOSE_HISTORY }.joinToString(";") { + "${it.name},false" +} + val defaultClipboardToolbarPref by lazy { val default = listOf(ONE_HANDED, UNDO, UP, DOWN, LEFT, RIGHT, CLEAR_CLIPBOARD, COPY, CUT, SELECT_WORD, CLOSE_HISTORY) val others = entries.filterNot { it in default } @@ -132,6 +134,7 @@ val defaultClipboardToolbarPref by lazy { /** add missing keys, typically because a new key has been added */ fun upgradeToolbarPrefs(prefs: SharedPreferences) { upgradeToolbarPref(prefs, Settings.PREF_TOOLBAR_KEYS, defaultToolbarPref) + upgradeToolbarPref(prefs, Settings.PREF_PINNED_TOOLBAR_KEYS, defaultPinnedToolbarPref) upgradeToolbarPref(prefs, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, defaultClipboardToolbarPref) } @@ -159,8 +162,31 @@ private fun upgradeToolbarPref(prefs: SharedPreferences, pref: String, default: fun getEnabledToolbarKeys(prefs: SharedPreferences) = getEnabledToolbarKeys(prefs, Settings.PREF_TOOLBAR_KEYS, defaultToolbarPref) +fun getPinnedToolbarKeys(prefs: SharedPreferences) = getEnabledToolbarKeys(prefs, Settings.PREF_PINNED_TOOLBAR_KEYS, defaultPinnedToolbarPref) + fun getEnabledClipboardToolbarKeys(prefs: SharedPreferences) = getEnabledToolbarKeys(prefs, Settings.PREF_CLIPBOARD_TOOLBAR_KEYS, defaultClipboardToolbarPref) +fun addPinnedKey(prefs: SharedPreferences, key: ToolbarKey) { + // remove the existing version of this key and add the enabled one after the last currently enabled key + val string = prefs.getString(Settings.PREF_PINNED_TOOLBAR_KEYS, defaultPinnedToolbarPref)!! + val keys = string.split(";").toMutableList() + keys.removeAll { it.startsWith(key.name + ",") } + val lastEnabledIndex = keys.indexOfLast { it.endsWith("true") } + keys.add(lastEnabledIndex + 1, key.name + ",true") + prefs.edit { putString(Settings.PREF_PINNED_TOOLBAR_KEYS, keys.joinToString(";")) } +} + +fun removePinnedKey(prefs: SharedPreferences, key: ToolbarKey) { + // just set it to disabled + val string = prefs.getString(Settings.PREF_PINNED_TOOLBAR_KEYS, defaultPinnedToolbarPref)!! + val result = string.split(";").joinToString(";") { + if (it.startsWith(key.name + ",")) + key.name + ",false" + else it + } + prefs.edit { putString(Settings.PREF_PINNED_TOOLBAR_KEYS, result) } +} + private fun getEnabledToolbarKeys(prefs: SharedPreferences, pref: String, default: String): List { val string = prefs.getString(pref, default)!! return string.split(";").mapNotNull { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f8dcbb9e5..51132e979 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -207,21 +207,21 @@ More keys Languages & Layouts - + Number row Always show number row - + Localize number row Prefer localized over latin numbers - + Show key hints Show long-press hints - + Select hint source - + Select popup key order Number row @@ -229,7 +229,7 @@ Language (priority) Layout Symbols - + Select toolbar keys @android:string/copy @@ -250,9 +250,15 @@ Undo Redo Close clipboard history - + Select clipboard toolbar keys - + + Select pinned toolbar keys + + Pin toolbar key on long press + + This will disable other long press actions for toolbar keys that are not pinned + Show functional hints Show hints if long-pressing a key triggers additional functionality @@ -264,9 +270,9 @@ Long press symbols key for numpad Narrow key gaps - + Keyboard height scale - + Bottom padding scale @@ -494,13 +500,13 @@ disposition rather than other common dispositions for Latin languages. [CHAR LIM Day Night - + Keypress vibration duration - + Keypress sound volume - + Key long press delay - + Emoji for physical keyboard Physical Alt key shows the emoji palette @@ -810,15 +816,15 @@ New dictionary: Pause Wait - + Horizontal spacebar swipe gesture - + Vertical spacebar swipe gesture None Move Cursor - + Variable toolbar direction Reverse direction when a right-to-left keyboard subtype is selected diff --git a/app/src/main/res/xml/prefs_screen_preferences.xml b/app/src/main/res/xml/prefs_screen_preferences.xml index 7db5936d7..8bd1fc582 100644 --- a/app/src/main/res/xml/prefs_screen_preferences.xml +++ b/app/src/main/res/xml/prefs_screen_preferences.xml @@ -99,10 +99,21 @@ android:key="toolbar_keys" android:title="@string/toolbar_keys" /> + + + +