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.calendar.event.EditEventView.java

private void sendAccessibilityEvent() {
    AccessibilityManager am = (AccessibilityManager) mActivity.getSystemService(Service.ACCESSIBILITY_SERVICE);
    if (!am.isEnabled() || mModel == null) {
        return;/* w  ww  . j  ava 2  s.  c o  m*/
    }
    StringBuilder b = new StringBuilder();
    addFieldsRecursive(b, mView);
    CharSequence msg = b.toString();

    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    event.setClassName(getClass().getName());
    event.setPackageName(mActivity.getPackageName());
    event.getText().add(msg);
    event.setAddedCount(msg.length());

    am.sendAccessibilityEvent(event);
}

From source file:com.android.launcher3.Utilities.java

public static void sendCustomAccessibilityEvent(View target, int type, String text) {
    AccessibilityManager accessibilityManager = (AccessibilityManager) target.getContext()
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(type);
        target.onInitializeAccessibilityEvent(event);
        event.getText().add(text);//from  w  w  w .j a  va2s  . com
        accessibilityManager.sendAccessibilityEvent(event);
    }
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static void emitGeckoAccessibilityEvent(int eventType, String role, String text, String description,
        boolean enabled, boolean checked, boolean password) {
    AccessibilityManager accessibilityManager = (AccessibilityManager) GeckoApp.mAppContext
            .getSystemService(Context.ACCESSIBILITY_SERVICE);

    if (!accessibilityManager.isEnabled())
        return;/*  w  w w.  j a  v a 2  s  .  c  om*/

    LayerController layerController = GeckoApp.mAppContext.getLayerController();
    LayerView layerView = layerController.getView();

    AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.setClassName(layerView.getClass().getName() + "$" + role);
    event.setPackageName(GeckoApp.mAppContext.getPackageName());
    event.setEnabled(enabled);
    event.setChecked(checked);
    event.setPassword(password);
    event.setContentDescription(description);
    event.getText().add(text);

    accessibilityManager.sendAccessibilityEvent(event);
}

From source file:com.android.calendar.EventInfoFragment.java

private void sendAccessibilityEvent() {
    AccessibilityManager am = (AccessibilityManager) getActivity()
            .getSystemService(Service.ACCESSIBILITY_SERVICE);
    if (!am.isEnabled()) {
        return;/*from www  .  ja  v a2s  .  c om*/
    }

    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    event.setClassName(EventInfoFragment.class.getName());
    event.setPackageName(getActivity().getPackageName());
    List<CharSequence> text = event.getText();

    addFieldToAccessibilityEvent(text, mTitle, null);
    addFieldToAccessibilityEvent(text, mWhenDateTime, null);
    addFieldToAccessibilityEvent(text, mWhere, null);
    addFieldToAccessibilityEvent(text, null, mDesc);

    if (mResponseRadioGroup.getVisibility() == View.VISIBLE) {
        int id = mResponseRadioGroup.getCheckedRadioButtonId();
        if (id != View.NO_ID) {
            text.add(((TextView) getView().findViewById(R.id.response_label)).getText());
            text.add((((RadioButton) (mResponseRadioGroup.findViewById(id))).getText() + PERIOD_SPACE));
        }
    }

    am.sendAccessibilityEvent(event);
}