アプリ内で TalkBack を使用したいが、一部のアクティビティの動作が異なるようにしたい。たとえば、特定のアクティビティに入るときに、そのボタンから指を離すときにボタンを選択する (ボタン クリックをトリガーする) 必要があります。TalkBack では、ダブルクリックのみでボタンを選択できます。
TalkBack ジェスチャを「オーバーライド」するにはどうすればよいですか?
ありがとう!
アプリ内で TalkBack を使用したいが、一部のアクティビティの動作が異なるようにしたい。たとえば、特定のアクティビティに入るときに、そのボタンから指を離すときにボタンを選択する (ボタン クリックをトリガーする) 必要があります。TalkBack では、ダブルクリックのみでボタンを選択できます。
TalkBack ジェスチャを「オーバーライド」するにはどうすればよいですか?
ありがとう!
HOVER_EXIT でクリック アクションを実行できますが、TalkBack が通常のダブルクリック アクションを期待しないようにするために、いくつかの作業を行う必要があります。電話ダイヤラーのDialPadImageButtonは、この動作の良い例です。そのクラスのコードの関連部分を次に示します。
@Override
public boolean onHoverEvent(MotionEvent event) {
// When touch exploration is turned on, lifting a finger while inside
// the button's hover target bounds should perform a click action.
if (mAccessibilityManager.isEnabled()
&& mAccessibilityManager.isTouchExplorationEnabled()) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_HOVER_ENTER:
// Lift-to-type temporarily disables double-tap activation.
setClickable(false);
break;
case MotionEvent.ACTION_HOVER_EXIT:
if (mHoverBounds.contains((int) event.getX(), (int) event.getY())) {
simulateClickForAccessibility();
}
setClickable(true);
break;
}
}
return super.onHoverEvent(event);
}
/**
* When accessibility is on, simulate press and release to preserve the
* semantic meaning of performClick(). Required for Braille support.
*/
private void simulateClickForAccessibility() {
// Checking the press state prevents double activation.
if (isPressed()) {
return;
}
setPressed(true);
// Stay consistent with performClick() by sending the event after
// setting the pressed state but before performing the action.
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
setPressed(false);
}