Example usage for android.support.v4.view ViewCompat setAccessibilityDelegate

List of usage examples for android.support.v4.view ViewCompat setAccessibilityDelegate

Introduction

In this page you can find the example usage for android.support.v4.view ViewCompat setAccessibilityDelegate.

Prototype

public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) 

Source Link

Document

Sets a delegate for implementing accessibility support via compositon as opposed to inheritance.

Usage

From source file:org.chromium.chrome.browser.compositor.CompositorViewHolder.java

/**
 * Called when the accessibility enabled state changes.
 * @param enabled Whether accessibility is enabled.
 *///w  ww. j  a  v  a 2 s  .c om
public void onAccessibilityStatusChanged(boolean enabled) {
    // Instantiate and install the accessibility node provider on this view if necessary.
    // This overrides any hover event listeners or accessibility delegates
    // that may have been added elsewhere.
    if (enabled && (mNodeProvider == null)) {
        mAccessibilityView = new View(getContext());
        addView(mAccessibilityView);
        mNodeProvider = new CompositorAccessibilityProvider(mAccessibilityView);
        ViewCompat.setAccessibilityDelegate(mAccessibilityView, mNodeProvider);
    }
}

From source file:com.facebook.litho.MountState.java

private static void unsetAccessibilityDelegate(View view) {
    if (!(view instanceof ComponentHost) && view.getTag(R.id.component_node_info) == null) {
        return;//ww w .  j  a v a2  s .  c o m
    }
    view.setTag(R.id.component_node_info, null);
    if (!(view instanceof ComponentHost)) {
        ViewCompat.setAccessibilityDelegate(view, null);
    }
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    // Until a drawer is open, it is hidden from accessibility.
    if (index > 0 || (index < 0 && getChildCount() > 0)) {
        ViewCompat.setImportantForAccessibility(child,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
        // Also set a delegate to break the child-parent relation if the
        // child is hidden. For details (see incluceChildForAccessibility).
        ViewCompat.setAccessibilityDelegate(child, mChildAccessibilityDelegate);
    } else {/*from  ww w. j a  va 2 s .  c  o m*/
        // Initially, the content is shown for accessibility.
        ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    super.addView(child, index, params);
}

From source file:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    super.addView(child, index, params);

    final View openDrawer = findOpenDrawer();
    if (openDrawer != null || isDrawerView(child)) {
        // A drawer is already open or the new view is a drawer, so the
        // new view should start out hidden.
        ViewCompat.setImportantForAccessibility(child,
                ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
    } else {//from  w  w w  .  j a va 2  s .c o m
        // Otherwise this is a content view and no drawer is open, so the
        // new view should start out visible.
        ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    // We only need a delegate here if the framework doesn't understand
    // NO_HIDE_DESCENDANTS importance.
    if (!CAN_HIDE_DESCENDANTS) {
        ViewCompat.setAccessibilityDelegate(child, mChildAccessibilityDelegate);
    }
}

From source file:com.appunite.list.AbsHorizontalListView.java

/**
 * Get a view and have it show the data associated with the specified
 * position. This is called when we have already discovered that the view is
 * not available for reuse in the recycle bin. The only choices left are
 * converting an old view or making a new one.
 *
 * @param position The position to display
 * @param isScrap Array of at least 1 boolean, the first entry will become true if
 *                the returned view was taken from the scrap heap, false if otherwise.
 *
 * @return A view displaying the data associated with the specified position
 *//*from  w ww .jav  a  2 s . co  m*/
View obtainView(int position, boolean[] isScrap) {
    isScrap[0] = false;
    View scrapView;

    scrapView = mRecycler.getTransientStateView(position);
    if (scrapView != null) {
        return scrapView;
    }

    scrapView = mRecycler.getScrapView(position);

    View child;
    if (scrapView != null) {
        child = mAdapter.getView(position, scrapView, this);

        if (ViewCompat.getImportantForAccessibility(child) == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
            ViewCompat.setImportantForAccessibility(child, IMPORTANT_FOR_ACCESSIBILITY_YES);
        }

        if (child != scrapView) {
            mRecycler.addScrapView(scrapView, position);
            if (mCacheColorHint != 0) {
                child.setDrawingCacheBackgroundColor(mCacheColorHint);
            }
        } else {
            isScrap[0] = true;
            AdapterView.dispatchStartTemporaryDetach(child);
        }
    } else {
        child = mAdapter.getView(position, null, this);

        if (ViewCompat.getImportantForAccessibility(child) == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
            ViewCompat.setImportantForAccessibility(child, IMPORTANT_FOR_ACCESSIBILITY_YES);
        }

        if (mCacheColorHint != 0) {
            child.setDrawingCacheBackgroundColor(mCacheColorHint);
        }
    }

    if (mAdapterHasStableIds) {
        final ViewGroup.LayoutParams vlp = child.getLayoutParams();
        LayoutParams lp;
        if (vlp == null) {
            lp = (LayoutParams) generateDefaultLayoutParams();
        } else if (!checkLayoutParams(vlp)) {
            lp = (LayoutParams) generateLayoutParams(vlp);
        } else {
            lp = (LayoutParams) vlp;
        }
        lp.itemId = mAdapter.getItemId(position);
        child.setLayoutParams(lp);
    }

    if (getAccessibilityManager().isEnabled()) {
        if (mAccessibilityDelegate == null) {
            mAccessibilityDelegate = new ListItemAccessibilityDelegate();
        }
        ViewCompat.setAccessibilityDelegate(child, mAccessibilityDelegate);
    }

    return child;
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

@TargetApi(16)
private View obtainView(int position, boolean[] isScrap) {
    isScrap[0] = false;//  ww w  .ja  v  a  2 s  .  c o m

    View scrapView = mRecycler.getTransientStateView(position);
    if (scrapView != null) {
        return scrapView;
    }

    scrapView = mRecycler.getScrapView(position);

    final View child;
    if (scrapView != null) {
        child = mAdapter.getView(position, scrapView, this);

        if (child != scrapView) {
            mRecycler.addScrapView(scrapView, position);
        } else {
            isScrap[0] = true;
        }
    } else {
        child = mAdapter.getView(position, null, this);
    }

    if (ViewCompat.getImportantForAccessibility(child) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(child, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    if (mHasStableIds) {
        LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (lp == null) {
            lp = generateDefaultLayoutParams();
        } else if (!checkLayoutParams(lp)) {
            lp = generateLayoutParams(lp);
        }

        lp.id = mAdapter.getItemId(position);

        child.setLayoutParams(lp);
    }

    if (mAccessibilityDelegate == null) {
        mAccessibilityDelegate = new ListItemAccessibilityDelegate();
    }

    ViewCompat.setAccessibilityDelegate(child, mAccessibilityDelegate);

    return child;
}