Java Code Examples for android.support.v4.view.ViewCompat#getTranslationX()

The following examples show how to use android.support.v4.view.ViewCompat#getTranslationX() . 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: HorizontalItemAnimator.java    From JumpGo with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    resetAnimation(holder);
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 2
Source File: DefaultItemAnimator.java    From Mupdf with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder,
        int fromX, int fromY, int toX, int toY) {
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null && newHolder.itemView != null) {
        // carry over translation values
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
Example 3
Source File: MyDefaultItemAnimator.java    From Dota2Helper with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    resetAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 4
Source File: BaseItemAnimator.java    From SimpleNews with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
  final View view = holder.itemView;
  fromX += ViewCompat.getTranslationX(holder.itemView);
  fromY += ViewCompat.getTranslationY(holder.itemView);
  endAnimation(holder);
  int deltaX = toX - fromX;
  int deltaY = toY - fromY;
  if (deltaX == 0 && deltaY == 0) {
    dispatchMoveFinished(holder);
    return false;
  }
  if (deltaX != 0) {
    ViewCompat.setTranslationX(view, -deltaX);
  }
  if (deltaY != 0) {
    ViewCompat.setTranslationY(view, -deltaY);
  }
  mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
  return true;
}
 
Example 5
Source File: SwipeableItemClickListener.java    From android-swipe-to-dismiss-undo with MIT License 6 votes vote down vote up
private View findChildViewUnder(ViewGroup viewGroup, float x, float y) {
    final int count = viewGroup.getChildCount();
    for (int i = count - 1; i >= 0; i--) {
        final View child = viewGroup.getChildAt(i);
        if (child.getVisibility() == View.GONE) continue;
        final float translationX = ViewCompat.getTranslationX(child);
        final float translationY = ViewCompat.getTranslationY(child);
        if (x >= child.getLeft() + translationX &&
                x <= child.getRight() + translationX &&
                y >= child.getTop() + translationY &&
                y <= child.getBottom() + translationY) {
            return child;
        }
    }
    return null;
}
 
Example 6
Source File: CircularRevealItemAnimator.java    From ExpandableRecyclerView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    resetAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new CircularRevealItemAnimator.MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 7
Source File: BaseItemAnimator.java    From RecyclerviewAnimators with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final ViewHolder holder, int fromX, int fromY,
        int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    endAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 8
Source File: ClassifyItemAnimator.java    From ClassifyView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean animateMove(final RecyclerView.ViewHolder holder, int fromX, int fromY,
                           int toX, int toY) {
    final View view = holder.itemView;
    fromX += ViewCompat.getTranslationX(holder.itemView);
    fromY += ViewCompat.getTranslationY(holder.itemView);
    resetAnimation(holder);
    int deltaX = toX - fromX;
    int deltaY = toY - fromY;
    if (deltaX == 0 && deltaY == 0) {
        dispatchMoveFinished(holder);
        return false;
    }
    if (deltaX != 0) {
        ViewCompat.setTranslationX(view, -deltaX);
    }
    if (deltaY != 0) {
        ViewCompat.setTranslationY(view, -deltaY);
    }
    mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
    return true;
}
 
Example 9
Source File: ReItemTouchHelper.java    From ReSwipeCard with Apache License 2.0 5 votes vote down vote up
public void update() {
    if (mStartDx == mTargetX) {
        mX = ViewCompat.getTranslationX(mViewHolder.itemView);
    } else {
        mX = mStartDx + mFraction * (mTargetX - mStartDx);
    }
    if (mStartDy == mTargetY) {
        mY = ViewCompat.getTranslationY(mViewHolder.itemView);
    } else {
        mY = mStartDy + mFraction * (mTargetY - mStartDy);
    }
}
 
