Example usage for android.animation AnimatorSet start

List of usage examples for android.animation AnimatorSet start

Introduction

In this page you can find the example usage for android.animation AnimatorSet start.

Prototype

@SuppressWarnings("unchecked")
@Override
public void start() 

Source Link

Document

Starting this AnimatorSet will, in turn, start the animations for which it is responsible.

Usage

From source file:com.b44t.ui.ActionBar.BottomSheet.java

@Override
public void dismiss() {
    if (dismissed) {
        return;/*from   w  w w. jav a2 s .c o m*/
    }
    dismissed = true;
    cancelSheetAnimation();
    if (!allowCustomAnimation || !onCustomCloseAnimation()) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(containerView, "translationY",
                        containerView.getMeasuredHeight() + AndroidUtilities.dp(10)),
                ObjectAnimator.ofInt(backDrawable, "alpha", 0));
        if (useFastDismiss) {
            int height = containerView.getMeasuredHeight();
            animatorSet.setDuration(
                    Math.max(60, (int) (180 * (height - containerView.getTranslationY()) / (float) height)));
            useFastDismiss = false;
        } else {
            animatorSet.setDuration(180);
        }
        animatorSet.setInterpolator(new AccelerateInterpolator());
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                    AndroidUtilities.runOnUIThread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                dismissInternal();
                            } catch (Exception e) {
                                FileLog.e("messenger", e);
                            }
                        }
                    });
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                    currentSheetAnimation = null;
                }
            }
        });
        animatorSet.start();
        currentSheetAnimation = animatorSet;
    }
}

From source file:org.michaelbel.bottomsheet.BottomSheet.java

@Override
public void dismiss() {
    if (dismissed) {
        return;/*from   ww w  . j a  va 2 s.  co m*/
    }

    dismissed = true;
    cancelSheetAnimation();

    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(
            ObjectAnimator.ofFloat(containerView, "translationY",
                    containerView.getMeasuredHeight() + Utils.dp(getContext(), 10)),
            ObjectAnimator.ofInt(backDrawable, "alpha", 0));
    if (useFastDismiss) {
        int height = containerView.getMeasuredHeight();
        animatorSet.setDuration(
                Math.max(60, (int) (180 * (height - containerView.getTranslationY()) / (float) height)));
        useFastDismiss = false;
    } else {
        animatorSet.setDuration(180);
    }
    animatorSet.setInterpolator(new AccelerateInterpolator());
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            dismissInternal();
                        } catch (Exception e) {
                            Log.e(TAG, e.getMessage());
                        }
                    }
                });
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) {
                currentSheetAnimation = null;
            }
        }
    });
    animatorSet.start();
    currentSheetAnimation = animatorSet;

    if (bottomSheetCallBack != null) {
        bottomSheetCallBack.onClose();
    }
}

From source file:org.telegram.ui.Components.ChatAttachAlert.java

@TargetApi(16)
public void closeCamera(boolean animated) {
    if (takingPhoto || cameraView == null) {
        return;//from   ww w .jav  a2s.c om
    }
    animateCameraValues[1] = AndroidUtilities.dp(80) - cameraViewOffsetX;
    animateCameraValues[2] = AndroidUtilities.dp(80) - cameraViewOffsetY;
    if (animated) {
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) cameraView.getLayoutParams();
        animateCameraValues[0] = layoutParams.topMargin = (int) cameraView.getTranslationY();
        cameraView.setLayoutParams(layoutParams);
        cameraView.setTranslationY(0);

        cameraAnimationInProgress = true;
        ArrayList<Animator> animators = new ArrayList<>();
        animators.add(ObjectAnimator.ofFloat(ChatAttachAlert.this, "cameraOpenProgress", 0.0f));
        animators.add(ObjectAnimator.ofFloat(cameraPanel, "alpha", 0.0f));
        for (int a = 0; a < 2; a++) {
            if (flashModeButton[a].getVisibility() == View.VISIBLE) {
                animators.add(ObjectAnimator.ofFloat(flashModeButton[a], "alpha", 0.0f));
                break;
            }
        }
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);
        animatorSet.setDuration(200);
        animatorSet.addListener(new AnimatorListenerAdapterProxy() {
            @Override
            public void onAnimationEnd(Animator animator) {
                cameraAnimationInProgress = false;
                cameraPanel.setVisibility(View.GONE);
                cameraOpened = false;
                if (Build.VERSION.SDK_INT >= 21) {
                    cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                }
            }
        });
        animatorSet.start();
    } else {
        animateCameraValues[0] = 0;
        setCameraOpenProgress(0);
        cameraPanel.setAlpha(0);
        cameraPanel.setVisibility(View.GONE);
        for (int a = 0; a < 2; a++) {
            if (flashModeButton[a].getVisibility() == View.VISIBLE) {
                flashModeButton[a].setAlpha(0.0f);
                break;
            }
        }
        cameraOpened = false;
        if (Build.VERSION.SDK_INT >= 21) {
            cameraView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }
    }
}

