List of usage examples for android.view View isFocusable
@ViewDebug.ExportedProperty(category = "focus") public final boolean isFocusable()
From source file:cn.ismartv.tvrecyclerview.widget.GridLayoutManager.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { View prevFocusedChild = findContainingItemView(focused); if (prevFocusedChild == null) { return null; }//from w w w . j a v a 2 s . co m LayoutParams lp = (LayoutParams) prevFocusedChild.getLayoutParams(); final int prevSpanStart = lp.mSpanIndex; final int prevSpanEnd = lp.mSpanIndex + lp.mSpanSize; View view = super.onFocusSearchFailed(focused, focusDirection, recycler, state); if (view == null) { return null; } // LinearLayoutManager finds the last child. What we want is the child which has the same // spanIndex. final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection); final boolean ascend = (layoutDir == LayoutState.LAYOUT_END) != mShouldReverseLayout; final int start, inc, limit; if (ascend) { start = getChildCount() - 1; inc = -1; limit = -1; } else { start = 0; inc = 1; limit = getChildCount(); } final boolean preferLastSpan = mOrientation == VERTICAL && isLayoutRTL(); View weakCandidate = null; // somewhat matches but not strong int weakCandidateSpanIndex = -1; int weakCandidateOverlap = 0; // how many spans overlap for (int i = start; i != limit; i += inc) { View candidate = getChildAt(i); if (candidate == prevFocusedChild) { break; } if (!candidate.isFocusable()) { continue; } final LayoutParams candidateLp = (LayoutParams) candidate.getLayoutParams(); final int candidateStart = candidateLp.mSpanIndex; final int candidateEnd = candidateLp.mSpanIndex + candidateLp.mSpanSize; if (candidateStart == prevSpanStart && candidateEnd == prevSpanEnd) { return candidate; // perfect match } boolean assignAsWeek = false; if (weakCandidate == null) { assignAsWeek = true; } else { int maxStart = Math.max(candidateStart, prevSpanStart); int minEnd = Math.min(candidateEnd, prevSpanEnd); int overlap = minEnd - maxStart; if (overlap > weakCandidateOverlap) { assignAsWeek = true; } else if (overlap == weakCandidateOverlap && preferLastSpan == (candidateStart > weakCandidateSpanIndex)) { assignAsWeek = true; } } if (assignAsWeek) { weakCandidate = candidate; weakCandidateSpanIndex = candidateLp.mSpanIndex; weakCandidateOverlap = Math.min(candidateEnd, prevSpanEnd) - Math.max(candidateStart, prevSpanStart); } } return weakCandidate; }
From source file:android.support.v7.extensions.BaseLayoutManager.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { resolveShouldLayoutReverse();/*from www. j a v a2s. co m*/ if (getChildCount() == 0) { return null; } final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection); if (layoutDir == RenderState.INVALID_LAYOUT) { return null; } final View referenceChild; if (layoutDir == RenderState.LAYOUT_START) { referenceChild = getChildClosestToStart(); } else { referenceChild = getChildClosestToEnd(); } ensureRenderState(); final int maxScroll = (int) (MAX_SCROLL_FACTOR * (mOrientationHelper.getEndAfterPadding() - mOrientationHelper.getStartAfterPadding())); updateRenderState(layoutDir, maxScroll, false, state); mRenderState.mScrollingOffset = RenderState.SCOLLING_OFFSET_NaN; fill(recycler, mRenderState, state, true); final View nextFocus; if (layoutDir == RenderState.LAYOUT_START) { nextFocus = getChildClosestToStart(); } else { nextFocus = getChildClosestToEnd(); } if (nextFocus == referenceChild || !nextFocus.isFocusable()) { return null; } return nextFocus; }
From source file:com.alibaba.android.layoutmanager.ExposeLinearLayoutManagerEx.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { myResolveShouldLayoutReverse();/*from w w w .j a va2s .c o m*/ if (getChildCount() == 0) { return null; } final int layoutDir = convertFocusDirectionToLayoutDirectionExpose(focusDirection); if (layoutDir == LayoutState.INVALID_LAYOUT) { return null; } View referenceChild = null; if (layoutDir == LayoutState.LAYOUT_START) { referenceChild = myFindReferenceChildClosestToStart(state); } else { referenceChild = myFindReferenceChildClosestToEnd(state); } if (referenceChild == null) { if (DEBUG) { Log.d(TAG, "Cannot find a child with a valid position to be used for focus search."); } return null; } ensureLayoutStateExpose(); final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace()); updateLayoutStateExpose(layoutDir, maxScroll, false, state); mLayoutState.mScrollingOffset = LayoutState.SCOLLING_OFFSET_NaN; mLayoutState.mRecycle = false; mLayoutState.mOnRefresLayout = false; fill(recycler, mLayoutState, state, true); final View nextFocus; if (layoutDir == LayoutState.LAYOUT_START) { nextFocus = getChildClosestToStartExpose(); } else { nextFocus = getChildClosestToEndExpose(); } if (nextFocus == referenceChild || !nextFocus.isFocusable()) { return null; } return nextFocus; }
From source file:android.support.v7.widget.LinearLayoutManagerEx.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerViewEx.Recycler recycler, RecyclerViewEx.State state) { resolveShouldLayoutReverse();/*from w w w . jav a 2 s .co m*/ if (getChildCount() == 0) { return null; } final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection); if (layoutDir == LayoutState.INVALID_LAYOUT) { return null; } ensureLayoutState(); final View referenceChild; if (layoutDir == LayoutState.LAYOUT_START) { referenceChild = findReferenceChildClosestToStart(state); } else { referenceChild = findReferenceChildClosestToEnd(state); } if (referenceChild == null) { if (DEBUG) { Log.d(TAG, "Cannot find a child with a valid position to be used for focus search."); } return null; } ensureLayoutState(); final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace()); updateLayoutState(layoutDir, maxScroll, false, state); mLayoutState.mScrollingOffset = LayoutState.SCOLLING_OFFSET_NaN; mLayoutState.mRecycle = false; fill(recycler, mLayoutState, state, true); final View nextFocus; if (layoutDir == LayoutState.LAYOUT_START) { nextFocus = getChildClosestToStart(); } else { nextFocus = getChildClosestToEnd(); } if (nextFocus == referenceChild || !nextFocus.isFocusable()) { return null; } return nextFocus; }
From source file:android.support.v7.widget.ChatLinearLayoutManager.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { resolveShouldLayoutReverse();//from w ww . j a va 2s. c o m if (getChildCount() == 0) { return null; } final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection); if (layoutDir == LayoutState.INVALID_LAYOUT) { return null; } ensureLayoutState(); final View referenceChild; if (layoutDir == LayoutState.LAYOUT_START) { referenceChild = findReferenceChildClosestToStart(state); } else { referenceChild = findReferenceChildClosestToEnd(state); } if (referenceChild == null) { if (DEBUG) { Log.d(TAG, "Cannot find a child with a valid position to be used for focus search."); } return null; } ensureLayoutState(); final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace()); updateLayoutState(layoutDir, maxScroll, false, state); mLayoutState.mScrollingOffset = LayoutState.SCOLLING_OFFSET_NaN; mLayoutState.mRecycle = false; fill(recycler, mLayoutState, state, true); final View nextFocus; if (layoutDir == LayoutState.LAYOUT_START) { nextFocus = getChildClosestToStart(); } else { nextFocus = getChildClosestToEnd(); } if (nextFocus == referenceChild || !nextFocus.isFocusable()) { return null; } return nextFocus; }
From source file:android.support.v71.widget.LinearLayoutManager.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { resolveShouldLayoutReverse();//from www.ja v a 2s . co m if (getChildCount() == 0) { return null; } final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection); if (layoutDir == LayoutState.INVALID_LAYOUT) { return null; } ensureLayoutState(); final View referenceChild; if (layoutDir == LayoutState.LAYOUT_START) { referenceChild = findReferenceChildClosestToStart(recycler, state); } else { referenceChild = findReferenceChildClosestToEnd(recycler, state); } if (referenceChild == null) { if (DEBUG) { Log.d(TAG, "Cannot find a child with a valid position to be used for focus search."); } return null; } ensureLayoutState(); final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace()); updateLayoutState(layoutDir, maxScroll, false, state); mLayoutState.mScrollingOffset = LayoutState.SCOLLING_OFFSET_NaN; mLayoutState.mRecycle = false; fill(recycler, mLayoutState, state, true); final View nextFocus; if (layoutDir == LayoutState.LAYOUT_START) { nextFocus = getChildClosestToStart(); } else { nextFocus = getChildClosestToEnd(); } if (nextFocus == referenceChild || !nextFocus.isFocusable()) { return null; } return nextFocus; }
From source file:cn.ismartv.tvrecyclerview.widget.LinearLayoutManager.java
@Override public View onFocusSearchFailed(View focused, int focusDirection, RecyclerView.Recycler recycler, RecyclerView.State state) { resolveShouldLayoutReverse();//from w w w.j a v a 2 s .c o m if (getChildCount() == 0) { return null; } final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection); if (layoutDir == LayoutState.INVALID_LAYOUT) { return null; } ensureLayoutState(); final View referenceChild; if (layoutDir == LayoutState.LAYOUT_START) { referenceChild = findReferenceChildClosestToStart(recycler, state); } else { referenceChild = findReferenceChildClosestToEnd(recycler, state); } if (referenceChild == null) { if (DEBUG) { Log.d(TAG, "Cannot find a child with a valid position to be used for focus search."); } return null; } ensureLayoutState(); final int maxScroll = (int) (MAX_SCROLL_FACTOR * mOrientationHelper.getTotalSpace()); updateLayoutState(layoutDir, maxScroll, false, state); mLayoutState.mScrollingOffset = LayoutState.SCROLLING_OFFSET_NaN; mLayoutState.mRecycle = false; fill(recycler, mLayoutState, state, true); final View nextFocus; if (layoutDir == LayoutState.LAYOUT_START) { nextFocus = getChildClosestToStart(); } else { nextFocus = getChildClosestToEnd(); } if (nextFocus == referenceChild || !nextFocus.isFocusable()) { return null; } return nextFocus; }
From source file:com.google.android.apps.common.testing.accessibility.framework.uielement.ViewHierarchyElement.java
ViewHierarchyElement(int id, @Nullable ViewHierarchyElement parent, View fromView) { // Bookkeeping this.id = id; this.parentId = (parent != null) ? parent.getId() : null; // API 16+ properties this.scrollable = AT_16 ? fromView.isScrollContainer() : null; // API 11+ properties this.backgroundDrawableColor = (AT_11 && (fromView != null) && (fromView.getBackground() instanceof ColorDrawable)) ? ((ColorDrawable) fromView.getBackground()).getColor() : null;/*w w w.j a v a2 s . c om*/ // Base properties this.visibleToUser = ViewAccessibilityUtils.isVisibleToUser(fromView); this.className = fromView.getClass().getName(); this.accessibilityClassName = null; this.packageName = fromView.getContext().getPackageName(); this.resourceName = (fromView.getId() != View.NO_ID) ? ViewAccessibilityUtils.getResourceNameForView(fromView) : null; this.contentDescription = SpannableString.valueOf(fromView.getContentDescription()); this.enabled = fromView.isEnabled(); if (fromView instanceof TextView) { TextView textView = (TextView) fromView; // Hint text takes precedence if no text is present. CharSequence text = textView.getText(); if (TextUtils.isEmpty(text)) { text = textView.getHint(); } this.text = SpannableString.valueOf(text); this.textSize = textView.getTextSize(); this.textColor = textView.getCurrentTextColor(); this.typefaceStyle = (textView.getTypeface() != null) ? textView.getTypeface().getStyle() : null; } else { this.text = null; this.textSize = null; this.textColor = null; this.typefaceStyle = null; } this.importantForAccessibility = ViewAccessibilityUtils.isImportantForAccessibility(fromView); this.clickable = fromView.isClickable(); this.longClickable = fromView.isLongClickable(); this.focusable = fromView.isFocusable(); this.editable = ViewAccessibilityUtils.isViewEditable(fromView); this.canScrollForward = (ViewCompat.canScrollVertically(fromView, 1) || ViewCompat.canScrollHorizontally(fromView, 1)); this.canScrollBackward = (ViewCompat.canScrollVertically(fromView, -1) || ViewCompat.canScrollHorizontally(fromView, -1)); this.checkable = (fromView instanceof Checkable); this.checked = (fromView instanceof Checkable) ? ((Checkable) fromView).isChecked() : null; this.hasTouchDelegate = (fromView.getTouchDelegate() != null); // There may be subtle differences between the bounds from a View instance compared to that of // its AccessibilityNodeInfo. The latter uses a @hide getBoundsOnScreen method, which clips to // parent bounds. android.graphics.Rect tempRect = new android.graphics.Rect(); if (fromView.getGlobalVisibleRect(tempRect)) { this.boundsInScreen = new Rect(tempRect); } else { this.boundsInScreen = null; } this.nonclippedHeight = fromView.getHeight(); this.nonclippedWidth = fromView.getWidth(); }
From source file:com.dgmltn.veggielist.LinearLayoutManager.java
/** * The magic functions :). Fills the given layout, defined by the renderState. This is fairly * independent from the rest of the {@link android.support.v7.widget.LinearLayoutManager} * and with little change, can be made publicly available as a helper class. * * @param recycler Current recycler that is attached to RecyclerView * @param renderState Configuration on how we should fill out the available space. * @param state Context passed by the RecyclerView to control scroll steps. * @param stopOnFocusable If true, filling stops in the first focusable new child * @return Number of pixels that it added. Useful for scoll functions. */// w ww.jav a2 s .c o m private int fill(RecyclerView.Recycler recycler, RenderState renderState, RecyclerView.State state, boolean stopOnFocusable) { // max offset we should set is mFastScroll + available final int start = renderState.mAvailable; if (renderState.mScrollingOffset != RenderState.SCOLLING_OFFSET_NaN) { // TODO ugly bug fix. should not happen if (renderState.mAvailable < 0) { renderState.mScrollingOffset += renderState.mAvailable; } recycleByRenderState(recycler, renderState); } int remainingSpace = renderState.mAvailable + renderState.mExtra; while (remainingSpace > 0 && renderState.hasMore(state)) { View view = renderState.next(recycler); if (view == null) { // if we are laying out views in scrap, this may return null which means there is // no more items to layout. break; } RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams(); if (!params.isItemRemoved() && mRenderState.mScrapList == null) { if (mShouldReverseLayout == (renderState.mLayoutDirection == RenderState.LAYOUT_START)) { addView(view); } else { addView(view, 0); } } measureChildWithMargins(view, 0, 0); int consumed = mOrientationHelper.getDecoratedMeasurement(view); int left, top, right, bottom; if (mOrientation == VERTICAL) { if (isLayoutRTL()) { right = getWidth() - getPaddingRight(); left = right - mOrientationHelper.getDecoratedMeasurementInOther(view); } else { left = getPaddingLeft(); right = left + mOrientationHelper.getDecoratedMeasurementInOther(view); } if (renderState.mLayoutDirection == RenderState.LAYOUT_START) { bottom = renderState.mOffset; top = renderState.mOffset - consumed; } else { top = renderState.mOffset; bottom = renderState.mOffset + consumed; } } else { top = getPaddingTop(); bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view); if (renderState.mLayoutDirection == RenderState.LAYOUT_START) { right = renderState.mOffset; left = renderState.mOffset - consumed; } else { left = renderState.mOffset; right = renderState.mOffset + consumed; } } // We calculate everything with View's bounding box (which includes decor and margins) // To calculate correct layout position, we subtract margins. layoutDecorated(view, left + params.leftMargin, top + params.topMargin, right - params.rightMargin, bottom - params.bottomMargin); if (DEBUG) { Log.d(TAG, "laid out child at position " + getPosition(view) + ", with l:" + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin)); } renderState.mOffset += consumed * renderState.mLayoutDirection; if (!params.isItemRemoved()) { renderState.mAvailable -= consumed; // we keep a separate remaining space because mAvailable is important for recycling remainingSpace -= consumed; } if (renderState.mScrollingOffset != RenderState.SCOLLING_OFFSET_NaN) { renderState.mScrollingOffset += consumed; if (renderState.mAvailable < 0) { renderState.mScrollingOffset += renderState.mAvailable; } recycleByRenderState(recycler, renderState); } if (stopOnFocusable && view.isFocusable()) { break; } if (state != null && state.getTargetScrollPosition() == getPosition(view)) { break; } } if (DEBUG) { validateChildOrder(); } return start - renderState.mAvailable; }
From source file:android.support.v7.widget.LinearLayoutManagerEx.java
void layoutChunk(RecyclerViewEx.Recycler recycler, RecyclerViewEx.State state, LayoutState layoutState, LayoutChunkResult result) {//from w w w . jav a2 s . c o m View view = layoutState.next(recycler); if (view == null) { if (DEBUG && layoutState.mScrapList == null) { throw new RuntimeException("received null view when unexpected"); } // if we are laying out views in scrap, this may return null which means there is // no more items to layout. result.mFinished = true; return; } RecyclerViewEx.LayoutParams params = (RecyclerViewEx.LayoutParams) view.getLayoutParams(); if (layoutState.mScrapList == null) { if (mShouldReverseLayout == (layoutState.mLayoutDirection == LayoutState.LAYOUT_START)) { addView(view); } else { addView(view, 0); } } else { if (mShouldReverseLayout == (layoutState.mLayoutDirection == LayoutState.LAYOUT_START)) { addDisappearingView(view); } else { addDisappearingView(view, 0); } } measureChildWithMargins(view, 0, 0); result.mConsumed = mOrientationHelper.getDecoratedMeasurement(view); int left, top, right, bottom; if (mOrientation == VERTICAL) { if (isLayoutRTL()) { right = getWidth() - getPaddingRight(); left = right - mOrientationHelper.getDecoratedMeasurementInOther(view); } else { left = getPaddingLeft(); right = left + mOrientationHelper.getDecoratedMeasurementInOther(view); } if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) { bottom = layoutState.mOffset; top = layoutState.mOffset - result.mConsumed; } else { top = layoutState.mOffset; bottom = layoutState.mOffset + result.mConsumed; } } else { top = getPaddingTop(); bottom = top + mOrientationHelper.getDecoratedMeasurementInOther(view); if (layoutState.mLayoutDirection == LayoutState.LAYOUT_START) { right = layoutState.mOffset; left = layoutState.mOffset - result.mConsumed; } else { left = layoutState.mOffset; right = layoutState.mOffset + result.mConsumed; } } // We calculate everything with View's bounding box (which includes decor and margins) // To calculate correct layout position, we subtract margins. layoutDecorated(view, left + params.leftMargin, top + params.topMargin, right - params.rightMargin, bottom - params.bottomMargin); if (DEBUG) { Log.d(TAG, "laid out child at position " + getPosition(view) + ", with l:" + (left + params.leftMargin) + ", t:" + (top + params.topMargin) + ", r:" + (right - params.rightMargin) + ", b:" + (bottom - params.bottomMargin)); } // Consume the available space if the view is not removed OR changed if (params.isItemRemoved() || params.isItemChanged()) { result.mIgnoreConsumed = true; } result.mFocusable = view.isFocusable(); }