下面列出了android.view.View#getImportantForAccessibility ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
void refreshChildren() {
if (mAdapter == null) return;
for (int i = mCurrentWindowStart; i <= mCurrentWindowEnd; i++) {
int index = modulo(i, getWindowSize());
int adapterCount = getCount();
// get the fresh child from the adapter
final View updatedChild = mAdapter.getView(modulo(i, adapterCount), null, this);
if (updatedChild.getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
updatedChild.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
}
if (mViewsMap.containsKey(index)) {
final FrameLayout fl = (FrameLayout) mViewsMap.get(index).view;
// add the new child to the frame, if it exists
if (updatedChild != null) {
// flush out the old child
fl.removeAllViewsInLayout();
fl.addView(updatedChild);
}
}
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* 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);
}
}
/**
* Sets the view to show if the adapter is empty
*/
@android.view.RemotableViewMethod
public void setEmptyView(View emptyView) {
mEmptyView = emptyView;
// 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);
}
@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);
}
static boolean includeChildForAccessibility(View child) {
// If the child is not important for accessibility we make
// sure this hides the entire subtree rooted at it as the
// IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDATS is not
// supported on older platforms but we want to hide the entire
// content and not opened drawers if a drawer is opened.
return child.getImportantForAccessibility() != IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS
&& child.getImportantForAccessibility() != IMPORTANT_FOR_ACCESSIBILITY_NO;
}
/**
* 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 );
}
/**
* @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;
}
public static int getImportantForAccessibility(View view) {
return view.getImportantForAccessibility();
}
/** See {@link View#isImportantForAccessibility()}. */
public static boolean isImportantForAccessibility(View view) {
if (view == null) {
return false;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return view.isImportantForAccessibility();
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
// Prior to Jelly Bean, all Views were considered important for accessibility.
return true;
} else {
// On APIs between 16 and 21, we must piece together accessibility importance from the
// available properties. We return false incorrectly for some cases where unretrievable
// listeners prevent us from determining importance.
// If the developer marked the view as explicitly not important, it isn't.
int mode = view.getImportantForAccessibility();
if ((mode == View.IMPORTANT_FOR_ACCESSIBILITY_NO)
|| (mode == View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS)) {
return false;
}
// No parent view can be hiding us. (APIs 19 to 21)
ViewParent parent = view.getParent();
while (parent instanceof View) {
if (((View) parent).getImportantForAccessibility()
== View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS) {
return false;
}
parent = parent.getParent();
}
// Interrogate the view's other properties to determine importance.
return (mode == View.IMPORTANT_FOR_ACCESSIBILITY_YES)
|| isActionableForAccessibility(view)
|| hasListenersForAccessibility(view)
|| (view.getAccessibilityNodeProvider() != null)
|| (ViewCompat.getAccessibilityLiveRegion(view)
!= ViewCompat.ACCESSIBILITY_LIVE_REGION_NONE);
}
}
public static int c(View view)
{
return view.getImportantForAccessibility();
}
public static int getImportantForAccessibility(View view) {
return view.getImportantForAccessibility();
}
public static int getImportantForAccessibility(View view) {
return view.getImportantForAccessibility();
}
/**
* 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;
}
public static int getImportantForAccessibility(View view) {
return view.getImportantForAccessibility();
}
public static int getImportantForAccessibility(View view) {
return view.getImportantForAccessibility();
}