2013-06-10 3 views
2

내 앱에서 음성 안내 지원을 사용하고 싶지만 일부 활동이 다르게 동작하기를 원합니다. 예를 들어 특정 활동을 입력 할 때 해당 버튼에서 손가락을 들어 올리면 버튼을 클릭 (버튼 클릭 트리거)하고 싶습니다. 음성 안내 지원을 사용하면 두 번 클릭하여 버튼을 선택할 수 있습니다.Android - 음성 안내 동작 무시

음성 안내 지원 동작을 어떻게 "재정의"할 수 있습니까?

감사합니다.

+0

안녕하세요 @ Amir .. 거기에 어떤 해결책이 있습니까 ?? – Prabs

답변

2

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); 
}