Java Code Examples for android.view.ViewPropertyAnimator#x()

The following examples show how to use android.view.ViewPropertyAnimator#x() . 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: TabletTabSwitcherLayout.java    From ChromeLikeTabSwitcher with Apache License 2.0 6 votes vote down vote up
/**
 * Animates a tab to be swiped horizontally.
 *
 * @param tabItem
 *         The tab item, which corresponds to the tab, which should be swiped, as an instance of
 *         the class {@link TabItem}. The tab item may not be null
 * @param targetPosition
 *         The position on the x-axis, the tab should be moved to, in pixels as a {@link Float}
 *         value
 * @param selected
 *         True, if the tab should become the selected one, false otherwise
 * @param animationDuration
 *         The duration of the animation in milliseconds as a {@link Long} value
 * @param velocity
 *         The velocity of the drag gesture, which caused the tab to be swiped, in pixels per
 *         second as a {@link Float} value
 */
private void animateSwipe(@NonNull final TabItem tabItem, final float targetPosition,
                          final boolean selected, final long animationDuration,
                          final float velocity) {
    View view = contentViewRecycler.getView(tabItem.getTab());

    if (view != null) {
        float currentPosition = view.getX();
        float distance = Math.abs(targetPosition - currentPosition);
        float maxDistance = getTabSwitcher().getWidth() + swipedTabDistance;
        long duration = velocity > 0 ? Math.round((distance / velocity) * 1000) :
                Math.round(animationDuration * (distance / maxDistance));
        ViewPropertyAnimator animation = view.animate();
        animation.setListener(new AnimationListenerWrapper(
                selected ? createSwipeSelectedTabAnimationListener(tabItem) :
                        createSwipeNeighborAnimationListener(tabItem)));
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.setDuration(duration);
        animation.setStartDelay(0);
        animation.x(targetPosition);
        animation.start();
    }
}
 
Example 2
Source File: ZoomableRecyclerView.java    From Hentoid with Apache License 2.0 6 votes vote down vote up
boolean zoomFling(int velocityX, int velocityY) {
    if (scale <= DEFAULT_SCALE) return false;

    float distanceTimeFactor = 0.4f;
    Float newX = null;
    Float newY = null;

    if (velocityX != 0 && canMoveHorizontally()) {
        float dx = (distanceTimeFactor * velocityX / 2);
        newX = getPositionX(getX() + dx);
    }
    if (velocityY != 0 && canMoveVertically()) {
        float dy = (distanceTimeFactor * velocityY / 2);
        newY = getPositionY(getY() + dy);
    }

    ViewPropertyAnimator animation = animate();
    if (newX != null) animation.x(newX);
    if (newY != null) animation.y(newY);
    animation.setInterpolator(new DecelerateInterpolator())
            .setDuration(400)
            .start();

    return true;
}
 
Example 3
Source File: PhoneArithmetics.java    From ChromeLikeTabSwitcher with Apache License 2.0 5 votes vote down vote up
@Override
public final void animatePosition(@NonNull final Axis axis,
                                  @NonNull final ViewPropertyAnimator animator,
                                  @NonNull final AbstractItem item, final float position,
                                  final boolean includePadding) {
    Condition.INSTANCE.ensureNotNull(axis, "The axis may not be null");
    Condition.INSTANCE.ensureNotNull(animator, "The animator may not be null");
    Condition.INSTANCE.ensureNotNull(item, "The item may not be null");

    if (getOrientationInvariantAxis(axis) == Axis.DRAGGING_AXIS) {
        Toolbar[] toolbars = getTabSwitcher().getToolbars();
        animator.y((getTabSwitcher().areToolbarsShown() && getTabSwitcher().isSwitcherShown() &&
                toolbars != null ?
                toolbars[TabSwitcher.PRIMARY_TOOLBAR_INDEX].getHeight() - tabInset : 0) +
                (includePadding ? getTabSwitcherPadding(axis, Gravity.START) : 0) + position);
    } else {
        View view = item.getView();
        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) view.getLayoutParams();
        animator.x(position + layoutParams.leftMargin + (includePadding ?
                getTabSwitcher().getPaddingLeft() / 2f -
                        getTabSwitcher().getPaddingRight() / 2f : 0) -
                (getTabSwitcher().getLayout() == Layout.PHONE_LANDSCAPE &&
                        getTabSwitcher().isSwitcherShown() ?
                        stackedTabCount * stackedTabSpacing / 2f : 0));
    }
}
 
Example 4
Source File: ActionMenu.java    From SpringActionMenu with Apache License 2.0 5 votes vote down vote up
/**
 * buttonItem open animation
 */
private void buttonItemOpenAnimation(int index,ActionButtonItems view) {
    if (index == 0) {
        view.startFactorAnimation(duration / 6, 0, 1);
    } else {
        ViewPropertyAnimator propertyAnimator = view.animate().alpha(1).
                setInterpolator(new OvershootInterpolator()).setDuration(duration / 3);

        switch (expandDirect) {
            case expandDirectTop:
                propertyAnimator.y((circleRadius * 2 + dimens) * (childViewCount - 1 - index) + circleRadius * 2);
                break;
            case expandDirectDown:
                propertyAnimator.y(circleRadius * 2 * index + dimens * (index - 1));
                break;
            case expandDirectLeft:
                propertyAnimator.x((circleRadius * 2 + dimens) * (childViewCount - 1 - index) + circleRadius * 2);
                break;
            case expandDirectRight:
                propertyAnimator.x(circleRadius * 2 * index + dimens * (index - 1));
                break;
        }
        if (isOpen) {
            view.setVisibility(View.VISIBLE);
        }

        propertyAnimator.start();

        // start factor animation
        view.startFactorAnimation(duration / 6, 0, -1);
    }
    view.setOpen(isOpen);
}
 
Example 5
Source File: g.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public com.nineoldandroids.view.ViewPropertyAnimator x(float f)
{
    ViewPropertyAnimator viewpropertyanimator = (ViewPropertyAnimator)b.get();
    if (viewpropertyanimator != null)
    {
        viewpropertyanimator.x(f);
    }
    return this;
}