Search in sources :

Example 21 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project UltimateAndroid by cymcsg.

the class StaticGridLayoutManager method scrollVerticallyBy.

/*
     * This method describes how far RecyclerView thinks the contents should scroll vertically.
     * You are responsible for verifying edge boundaries, and determining if this scroll
     * event somehow requires that new views be added or old views get recycled.
     */
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
    if (getChildCount() == 0) {
        return 0;
    }
    //Take top measurements from the top-left child
    final View topView = getChildAt(0);
    //Take bottom measurements from the bottom-right child.
    final View bottomView = getChildAt(getChildCount() - 1);
    //Optimize the case where the entire data set is too small to scroll
    int viewSpan = getDecoratedBottom(bottomView) - getDecoratedTop(topView);
    if (viewSpan <= getVerticalSpace()) {
        //We cannot scroll in either direction
        return 0;
    }
    int delta;
    int maxRowCount = getTotalRowCount();
    boolean topBoundReached = getFirstVisibleRow() == 0;
    boolean bottomBoundReached = getLastVisibleRow() >= maxRowCount;
    if (dy > 0) {
        //Check against bottom bound
        if (bottomBoundReached) {
            //If we've reached the last row, enforce limits
            int bottomOffset;
            if (rowOfIndex(getChildCount() - 1) >= (maxRowCount - 1)) {
                //We are truly at the bottom, determine how far
                bottomOffset = getVerticalSpace() - getDecoratedBottom(bottomView) + getPaddingBottom();
            } else {
                /*
                     * Extra space added to account for allowing bottom space in the grid.
                     * This occurs when the overlap in the last row is not large enough to
                     * ensure that at least one element in that row isn't fully recycled.
                     */
                bottomOffset = getVerticalSpace() - (getDecoratedBottom(bottomView) + mDecoratedChildHeight) + getPaddingBottom();
            }
            delta = Math.max(-dy, bottomOffset);
        } else {
            //No limits while the last row isn't visible
            delta = -dy;
        }
    } else {
        //Check against top bound
        if (topBoundReached) {
            int topOffset = -getDecoratedTop(topView) + getPaddingTop();
            delta = Math.min(-dy, topOffset);
        } else {
            delta = -dy;
        }
    }
    offsetChildrenVertical(delta);
    if (dy > 0) {
        if (getDecoratedBottom(topView) < 0 && !bottomBoundReached) {
            fillGrid(DIRECTION_DOWN, recycler);
        } else if (!bottomBoundReached) {
            fillGrid(DIRECTION_NONE, recycler);
        }
    } else {
        if (getDecoratedTop(topView) > 0 && !topBoundReached) {
            fillGrid(DIRECTION_UP, recycler);
        } else if (!topBoundReached) {
            fillGrid(DIRECTION_NONE, recycler);
        }
    }
    /*
         * Return value determines if a boundary has been reached
         * (for edge effects and flings). If returned value does not
         * match original delta (passed in), RecyclerView will draw
         * an edge effect.
         */
    return -delta;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 22 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project android_frameworks_base by DirtyUnicorns.

the class FocusManager method findTargetPosition.

/**
     * Finds the destination position where the focus should land for a given navigation event.
     *
     * @param view The view that received the event.
     * @param keyCode The key code for the event.
     * @param event
     * @return The adapter position of the destination item. Could be RecyclerView.NO_POSITION.
     */
private int findTargetPosition(View view, int keyCode, KeyEvent event) {
    switch(keyCode) {
        case KeyEvent.KEYCODE_MOVE_HOME:
            return 0;
        case KeyEvent.KEYCODE_MOVE_END:
            return mAdapter.getItemCount() - 1;
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_PAGE_DOWN:
            return findPagedTargetPosition(view, keyCode, event);
    }
    // Find a navigation target based on the arrow key that the user pressed.
    int searchDir = -1;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            searchDir = View.FOCUS_UP;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            searchDir = View.FOCUS_DOWN;
            break;
    }
    if (inGridMode()) {
        int currentPosition = mView.getChildAdapterPosition(view);
        // Left and right arrow keys only work in grid mode.
        switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (currentPosition > 0) {
                    // Stop backward focus search at the first item, otherwise focus will wrap
                    // around to the last visible item.
                    searchDir = View.FOCUS_BACKWARD;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (currentPosition < mAdapter.getItemCount() - 1) {
                    // Stop forward focus search at the last item, otherwise focus will wrap
                    // around to the first visible item.
                    searchDir = View.FOCUS_FORWARD;
                }
                break;
        }
    }
    if (searchDir != -1) {
        // Focus search behaves badly if the parent RecyclerView is focused. However, focusable
        // shouldn't be unset on RecyclerView, otherwise focus isn't properly restored after
        // events that cause a UI rebuild (like rotating the device). Compromise: turn focusable
        // off while performing the focus search.
        // TODO: Revisit this when RV focus issues are resolved.
        mView.setFocusable(false);
        View targetView = view.focusSearch(searchDir);
        mView.setFocusable(true);
        // of the list.
        if (targetView != null) {
            // Ignore navigation targets that aren't items in the RecyclerView.
            if (targetView.getParent() == mView) {
                return mView.getChildAdapterPosition(targetView);
            }
        }
    }
    return RecyclerView.NO_POSITION;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 23 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project android_frameworks_base by DirtyUnicorns.

the class TileAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final Holder holder, int position) {
    if (holder.getItemViewType() == TYPE_DIVIDER) {
        holder.itemView.setVisibility(mTileDividerIndex < mTiles.size() - 1 ? View.VISIBLE : View.INVISIBLE);
        return;
    }
    if (holder.getItemViewType() == TYPE_EDIT) {
        ((TextView) holder.itemView.findViewById(android.R.id.title)).setText(mCurrentDrag != null ? R.string.drag_to_remove_tiles : R.string.drag_to_add_tiles);
        return;
    }
    if (holder.getItemViewType() == TYPE_ACCESSIBLE_DROP) {
        holder.mTileView.setClickable(true);
        holder.mTileView.setFocusable(true);
        holder.mTileView.setFocusableInTouchMode(true);
        holder.mTileView.setVisibility(View.VISIBLE);
        holder.mTileView.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_YES);
        holder.mTileView.setContentDescription(mContext.getString(R.string.accessibility_qs_edit_position_label, position + 1));
        holder.mTileView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                selectPosition(holder.getAdapterPosition(), v);
            }
        });
        if (mNeedsFocus) {
            // Wait for this to get laid out then set its focus.
            // Ensure that tile gets laid out so we get the callback.
            holder.mTileView.requestLayout();
            holder.mTileView.addOnLayoutChangeListener(new OnLayoutChangeListener() {

                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    holder.mTileView.removeOnLayoutChangeListener(this);
                    holder.mTileView.requestFocus();
                }
            });
            mNeedsFocus = false;
        }
        return;
    }
    TileInfo info = mTiles.get(position);
    if (position > mEditIndex) {
        info.state.contentDescription = mContext.getString(R.string.accessibility_qs_edit_add_tile_label, info.state.label);
    } else if (mAccessibilityMoving) {
        info.state.contentDescription = mContext.getString(R.string.accessibility_qs_edit_position_label, position + 1);
    } else {
        info.state.contentDescription = mContext.getString(R.string.accessibility_qs_edit_tile_label, position + 1, info.state.label);
    }
    holder.mTileView.onStateChanged(info.state);
    holder.mTileView.setAppLabel(info.appLabel);
    holder.mTileView.setShowAppLabel(position > mEditIndex && !info.isSystem);
    if (mAccessibilityManager.isTouchExplorationEnabled()) {
        final boolean selectable = !mAccessibilityMoving || position < mEditIndex;
        holder.mTileView.setClickable(selectable);
        holder.mTileView.setFocusable(selectable);
        holder.mTileView.setImportantForAccessibility(selectable ? View.IMPORTANT_FOR_ACCESSIBILITY_YES : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
        if (selectable) {
            holder.mTileView.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    int position = holder.getAdapterPosition();
                    if (mAccessibilityMoving) {
                        selectPosition(position, v);
                    } else {
                        if (position < mEditIndex) {
                            showAccessibilityDialog(position, v);
                        } else {
                            startAccessibleDrag(position);
                        }
                    }
                }
            });
        }
    }
}
Also used : TileInfo(com.android.systemui.qs.customize.TileQueryHelper.TileInfo) OnLayoutChangeListener(android.view.View.OnLayoutChangeListener) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) QSIconView(com.android.systemui.qs.QSIconView)

Example 24 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project platform_frameworks_base by android.

the class FocusManager method findTargetPosition.