From source file:org.telegram.ui.ActionBar.ActionBarLayout.java

public boolean onTouchEvent(MotionEvent ev) {
    if (!checkTransitionAnimation() && !inActionMode && !animationInProgress) {
        if (fragmentsStack.size() > 1) {
            if (ev != null && ev.getAction() == MotionEvent.ACTION_DOWN && !startedTracking
                    && !maybeStartTracking) {
                BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
                if (!currentFragment.swipeBackEnabled) {
                    return false;
                }/*from www .j  av  a2  s.  co m*/
                startedTrackingPointerId = ev.getPointerId(0);
                maybeStartTracking = true;
                startedTrackingX = (int) ev.getX();
                startedTrackingY = (int) ev.getY();
                if (velocityTracker != null) {
                    velocityTracker.clear();
                }
            } else if (ev != null && ev.getAction() == MotionEvent.ACTION_MOVE
                    && ev.getPointerId(0) == startedTrackingPointerId) {
                if (velocityTracker == null) {
                    velocityTracker = VelocityTracker.obtain();
                }
                int dx = Math.max(0, (int) (ev.getX() - startedTrackingX));
                int dy = Math.abs((int) ev.getY() - startedTrackingY);
                velocityTracker.addMovement(ev);
                if (maybeStartTracking && !startedTracking && dx >= AndroidUtilities.getPixelsInCM(0.4f, true)
                        && Math.abs(dx) / 3 > dy) {
                    prepareForMoving(ev);
                } else if (startedTracking) {
                    if (!beginTrackingSent) {
                        if (parentActivity.getCurrentFocus() != null) {
                            AndroidUtilities.hideKeyboard(parentActivity.getCurrentFocus());
                        }
                        BaseFragment currentFragment = fragmentsStack.get(fragmentsStack.size() - 1);
                        currentFragment.onBeginSlide();
                        beginTrackingSent = true;
                    }
                    containerView.setTranslationX(dx);
                    setInnerTranslationX(dx);
                }
            } else if (ev != null && ev.getPointerId(0) == startedTrackingPointerId
                    && (ev.getAction() == MotionEvent.ACTION_CANCEL || ev.getAction() == MotionEvent.ACTION_UP
                            || ev.getAction() == MotionEvent.ACTION_POINTER_UP)) {
                if (velocityTracker == null) {
                    velocityTracker = VelocityTracker.obtain();
                }
                velocityTracker.computeCurrentVelocity(1000);
                if (!startedTracking && fragmentsStack.get(fragmentsStack.size() - 1).swipeBackEnabled) {
                    float velX = velocityTracker.getXVelocity();
                    float velY = velocityTracker.getYVelocity();
                    if (velX >= 3500 && velX > Math.abs(velY)) {
                        prepareForMoving(ev);
                        if (!beginTrackingSent) {
                            if (((Activity) getContext()).getCurrentFocus() != null) {
                                AndroidUtilities.hideKeyboard(((Activity) getContext()).getCurrentFocus());
                            }
                            beginTrackingSent = true;
                        }
                    }
                }
                if (startedTracking) {
                    float x = containerView.getX();
                    AnimatorSet animatorSet = new AnimatorSet();
                    float velX = velocityTracker.getXVelocity();
                    float velY = velocityTracker.getYVelocity();
                    final boolean backAnimation = x < containerView.getMeasuredWidth() / 3.0f
                            && (velX < 3500 || velX < velY);
                    float distToMove;
                    if (!backAnimation) {
                        distToMove = containerView.getMeasuredWidth() - x;
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(containerView, "translationX",
                                        containerView.getMeasuredWidth()),
                                ObjectAnimator.ofFloat(this, "innerTranslationX",
                                        (float) containerView.getMeasuredWidth()));
                    } else {
                        distToMove = x;
                        animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationX", 0),
                                ObjectAnimator.ofFloat(this, "innerTranslationX", 0.0f));
                    }

                    animatorSet.setDuration(
                            Math.max((int) (200.0f / containerView.getMeasuredWidth() * distToMove), 50));
                    animatorSet.addListener(new AnimatorListenerAdapterProxy() {
                        @Override
                        public void onAnimationEnd(Animator animator) {
                            onSlideAnimationEnd(backAnimation);
                        }
                    });
                    animatorSet.start();
                    animationInProgress = true;
                } else {
                    maybeStartTracking = false;
                    startedTracking = false;
                }
                if (velocityTracker != null) {
                    velocityTracker.recycle();
                    velocityTracker = null;
                }
            } else if (ev == null) {
                maybeStartTracking = false;
                startedTracking = false;
                if (velocityTracker != null) {
                    velocityTracker.recycle();
                    velocityTracker = null;
                }
            }
        }
        return startedTracking;
    }
    return false;
}

