Example usage for android.view.accessibility AccessibilityEvent TYPE_ANNOUNCEMENT

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

Introduction

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

Prototype

int TYPE_ANNOUNCEMENT

To view the source code for android.view.accessibility AccessibilityEvent TYPE_ANNOUNCEMENT.

Click Source Link

Document

Represents the event of an application making an announcement.

Usage

From source file:com.android.talkback.TalkBackKeyboardShortcutPreferencesActivity.java

/**
 * Utility method for announcing text via accessibility event.
 *//* w ww  .  ja va  2  s . c  om*/
public static void announceText(String text, Context context) {
    AccessibilityManager accessibilityManager = (AccessibilityManager) context
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    if (accessibilityManager.isEnabled()) {
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        event.setContentDescription(text);
        accessibilityManager.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);
    }/*from w w w . j a  va  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.utils.AccessibilityEventUtils.java

public static int[] getAllEventTypes() {
    return new int[] { AccessibilityEvent.TYPE_ANNOUNCEMENT, AccessibilityEvent.TYPE_ASSIST_READING_CONTEXT,
            AccessibilityEvent.TYPE_GESTURE_DETECTION_END, AccessibilityEvent.TYPE_GESTURE_DETECTION_START,
            AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED,
            AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END,
            AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_START,
            AccessibilityEvent.TYPE_TOUCH_INTERACTION_END, AccessibilityEvent.TYPE_TOUCH_INTERACTION_START,
            AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED,
            AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED, AccessibilityEvent.TYPE_VIEW_CLICKED,
            AccessibilityEvent.TYPE_VIEW_CONTEXT_CLICKED, AccessibilityEvent.TYPE_VIEW_FOCUSED,
            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER, AccessibilityEvent.TYPE_VIEW_HOVER_EXIT,
            AccessibilityEvent.TYPE_VIEW_LONG_CLICKED, AccessibilityEvent.TYPE_VIEW_SCROLLED,
            AccessibilityEvent.TYPE_VIEW_SELECTED, AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED,
            AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED,
            AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY,
            AccessibilityEvent.TYPE_WINDOWS_CHANGED, AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED,
            AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED };
}

From source file:com.android.mail.utils.ViewUtils.java

/**
 * Convenience method for sending a {@link android.view.accessibility.AccessibilityEvent#TYPE_ANNOUNCEMENT}
 * {@link android.view.accessibility.AccessibilityEvent} to make an announcement which is related to some
 * sort of a context change for which none of the events representing UI transitions
 * is a good fit. For example, announcing a new page in a book. If accessibility
 * is not enabled this method does nothing.
 *
 * @param view view to perform the accessibility announcement
 * @param text The announcement text./*from  w  w w.ja  va  2s.c om*/
 */
public static void announceForAccessibility(View view, CharSequence text) {
    final AccessibilityManager accessibilityManager = (AccessibilityManager) view.getContext()
            .getSystemService(Context.ACCESSIBILITY_SERVICE);
    final ViewParent parent = view.getParent();
    if (accessibilityManager.isEnabled() && parent != null) {
        AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        view.onInitializeAccessibilityEvent(event);
        event.getText().add(text);
        event.setContentDescription(null);
        parent.requestSendAccessibilityEvent(view, event);
    }
}

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

@Override
public void onClick(final View v) {
    mRating = (int) v.getTag();
    drawRatingViews();//from  w  ww  .  j a  v a 2  s .c  o m
    int eventType = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
            ? AccessibilityEvent.TYPE_ANNOUNCEMENT
            : AccessibilityEvent.TYPE_VIEW_FOCUSED;
    sendAccessibilityEvent(eventType);
}

From source file:com.android.screenspeak.eventprocessor.ProcessorPhoneticLetters.java

/**
 * Returns true if a pending phonetic letter should be interrupted.
 *///from   w  w  w .ja va 2s . c  om
private boolean shouldCancelPhoneticLetter(AccessibilityEvent event) {
    return event.getEventType() != AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED
            && event.getEventType() != AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED
            && event.getEventType() != AccessibilityEvent.TYPE_VIEW_LONG_CLICKED
            && event.getEventType() != AccessibilityEvent.TYPE_ANNOUNCEMENT;
}

From source file:gov.wa.wsdot.android.wsdot.ui.mountainpasses.passitem.MountainPassItemActivity.java

