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

The following examples show how to use android.view.View#setImportantForAccessibility() . 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 check out the related API usage on the sidebar.
Example 1
Source File: DrawerLayoutContainer.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
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 File: Tab.java    From 365browser with 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 3
Source File: DrawerLayout.java    From Dashchan with 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 4
Source File: Tab.java    From AndroidChromium with 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 5
Source File: HideFromAccessibilityHelper.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
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 6
Source File: ModeListView.java    From Camera2 with 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 File: AdapterView.java    From Klyph with 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
Source File: NotificationFooterLayout.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 File: AdapterView.java    From letv with 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 File: ConsumerCreditsFragment.java    From px-android with 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 File: UIUtils.java    From ZhihuDaily with 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 File: UIUtils.java    From RetailStore with 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 File: DrawerLayout.java    From Dashchan with 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 File: AbsHListView.java    From Klyph with 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;
}
 
Example 15
Source File: AbsSpinner.java    From android_9.0.0_r45 with 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 16
Source File: ViewCompatJB.java    From guideshow with MIT License 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 17
Source File: ViewCompatJB.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 18
Source File: ViewCompatJB.java    From letv with Apache License 2.0 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 19
Source File: ViewCompatJB.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
public static void setImportantForAccessibility(View view, int mode) {
    view.setImportantForAccessibility(mode);
}
 
Example 20
Source File: am.java    From MiBandDecompiled with Apache License 2.0 4 votes vote down vote up
public static void a(View view, int i)
{
    view.setImportantForAccessibility(i);
}