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

The following examples show how to use android.view.View#hasFocusable() . 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: GridLayoutManager.java    From TvRecyclerView with Apache License 2.0 6 votes vote down vote up
public void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    if (DEBUG) {
        Log.d(TAG, "onFocusChanged: gainFocus=" + gainFocus);
    }
    if (gainFocus) {
        // if moduleRecyclerView.requestFocus() is called, select first focusable child.
        for (int i = mFocusPosition; ;i++) {
            View view = findViewByPosition(i);
            if (view == null) {
                break;
            }
            if (view.getVisibility() == View.VISIBLE && view.hasFocusable()) {
                view.requestFocus();
                break;
            }
        }
    }
}
 
Example 2
Source File: ViewUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取当前 View 或者子 View 是否可以获取焦点
 * @param view {@link View}
 * @return {@code true} yes, {@code false} no
 */
public static boolean hasFocusable(final View view) {
    if (view != null) {
        return view.hasFocusable();
    }
    return false;
}
 
Example 3
Source File: AbsHListView.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void keyPressed() {
    if (isEnabled() && isClickable()) {
        Drawable selector = this.mSelector;
        Rect selectorRect = this.mSelectorRect;
        if (selector == null) {
            return;
        }
        if ((isFocused() || touchModeDrawsInPressedState()) && !selectorRect.isEmpty()) {
            View v = getChildAt(this.mSelectedPosition - this.mFirstPosition);
            if (v != null) {
                if (!v.hasFocusable()) {
                    v.setPressed(true);
                } else {
                    return;
                }
            }
            setPressed(true);
            boolean longClickable = isLongClickable();
            Drawable d = selector.getCurrent();
            if (d != null && (d instanceof TransitionDrawable)) {
                if (longClickable) {
                    ((TransitionDrawable) d).startTransition(ViewConfiguration.getLongPressTimeout());
                } else {
                    ((TransitionDrawable) d).resetTransition();
                }
            }
            if (longClickable && !this.mDataChanged) {
                if (this.mPendingCheckForKeyLongPress == null) {
                    this.mPendingCheckForKeyLongPress = new CheckForKeyLongPress(this, null);
                }
                this.mPendingCheckForKeyLongPress.rememberWindowAttachCount();
                postDelayed(this.mPendingCheckForKeyLongPress, (long) ViewConfiguration.getLongPressTimeout());
            }
        }
    }
}
 
Example 4
Source File: PLA_AbsListView.java    From EverMemo with MIT License 5 votes vote down vote up
public void run() {
	if (mTouchMode == TOUCH_MODE_DOWN) {
		mTouchMode = TOUCH_MODE_TAP;
		final View child = getChildAt(mMotionPosition - mFirstPosition);
		if (child != null && !child.hasFocusable()) {
			mLayoutMode = LAYOUT_NORMAL;

			if (!mDataChanged) {
				layoutChildren();
				child.setPressed(true);
				positionSelector(child);
				setPressed(true);

				final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
				final boolean longClickable = isLongClickable();

				if (mSelector != null) {
					Drawable d = mSelector.getCurrent();
					if (d != null && d instanceof TransitionDrawable) {
						if (longClickable) {
							((TransitionDrawable) d).startTransition(longPressTimeout);
						} else {
							((TransitionDrawable) d).resetTransition();
						}
					}
				}

				if (longClickable) {
				} else {
					mTouchMode = TOUCH_MODE_DONE_WAITING;
				}
			} else {
				mTouchMode = TOUCH_MODE_DONE_WAITING;
			}
		}
	}
}
 
Example 5
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if (mTouchMode == TOUCH_MODE_DOWN) {
        mTouchMode = TOUCH_MODE_TAP;
        final View child = getChildAt(mMotionPosition - mFirstPosition);
        if (child != null && !child.hasFocusable()) {
            mLayoutMode = LAYOUT_NORMAL;
            if (!mDataChanged) {
                child.setPressed(true);
                positionSelector(mMotionPosition, child);
                setPressed(true);
                refreshDrawableState();
                final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
                final boolean longClickable = isLongClickable();
                if (mSelector != null) {
                    Drawable d = mSelector.getCurrent();
                    if (d != null && d instanceof TransitionDrawable) {
                        if (longClickable) {
                            ((TransitionDrawable) d).startTransition(longPressTimeout);
                        } else {
                            ((TransitionDrawable) d).resetTransition();
                        }
                    }
                }
                mTouchMode = TOUCH_MODE_DONE_WAITING;
            } else {
                mTouchMode = TOUCH_MODE_DONE_WAITING;
            }
        }
    }
}
 
Example 6
Source File: TwoWayAbsListView.java    From recent-images with MIT License 5 votes vote down vote up
/**
 * Sets the selector state to "pressed" and posts a CheckForKeyLongPress to see if
 * this is a long press.
 */
void keyPressed() {
	if (!isEnabled() || !isClickable()) {
		return;
	}

	Drawable selector = mSelector;
	Rect selectorRect = mSelectorRect;
	if (selector != null && (isFocused() || touchModeDrawsInPressedState())
			&& selectorRect != null && !selectorRect.isEmpty()) {

		final View v = getChildAt(mSelectedPosition - mFirstPosition);

		if (v != null) {
			if (v.hasFocusable()) return;
			v.setPressed(true);
		}
		setPressed(true);

		final boolean longClickable = isLongClickable();
		Drawable d = selector.getCurrent();
		if (d != null && d instanceof TransitionDrawable) {
			if (longClickable) {
				((TransitionDrawable) d).startTransition(
						ViewConfiguration.getLongPressTimeout());
			} else {
				((TransitionDrawable) d).resetTransition();
			}
		}
		if (longClickable && !mDataChanged) {
			if (mPendingCheckForKeyLongPress == null) {
				mPendingCheckForKeyLongPress = new CheckForKeyLongPress();
			}
			mPendingCheckForKeyLongPress.rememberWindowAttachCount();
			postDelayed(mPendingCheckForKeyLongPress, ViewConfiguration.getLongPressTimeout());
		}
	}
}
 
Example 7
Source File: PLAAbsListView.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
public void run() {
    if (mTouchMode == TOUCH_MODE_DOWN) {
        mTouchMode = TOUCH_MODE_TAP;
        final View child = getChildAt(mMotionPosition - mFirstPosition);
        if (child != null && !child.hasFocusable()) {
            mLayoutMode = LAYOUT_NORMAL;

            if (!mDataChanged) {
                layoutChildren();
                child.setPressed(true);
                positionSelector(child);
                setPressed(true);

                final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
                final boolean longClickable = isLongClickable();

                if (mSelector != null) {
                    Drawable d = mSelector.getCurrent();
                    if (d != null && d instanceof TransitionDrawable) {
                        if (longClickable) {
                            ((TransitionDrawable) d).startTransition(longPressTimeout);
                        } else {
                            ((TransitionDrawable) d).resetTransition();
                        }
                    }
                }

                if (longClickable) {
                } else {
                    mTouchMode = TOUCH_MODE_DONE_WAITING;
                }
            } else {
                mTouchMode = TOUCH_MODE_DONE_WAITING;
            }
        }
    }
}
 
Example 8
Source File: PLAAbsListView.java    From Lay-s with MIT License 5 votes vote down vote up
public void run() {
    if (mTouchMode == TOUCH_MODE_DOWN) {
        mTouchMode = TOUCH_MODE_TAP;
        final View child = getChildAt(mMotionPosition - mFirstPosition);
        if (child != null && !child.hasFocusable()) {
            mLayoutMode = LAYOUT_NORMAL;

            if (!mDataChanged) {
                layoutChildren();
                child.setPressed(true);
                positionSelector(child);
                setPressed(true);

                final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
                final boolean longClickable = isLongClickable();

                if (mSelector != null) {
                    Drawable d = mSelector.getCurrent();
                    if (d != null && d instanceof TransitionDrawable) {
                        if (longClickable) {
                            ((TransitionDrawable) d).startTransition(longPressTimeout);
                        } else {
                            ((TransitionDrawable) d).resetTransition();
                        }
                    }
                }

                if (longClickable) {
                } else {
                    mTouchMode = TOUCH_MODE_DONE_WAITING;
                }
            } else {
                mTouchMode = TOUCH_MODE_DONE_WAITING;
            }
        }
    }
}
 
Example 9
Source File: LinearLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
        RecyclerView.Recycler recycler, RecyclerView.State state) {
    resolveShouldLayoutReverse();
    if (getChildCount() == 0) {
        return null;
    }

    final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
    if (layoutDir == LayoutState.INVALID_LAYOUT) {
        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);

    // nextCandidate is the first child view in the layout direction that's partially
    // within RV's bounds, i.e. part of it is visible or it's completely invisible but still
    // touching RV's bounds. This will be the unfocusable candidate view to become visible onto
    // the screen if no focusable views are found in the given layout direction.
    final View nextCandidate;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToStart();
    } else {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToEnd();
    }
    // nextFocus is meaningful only if it refers to a focusable child, in which case it
    // indicates the next view to gain focus.
    final View nextFocus;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextFocus = getChildClosestToStart();
    } else {
        nextFocus = getChildClosestToEnd();
    }
    if (nextFocus.hasFocusable()) {
        if (nextCandidate == null) {
            return null;
        }
        return nextFocus;
    }
    return nextCandidate;
}
 
Example 10
Source File: LinearLayoutManager.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state,
        LayoutState layoutState, LayoutChunkResult result) {
    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;
    }
    LayoutParams params = (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.
    layoutDecoratedWithMargins(view, left, top, right, bottom);
    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.hasFocusable();
}
 
Example 11
Source File: LinearLayoutManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state,
        LayoutState layoutState, LayoutChunkResult result) {
    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;
    }
    RecyclerView.LayoutParams params = (RecyclerView.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.
    layoutDecoratedWithMargins(view, left, top, right, bottom);
    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.hasFocusable();
}
 
Example 12
Source File: ExtendableListView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
private boolean onTouchUpTap(final MotionEvent event) {
    final int motionPosition = mMotionPosition;
    if (motionPosition >= 0) {
        final View child = getChildAt(motionPosition);
        if (child != null && !child.hasFocusable()) {
            if (mTouchMode != TOUCH_MODE_DOWN) {
                child.setPressed(false);
            }

            if (mPerformClick == null) {
                invalidate();
                mPerformClick = new PerformClick();
            }

            final PerformClick performClick = mPerformClick;
            performClick.mClickMotionPosition = motionPosition;
            performClick.rememberWindowAttachCount();

//            mResurrectToPosition = motionPosition;

            if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                final Handler handler = getHandler();
                if (handler != null) {
                    handler.removeCallbacks(mTouchMode == TOUCH_MODE_DOWN ?
                            mPendingCheckForTap : mPendingCheckForLongPress);
                }
                mLayoutMode = LAYOUT_NORMAL;
                if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) {
                    mTouchMode = TOUCH_MODE_TAP;
                    layoutChildren();
                    child.setPressed(true);
                    setPressed(true);
                    postDelayed(new Runnable() {
                        public void run() {
                            child.setPressed(false);
                            setPressed(false);
                            if (!mDataChanged) {
                                post(performClick);
                            }
                            mTouchMode = TOUCH_MODE_IDLE;
                        }
                    }, ViewConfiguration.getPressedStateDuration());
                } else {
                    mTouchMode = TOUCH_MODE_IDLE;
                }
                return true;
            } else if (!mDataChanged && motionPosition >= 0 && mAdapter.isEnabled(motionPosition)) {
                post(performClick);
            }
        }
    }
    mTouchMode = TOUCH_MODE_IDLE;

    return true;
}
 
Example 13
Source File: LinearLayoutManager.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
        RecyclerView.Recycler recycler, RecyclerView.State state) {
    resolveShouldLayoutReverse();
    if (getChildCount() == 0) {
        return null;
    }

    final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
    if (layoutDir == LayoutState.INVALID_LAYOUT) {
        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);

    // nextCandidate is the first child view in the layout direction that's partially
    // within RV's bounds, i.e. part of it is visible or it's completely invisible but still
    // touching RV's bounds. This will be the unfocusable candidate view to become visible onto
    // the screen if no focusable views are found in the given layout direction.
    final View nextCandidate;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToStart();
    } else {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToEnd();
    }
    // nextFocus is meaningful only if it refers to a focusable child, in which case it
    // indicates the next view to gain focus.
    final View nextFocus;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextFocus = getChildClosestToStart();
    } else {
        nextFocus = getChildClosestToEnd();
    }
    if (nextFocus.hasFocusable()) {
        if (nextCandidate == null) {
            return null;
        }
        return nextFocus;
    }
    return nextCandidate;
}
 
Example 14
Source File: AbsHListView.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public void run() {
	if ( mTouchMode == TOUCH_MODE_DOWN ) {
		mTouchMode = TOUCH_MODE_TAP;
		final View child = getChildAt( mMotionPosition - mFirstPosition );
		if ( child != null && !child.hasFocusable() ) {
			mLayoutMode = LAYOUT_NORMAL;

			if ( !mDataChanged ) {
				child.setPressed( true );
				setPressed( true );
				layoutChildren();
				positionSelector( mMotionPosition, child );
				refreshDrawableState();

				final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
				final boolean longClickable = isLongClickable();

				if ( mSelector != null ) {
					Drawable d = mSelector.getCurrent();
					if ( d != null && d instanceof TransitionDrawable ) {
						if ( longClickable ) {
							( (TransitionDrawable) d ).startTransition( longPressTimeout );
						} else {
							( (TransitionDrawable) d ).resetTransition();
						}
					}
				}

				if ( longClickable ) {
					if ( mPendingCheckForLongPress == null ) {
						mPendingCheckForLongPress = new CheckForLongPress();
					}
					mPendingCheckForLongPress.rememberWindowAttachCount();
					postDelayed( mPendingCheckForLongPress, longPressTimeout );
				} else {
					mTouchMode = TOUCH_MODE_DONE_WAITING;
				}
			} else {
				mTouchMode = TOUCH_MODE_DONE_WAITING;
			}
		}
	}
}
 
Example 15
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 4 votes vote down vote up
@Override
public void run() {
	if (mTouchMode == TOUCH_MODE_DOWN) {
		mTouchMode = TOUCH_MODE_TAP;
		final View child = getChildAt(mMotionPosition - mFirstPosition);
		if (child != null && !child.hasFocusable()) {
			mLayoutMode = LAYOUT_NORMAL;
			if (!mDataChanged) {
				child.setPressed(true);
				positionSelector(mMotionPosition, child);
				setPressed(true);
				refreshDrawableState();
				final int longPressTimeout = ViewConfiguration
						.getLongPressTimeout();
				final boolean longClickable = isLongClickable();
				if (mSelector != null) {
					Drawable d = mSelector.getCurrent();
					if (d != null && d instanceof TransitionDrawable) {
						if (longClickable) {
							((TransitionDrawable) d)
									.startTransition(longPressTimeout);
						} else {
							((TransitionDrawable) d).resetTransition();
						}
					}
				}
				if (longClickable) {
					if (mPendingCheckForLongPress == null) {
						mPendingCheckForLongPress = new CheckForLongPress();
					}
					mPendingCheckForLongPress
							.rememberWindowAttachCount();
					postDelayed(mPendingCheckForLongPress,
							longPressTimeout);
				} else {
					mTouchMode = TOUCH_MODE_DONE_WAITING;
				}
			} else {
				mTouchMode = TOUCH_MODE_DONE_WAITING;
			}
		}
	}
}
 
Example 16
Source File: TwoWayAbsListView.java    From recent-images with MIT License 4 votes vote down vote up
public void run() {
	if (mTouchMode == TOUCH_MODE_DOWN) {
		mTouchMode = TOUCH_MODE_TAP;
		final View child = getChildAt(mMotionPosition - mFirstPosition);
		if (child != null && !child.hasFocusable()) {
			mLayoutMode = LAYOUT_NORMAL;

			if (!mDataChanged) {
				layoutChildren();
				child.setPressed(true);
				positionSelector(child);
				setPressed(true);

				final int longPressTimeout = ViewConfiguration.getLongPressTimeout();
				final boolean longClickable = isLongClickable();

				if (mSelector != null) {
					Drawable d = mSelector.getCurrent();
					if (d != null && d instanceof TransitionDrawable) {
						if (longClickable) {
							((TransitionDrawable) d).startTransition(longPressTimeout);
						} else {
							((TransitionDrawable) d).resetTransition();
						}
					}
				}

				if (longClickable) {
					if (mPendingCheckForLongPress == null) {
						mPendingCheckForLongPress = new CheckForLongPress();
					}
					mPendingCheckForLongPress.rememberWindowAttachCount();
					postDelayed(mPendingCheckForLongPress, longPressTimeout);
				} else {
					mTouchMode = TOUCH_MODE_DONE_WAITING;
				}
			} else {
				mTouchMode = TOUCH_MODE_DONE_WAITING;
			}
		}
	}
}
 
Example 17
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
private void onTouchUp(MotionEvent ev) {
    switch (mTouchMode) {
    case TOUCH_MODE_DOWN:
    case TOUCH_MODE_TAP:
    case TOUCH_MODE_DONE_WAITING:
        final int motionPosition = mMotionPosition;
        final View child =
                getChildCount() == 0 ? null : getChildAt(motionPosition - mFirstPosition);
        if (child != null) {
            if (mTouchMode != TOUCH_MODE_DOWN) {
                child.setPressed(false);
            }
            final float x = ev.getX();
            final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
            if (inList && !child.hasFocusable()) {
                if (mPerformClick == null) {
                    mPerformClick = new PerformClick();
                }
                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();
                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    mLayoutMode = LAYOUT_NORMAL;
                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchModeReset = null;
                                mTouchMode = TOUCH_MODE_REST;
                                child.setPressed(false);
                                setPressed(false);
                                invalidate();
                                if (!mDataChanged && mIsAttached) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset,
                                ViewConfiguration.getPressedStateDuration());
                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                        updateSelectorState();
                    }
                    return;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }
        }
        mTouchMode = TOUCH_MODE_REST;
        updateSelectorState();
        break;
    case TOUCH_MODE_SCROLL:
        if (mFlingRunnable == null) {
            mFlingRunnable = new FlingRunnable();
        }
        if (!mFlingRunnable.scrollToAdjustViewsUpOrDown()) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocity =
                    (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale);
            if (Math.abs(initialVelocity) > mMinimumVelocity) {
                if (mFlingRunnable == null) {
                    mFlingRunnable = new FlingRunnable();
                }
                reportScrollStateChange(ZrcListView.OnScrollListener.SCROLL_STATE_FLING);
                mFlingRunnable.start(-initialVelocity);
            } else {
                mTouchMode = TOUCH_MODE_REST;
                reportScrollStateChange(ZrcListView.OnScrollListener.SCROLL_STATE_IDLE);
                if (mFlingRunnable != null) {
                    mFlingRunnable.endFling();
                }
            }
        }
        break;
    }
    setPressed(false);
    invalidate();
    recycleVelocityTracker();
    mActivePointerId = INVALID_POINTER;
}
 
Example 18
Source File: LinearLayoutManager.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
        RecyclerView.Recycler recycler, RecyclerView.State state) {
    resolveShouldLayoutReverse();
    if (getChildCount() == 0) {
        return null;
    }

    final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
    if (layoutDir == LayoutState.INVALID_LAYOUT) {
        return null;
    }
    ensureLayoutState();
    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);

    // nextCandidate is the first child view in the layout direction that's partially
    // within RV's bounds, i.e. part of it is visible or it's completely invisible but still
    // touching RV's bounds. This will be the unfocusable candidate view to become visible onto
    // the screen if no focusable views are found in the given layout direction.
    final View nextCandidate;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToStart(recycler, state);
    } else {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToEnd(recycler, state);
    }
    // nextFocus is meaningful only if it refers to a focusable child, in which case it
    // indicates the next view to gain focus.
    final View nextFocus;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextFocus = getChildClosestToStart();
    } else {
        nextFocus = getChildClosestToEnd();
    }
    if (nextFocus.hasFocusable()) {
        if (nextCandidate == null) {
            return null;
        }
        return nextFocus;
    }
    return nextCandidate;
}
 
Example 19
Source File: LinearLayoutManager.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
void layoutChunk(RecyclerView.Recycler recycler, RecyclerView.State state,
        LayoutState layoutState, LayoutChunkResult result) {
    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;
    }
    RecyclerView.LayoutParams params = (RecyclerView.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.
    layoutDecoratedWithMargins(view, left, top, right, bottom);
    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.hasFocusable();
}
 
Example 20
Source File: LinearLayoutManager.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View onFocusSearchFailed(View focused, int focusDirection,
        RecyclerView.Recycler recycler, RecyclerView.State state) {
    resolveShouldLayoutReverse();
    if (getChildCount() == 0) {
        return null;
    }

    final int layoutDir = convertFocusDirectionToLayoutDirection(focusDirection);
    if (layoutDir == LayoutState.INVALID_LAYOUT) {
        return null;
    }
    ensureLayoutState();
    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);

    // nextCandidate is the first child view in the layout direction that's partially
    // within RV's bounds, i.e. part of it is visible or it's completely invisible but still
    // touching RV's bounds. This will be the unfocusable candidate view to become visible onto
    // the screen if no focusable views are found in the given layout direction.
    final View nextCandidate;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToStart(recycler, state);
    } else {
        nextCandidate = findPartiallyOrCompletelyInvisibleChildClosestToEnd(recycler, state);
    }
    // nextFocus is meaningful only if it refers to a focusable child, in which case it
    // indicates the next view to gain focus.
    final View nextFocus;
    if (layoutDir == LayoutState.LAYOUT_START) {
        nextFocus = getChildClosestToStart();
    } else {
        nextFocus = getChildClosestToEnd();
    }
    if (nextFocus.hasFocusable()) {
        if (nextCandidate == null) {
            return null;
        }
        return nextFocus;
    }
    return nextCandidate;
}