Example usage for android.view.accessibility AccessibilityEvent setEnabled

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

Introduction

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

Prototype

public void setEnabled(boolean isEnabled) 

Source Link

Document

Sets if the source is enabled.

Usage

From source file:Main.java

/**
 * Announce text through the AccessibilityManager for a view.
 *
 * @param text//  ww w . jav a 2 s. c om
 * @param view
 * @param manager
 */
public static void announceText(String text, View view, AccessibilityManager manager) {
    // Only announce text if the accessibility service is enabled
    if (!manager.isEnabled()) {
        return;
    }
    AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    event.getText().add(text);
    event.setEnabled(true);
    // Tie the event to the view
    event.setClassName(view.getClass().getName());
    event.setPackageName(view.getContext().getPackageName());
    AccessibilityEventCompat.asRecord(event).setSource(view);

    // Send the announcement
    manager.sendAccessibilityEvent(event);

}

From source file:com.android.messaging.util.AccessibilityUtil.java

public static void announceForAccessibilityCompat(final View view,
        @Nullable AccessibilityManager accessibilityManager, final CharSequence text) {
    final Context context = view.getContext().getApplicationContext();
    if (accessibilityManager == null) {
        accessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
    }/* www . j  ava 2  s  . c o m*/

    if (!accessibilityManager.isEnabled()) {
        return;
    }

    // Jelly Bean added support for speaking text verbatim
    final int eventType = OsUtil.isAtLeastJB() ? AccessibilityEvent.TYPE_ANNOUNCEMENT
            : AccessibilityEvent.TYPE_VIEW_FOCUSED;

    // 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.setEnabled(view.isEnabled());
    event.setClassName(view.getClass().getName());
    event.setPackageName(context.getPackageName());

    // JellyBean MR1 requires a source view to set the window ID.
    final AccessibilityRecordCompat record = AccessibilityEventCompat.asRecord(event);
    record.setSource(view);

    // Sends the event directly through the accessibility manager. If we only supported SDK 14+
    // we could have done:
    // getParent().requestSendAccessibilityEvent(this, event);
    accessibilityManager.sendAccessibilityEvent(event);
}

From source file:com.android.gallery3d.util.AccessibilityUtils.java

public static void makeAnnouncement(View view, CharSequence announcement) {
    if (view == null)
        return;// w w w.  j  a  v a2s . com
    if (ApiHelper.HAS_ANNOUNCE_FOR_ACCESSIBILITY) {
        view.announceForAccessibility(announcement);
    } else {
        // For API 15 and earlier, we need to construct an accessibility event
        Context ctx = view.getContext();
        AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!am.isEnabled())
            return;
        AccessibilityEvent event = AccessibilityEvent
                .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
        AccessibilityRecordCompat arc = new AccessibilityRecordCompat(event);
        arc.setSource(view);
        event.setClassName(view.getClass().getName());
        event.setPackageName(view.getContext().getPackageName());
        event.setEnabled(view.isEnabled());
        event.getText().add(announcement);
        am.sendAccessibilityEvent(event);
    }
}

From source file:com.android.fastergallery.util.AccessibilityUtils.java

public static void makeAnnouncement(View view, CharSequence announcement) {
    if (view == null)
        return;// www .  ja  va2  s.  c o m
    if (ApiHelper.HAS_ANNOUNCE_FOR_ACCESSIBILITY) {
        view.announceForAccessibility(announcement);
    } else {
        // For API 15 and earlier, we need to construct an accessibility
        // event
        Context ctx = view.getContext();
        AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!am.isEnabled())
            return;
        AccessibilityEvent event = AccessibilityEvent
                .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
        AccessibilityRecordCompat arc = new AccessibilityRecordCompat(event);
        arc.setSource(view);
        event.setClassName(view.getClass().getName());
        event.setPackageName(view.getContext().getPackageName());
        event.setEnabled(view.isEnabled());
        event.getText().add(announcement);
        am.sendAccessibilityEvent(event);
    }
}

From source file:com.appeaser.sublimepickerlibrary.utilities.AccessibilityUtils.java

public static void makeAnnouncement(View view, CharSequence announcement) {
    if (view == null)
        return;/*  w w  w .ja  va2s .c  o m*/
    if (SUtils.isApi_16_OrHigher()) {
        view.announceForAccessibility(announcement);
    } else {
        // For API 15 and earlier, we need to construct an accessibility event
        Context ctx = view.getContext();
        AccessibilityManager am = (AccessibilityManager) ctx.getSystemService(Context.ACCESSIBILITY_SERVICE);
        if (!am.isEnabled())
            return;

        AccessibilityEvent event = AccessibilityEvent
                .obtain(AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED);
        AccessibilityRecordCompat arc = AccessibilityEventCompat.asRecord(event);
        arc.setSource(view);
        event.setClassName(view.getClass().getName());
        event.setPackageName(view.getContext().getPackageName());
        event.setEnabled(view.isEnabled());
        event.getText().add(announcement);
        am.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,/*from w w w  . jav  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.phonemetra.turbo.keyboard.accessibility.AccessibilityUtils.java

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.//from  ww  w  .  j a v a  2s.  c om
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

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

/**
 * Sends the specified text to the {@link AccessibilityManager} to be
 * spoken.//from   ww  w. j a va 2 s .co  m
 *
 * @param view The source view.
 * @param text The text to speak.
 */
public void announceForAccessibility(final View view, final CharSequence text) {
    if (!mAccessibilityManager.isEnabled()) {
        Log.e(TAG, "Attempted to speak when accessibility was disabled!");
        return;
    }

    // The following is a hack to avoid using the heavy-weight TextToSpeech
    // class. Instead, we're just forcing a fake AccessibilityEvent into
    // the screen reader to make it speak.
    final AccessibilityEvent event = AccessibilityEvent.obtain();

    event.setPackageName(PACKAGE);
    event.setClassName(CLASS);
    event.setEventTime(SystemClock.uptimeMillis());
    event.setEnabled(true);
    event.getText().add(text);

    // Platforms starting at SDK version 16 (Build.VERSION_CODES.JELLY_BEAN) should use
    // announce events.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        event.setEventType(AccessibilityEventCompat.TYPE_ANNOUNCEMENT);
    } else {
        event.setEventType(AccessibilityEvent.TYPE_VIEW_FOCUSED);
    }

    final ViewParent viewParent = view.getParent();
    if ((viewParent == null) || !(viewParent instanceof ViewGroup)) {
        Log.e(TAG, "Failed to obtain ViewParent in announceForAccessibility");
        return;
    }

    viewParent.requestSendAccessibilityEvent(view, event);
}

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

@Override
public void sendAccessibilityEvent(final int eventType) {
    if (!AccessibilityUtils.isAccessibilityEnabled(getContext())) {
        return;/*from   ww w.j  a v a2 s  . co  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.//  w w  w . jav 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;
}