From ec3ccd75745cda79b52bf71b427df04ff11c8615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vlad=20Me=C8=99co?= Date: Sun, 18 Aug 2024 13:58:05 +0300 Subject: [PATCH] Added: ExtraKeys accessibility, announce state changes of special keys (CTRL, ALT, etc) --- .../termux/extrakeys/ExtraKeysView.java | 34 +++++++++++++++++-- termux-shared/src/main/res/values/strings.xml | 3 ++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/termux-shared/src/main/java/com/termux/shared/termux/extrakeys/ExtraKeysView.java b/termux-shared/src/main/java/com/termux/shared/termux/extrakeys/ExtraKeysView.java index 86619e62e0..2d464ebf2d 100644 --- a/termux-shared/src/main/java/com/termux/shared/termux/extrakeys/ExtraKeysView.java +++ b/termux-shared/src/main/java/com/termux/shared/termux/extrakeys/ExtraKeysView.java @@ -25,6 +25,7 @@ import android.view.View; import android.view.ViewConfiguration; import android.view.ViewGroup; +import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityNodeInfo; import android.widget.GridLayout; import android.widget.PopupWindow; @@ -209,6 +210,7 @@ public interface IExtraKeysView { protected SpecialButtonsLongHoldRunnable mSpecialButtonsLongHoldRunnable; protected int mLongPressCount; + protected boolean mAccessibilityEnabled; public ExtraKeysView(Context context, AttributeSet attrs) { super(context, attrs); @@ -224,6 +226,9 @@ public ExtraKeysView(Context context, AttributeSet attrs) { setLongPressTimeout(ViewConfiguration.getLongPressTimeout()); setLongPressRepeatDelay(DEFAULT_LONG_PRESS_REPEAT_DELAY); + + AccessibilityManager am = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE); + mAccessibilityEnabled = am.isEnabled(); } @@ -540,11 +545,32 @@ public void onAnyExtraKeyButtonClick(View view, @NonNull ExtraKeyButton buttonIn state.setIsActive(!state.isActive); if (!state.isActive) state.setIsLocked(false); + + announceSpecialKeyStateChangeForAccessibility(buttonInfo, state); } else { onExtraKeyButtonClick(view, buttonInfo, button); } } + private void announceSpecialKeyStateChangeForAccessibility(@NonNull ExtraKeyButton buttonInfo, SpecialButtonState state) { + if(mAccessibilityEnabled) { + CharSequence stateText; + if(!state.isActive) { + stateText = getResources().getText(R.string.a11y_special_key_off); + } else if(state.isLocked) { + stateText = getResources().getText(R.string.a11y_special_key_latched_on); + } else { + stateText = getResources().getText(R.string.a11y_special_key_on); + + } + String announcementText = buttonInfo.getKey() + + " " + + stateText + ; + announceForAccessibility(announcementText); + } + } + public void startScheduledExecutors(View view, ExtraKeyButton buttonInfo, MaterialButton button) { stopScheduledExecutors(); @@ -566,7 +592,7 @@ public void startScheduledExecutors(View view, ExtraKeyButton buttonInfo, Materi if (state == null) return; if (mHandler == null) mHandler = new Handler(Looper.getMainLooper()); - mSpecialButtonsLongHoldRunnable = new SpecialButtonsLongHoldRunnable(state); + mSpecialButtonsLongHoldRunnable = new SpecialButtonsLongHoldRunnable(state, buttonInfo); mHandler.postDelayed(mSpecialButtonsLongHoldRunnable, mLongPressTimeout); } } @@ -585,9 +611,11 @@ public void stopScheduledExecutors() { public class SpecialButtonsLongHoldRunnable implements Runnable { public final SpecialButtonState mState; + public final ExtraKeyButton mButtonInfo; - public SpecialButtonsLongHoldRunnable(SpecialButtonState state) { + public SpecialButtonsLongHoldRunnable(SpecialButtonState state, ExtraKeyButton buttonInfo) { mState = state; + mButtonInfo = buttonInfo; } public void run() { @@ -595,6 +623,8 @@ public void run() { mState.setIsLocked(!mState.isActive); mState.setIsActive(!mState.isActive); mLongPressCount++; + + announceSpecialKeyStateChangeForAccessibility(mButtonInfo, mState); } } diff --git a/termux-shared/src/main/res/values/strings.xml b/termux-shared/src/main/res/values/strings.xml index d585e24f97..b5e4ce4dba 100644 --- a/termux-shared/src/main/res/values/strings.xml +++ b/termux-shared/src/main/res/values/strings.xml @@ -134,5 +134,8 @@ Verbose *Unknown* Logcat log level set to \"%1$s\" + on, locked + off + on