Example usage for android.view.accessibility AccessibilityEvent obtain

List of usage examples for android.view.accessibility AccessibilityEvent obtain

Introduction

In this page you can find the example usage for android.view.accessibility AccessibilityEvent obtain.

Prototype

public static AccessibilityEvent obtain(AccessibilityEvent event) 

Source Link

Document

Returns a cached instance if such is available or a new one is created.

Usage

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityDelegate.java

/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 *//*from  ww w.  jav  a 2 s .c om*/
protected void sendWindowStateChanged(final String text) {
    final AccessibilityEvent stateChange = AccessibilityEvent
            .obtain(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    mKeyboardView.onInitializeAccessibilityEvent(stateChange);
    stateChange.getText().add(text);
    stateChange.setContentDescription(null);

    final ViewParent parent = mKeyboardView.getParent();
    if (parent != null) {
        parent.requestSendAccessibilityEvent(mKeyboardView, stateChange);
    }
}

From source file:com.android.hareime.accessibility.AccessibilityEntityProvider.java

/**
 * Creates and populates an {@link AccessibilityEvent} for the specified key
 * and event type./*from ww  w  .  ja  v a 2s  .c  o  m*/
 *
 * @param key A key on the host keyboard view.
 * @param eventType The event type to create.
 * @return A populated {@link AccessibilityEvent} for the key.
 * @see AccessibilityEvent
 */
public AccessibilityEvent createAccessibilityEvent(Key key, int eventType) {
    final int virtualViewId = generateVirtualViewIdForKey(key);
    final String keyDescription = getKeyDescription(key);

    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mKeyboardView.getContext().getPackageName());
    event.setClassName(key.getClass().getName());
    event.setContentDescription(keyDescription);
    event.setEnabled(true);

    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mKeyboardView, virtualViewId);

    return event;
}

From source file:com.aprz.easy_iosched.ui.widget.CustomRatingBar.java

@Override
public void sendAccessibilityEvent(final int eventType) {
    if (!AccessibilityUtils.isAccessibilityEnabled(getContext())) {
        return;//w w  w . ja v a 2  s  .  c o m
    }
    super.sendAccessibilityEvent(eventType);

    AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    // Get the Talkback text.
    event.getText().add(
            getContext().getResources().getString(R.string.feedback_rating_confirmation, mRating, mMaxRating));
    event.setEnabled(true);
    AccessibilityManager accessibilityManager = (AccessibilityManager) getContext()
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    accessibilityManager.sendAccessibilityEvent(event);
}

From source file:com.onyx.latinime.accessibility.AccessibilityEntityProvider.java

/**
 * Creates and populates an {@link AccessibilityEvent} for the specified key
 * and event type.//from w w  w. j  a  v  a  2  s.  c o m
 *
 * @param key A key on the host keyboard view.
 * @param eventType The event type to create.
 * @return A populated {@link AccessibilityEvent} for the key.
 * @see AccessibilityEvent
 */
public AccessibilityEvent createAccessibilityEvent(final Key key, final int eventType) {
    final int virtualViewId = generateVirtualViewIdForKey(key);
    final String keyDescription = getKeyDescription(key);
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mKeyboardView.getContext().getPackageName());
    event.setClassName(key.getClass().getName());
    event.setContentDescription(keyDescription);
    event.setEnabled(true);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    record.setSource(mKeyboardView, virtualViewId);
    return event;
}

From source file:ti.modules.titanium.app.AppModule.java

@Kroll.method
public void fireSystemEvent(String eventName, @Kroll.argument(optional = true) Object arg) {
    if (eventName.equals(EVENT_ACCESSIBILITY_ANNOUNCEMENT)) {

        if (!getAccessibilityEnabled()) {
            Log.w(TAG,//from   ww w .  j a  va  2 s.  c o  m
                    "Accessibility announcement ignored. Accessibility services are not enabled on this device.");
            return;
        }

        if (arg == null) {
            Log.w(TAG, "Accessibility announcement ignored. No announcement text was provided.");
            return;
        }

        AccessibilityManager accessibilityManager = TiApplication.getInstance().getAccessibilityManager();
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
        event.setEnabled(true);
        event.getText().clear();
        event.getText().add(TiConvert.toString(arg));
        accessibilityManager.sendAccessibilityEvent(event);

    } else {
        Log.w(TAG, "Unknown system event: " + eventName);
    }
}

From source file:com.android.inputmethod.accessibility.KeyboardAccessibilityNodeProvider.java

/**
 * Creates and populates an {@link AccessibilityEvent} for the specified key
 * and event type./*w  w  w.j  av a 2s  .c om*/
 *
 * @param key A key on the host keyboard view.
 * @param eventType The event type to create.
 * @return A populated {@link AccessibilityEvent} for the key.
 * @see AccessibilityEvent
 */
public AccessibilityEvent createAccessibilityEvent(final Key key, final int eventType) {
    final int virtualViewId = getVirtualViewIdOf(key);
    final String keyDescription = getKeyDescription(key);
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setPackageName(mKeyboardView.getContext().getPackageName());
    event.setClassName(key.getClass().getName());
    event.setContentDescription(keyDescription);
    event.setEnabled(true);
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mKeyboardView, virtualViewId);
    return event;
}

From source file:com.onyx.latinime.accessibility.AccessibleKeyboardViewProxy.java

/**
 * Sends a window state change event with the specified text.
 *
 * @param text The text to send with the event.
 *//* w w w .j  ava 2  s  . co  m*/
private void sendWindowStateChanged(final String text) {
    final AccessibilityEvent stateChange = AccessibilityEvent
            .obtain(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    mView.onInitializeAccessibilityEvent(stateChange);
    stateChange.getText().add(text);
    stateChange.setContentDescription(null);

    final ViewParent parent = mView.getParent();
    if (parent != null) {
        parent.requestSendAccessibilityEvent(mView, stateChange);
    }
}

From source file:com.android.yijiang.kzx.widget.betterpickers.TouchExplorationHelper.java

private AccessibilityEvent getEventForItem(T item, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    event.setEnabled(true);/*from w  w  w. j  a  va 2  s. c  o  m*/

    // Allow the client to populate the event.
    populateEventForItem(item, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setClassName(item.getClass().getName());
    event.setPackageName(mParentView.getContext().getPackageName());
    record.setSource(mParentView, virtualDescendantId);

    return event;
}

From source file:com.deange.datetimepicker.TouchExplorationHelper.java

private AccessibilityEvent getEventForItem(T item, int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
    final int virtualDescendantId = getIdForItem(item);

    // Ensure the client has good defaults.
    event.setEnabled(true);//from  ww w  .  ja va2 s. co  m

    // Allow the client to populate the event.
    populateEventForItem(item, event);

    if (event.getText().isEmpty() && TextUtils.isEmpty(event.getContentDescription())) {
        throw new RuntimeException("You must add text or a content description in populateEventForItem()");
    }

    // Don't allow the client to override these properties.
    event.setClassName(item.getClass().getName());
    event.setPackageName(mParentView.getContext().getPackageName());
    record.setSource(mParentView, virtualDescendantId);

    return event;
}

From source file:com.android.utils.ExploreByTouchHelper.java

private AccessibilityEvent getEventForRoot(int eventType) {
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    mHost.onInitializeAccessibilityEvent(event);

    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(mHost, ROOT_ID);// www .  jav a  2s  .  c  o m

    return event;
}