Example 10
Source File: MyDefaultItemAnimator.java    From Dota2Helper with Apache License 2.0 5 votes vote down vote up
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
                             int fromX, int fromY, int toX, int toY) {
    if (oldHolder == newHolder) {
        // Don't know how to run change animations when the same view holder is re-used.
        // run a move animation to handle position changes.
        return animateMove(oldHolder, fromX, fromY, toX, toY);
    }
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null) {
        // carry over translation values
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
Example 11
Source File: SuggestionItemDecorator.java    From FloatingSearchView with Apache License 2.0 5 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int visibleCount = parent.getChildCount();
    int count = state.getItemCount();
    RecyclerView.Adapter adapter = parent.getAdapter();
    int adapterCount = adapter != null ? adapter.getItemCount() : 0;

    for (int i = 0; i < visibleCount; i++) {
        View view = parent.getChildAt(i);
        int position = parent.getChildAdapterPosition(view);
        float translationX = ViewCompat.getTranslationX(view);
        float translationY = ViewCompat.getTranslationY(view);
        float alpha = ViewCompat.getAlpha(view);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();

        int shadows = LEFT|RIGHT;
        if(position == count - 1 && adapterCount != 0) shadows|=BOTTOM;

        drawable.setAlpha((int) (255*alpha));
        drawable.setShadow(shadows);
        drawable.setBounds(0, 0, parent.getWidth(), view.getHeight());
        int saved = canvas.save();
            canvas.translate(parent.getPaddingLeft() + translationX,
                            view.getTop() + params.topMargin + translationY);
            drawable.draw(canvas);
        canvas.restoreToCount(saved);
    }
}
 
Example 12
Source File: ViewUtil.java    From RetroMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static boolean hitTest(View v, int x, int y) {
    final int tx = (int) (ViewCompat.getTranslationX(v) + 0.5f);
    final int ty = (int) (ViewCompat.getTranslationY(v) + 0.5f);
    final int left = v.getLeft() + tx;
    final int right = v.getRight() + tx;
    final int top = v.getTop() + ty;
    final int bottom = v.getBottom() + ty;

    return (x >= left) && (x <= right) && (y >= top) && (y <= bottom);
}
 
Example 13
Source File: ClassifyItemAnimator.java    From ClassifyView with Apache License 2.0 5 votes vote down vote up
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
                             int fromX, int fromY, int toX, int toY) {
    if (oldHolder == newHolder) {
        // Don't know how to run change animations when the same view holder is re-used.
        // run a move animation to handle position changes.
        return animateMove(oldHolder, fromX, fromY, toX, toY);
    }
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null) {
        // carry over translation values
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
Example 14
Source File: HorizontalDivider.java    From TitanRecyclerView with MIT License 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.left = parent.getPaddingLeft() +
            mMarginProvider.dividerLeftMargin(position, parent) + transitionX;
    bounds.right = parent.getWidth() - parent.getPaddingRight() -
            mMarginProvider.dividerRightMargin(position, parent) + transitionX;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set top and bottom position of divider
        if (mPositionInsideItem) {
            bounds.bottom = child.getBottom() + params.topMargin + transitionY;
            bounds.top = bounds.bottom - dividerSize;
        } else {
            bounds.top = child.getBottom() + params.topMargin + transitionY;
            bounds.bottom = bounds.top + dividerSize;
        }
    } else {
        // set center point of divider
        if (mPositionInsideItem) {
            bounds.top = child.getBottom() + params.topMargin - dividerSize / 2 + transitionY;
        } else {
            bounds.top = child.getBottom() + params.topMargin + dividerSize / 2 + transitionY;
        }
        bounds.bottom = bounds.top;
    }

    return bounds;
}
 
