From 0cd36adadf8ee73b987edd247eb09d4a1eb730b6 Mon Sep 17 00:00:00 2001 From: Twaik Yont Date: Mon, 15 Jul 2024 15:26:48 +0300 Subject: [PATCH] Moving the most of visible texts and labels to strings.xml --- .../java/com/termux/x11/LoriePreferences.java | 83 ++-- .../java/com/termux/x11/MainActivity.java | 2 +- .../termux/x11/input/TouchInputHandler.java | 13 +- app/src/main/res/values/strings.xml | 102 ++++- app/src/main/res/xml/preferences.xml | 395 +++--------------- 5 files changed, 204 insertions(+), 391 deletions(-) diff --git a/app/src/main/java/com/termux/x11/LoriePreferences.java b/app/src/main/java/com/termux/x11/LoriePreferences.java index aee98635f..f9c0b0841 100644 --- a/app/src/main/java/com/termux/x11/LoriePreferences.java +++ b/app/src/main/java/com/termux/x11/LoriePreferences.java @@ -39,9 +39,9 @@ import androidx.appcompat.app.AppCompatActivity; import androidx.preference.PreferenceDataStore; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.PreferenceGroup; import androidx.preference.Preference.OnPreferenceChangeListener; +import androidx.preference.PreferenceScreen; import androidx.preference.SeekBarPreference; import android.provider.Settings; @@ -221,6 +221,12 @@ private void with(CharSequence key, Consumer action) { action.accept(p); } + @SuppressLint("DiscouragedApi") + int findId(String name) { + //noinspection DataFlowIssue + return getResources().getIdentifier("pref_" + name, "string", getContext().getPackageName()); + } + /** @noinspection DataFlowIssue*/ @Override @SuppressLint("ApplySharedPref") public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) { @@ -230,17 +236,37 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S prefs.touchMode.put("1"); setPreferencesFromResource(R.xml.preferences, root == null ? "main" : root); + + int id; + PreferenceScreen screen = getPreferenceScreen(); + if ((id = findId(screen.getKey())) != 0) + getPreferenceScreen().setTitle(getResources().getString(id)); + for (int i=0; i p.setLayoutResource(R.layout.preference)); with("version", p -> p.setSummary(BuildConfig.VERSION_NAME)); - String requiresExactOrCustom = "Requires \"display resolution mode\" to be \"exact\" or \"custom\""; - String requiresIntercepting = "Requires intercepting system shortcuts with Dex mode or with Accessibility service"; - String requiresTrackpadAndNative = "Requires \"Touchscreen input mode\" to be \"Trackpad\" and \"Display resolution mode\" to be not \"native\""; - - setSummary("displayStretch", requiresExactOrCustom); - setSummary("adjustResolution", requiresExactOrCustom); - setSummary("pauseKeyInterceptingWithEsc", requiresIntercepting); - setSummary("scaleTouchpad", requiresTrackpadAndNative); + setSummary("displayStretch", R.string.pref_summary_requiresExactOrCustom); + setSummary("adjustResolution", R.string.pref_summary_requiresExactOrCustom); + setSummary("pauseKeyInterceptingWithEsc", R.string.pref_summary_requiresIntercepting); + setSummary("scaleTouchpad", R.string.pref_summary_requiresTrackpadAndNative); if (!SamsungDexUtils.available()) setVisible("dexMetaKeyCapture", false); @@ -256,26 +282,18 @@ public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable S setVisible("showStylusClickOverride", stylusAvailable); setVisible("stylusIsMouse", stylusAvailable); setVisible("stylusButtonContactModifierMode", stylusAvailable); - - ListPreference p; - for (String key: prefs.keys.keySet()) { - if (!key.endsWith("Action") || (p = findPreference(key)) == null) - continue; - - p.setEntries(prefs.keys.get(key).asList().getEntries()); - p.setEntryValues(prefs.keys.get(key).asList().getValues()); - } + setVisible("xrMode", XrActivity.isSupported()); setNoActionOptionText(findPreference("volumeDownAction"), "android volume control"); setNoActionOptionText(findPreference("volumeUpAction"), "android volume control"); } - private void setSummary(CharSequence key, CharSequence disabled) { + private void setSummary(CharSequence key, int disabled) { Preference pref = findPreference(key); if (pref != null) pref.setSummaryProvider(new Preference.SummaryProvider<>() { @Nullable @Override public CharSequence provideSummary(@NonNull Preference p) { - return p.isEnabled() ? null : disabled; + return p.isEnabled() ? null : getResources().getString(disabled); } }); } @@ -297,7 +315,11 @@ void updatePreferencesLayout() { if (getContext() == null) return; - reloadPrefs(); + for (String key : prefs.keys.keySet()) { + Preference p = findPreference(key); + if (p != null) + onSetInitialValue(p); + } String displayResMode = prefs.displayResolutionMode.get(); setVisible("displayScale", displayResMode.contentEquals("scaled")); @@ -341,20 +363,9 @@ private void setNoActionOptionText(Preference preference, CharSequence text) { public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setListeners(getPreferenceScreen()); updatePreferencesLayout(); } - void setListeners(PreferenceGroup g) { - for (int i=0; i < g.getPreferenceCount(); i++) { - g.getPreference(i).setOnPreferenceChangeListener(this); - g.getPreference(i).setPreferenceDataStore(prefs); - - if (g.getPreference(i) instanceof PreferenceGroup) - setListeners((PreferenceGroup) g.getPreference(i)); - } - } - @Override public boolean onPreferenceTreeClick(@NonNull Preference p) { if (p.getKey() == null) @@ -378,14 +389,6 @@ public boolean onPreferenceTreeClick(@NonNull Preference p) { return super.onPreferenceTreeClick(p); } - public void reloadPrefs() { - for (String key : prefs.keys.keySet()) { - Preference p = findPreference(key); - if (p != null) - onSetInitialValue(p); - } - } - @SuppressLint("ApplySharedPref") @Override public boolean onPreferenceChange(Preference preference, Object newValue) { diff --git a/app/src/main/java/com/termux/x11/MainActivity.java b/app/src/main/java/com/termux/x11/MainActivity.java index 3129940aa..883052b81 100644 --- a/app/src/main/java/com/termux/x11/MainActivity.java +++ b/app/src/main/java/com/termux/x11/MainActivity.java @@ -635,7 +635,7 @@ Notification buildNotification() { NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getNotificationChannel(mNotificationManager)) .setContentTitle("Termux:X11") .setSmallIcon(R.drawable.ic_x11_icon) - .setContentText("Pull down to show options") + .setContentText(getResources().getText(R.string.notification_content_text)) .setOngoing(true) .setPriority(Notification.PRIORITY_MAX) .setSilent(true) diff --git a/app/src/main/java/com/termux/x11/input/TouchInputHandler.java b/app/src/main/java/com/termux/x11/input/TouchInputHandler.java index cd77fd2e5..80b3f2369 100644 --- a/app/src/main/java/com/termux/x11/input/TouchInputHandler.java +++ b/app/src/main/java/com/termux/x11/input/TouchInputHandler.java @@ -516,20 +516,15 @@ public PendingIntent extractIntentFromPreferences(Prefs p, String name, int requ } } + @SuppressLint("DiscouragedApi") public String extractTitleFromPreferences(Prefs p, String name) { LoriePreferences.PrefsProto.Preference pref = p.keys.get(name + "Action"); if (pref == null) return null; - switch(pref.asList().get()) { - case "open preferences": return "Preferences"; - case "exit": return "Exit"; - case "restart activity": return "Restart"; - case "toggle soft keyboard": return "Toggle IME"; - case "toggle additional key bar": return "Toggle additional keyboard"; - case "release pointer and keyboard capture": return "Release captures"; - default: return null; - } + String key = pref.asList().get().replace(' ', '_'); + int id = mActivity.getResources().getIdentifier("notification_" + key, "string", mActivity.getPackageName()); + return id == 0 ? null : mActivity.getResources().getString(id); } public NotificationCompat.Builder setupNotification(Prefs prefs, NotificationCompat.Builder builder) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 32918e1cb..8a6d41b55 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -44,13 +44,99 @@ E.g. META for META key, \n MOUSE_HELPER for mouse helper toggling key, \n STYLUS_HELPER for stylus click override overlay toggling key, \n EXIT for application exit key. + Pull down to show options + Preferences + Exit + Restart + Toggle IME + Toggle additional keyboard + Release captures - - Log Level - Off - Normal - Debug - Verbose - *Unknown* - Logcat log level set to \"%1$s\" + Preferences + Output + Pointer + Keyboard + Other + Version + Extra key bar preferences + Response to user actions + + Display resolution mode + Display scale, % + Display resolution + Display resolution + Adjust the set resolution to fit screen orientation + Stretch to fit display + Reseed screen while soft keyboard is open + The screen size will be adjusted while Soft Keyboard is open. + PIP mode + Show app in picture-in-picture mode when home button or recents button is pressed + Fullscreen + Toggle immersive mode in your device display + Force screen orientation + Hide display cutout (if any) + Keep Screen On + + Touchscreen input mode + Apply display scale factor to touchpad + Show stylus click options + Stylus touch override, left, middle or right click (stylus only) + Enable stylus mouse mode + Make your stylus work like a mouse. When activated, stylus will only move the cursor and send mouse clicks, ignoring pressure, angle, and tilt. + Stylus button contact modifier mode + Enable this option to send right or middle mouse buttons only when stylus touches the screen while the button is pressed. + Show mouse click helper overlay + Onscreen mouse buttons usable with touchpad + Capture external pointer devices when possible + Intercept all hardware pointer events. Pointer is back to Android after pressing Escape key. + Transform captured pointer movements + Captured pointer speed factor, % + Enable tap-to-move for touchpads + + Show additional keyboard + Show keyboard with additional keys. + Show IME with external keyboard + Show software keyboard while hardware keyboard is connected. + Prefer scancodes when possible + Let X server handle hardware keyboard layout (with DE settings or setxkbmap). + Hardware keyboard scancodes workaround + Fixes scancodes on some devices. Might cause problems with multiple layouts. + Intercept system shortcuts + Samsung Dex only. Allows interception of "Alt+F4", "Meta+D", "Meta+E", etc. + Enable Accessibility service for intercepting system shortcuts manually. + Open Accessibility settings. + Enable Accessibility service for intercepting system shortcuts automatically. + Requires WRITE_SECURE_SETTINGS permission. + Pause key intercepting with Esc key + Filter out intercepted Win (Meta/Mod4) key. + Allows you to use Dex shortcuts while intercepting. Requires Accessibility service to work. + Workaround to enable CJK Gboard + May require Android 14 and Gboard 14 + + Clipboard sharing + Request notification permission + Meta Oculus XR mode + Configure response to user actions + Store preferences for secondary displays separately + Open this screen on display you want to configure + + Adjust display height for extra keys bar + May cause screen flickering during toggling EK bar. + Deactivate special keys on additional key bar after each keypress + Use long-tap to lock special keys + Opacity of extra keys bar, % + Extra keys config + + Three finger swipe up + Three finger swipe down + Volume up + Volume down + Back button + Notification tap + Notification first button + Notification second button + + Requires "display resolution mode" to be "exact" or "custom" + Requires intercepting system shortcuts with Dex mode or with Accessibility service + Requires "Touchscreen input mode" to be "Trackpad" and "Display resolution mode" to be not "native" diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index dad667b34..62037c1ad 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -2,347 +2,76 @@ - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - + + - - - - - - - - - - - + + + + + + - - - - - - - - + + + + - - - - - - - - - - - + + + + + + - - - - - - - - - + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + +