Java Code Examples for android.view.View#setImportantForAccessibility()

The following examples show how to use android.view.View#setImportantForAccessibility() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private void onDrawerAnimationEnd(boolean opened) {
    startedTracking = false;
    currentAnimation = null;
    drawerOpened = opened;
    if (!opened) {
        if (drawerLayout instanceof ListView) {
            ((ListView) drawerLayout).setSelectionFromTop(0, 0);
        }
    }
    if (Build.VERSION.SDK_INT >= 19) {
        for (int i = 0; i < getChildCount(); i++) {
            View child = getChildAt(i);
            if (child != drawerLayout) {
                child.setImportantForAccessibility(opened ? View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS : View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
            }
        }
    }
    sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
}
 
Example 2
Source Project: Dashchan   File: DrawerLayout.java    License: Apache License 2.0 6 votes vote down vote up
@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.
		child.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
	} else {
		// Otherwise this is a content view and no drawer is open, so the
		// new view should start out visible.
		child.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
	}

	// We only need a delegate here if the framework doesn't understand
	// NO_HIDE_DESCENDANTS importance.
	if (!CAN_HIDE_DESCENDANTS) {
		child.setAccessibilityDelegate(mChildAccessibilityDelegate);
	}
}
 
Example 3
Source Project: AndroidChromium   File: Tab.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Update whether or not the current native tab and/or web contents are
 * currently visible (from an accessibility perspective), or whether
 * they're obscured by another view.
 */
