Example usage for android.view.accessibility AccessibilityEvent getText

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

Introduction

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

Prototype

public List<CharSequence> getText() 

Source Link

Document

Gets the text of the event.

Usage

From source file:com.partynetwork.iparty.app.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/*ww  w.j av  a 2 s . c o m*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/
 * accessibility_codelab_demos_v2_src.zip via
 * https://github.com/coreform/android-formidable-validation
 * 
 * @param context
 *            Used to get {@link AccessibilityManager}
 * @param text
 *            The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = null;
        if (null != context) {
            accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
        }
        if (null == accessibilityManager || !accessibilityManager.isEnabled()) {
            return;
        }

        // Prior to SDK 16, announcements could only be made through FOCUSED
        // events. Jelly Bean (SDK 16) added support for speaking text
        // verbatim
        // using the ANNOUNCEMENT event type.
        final int eventType;
        if (Build.VERSION.SDK_INT < 16) {
            eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
        } else {
            eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
        }

        // Construct an accessibility event with the minimum recommended
        // attributes. An event without a class name or package may be
        // dropped.
        final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.getText().add(text);
        event.setClassName(Manager.class.getName());
        event.setPackageName(context.getPackageName());

        // Sends the event directly through the accessibility manager. If
        // your
        // application only targets SDK 14+, you should just call
        // getParent().requestSendAccessibilityEvent(this, event);
        accessibilityManager.sendAccessibilityEvent(event);
    }
}

From source file:com.arta.lib.widget.crouton.Manager.java

/**
 * Generates and dispatches an SDK-specific spoken announcement.
 * <p>/* w  ww .ja  va2 s.co m*/
 * For backwards compatibility, we're constructing an event from scratch
 * using the appropriate event type. If your application only targets SDK
 * 16+, you can just call View.announceForAccessibility(CharSequence).
 * </p>
 * <p/>
 * note: AccessibilityManager is only available from API lvl 4.
 * <p/>
 * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
 * via https://github.com/coreform/android-formidable-validation
 *
 * @param context
 *     Used to get {@link AccessibilityManager}
 * @param text
 *     The text to announce.
 */
public static void announceForAccessibilityCompat(Context context, CharSequence text) {
    if (Build.VERSION.SDK_INT >= 4) {
        AccessibilityManager accessibilityManager = null;
        if (null != context) {
            accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
        }
        if (null == accessibilityManager || !accessibilityManager.isEnabled()) {
            return;
        }

        // Prior to SDK 16, announcements could only be made through FOCUSED
        // events. Jelly Bean (SDK 16) added support for speaking text verbatim
        // using the ANNOUNCEMENT event type.
        final int eventType;
        if (Build.VERSION.SDK_INT < 16) {
            eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
        } else {
            eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
        }

        // Construct an accessibility event with the minimum recommended
        // attributes. An event without a class name or package may be dropped.
        final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
        event.getText().add(text);
        event.setClassName(Manager.class.getName());
        event.setPackageName(context.getPackageName());

        // Sends the event directly through the accessibility manager. If your
        // application only targets SDK 14+, you should just call
        // getParent().requestSendAccessibilityEvent(this, event);
        accessibilityManager.sendAccessibilityEvent(event);
    }
}

From source file:com.coreform.open.android.formidablevalidation.ValidationManager.java

/**
  * Generates and dispatches an SDK-specific spoken announcement.
  * <p>/*from ww w  .  j a v a 2 s . co m*/
  * For backwards compatibility, we're constructing an event from scratch
  * using the appropriate event type. If your application only targets SDK
  * 16+, you can just call View.announceForAccessibility(CharSequence).
  * </p>
  * 
  * Adapted from https://http://eyes-free.googlecode.com/files/accessibility_codelab_demos_v2_src.zip
  *
  * @param text The text to announce.
  */
public static void announceForAccessibilityCompat(CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // Prior to SDK 16, announcements could only be made through FOCUSED
    // events. Jelly Bean (SDK 16) added support for speaking text verbatim
    // using the ANNOUNCEMENT event type.
    final int eventType;
    if (Build.VERSION.SDK_INT < 16) {
        eventType = AccessibilityEvent.TYPE_VIEW_FOCUSED;
    } else {
        eventType = AccessibilityEventCompat.TYPE_ANNOUNCEMENT;
    }

    // Construct an accessibility event with the minimum recommended
    // attributes. An event without a class name or package may be dropped.
    final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
    event.getText().add(text);
    event.setClassName(SetErrorHandler.class.getName());
    event.setPackageName(mContext.getPackageName());

    // Sends the event directly through the accessibility manager. If your
    // application only targets SDK 14+, you should just call
    // getParent().requestSendAccessibilityEvent(this, event);
    mAccessibilityManager.sendAccessibilityEvent(event);
}

From source file:com.android.screenspeak.formatter.TextFormatters.java

