use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT 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;
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT 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);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project Hummingbird-for-Android by xiprox.
the class DividerItemDecoration method drawHorizontal.
public void drawHorizontal(Canvas c, RecyclerView parent) {
final int top = parent.getPaddingTop();
final int bottom = parent.getHeight() - parent.getPaddingBottom();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
final int left = child.getRight() + params.rightMargin;
final int right = left + mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project LookLook by xinghongfei.
the class GridItemDividerDecoration method onDrawOver.
@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
if (parent.isAnimating())
return;
final int childCount = parent.getChildCount();
final RecyclerView.LayoutManager lm = parent.getLayoutManager();
for (int i = 0; i < childCount; i++) {
final View child = parent.getChildAt(i);
RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
if (requiresDivider(viewHolder)) {
final int right = lm.getDecoratedRight(child);
final int bottom = lm.getDecoratedBottom(child);
// draw the bottom divider
canvas.drawRect(lm.getDecoratedLeft(child), bottom - dividerSize, right, bottom, paint);
// draw the right edge divider
canvas.drawRect(right - dividerSize, lm.getDecoratedTop(child), right, bottom - dividerSize, paint);
}
}
}
use of android.support.v7.widget.helper.ItemTouchHelper.RIGHT in project FlyRefresh by race604.
the class SampleItemAnimator method animateAddImpl.
@Override
protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
View target = holder.itemView;
View icon = target.findViewById(R.id.icon);
Animator swing = ObjectAnimator.ofFloat(icon, "rotationX", 45, 0);
swing.setInterpolator(new OvershootInterpolator(5));
View right = holder.itemView.findViewById(R.id.right);
Animator rotateIn = ObjectAnimator.ofFloat(right, "rotationY", 90, 0);
rotateIn.setInterpolator(new DecelerateInterpolator());
AnimatorSet animator = new AnimatorSet();
animator.setDuration(getAddDuration());
animator.playTogether(swing, rotateIn);
animator.start();
}
Aggregations