Skip to content

Commit

Permalink
Added: ExtraKeys accessibility, announce state changes of special key…
Browse files Browse the repository at this point in the history
…s (CTRL, ALT, etc)
  • Loading branch information
alzwded committed Aug 18, 2024
1 parent 155efaa commit ec3ccd7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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();
}


Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
}
Expand All @@ -585,16 +611,20 @@ 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() {
// Toggle active and lock state
mState.setIsLocked(!mState.isActive);
mState.setIsActive(!mState.isActive);
mLongPressCount++;

announceSpecialKeyStateChangeForAccessibility(mButtonInfo, mState);
}
}

Expand Down
3 changes: 3 additions & 0 deletions termux-shared/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,8 @@
<string name="log_level_verbose">Verbose</string>
<string name="log_level_unknown">*Unknown*</string>
<string name="log_level_value">Logcat log level set to \"%1$s\"</string>
<string name="a11y_special_key_latched_on">on, locked</string>
<string name="a11y_special_key_off">off</string>
<string name="a11y_special_key_on">on</string>

</resources>

0 comments on commit ec3ccd7

Please sign in to comment.