public void updateAccessibilityVisibility() {
    View view = getView();
    if (view != null) {
        int importantForAccessibility = isObscuredByAnotherViewForAccessibility()
                ? View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                : View.IMPORTANT_FOR_ACCESSIBILITY_YES;
        if (view.getImportantForAccessibility() != importantForAccessibility) {
            view.setImportantForAccessibility(importantForAccessibility);
            view.sendAccessibilityEvent(
                    AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
        }
    }

    ContentViewCore cvc = getContentViewCore();
    if (cvc != null) {
        boolean isWebContentObscured = isObscuredByAnotherViewForAccessibility()
                || isShowingSadTab();
        cvc.setObscuredByAnotherView(isWebContentObscured);
    }
}
 
Example 4
private void restoreImportantForAccessibilityHelper(View v) {
    Integer important = mPreviousValues.get(v);
    v.setImportantForAccessibility(important);
    mPreviousValues.remove(v);

    // Call method on children recursively
    if (v instanceof ViewGroup) {
        ViewGroup vg = (ViewGroup) v;

        // We assume if a class implements OnHierarchyChangeListener, it listens
        // to changes to any of its children (happens to be the case in Launcher)
        if (vg instanceof OnHierarchyChangeListener) {
            vg.setOnHierarchyChangeListener((OnHierarchyChangeListener) vg);
        } else {
            vg.setOnHierarchyChangeListener(null);
        }
        for (int i = 0; i < vg.getChildCount(); i++) {
            View child = vg.getChildAt(i);
            if (includeView(child)) {
                restoreImportantForAccessibilityHelper(child);
            }
        }
    }
}
 
Example 5
Source Project: 365browser   File: Tab.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Update whether or not the current native tab and/or web contents are
 * currently visible (from an accessibility perspective), or whether
 * they're obscured by another view.
 */
public void updateAccessibilityVisibility() {
    View view = getView();
    if (view != null) {
        int importantForAccessibility = isObscuredByAnotherViewForAccessibility()
                ? View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
                : View.IMPORTANT_FOR_ACCESSIBILITY_YES;
        if (view.getImportantForAccessibility() != importantForAccessibility) {
            view.setImportantForAccessibility(importantForAccessibility);
            view.sendAccessibilityEvent(
                    AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED);
        }
    }

    ContentViewCore cvc = getContentViewCore();
    if (cvc != null) {
        boolean isWebContentObscured = isObscuredByAnotherViewForAccessibility()
                || isShowingSadTab();
        cvc.setObscuredByAnotherView(isWebContentObscured);
    }
}
 
Example 6
Source Project: Camera2   File: ModeListView.java    License: Apache License 2.0 5 votes vote down vote up
private void disableA11yOnModeSelectorItems()
{
    for (View selectorItem : mModeSelectorItems)
    {
        selectorItem.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
}
 
Example 7
Source Project: Klyph   File: AdapterView.java    License: MIT License 5 votes vote down vote up
/**
 * Sets the view to show if the adapter is empty
 */
public void setEmptyView( View emptyView ) {
	mEmptyView = emptyView;

	if( android.os.Build.VERSION.SDK_INT >= 16 ) {
		// If not explicitly specified this view is important for accessibility.
		if ( emptyView != null && emptyView.getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO ) {
			emptyView.setImportantForAccessibility( IMPORTANT_FOR_ACCESSIBILITY_YES );
		}
	}

	final T adapter = getAdapter();
	final boolean empty = ( ( adapter == null ) || adapter.isEmpty() );
	updateEmptyStatus( empty );
}
 
Example 8
/**
 * Creates an icon for the given NotificationInfo, and adds it to the icon row.
 * @return the icon view that was added
 */
private View addNotificationIconForInfo(NotificationInfo info) {
    View icon = new View(getContext());
    icon.setBackground(info.getIconForBackground(getContext(), mBackgroundColor));
    icon.setOnClickListener(info);
    icon.setTag(info);
    icon.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
    mIconRow.addView(icon, 0, mIconLayoutParams);
    return icon;
}
 
Example 9
Source Project: letv   File: AdapterView.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(16)
public void setEmptyView(View emptyView) {
    boolean empty = true;
    this.mEmptyView = emptyView;
    if (VERSION.SDK_INT >= 16 && emptyView != null && emptyView.getImportantForAccessibility() == 0) {
        emptyView.setImportantForAccessibility(1);
    }
    T adapter = getAdapter();
    if (!(adapter == null || adapter.isEmpty())) {
        empty = false;
    }
    updateEmptyStatus(empty);
}
 
Example 10
Source Project: px-android   File: ConsumerCreditsFragment.java    License: MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("ConstantConditions")
public void initializeViews(@NonNull final View view) {
    super.initializeViews(view);
    creditsLagout = view.findViewById(R.id.credits_layout);
    background = view.findViewById(R.id.background);
    logo = view.findViewById(R.id.logo);
    topText = view.findViewById(R.id.top_text);
    bottomText = view.findViewById(R.id.bottom_text);
    final ConsumerCreditsDisplayInfo displayInfo = model.metadata.displayInfo;
    tintBackground(view.findViewById(R.id.background), displayInfo.color);
    showDisplayInfo(view, displayInfo);
    view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
}
 
Example 11
Source Project: ZhihuDaily   File: UIUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void setAccessiblityIgnore(View view) {
    view.setClickable(false);
    view.setFocusable(false);
    view.setContentDescription("");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
}
 
Example 12
Source Project: RetailStore   File: UIUtils.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public static void setAccessibilityIgnore(View view) {
    view.setClickable(false);
    view.setFocusable(false);
    view.setContentDescription("");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        view.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
    }
}
 
Example 13
Source Project: Dashchan   File: DrawerLayout.java    License: Apache License 2.0 5 votes vote down vote up
private void updateChildrenImportantForAccessibility(View drawerView, boolean isDrawerOpen) {
	final int childCount = getChildCount();
	for (int i = 0; i < childCount; i++) {
		final View child = getChildAt(i);
		if (!isDrawerOpen && !isDrawerView(child) || isDrawerOpen && child == drawerView) {
			// Drawer is closed and this is a content view or this is an
			// open drawer view, so it should be visible.
			child.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
		} else {
			child.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
		}
	}
}
 
Example 14
Source Project: android_9.0.0_r45   File: AbsSpinner.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @see android.view.View#measure(int, int)
 *
 * Figure out the dimensions of this Spinner. The width comes from
 * the widthMeasureSpec as Spinnners can't have their width set to
 * UNSPECIFIED. The height is based on the height of the selected item
 * plus padding.
 */
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int widthSize;
    int heightSize;

    mSpinnerPadding.left = mPaddingLeft > mSelectionLeftPadding ? mPaddingLeft
            : mSelectionLeftPadding;
    mSpinnerPadding.top = mPaddingTop > mSelectionTopPadding ? mPaddingTop
            : mSelectionTopPadding;
    mSpinnerPadding.right = mPaddingRight > mSelectionRightPadding ? mPaddingRight
            : mSelectionRightPadding;
    mSpinnerPadding.bottom = mPaddingBottom > mSelectionBottomPadding ? mPaddingBottom
            : mSelectionBottomPadding;

    if (mDataChanged) {
        handleDataChanged();
    }

    int preferredHeight = 0;
    int preferredWidth = 0;
    boolean needsMeasuring = true;

    int selectedPosition = getSelectedItemPosition();
    if (selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter.getCount()) {
        // Try looking in the recycler. (Maybe we were measured once already)
        View view = mRecycler.get(selectedPosition);
        if (view == null) {
            // Make a new one
            view = mAdapter.getView(selectedPosition, null, this);

            if (view.getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
                view.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
            }
        }

        if (view != null) {
            // Put in recycler for re-measuring and/or layout
            mRecycler.put(selectedPosition, view);

            if (view.getLayoutParams() == null) {
                mBlockLayoutRequests = true;
                view.setLayoutParams(generateDefaultLayoutParams());
                mBlockLayoutRequests = false;
            }
            measureChild(view, widthMeasureSpec, heightMeasureSpec);

            preferredHeight = getChildHeight(view) + mSpinnerPadding.top + mSpinnerPadding.bottom;
            preferredWidth = getChildWidth(view) + mSpinnerPadding.left + mSpinnerPadding.right;

            needsMeasuring = false;
        }
    }

    if (needsMeasuring) {
        // No views -- just use padding
        preferredHeight = mSpinnerPadding.top + mSpinnerPadding.bottom;
        if (widthMode == MeasureSpec.UNSPECIFIED) {
            preferredWidth = mSpinnerPadding.left + mSpinnerPadding.right;
        }
    }

    preferredHeight = Math.max(preferredHeight, getSuggestedMinimumHeight());
    preferredWidth = Math.max(preferredWidth, getSuggestedMinimumWidth());

    heightSize = resolveSizeAndState(preferredHeight, heightMeasureSpec, 0);
    widthSize = resolveSizeAndState(preferredWidth, widthMeasureSpec, 0);

    setMeasuredDimension(widthSize, heightSize);
    mHeightMeasureSpec = heightMeasureSpec;
    mWidthMeasureSpec = widthMeasureSpec;
}
 