/**
 * Returns the text for an event sent from a {@link android.widget.TextView}
 * widget./*from   w  ww. j  a  va  2 s  .  c o m*/
 *
 * @param event The source event.
 * @return The widget text, or {@code null}.
 */
private static CharSequence getEventText(AccessibilityEvent event) {
    final List<CharSequence> eventText = event.getText();

    if (eventText.isEmpty()) {
        return "";
    }

    return eventText.get(0);
}

From source file:Main.java

/**
 * @return If the <code>first</code> event is equal to the <code>second</code>.
 *///from w w w.java  2s.  co m
public static boolean eventEquals(AccessibilityEvent first, AccessibilityEvent second) {
    // TODO: The framework should implement AccessibilityEvent#equals()
    if (first == null || second == null) {
        return false;
    }
    if (first.getEventType() != second.getEventType()) {
        return false;
    }
    if (first.getPackageName() == null) {
        if (second.getPackageName() != null) {
            return false;
        }
    } else if (!first.getPackageName().equals(second.getPackageName())) {
        return false;
    }
    if (first.getClassName() == null) {
        if (second.getClassName() != null) {
            return false;
        }
    } else if (!first.getClassName().equals(second.getClassName())) {
        return false;
    }
    if (!first.getText().equals(second.getText())) {
        // The result of getText() is never null.
        return false;
    }
    if (first.getContentDescription() == null) {
        if (second.getContentDescription() != null) {
            return false;
        }
    } else if (!first.getContentDescription().equals(second.getContentDescription())) {
        return false;
    }
    if (first.getBeforeText() == null) {
        if (second.getBeforeText() != null) {
            return false;
        }
    } else if (!first.getBeforeText().equals(second.getBeforeText())) {
        return false;
    }
    if (first.getParcelableData() != null) {
        // Parcelable data may not implement equals() correctly.
        return false;
    }
    if (first.getAddedCount() != second.getAddedCount()) {
        return false;
    }
    if (first.isChecked() != second.isChecked()) {
        return false;
    }
    if (first.isEnabled() != second.isEnabled()) {
        return false;
    }
    if (first.getFromIndex() != second.getFromIndex()) {
        return false;
    }
    if (first.isFullScreen() != second.isFullScreen()) {
        return false;
    }
    if (first.getCurrentItemIndex() != second.getCurrentItemIndex()) {
        return false;
    }
    if (first.getItemCount() != second.getItemCount()) {
        return false;
    }
    if (first.isPassword() != second.isPassword()) {
        return false;
    }
    if (first.getRemovedCount() != second.getRemovedCount()) {
        return false;
    }
    if (first.getEventTime() != second.getEventTime()) {
        return false;
    }
    return true;
}

From source file:com.google.android.apps.forscience.whistlepunk.review.GraphExploringSeekBar.java

private void init() {
    // Use an AccessibilityDelegate to add custom text to Accessibility events.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {
        @Override/*  www . j  a v  a  2s.c  om*/
        public void onPopulateAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onPopulateAccessibilityEvent(host, event);
            event.getText().clear();
            event.getText().add(generateEventText());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            info.setText(generateEventText());
        }
    });

    Resources res = getContext().getResources();
    mFormat = res.getString(R.string.graph_exploring_seekbar_content_description);

    // Always use LTR layout, since graphs are always LTR.
    setLayoutDirection(LAYOUT_DIRECTION_LTR);
}

From source file:com.example.android.MyVoice.MainActivity.java

@Override
public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    event.getText().add("My Voice, main menu");
    event.getText().add(topMenuTextList.get(menuSelection));

    return true;/*from  www .j ava  2 s . c om*/
}

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

@Override
public void sendAccessibilityEvent(final int eventType) {
    if (!AccessibilityUtils.isAccessibilityEnabled(getContext())) {
        return;/*from  w ww .  ja  va  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: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,//  w w w  .  j a  v a 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.redinput.datetimepickercompat.AccessibleLinearLayout.java

private void installAccessibilityDelegate() {
    // The accessibility delegate enables customizing accessibility behavior
    // via composition as opposed as inheritance. The main benefit is that
    // one can write a backwards compatible application by setting the delegate
    // only if the API level is high enough i.e. the delegate is part of the APIs.
    // The easiest way to achieve that is by using the support library which
    // takes the burden of checking API version and knowing which API version
    // introduced the delegate off the developer.
    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() {

        @Override//from  w w  w. jav  a  2  s . c  om
        public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) {
            super.onInitializeAccessibilityEvent(host, event);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            event.getText().add(Button.class.getName());
        }

        @Override
        public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) {
            super.onInitializeAccessibilityNodeInfo(host, info);
            // Note that View.onInitializeAccessibilityNodeInfo was introduced in
            // ICS and we would like to tweak a bit the text that is reported to
            // accessibility services via the AccessibilityNodeInfo.
            info.setText(Button.class.getName());
        }
    });
}