Example usage for android.widget TextView announceForAccessibility

List of usage examples for android.widget TextView announceForAccessibility

Introduction

In this page you can find the example usage for android.widget TextView announceForAccessibility.

Prototype

public void announceForAccessibility(CharSequence text) 

Source Link

Document

Convenience method for sending a AccessibilityEvent#TYPE_ANNOUNCEMENT 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.

Usage

From source file:pl.edu.agh.schedule.myschedule.MyScheduleActivity.java

private void setTabLayoutContentDescriptions() {
    LayoutInflater inflater = getLayoutInflater();
    int gap = 0;//w w w .  j av  a  2s . co m
    for (int i = 0, count = mTabLayout.getTabCount(); i < count; i++) {
        TabLayout.Tab tab = mTabLayout.getTabAt(i);
        if (tab != null) {
            TextView view = (TextView) inflater.inflate(R.layout.tab_my_schedule, mTabLayout, false);
            view.setId(baseTabViewId + i);
            view.setText(tab.getText());
            if (i == 0) {
                view.setContentDescription(
                        getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText())));
            } else {
                view.setContentDescription(getString(R.string.a11y_button, tab.getText()));
            }
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                view.announceForAccessibility(
                        getString(R.string.my_schedule_tab_desc_a11y, getDayName(i - gap)));
            }
            tab.setCustomView(view);
        } else {
            Log.e(TAG, "Tab is null.");
        }
    }
}

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java

private void setTabLayoutContentDescriptions() {
    LayoutInflater inflater = getLayoutInflater();
    int gap = mDayZeroAdapter == null ? 0 : 1;
    for (int i = 0, count = mTabLayout.getTabCount(); i < count; i++) {
        TabLayout.Tab tab = mTabLayout.getTabAt(i);
        TextView view = (TextView) inflater.inflate(R.layout.tab_my_schedule, mTabLayout, false);
        view.setId(baseTabViewId + i);//  w  w  w.  ja  va  2  s.  c o  m
        view.setText(tab.getText());
        if (i == 0) {
            view.setContentDescription(
                    getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText())));
        } else {
            view.setContentDescription(getString(R.string.a11y_button, tab.getText()));
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            view.announceForAccessibility(getString(R.string.my_schedule_tab_desc_a11y, getDayName(i - gap)));
        }
        tab.setCustomView(view);
    }
}

From source file:org.chromium.chrome.browser.autofill.CardUnmaskPrompt.java

private void onTooltipIconClicked() {
    // Don't show the popup if there's already one showing (or one has been dismissed
    // recently). This prevents a tap on the (?) from hiding and then immediately re-showing
    // the popup.
    if (mStoreLocallyTooltipPopup != null)
        return;//from  w ww .  j a va2  s .c o  m

    mStoreLocallyTooltipPopup = new PopupWindow(mDialog.getContext());
    TextView text = new TextView(mDialog.getContext());
    text.setText(R.string.autofill_card_unmask_prompt_storage_tooltip);
    // Width is the dialog's width less the margins and padding around the checkbox and
    // icon.
    text.setWidth(mMainView.getWidth() - ViewCompat.getPaddingStart(mStoreLocallyCheckbox)
            - ViewCompat.getPaddingEnd(mStoreLocallyTooltipIcon)
            - MarginLayoutParamsCompat
                    .getMarginStart((RelativeLayout.LayoutParams) mStoreLocallyCheckbox.getLayoutParams())
            - MarginLayoutParamsCompat
                    .getMarginEnd((RelativeLayout.LayoutParams) mStoreLocallyTooltipIcon.getLayoutParams()));
    text.setTextColor(Color.WHITE);
    Resources resources = mDialog.getContext().getResources();
    int hPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_horizontal_padding);
    int vPadding = resources.getDimensionPixelSize(R.dimen.autofill_card_unmask_tooltip_vertical_padding);
    text.setPadding(hPadding, vPadding, hPadding, vPadding);

    mStoreLocallyTooltipPopup.setContentView(text);
    mStoreLocallyTooltipPopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
    mStoreLocallyTooltipPopup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    mStoreLocallyTooltipPopup.setOutsideTouchable(true);
    mStoreLocallyTooltipPopup.setBackgroundDrawable(
            ApiCompatibilityUtils.getDrawable(resources, R.drawable.store_locally_tooltip_background));
    mStoreLocallyTooltipPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            Handler h = new Handler();
            h.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mStoreLocallyTooltipPopup = null;
                }
            }, 200);
        }
    });
    mStoreLocallyTooltipPopup.showAsDropDown(mStoreLocallyCheckbox,
            ViewCompat.getPaddingStart(mStoreLocallyCheckbox), 0);
    text.announceForAccessibility(text.getText());
}