Example 15
Source Project: MiBandDecompiled   File: am.java    License: Apache License 2.0 4 votes vote down vote up
public static void a(View view, int i)
{
    view.setImportantForAccessibility(i);
}
 
Example 16
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 17
Source Project: letv   File: ViewCompatJB.java    License: Apache License 2.0 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 18
Source Project: V.FlyoutTest   File: ViewCompatJB.java    License: MIT License 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 19
Source Project: guideshow   File: ViewCompatJB.java    License: MIT License 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 20
Source Project: Klyph   File: AbsHListView.java    License: MIT License 4 votes vote down vote up
/**
 * 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
 */
@SuppressLint ( "NewApi" )
protected 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 ( android.os.Build.VERSION.SDK_INT >= 16 ) {
			if ( child.getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO ) {
				child.setImportantForAccessibility( IMPORTANT_FOR_ACCESSIBILITY_YES );
			}
		}

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

		if ( android.os.Build.VERSION.SDK_INT >= 16 ) {
			if ( child.getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO ) {
				child.setImportantForAccessibility( 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 ( mAccessibilityManager.isEnabled() ) {
		if ( mAccessibilityDelegate == null ) {
			mAccessibilityDelegate = new ListItemAccessibilityDelegate();
		}

		// TODO: implement this ( hidden by google )
		// if (child.getAccessibilityDelegate() == null) {
		// child.setAccessibilityDelegate(mAccessibilityDelegate);
		// }
	}

	return child;
}