private void toggleStar(MenuItem item) {
    Snackbar added_snackbar = Snackbar.make(findViewById(R.id.activity_with_tabs), R.string.add_favorite,
            Snackbar.LENGTH_SHORT);//  w  w w. ja v a 2  s .  co m

    Snackbar removed_snackbar = Snackbar.make(findViewById(R.id.activity_with_tabs), R.string.remove_favorite,
            Snackbar.LENGTH_SHORT);

    added_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("added to favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    removed_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("removed from favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        item.setTitle("Favorite checkbox, not checked");
        viewModel.setIsStarredFor(mId, 0);
        removed_snackbar.show();
        mIsStarred = false;
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        item.setTitle("Favorite checkbox, checked");
        viewModel.setIsStarredFor(mId, 1);
        added_snackbar.show();
        mIsStarred = true;
    }
}

From source file:gov.wa.wsdot.android.wsdot.ui.ferries.departures.FerriesRouteSchedulesDayDeparturesActivity.java

private void toggleStar(MenuItem item) {
    Snackbar added_snackbar = Snackbar.make(findViewById(R.id.activity_ferry_sailings), R.string.add_favorite,
            Snackbar.LENGTH_SHORT);/*from w  w  w  .  j av  a2 s  . c  o m*/

    Snackbar removed_snackbar = Snackbar.make(findViewById(R.id.activity_ferry_sailings),
            R.string.remove_favorite, Snackbar.LENGTH_SHORT);

    added_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("added to favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    removed_snackbar.addCallback(new Snackbar.Callback() {
        @Override
        public void onShown(Snackbar snackbar) {
            super.onShown(snackbar);
            snackbar.getView().setContentDescription("removed from favorites");
            snackbar.getView().sendAccessibilityEvent(AccessibilityEvent.TYPE_ANNOUNCEMENT);
        }
    });

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        item.setTitle("Favorite checkbox, not checked");
        scheduleViewModel.setIsStarredFor(mScheduleId, 0);
        removed_snackbar.show();
        mIsStarred = false;
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        item.setTitle("Favorite checkbox, checked");
        scheduleViewModel.setIsStarredFor(mScheduleId, 1);
        added_snackbar.show();
        mIsStarred = true;
    }
}

From source file:com.android.incallui.CallCardFragment.java

public void dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
    if (event.getEventType() == AccessibilityEvent.TYPE_ANNOUNCEMENT) {
        // Indicate this call is in active if no label is provided. The label is empty when
        // the call is in active, not in other status such as onhold or dialing etc.
        if (!mCallStateLabel.isShown() || TextUtils.isEmpty(mCallStateLabel.getText())) {
            event.getText().add(TextUtils.expandTemplate(
                    getResources().getText(R.string.accessibility_call_is_active), mPrimaryName.getText()));
        } else {/* w  ww  . j av  a  2  s  .  c o  m*/
            dispatchPopulateAccessibilityEvent(event, mCallStateLabel);
            dispatchPopulateAccessibilityEvent(event, mPrimaryName);
            dispatchPopulateAccessibilityEvent(event, mCallTypeLabel);
            dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
        }
        return;
    }
    dispatchPopulateAccessibilityEvent(event, mCallStateLabel);
    dispatchPopulateAccessibilityEvent(event, mPrimaryName);
    dispatchPopulateAccessibilityEvent(event, mPhoneNumber);
    dispatchPopulateAccessibilityEvent(event, mCallTypeLabel);
    dispatchPopulateAccessibilityEvent(event, mSecondaryCallName);
    dispatchPopulateAccessibilityEvent(event, mSecondaryCallProviderLabel);

    return;
}

From source file:com.android.incallui.CallCardFragment.java

@Override
public void sendAccessibilityAnnouncement() {
    mHandler.postDelayed(new Runnable() {
        @Override//from  ww w  .java  2s. c  o m
        public void run() {
            if (getView() != null && getView().getParent() != null && isAccessibilityEnabled(getContext())) {
                AccessibilityEvent event = AccessibilityEvent.obtain(AccessibilityEvent.TYPE_ANNOUNCEMENT);
                dispatchPopulateAccessibilityEvent(event);
                getView().getParent().requestSendAccessibilityEvent(getView(), event);
            }
        }

        private boolean isAccessibilityEnabled(Context context) {
            AccessibilityManager accessibilityManager = (AccessibilityManager) context
                    .getSystemService(Context.ACCESSIBILITY_SERVICE);
            return accessibilityManager != null && accessibilityManager.isEnabled();

        }
    }, ACCESSIBILITY_ANNOUNCEMENT_DELAY_MS);
}