Example usage for android.view ViewPropertyAnimator translationYBy

List of usage examples for android.view ViewPropertyAnimator translationYBy

Introduction

In this page you can find the example usage for android.view ViewPropertyAnimator translationYBy.

Prototype

public ViewPropertyAnimator translationYBy(float value) 

Source Link

Document

This method will cause the View's translationY property to be animated by the specified value.

Usage

From source file:com.tapcentive.sdk.actions.TapMessageFragment.java

/**
 * Animate the game.//  w  w  w .  j ava  2s .  c o  m
 * 
 * @param view
 *            the view
 * @param gameLayout
 *            the game layout to animate
 * @param duration
 *            the duration of the animation in ms
 */
@SuppressLint("NewApi")
private void animateGame(final View view) {
    // stop screen from sleeping
    getActivity().getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    RelativeLayout layout = (RelativeLayout) view.findViewById(R.id.winning_layout_portrait);
    ViewPropertyAnimator animator = layout.animate();
    animator.translationYBy(-(1 + usableHeight)).setDuration(200);

    animator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            TapcentiveLibrary.getInstance().setAnimatedWhenStopped(false);
            TapcentiveLibrary.getInstance().setAnimationInProcess(false);
        }
    });
}

From source file:com.ayuget.redface.ui.activity.ReplyActivity.java

@OnClick(R.id.show_smileys_picker)
protected void showSmileyPicker() {
    float neededTranslation = -(smileysSelector.getY() - toolbarHeight);
    ViewPropertyAnimator viewPropertyAnimator = smileysSelector.animate();

    viewPropertyAnimator.translationYBy(neededTranslation).setDuration(150).start();

    showSmileysToolbar();/*w w w .  j a  v a2s .c o m*/
    hideSoftKeyboard();
}

From source file:com.ayuget.redface.ui.activity.ReplyActivity.java

/**
 * Initializes both the smiley selector//from   ww w .  j a v  a2  s.  co  m
 */
protected void setupSmileySelector() {
    smileyList.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            final int action = MotionEventCompat.getActionMasked(event);

            switch (action) {
            case MotionEvent.ACTION_DOWN: {
                final int pointerIndex = MotionEventCompat.getActionIndex(event);
                lastTouchY = MotionEventCompat.getY(event, pointerIndex);
                activePointerId = MotionEventCompat.getPointerId(event, 0);
                break;
            }
            case MotionEvent.ACTION_MOVE: {
                if (smileyList.getScrollY() == 0) {
                    final int pointerIndex = MotionEventCompat.findPointerIndex(event, activePointerId);

                    if (pointerIndex != -1) {
                        final float y = MotionEventCompat.getY(event, pointerIndex);

                        // Distance
                        float dy = y - lastTouchY;
                        isUpwardMovement = dy < 0;
                        float targetY = smileysSelector.getY() + dy;

                        if (targetY < toolbarHeight) {
                            float difference = toolbarHeight - targetY;
                            dy += difference;
                        } else if (targetY > smileySelectorTopOffset) {
                            float difference = targetY - smileySelectorTopOffset;
                            dy -= difference;
                        }

                        smileysSelector.setY(smileysSelector.getY() + dy);

                        // Show or hide the smileys toolbar based on current position
                        if (isUpwardMovement && smileysSelector.getY() < replyWindowMaxHeight) {
                            showSmileysToolbar();
                        } else {
                            hideSmileysToolbar();
                        }
                    }

                    break;
                }
            }
            case MotionEvent.ACTION_UP: {
                int upAnimationThreshold = replyWindowMaxHeight - toolbarHeight;

                float yTranslation;
                ViewPropertyAnimator viewPropertyAnimator = smileysSelector.animate();

                if (isUpwardMovement && smileysSelector.getY() == upAnimationThreshold) {
                    // Do not move in that case
                    yTranslation = 0;
                } else if (isUpwardMovement && smileysSelector.getY() < upAnimationThreshold) {
                    // Moving too far, let's avoid this
                    yTranslation = -(smileysSelector.getY() - toolbarHeight);
                } else {
                    // Replace the smiley selector at its original position
                    yTranslation = smileySelectorTopOffset - smileysSelector.getY();
                }

                if (yTranslation != 0) {
                    viewPropertyAnimator.translationYBy(yTranslation).setDuration(150).start();
                }

                break;
            }
            }

            boolean touchConsumed;
            if (smileysSelector.getY() != smileySelectorTopOffset) {
                touchConsumed = (smileysSelector.getY() != toolbarHeight);
            } else {
                touchConsumed = false;
            }

            return touchConsumed;
        }
    });
}