Example 15
Source File: BaseItemAnimator.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
@Override
public boolean animateChange(RecyclerView.ViewHolder oldHolder, RecyclerView.ViewHolder newHolder,
                             int fromX, int fromY, int toX, int toY) {
    if (oldHolder == newHolder) {
        // Don't know how to run change animations when the same view holder is re-used.
        // run a move animation to handle position changes.
        return animateMove(oldHolder, fromX, fromY, toX, toY);
    }
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null) {
        // carry over translation values
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
Example 16
Source File: HorizontalDividerItemDecoration.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.left = parent.getPaddingLeft() +
            mMarginProvider.dividerLeftMargin(position, parent) + transitionX;
    bounds.right = parent.getWidth() - parent.getPaddingRight() -
            mMarginProvider.dividerRightMargin(position, parent) + transitionX;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set top and bottom position of divider
        if (mPositionInsideItem) {
            bounds.bottom = child.getBottom() + params.topMargin + transitionY;
            bounds.top = bounds.bottom - dividerSize;
        } else {
            bounds.top = child.getBottom() + params.topMargin + transitionY;
            bounds.bottom = bounds.top + dividerSize;
        }
    } else {
        // set center point of divider
        if (mPositionInsideItem) {
            bounds.top = child.getBottom() + params.topMargin - dividerSize / 2 + transitionY;
        } else {
            bounds.top = child.getBottom() + params.topMargin + dividerSize / 2 + transitionY;
        }
        bounds.bottom = bounds.top;
    }

    return bounds;
}
 
Example 17
Source File: VerticalDividerItemDecoration.java    From AFBaseLibrary with Apache License 2.0 5 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (mPositionInsideItem) {
            bounds.right = child.getRight() + params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.leftMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        if (mPositionInsideItem) {
            bounds.left = child.getRight() + params.leftMargin - dividerSize / 2 + transitionX;
        } else {
            bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
        }
        bounds.right = bounds.left;
    }

    return bounds;
}
 
Example 18
Source File: ReItemTouchHelper.java    From ReSwipeCard with Apache License 2.0 5 votes vote down vote up
private void getSelectedDxDy(float[] outPosition) {
    float dx = isManually ? 0 : mDx;
    float dy = isManually ? 0 : mDy;
    if ((mSelectedFlags & (LEFT | RIGHT)) != 0) {
        outPosition[0] = mSelectedStartX + dx - mSelected.itemView.getLeft();
    } else {
        outPosition[0] = ViewCompat.getTranslationX(mSelected.itemView);
    }
    if ((mSelectedFlags & (UP | DOWN)) != 0) {
        outPosition[1] = mSelectedStartY + dy - mSelected.itemView.getTop();
    } else {
        outPosition[1] = ViewCompat.getTranslationY(mSelected.itemView);
    }
}
 
Example 19
Source File: VerticalDividerItemDecoration.java    From AccountBook with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top = parent.getPaddingTop() +
            mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom = parent.getHeight() - parent.getPaddingBottom() -
            mMarginProvider.dividerBottomMargin(position, parent) + transitionY;

    int dividerSize = getDividerSize(position, parent);
    boolean isReverseLayout = isReverseLayout(parent);
    if (mDividerType == DividerType.DRAWABLE) {
        // set left and right position of divider
        if (isReverseLayout) {
            bounds.right = child.getLeft() - params.leftMargin + transitionX;
            bounds.left = bounds.right - dividerSize;
        } else {
            bounds.left = child.getRight() + params.rightMargin + transitionX;
            bounds.right = bounds.left + dividerSize;
        }
    } else {
        // set center point of divider
        int halfSize = dividerSize / 2;
        if (isReverseLayout) {
            bounds.left = child.getLeft() - params.leftMargin - halfSize + transitionX;
        } else {
            bounds.left = child.getRight() + params.rightMargin + halfSize + transitionX;
        }
        bounds.right = bounds.left;
    }

    if (mPositionInsideItem) {
        if (isReverseLayout) {
            bounds.left += dividerSize;
            bounds.right += dividerSize;
        } else {
            bounds.left -= dividerSize;
            bounds.right -= dividerSize;
        }
    }

    return bounds;
}
 
Example 20
Source File: ViewOffsetHelper.java    From AppCompat-Extension-Library with Apache License 2.0 4 votes vote down vote up
private static void tickleInvalidationFlag(View view) {
    final float x = ViewCompat.getTranslationX(view);
    ViewCompat.setTranslationY(view, x + 1);
    ViewCompat.setTranslationY(view, x);
}