/**
     * Finds the destination position where the focus should land for a given navigation event.
     *
     * @param view The view that received the event.
     * @param keyCode The key code for the event.
     * @param event
     * @return The adapter position of the destination item. Could be RecyclerView.NO_POSITION.
     */
private int findTargetPosition(View view, int keyCode, KeyEvent event) {
    switch(keyCode) {
        case KeyEvent.KEYCODE_MOVE_HOME:
            return 0;
        case KeyEvent.KEYCODE_MOVE_END:
            return mAdapter.getItemCount() - 1;
        case KeyEvent.KEYCODE_PAGE_UP:
        case KeyEvent.KEYCODE_PAGE_DOWN:
            return findPagedTargetPosition(view, keyCode, event);
    }
    // Find a navigation target based on the arrow key that the user pressed.
    int searchDir = -1;
    switch(keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            searchDir = View.FOCUS_UP;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            searchDir = View.FOCUS_DOWN;
            break;
    }
    if (inGridMode()) {
        int currentPosition = mView.getChildAdapterPosition(view);
        // Left and right arrow keys only work in grid mode.
        switch(keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (currentPosition > 0) {
                    // Stop backward focus search at the first item, otherwise focus will wrap
                    // around to the last visible item.
                    searchDir = View.FOCUS_BACKWARD;
                }
                break;
            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (currentPosition < mAdapter.getItemCount() - 1) {
                    // Stop forward focus search at the last item, otherwise focus will wrap
                    // around to the first visible item.
                    searchDir = View.FOCUS_FORWARD;
                }
                break;
        }
    }
    if (searchDir != -1) {
        // Focus search behaves badly if the parent RecyclerView is focused. However, focusable
        // shouldn't be unset on RecyclerView, otherwise focus isn't properly restored after
        // events that cause a UI rebuild (like rotating the device). Compromise: turn focusable
        // off while performing the focus search.
        // TODO: Revisit this when RV focus issues are resolved.
        mView.setFocusable(false);
        View targetView = view.focusSearch(searchDir);
        mView.setFocusable(true);
        // of the list.
        if (targetView != null) {
            // Ignore navigation targets that aren't items in the RecyclerView.
            if (targetView.getParent() == mView) {
                return mView.getChildAdapterPosition(targetView);
            }
        }
    }
    return RecyclerView.NO_POSITION;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 25 with LEFT

use of android.support.v7.widget.helper.ItemTouchHelper.LEFT in project SearchView by lapism.

the class SearchDivider method onDraw.

@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    if (divider == null) {
        super.onDraw(c, parent, state);
        return;
    }
    int left = 0;
    int right = 0;
    int top = 0;
    int bottom = 0;
    final int orientation = getOrientation(parent);
    final int childCount = parent.getChildCount();
    final boolean vertical = orientation == LinearLayoutManager.VERTICAL;
    final int size;
    if (vertical) {
        size = dividerHeight;
        left = parent.getPaddingLeft();
        right = parent.getWidth() - parent.getPaddingRight();
    } else {
        size = dividerWidth;
        top = parent.getPaddingTop();
        bottom = parent.getHeight() - parent.getPaddingBottom();
    }
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int position = params.getViewLayoutPosition();
        if (position == 0) {
            continue;
        }
        if (vertical) {
            top = child.getTop() - params.topMargin - size;
            bottom = top + size;
        } else {
            left = child.getLeft() - params.leftMargin - size;
            right = left + size;
        }
        divider.setBounds(left, top, right, bottom);
        divider.draw(c);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

View (android.view.View)291 RecyclerView (android.support.v7.widget.RecyclerView)276 Paint (android.graphics.Paint)43 TextView (android.widget.TextView)36 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 ImageView (android.widget.ImageView)20 Rect (android.graphics.Rect)11 Intent (android.content.Intent)9 SuppressLint (android.annotation.SuppressLint)8 OnLayoutChangeListener (android.view.View.OnLayoutChangeListener)8 OrientationHelperEx (com.alibaba.android.vlayout.OrientationHelperEx)8 ArrayList (java.util.ArrayList)8 AlertDialog (android.support.v7.app.AlertDialog)7 Toolbar (android.support.v7.widget.Toolbar)7 ViewGroup (android.view.ViewGroup)7 GridLayoutManager (android.support.v7.widget.GridLayoutManager)6 Button (android.widget.Button)6 Animator (android.animation.Animator)5 TargetApi (android.annotation.TargetApi)5 Activity (android.app.Activity)5