From source file:cc.flydev.launcher.Page.java

private void onDropToDelete() {
    final View dragView = mDragView;

    final float toScale = 0f;
    final float toAlpha = 0f;

    // Create and start the complex animation
    ArrayList<Animator> animations = new ArrayList<Animator>();
    AnimatorSet motionAnim = new AnimatorSet();
    motionAnim.setInterpolator(new DecelerateInterpolator(2));
    motionAnim.playTogether(ObjectAnimator.ofFloat(dragView, "scaleX", toScale),
            ObjectAnimator.ofFloat(dragView, "scaleY", toScale));
    animations.add(motionAnim);// www . j  av  a 2 s. c  om

    AnimatorSet alphaAnim = new AnimatorSet();
    alphaAnim.setInterpolator(new LinearInterpolator());
    alphaAnim.playTogether(ObjectAnimator.ofFloat(dragView, "alpha", toAlpha));
    animations.add(alphaAnim);

    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);

    AnimatorSet anim = new AnimatorSet();
    anim.playTogether(animations);
    anim.setDuration(DRAG_TO_DELETE_FADE_OUT_DURATION);
    anim.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    anim.start();

    mDeferringForDelete = true;
}

From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java

private void closeProfileList() {
    Log.d(TAG, "closeProfileList()");
    if (profileListOpen) {
        AnimatorSet set = new AnimatorSet();
        set.playTogether(ObjectAnimator.ofFloat(linearListViewProfileList, "alpha", 1, 0f, 0f, 0f),
                ObjectAnimator.ofFloat(linearListViewProfileList, "translationY", 0,
                        -getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 4),
                ObjectAnimator.ofFloat(linearListView, "alpha", 0f, 1),
                ObjectAnimator.ofFloat(linearListView, "translationY",
                        getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 2, 0),
                ObjectAnimator.ofInt(imageViewOpenProfileListIcon.getDrawable(), PROPERTY_LEVEL, 10000, 0),
                ObjectAnimator.ofInt(scrollView, PROPERTY_SCROLL_POSITION, 0));
        set.setDuration(getResources().getInteger(R.integer.md_profile_list_open_anim_time));
        set.addListener(new Animator.AnimatorListener() {
            @Override/*from www.j  a v  a2  s . com*/
            public void onAnimationStart(Animator animation) {
                linearListView.setVisibility(VISIBLE);
                imageViewOpenProfileListIcon.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewOpenProfileListIcon.setClickable(true);

                profileListOpen = false;

                updateListVisibility();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set.start();
    } else {
        updateListVisibility();
    }
}

From source file:com.github.shareme.gwsmaterialdrawer.library.DrawerView.java

private void openProfileList() {
    Log.d(TAG, "openProfileList()");
    if (!profileListOpen) {
        AnimatorSet set = new AnimatorSet();
        set.playTogether(ObjectAnimator.ofFloat(linearListView, "alpha", 1, 0f, 0f, 0f),
                ObjectAnimator.ofFloat(linearListView, "translationY", 0,
                        getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 4),
                ObjectAnimator.ofFloat(linearListViewProfileList, "alpha", 0, 1),
                ObjectAnimator.ofFloat(linearListViewProfileList, "translationY",
                        -getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 2, 0),
                ObjectAnimator.ofInt(imageViewOpenProfileListIcon.getDrawable(), PROPERTY_LEVEL, 0, 10000),
                ObjectAnimator.ofInt(scrollView, PROPERTY_SCROLL_POSITION, 0));
        set.setDuration(getResources().getInteger(R.integer.md_profile_list_open_anim_time));
        set.addListener(new Animator.AnimatorListener() {
            @Override//from ww w  .j a  v  a2s  .  c  o m
            public void onAnimationStart(Animator animation) {
                linearListViewProfileList.setVisibility(VISIBLE);

                imageViewOpenProfileListIcon.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewOpenProfileListIcon.setClickable(true);

                profileListOpen = true;

                updateListVisibility();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set.start();
    } else {
        updateListVisibility();
    }
}

From source file:trendoidtechnologies.com.navigationdrawerlibrary.DrawerView.java

private void closeProfileList() {
    if (loggingEnabled)
        Log.d(TAG, "closeProfileList()");
    if (profileListOpen) {
        AnimatorSet set = new AnimatorSet();
        set.playTogether(ObjectAnimator.ofFloat(linearListViewProfileList, "alpha", 1, 0f, 0f, 0f),
                ObjectAnimator.ofFloat(linearListViewProfileList, "translationY", 0,
                        -getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 4),
                ObjectAnimator.ofFloat(linearListView, "alpha", 0f, 1),
                ObjectAnimator.ofFloat(linearListView, "translationY",
                        getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 2, 0),
                ObjectAnimator.ofInt(imageViewOpenProfileListIcon.getDrawable(), PROPERTY_LEVEL, 10000, 0),
                ObjectAnimator.ofInt(scrollView, PROPERTY_SCROLL_POSITION, 0));
        set.setDuration(getResources().getInteger(R.integer.md_profile_list_open_anim_time));
        set.addListener(new Animator.AnimatorListener() {
            @Override//from   ww  w.  ja v a  2  s  .c o m
            public void onAnimationStart(Animator animation) {
                linearListView.setVisibility(VISIBLE);
                imageViewOpenProfileListIcon.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewOpenProfileListIcon.setClickable(true);

                profileListOpen = false;

                updateListVisibility();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set.start();
    } else {
        updateListVisibility();
    }
}

From source file:cc.flydev.launcher.Page.java

private Runnable createPostDeleteAnimationRunnable(final View dragView) {
    return new Runnable() {
        @Override// www.  ja  v a2  s  . co m
        public void run() {
            int dragViewIndex = indexOfChild(dragView);

            // For each of the pages around the drag view, animate them from the previous
            // position to the new position in the layout (as a result of the drag view moving
            // in the layout)
            // NOTE: We can make an assumption here because we have side-bound pages that we
            //       will always have pages to animate in from the left
            getOverviewModePages(mTempVisiblePagesRange);
            boolean isLastWidgetPage = (mTempVisiblePagesRange[0] == mTempVisiblePagesRange[1]);
            boolean slideFromLeft = (isLastWidgetPage || dragViewIndex > mTempVisiblePagesRange[0]);

            // Setup the scroll to the correct page before we swap the views
            if (slideFromLeft) {
                snapToPageImmediately(dragViewIndex - 1);
            }

            int firstIndex = (isLastWidgetPage ? 0 : mTempVisiblePagesRange[0]);
            int lastIndex = Math.min(mTempVisiblePagesRange[1], getPageCount() - 1);
            int lowerIndex = (slideFromLeft ? firstIndex : dragViewIndex + 1);
            int upperIndex = (slideFromLeft ? dragViewIndex - 1 : lastIndex);
            ArrayList<Animator> animations = new ArrayList<Animator>();
            for (int i = lowerIndex; i <= upperIndex; ++i) {
                View v = getChildAt(i);
                // dragViewIndex < pageUnderPointIndex, so after we remove the
                // drag view all subsequent views to pageUnderPointIndex will
                // shift down.
                int oldX = 0;
                int newX = 0;
                if (slideFromLeft) {
                    if (i == 0) {
                        // Simulate the page being offscreen with the page spacing
                        oldX = getViewportOffsetX() + getChildOffset(i) - getChildWidth(i) - mPageSpacing;
                    } else {
                        oldX = getViewportOffsetX() + getChildOffset(i - 1);
                    }
                    newX = getViewportOffsetX() + getChildOffset(i);
                } else {
                    oldX = getChildOffset(i) - getChildOffset(i - 1);
                    newX = 0;
                }

                // Animate the view translation from its old position to its new
                // position
                AnimatorSet anim = (AnimatorSet) v.getTag();
                if (anim != null) {
                    anim.cancel();
                }

                // Note: Hacky, but we want to skip any optimizations to not draw completely
                // hidden views
                v.setAlpha(Math.max(v.getAlpha(), 0.01f));
                v.setTranslationX(oldX - newX);
                anim = new AnimatorSet();
                anim.playTogether(ObjectAnimator.ofFloat(v, "translationX", 0f),
                        ObjectAnimator.ofFloat(v, "alpha", 1f));
                animations.add(anim);
                v.setTag(ANIM_TAG_KEY, anim);
            }

            AnimatorSet slideAnimations = new AnimatorSet();
            slideAnimations.playTogether(animations);
            slideAnimations.setDuration(DELETE_SLIDE_IN_SIDE_PAGE_DURATION);
            slideAnimations.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mDeferringForDelete = false;
                    onEndReordering();
                    onRemoveViewAnimationCompleted();
                }
            });
            slideAnimations.start();

            removeView(dragView);
            onRemoveView(dragView, true);
        }
    };
}

From source file:trendoidtechnologies.com.navigationdrawerlibrary.DrawerView.java

private void openProfileList() {
    if (loggingEnabled)
        Log.d(TAG, "openProfileList()");
    if (!profileListOpen) {
        AnimatorSet set = new AnimatorSet();
        set.playTogether(ObjectAnimator.ofFloat(linearListView, "alpha", 1, 0f, 0f, 0f),
                ObjectAnimator.ofFloat(linearListView, "translationY", 0,
                        getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 4),
                ObjectAnimator.ofFloat(linearListViewProfileList, "alpha", 0, 1),
                ObjectAnimator.ofFloat(linearListViewProfileList, "translationY",
                        -getResources().getDimensionPixelSize(R.dimen.md_list_item_height) / 2, 0),
                ObjectAnimator.ofInt(imageViewOpenProfileListIcon.getDrawable(), PROPERTY_LEVEL, 0, 10000),
                ObjectAnimator.ofInt(scrollView, PROPERTY_SCROLL_POSITION, 0));
        set.setDuration(getResources().getInteger(R.integer.md_profile_list_open_anim_time));
        set.addListener(new Animator.AnimatorListener() {
            @Override//www  .ja v a 2s .c  o m
            public void onAnimationStart(Animator animation) {
                linearListViewProfileList.setVisibility(VISIBLE);

                imageViewOpenProfileListIcon.setClickable(false);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                imageViewOpenProfileListIcon.setClickable(true);

                profileListOpen = true;

                updateListVisibility();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        set.start();
    } else {
        updateListVisibility();
    }
}