Java Code Examples for android.animation.AnimatorSet#setDuration()

The following examples show how to use android.animation.AnimatorSet#setDuration() . 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: AndroidUtilities.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void shakeView(final View view, final float x, final int num)
{
    if (view == null)
    {
        return;
    }
    if (num == 6)
    {
        view.setTranslationX(0);
        return;
    }
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(view, "translationX", AndroidUtilities.dp(x)));
    animatorSet.setDuration(50);
    animatorSet.addListener(new AnimatorListenerAdapter()
    {
        @Override
        public void onAnimationEnd(Animator animation)
        {
            shakeView(view, num == 5 ? 0 : -x, num + 1);
        }
    });
    animatorSet.start();
}
 
Example 2
Source File: CircleLoading.java    From circleloading with Apache License 2.0 6 votes vote down vote up
private void setUpAnimators(int duration) {
    AnimatorSet outerAnimatorSet = createCircleAnimation(mOuterCircle, true);
    AnimatorSet innerAnimatorSet = createCircleAnimation(mInnerCircle, false);
    outerAnimatorSet.setDuration(duration);
    innerAnimatorSet.setDuration(duration);

    mCircleAnimator = new AnimatorSet();
    mCircleAnimator.playTogether(outerAnimatorSet, innerAnimatorSet);

    mCircleAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mCircleAnimator.start();
        }
    });
}
 
Example 3
Source File: AccessibilityTabModelListItem.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void runBlinkOutAnimation() {
    cancelRunningAnimation();
    mSwipedAway = 0;

    ObjectAnimator stretchX = ObjectAnimator.ofFloat(this, View.SCALE_X, 1.2f);
    ObjectAnimator shrinkY = ObjectAnimator.ofFloat(this, View.SCALE_Y, 0.f);
    ObjectAnimator fadeOut = ObjectAnimator.ofFloat(this, View.ALPHA, 0.f);

    AnimatorSet set = new AnimatorSet();
    set.playTogether(fadeOut, shrinkY, stretchX);
    set.addListener(mCloseAnimatorListener);
    set.setDuration(mCloseAnimationDurationMs);
    set.start();

    mActiveAnimation = set;
}
 
Example 4
Source File: PointView.java    From AndroidDemo with Apache License 2.0 6 votes vote down vote up
private void startAnimation() {
	Point startPoint = new Point(RADIUS, RADIUS);
	Point endPoint = new Point(getWidth() - RADIUS, getHeight() - RADIUS);
	ValueAnimator anim = ValueAnimator.ofObject(new PointEvaluator(), startPoint, endPoint);
	anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
		@Override
		public void onAnimationUpdate(ValueAnimator animation) {
			currentPoint = (Point) animation.getAnimatedValue();
			invalidate();
		}
	});
	ObjectAnimator anim2 = ObjectAnimator.ofObject(this, "color", new ColorEvaluator(),
			"#00FFFF", "#FF1100");
	AnimatorSet animSet = new AnimatorSet();
	animSet.play(anim).with(anim2);
	animSet.setDuration(5000);
	animSet.start();
}
 
Example 5
Source File: DrawerLayoutContainer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void openDrawer(boolean fast) {
    if (!allowOpenDrawer) {
        return;
    }
    if (AndroidUtilities.isTablet() && parentActionBarLayout != null && parentActionBarLayout.parentActivity != null) {
        AndroidUtilities.hideKeyboard(parentActionBarLayout.parentActivity.getCurrentFocus());
    }
    cancelCurrentAnimation();
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(ObjectAnimator.ofFloat(this, "drawerPosition", drawerLayout.getMeasuredWidth()));
    animatorSet.setInterpolator(new DecelerateInterpolator());
    if (fast) {
        animatorSet.setDuration(Math.max((int) (200.0f / drawerLayout.getMeasuredWidth() * (drawerLayout.getMeasuredWidth() - drawerPosition)), 50));
    } else {
        animatorSet.setDuration(250);
    }
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animator) {
            onDrawerAnimationEnd(true);
        }
    });
    animatorSet.start();
    currentAnimation = animatorSet;
}
 
Example 6
Source File: FloatingActionButton.java    From mobilecloud-15 with Apache License 2.0 6 votes vote down vote up
/**
 * Shows the Floating Action Button with some Animation.
 */
public void showFloatingActionButton() {
    if (mHidden) {
        ObjectAnimator scaleX =
            ObjectAnimator.ofFloat(this,
                                   "scaleX",
                                   0,
                                   1);
        ObjectAnimator scaleY =
            ObjectAnimator.ofFloat(this,
                                   "scaleY",
                                   0,
                                   1);
        AnimatorSet animSetXY =
            new AnimatorSet();
        animSetXY.playTogether(scaleX,
                               scaleY);
        animSetXY.setInterpolator(overshootInterpolator);
        animSetXY.setDuration(200);
        animSetXY.start();
        mHidden = false;
    }
}
 
Example 7
Source File: BorderEffect.java    From TvWidget with Apache License 2.0 6 votes vote down vote up
@Override
public void onFocusChanged(View oldFocus, View newFocus) {
    try {
        if (newFocus instanceof AbsListView) {
            return;
        }
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.setInterpolator(new DecelerateInterpolator(1));
        animatorSet.setDuration(mDurationTraslate);
        animatorSet.playTogether(mAnimatorList);
        for (Animator.AnimatorListener listener : mAnimatorListener) {
            animatorSet.addListener(listener);
        }
        mAnimatorSet = animatorSet;
        if (oldFocus == null) {
            animatorSet.setDuration(0);
            mTarget.setVisibility(View.VISIBLE);
        }
        animatorSet.start();
    }catch (Exception ex){
        ex.printStackTrace();
    }
}
 
Example 8
Source File: SecretMediaViewer.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
private void animateTo(float newScale, float newTx, float newTy, boolean isZoom, int duration) {
    if (scale == newScale && translationX == newTx && translationY == newTy) {
        return;
    }
    zoomAnimation = isZoom;
    animateToScale = newScale;
    animateToX = newTx;
    animateToY = newTy;
    animationStartTime = System.currentTimeMillis();
    imageMoveAnimation = new AnimatorSet();
    imageMoveAnimation.playTogether(
            ObjectAnimator.ofFloat(this, "animationValue", 0, 1)
    );
    imageMoveAnimation.setInterpolator(interpolator);
    imageMoveAnimation.setDuration(duration);
    imageMoveAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            imageMoveAnimation = null;
            containerView.invalidate();
        }
    });
    imageMoveAnimation.start();
}
 
Example 9
Source File: ExploreFragment.java    From C9MJ with Apache License 2.0 5 votes vote down vote up
@OnClick({
        R.id.iv_expandable,
        R.id.tv_section,
        R.id.scroll_view
})
public void onClick(View view) {
    switch (view.getId()) {
        case R.id.iv_expandable:

            navigator.notifyDataSetChanged();    // must call firstly
            fragmentAdapter.notifyDataSetChanged();

            isExpanded = !isExpanded;
            iv_expandable.setImageResource(isExpanded ? R.drawable.ic_expand_close : R.drawable.ic_expand_open);
            //栏目切换的动画
            ObjectAnimator animator0 = ObjectAnimator.ofFloat(tv_section, "translationX", isExpanded ? 0 : tv_section.getWidth());
            ObjectAnimator animator1 = ObjectAnimator.ofFloat(scrollView, "translationY", isExpanded ? 0 : -scrollView.getHeight());
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.playTogether(animator0, animator1);
            animatorSet.setDuration(500);
            animatorSet.setInterpolator(new BounceInterpolator());
            animatorSet.start();

            //保存已选择&未选择的栏目列表
            selectedTitleString = parseListToStringByColons(selectedTitleList);
            unselectedTitleString = parseListToStringByColons(unSelectedTitleList);
            App.getSpUtils().putString(Constants.STRING_TITLE_SELECTED, selectedTitleString);
            App.getSpUtils().putString(Constants.STRING_TITLE_UNSELECTED, unselectedTitleString);
            break;

        case R.id.tv_section:
            break;
        case R.id.scroll_view:
            break;
    }
}
 
Example 10
Source File: BossTransferView.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
private void handleRootView() {
    ObjectAnimator setScaleY = ObjectAnimator.ofFloat(mRootView, "scaleY", 1f, 0.95f);
    ObjectAnimator setScaleX = ObjectAnimator.ofFloat(mRootView, "scaleX", 1f, 0.95f);
    AnimatorSet set = new AnimatorSet();
    set.play(setScaleX).with(setScaleY);
    set.setDuration(500);
    set.start();
}
 
Example 11
Source File: CameraActivity.java    From KrGallery with GNU General Public License v2.0 5 votes vote down vote up
private boolean processTouchEvent(MotionEvent event) {
    if (!pressed && event.getActionMasked() == MotionEvent.ACTION_DOWN || event.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN) {
        if (!takingPhoto) {
            pressed = true;
            maybeStartDraging = true;
            lastY = event.getY();
        }
    } else if (pressed) {
        if (event.getActionMasked() == MotionEvent.ACTION_MOVE) {
        } else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL || event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_POINTER_UP) {
            pressed = false;
            if (dragging) {
                dragging = false;
                if (cameraView != null) {
                    if (Math.abs(cameraView.getTranslationY()) > cameraView.getMeasuredHeight() / 6.0f) {
                        closeCamera(true);
                    } else {
                        AnimatorSet animatorSet = new AnimatorSet();
                        animatorSet.playTogether(
                                ObjectAnimator.ofFloat(cameraView, "translationY", 0.0f),
                                ObjectAnimator.ofFloat(cameraPanel, "alpha", 1.0f),
                                ObjectAnimator.ofFloat(flashModeButton[0], "alpha", 1.0f),
                                ObjectAnimator.ofFloat(flashModeButton[1], "alpha", 1.0f));
                        animatorSet.setDuration(250);
                        animatorSet.setInterpolator(interpolator);
                        animatorSet.start();
                        cameraPanel.setTag(null);
                    }
                }
            } else {
                cameraView.getLocationOnScreen(viewPosition);
                float viewX = event.getRawX() - viewPosition[0];
                float viewY = event.getRawY() - viewPosition[1];
                cameraView.focusToPoint((int) viewX, (int) viewY);
            }
        }
    }
    return true;
}
 
Example 12
Source File: ColorPicker.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void toggleSecondField() {
    boolean hide = clearButton.getTag() != null;
    clearButton.setTag(hide ? null : 1);
    AnimatorSet animatorSet = new AnimatorSet();
    ArrayList<Animator> animators = new ArrayList<>();
    animators.add(ObjectAnimator.ofFloat(clearButton, View.ROTATION, hide ? 45 : 0));
    animators.add(ObjectAnimator.ofFloat(colorEditText[2], View.ALPHA, hide ? 0.0f : 1.0f));
    animators.add(ObjectAnimator.ofFloat(colorEditText[3], View.ALPHA, hide ? 0.0f : 1.0f));
    animators.add(ObjectAnimator.ofFloat(exchangeButton, View.ALPHA, hide ? 0.0f : 1.0f));
    if (currentResetType == 2 && !hide) {
        animators.add(ObjectAnimator.ofFloat(resetButton, View.ALPHA, 0.0f));
    }
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (currentResetType == 2 && !hide) {
                resetButton.setVisibility(GONE);
                resetButton.setTag(null);
            }
        }
    });
    animatorSet.playTogether(animators);
    animatorSet.setDuration(180);
    animatorSet.start();

    if (hide && !ignoreTextChange && (minBrightness > 0f || maxBrightness < 1f)) {
        setColorInner(getFieldColor(1, 0xffffffff));
        int color = getColor();
        int red = Color.red(color);
        int green = Color.green(color);
        int blue = Color.blue(color);
        ignoreTextChange = true;
        String text = String.format("%02x%02x%02x", (byte) red, (byte) green, (byte) blue).toUpperCase();
        colorEditText[1].setText(text);
        colorEditText[1].setSelection(text.length());
        ignoreTextChange = false;
        delegate.setColor(color, 0, true);
        invalidate();
    }
}
 
Example 13
Source File: FolderPopUpWindow.java    From ImagePicker with Apache License 2.0 5 votes vote down vote up
private void enterAnimator() {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(masker, "alpha", 0, 1);
    ObjectAnimator translationY = ObjectAnimator.ofFloat(listView, "translationY", listView.getHeight(), 0);
    AnimatorSet set = new AnimatorSet();
    set.setDuration(400);
    set.playTogether(alpha, translationY);
    set.setInterpolator(new AccelerateDecelerateInterpolator());
    set.start();
}
 
Example 14
Source File: ShareMenu.java    From PracticeDemo with Apache License 2.0 5 votes vote down vote up
private void closeMenu(){

        AnimatorSet set = new AnimatorSet();
        set.setDuration(200);
        int size = mViews.size();
        mObjectAnimators = new ObjectAnimator[size];
        for (int i = 0; i < size; i++) {
            View view = mViews.get(i);
            mObjectAnimators[i]= makeCloseAnimator(view);
        }

        set.playTogether(mObjectAnimators);
        set.addListener(mAnimatorListener);
        set.start();
    }
 
Example 15
Source File: MultiFloatingActionButton.java    From ReadMark with Apache License 2.0 5 votes vote down vote up
private void scaleToShow(){
    for(int i = 2; i<getChildCount(); i++){
        View view = getChildAt(i);
        view.setVisibility(VISIBLE);
        view.setAlpha(0);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 0f, 1f);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f);
        ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
        AnimatorSet set = new AnimatorSet();
        set.playTogether(scaleX, scaleY, alpha);
        set.setDuration(mAnimationDuration);
        set.start();
    }
}
 
Example 16
Source File: JCameraView.java    From EasyPhotos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean handlerFoucs(float x, float y) {
    if (y > mCaptureLayout.getTop()) {
        return false;
    }
    mFoucsView.setVisibility(VISIBLE);
    if (x < mFoucsView.getWidth() / 2) {
        x = mFoucsView.getWidth() / 2;
    }
    if (x > layout_width - mFoucsView.getWidth() / 2) {
        x = layout_width - mFoucsView.getWidth() / 2;
    }
    if (y < mFoucsView.getWidth() / 2) {
        y = mFoucsView.getWidth() / 2;
    }
    if (y > mCaptureLayout.getTop() - mFoucsView.getWidth() / 2) {
        y = mCaptureLayout.getTop() - mFoucsView.getWidth() / 2;
    }
    mFoucsView.setX(x - mFoucsView.getWidth() / 2);
    mFoucsView.setY(y - mFoucsView.getHeight() / 2);
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(mFoucsView, "scaleX", 1, 0.6f);
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(mFoucsView, "scaleY", 1, 0.6f);
    ObjectAnimator alpha = ObjectAnimator.ofFloat(mFoucsView, "alpha", 1f, 0.4f, 1f, 0.4f, 1f, 0.4f, 1f);
    AnimatorSet animSet = new AnimatorSet();
    animSet.play(scaleX).with(scaleY).before(alpha);
    animSet.setDuration(400);
    animSet.start();
    return true;
}
 
Example 17
Source File: VoteAnimation.java    From kaif-android with Apache License 2.0 5 votes vote down vote up
public static Animator voteUpAnimation(View view) {
  Context context = view.getContext();
  ValueAnimator colorAnimation = colorChangeAnimation(view,
      context.getResources().getColor(R.color.vote_state_empty),
      context.getResources().getColor(R.color.vote_state_up));
  AnimatorSet animatorSet = new AnimatorSet();
  final ObjectAnimator rotateAnimation = ObjectAnimator.ofFloat(view, "rotation", 0, 360f);
  animatorSet.play(colorAnimation).with(rotateAnimation);
  animatorSet.setDuration(300);
  return animatorSet;
}
 
Example 18
Source File: MainActivity.java    From AndroidHeros with MIT License 5 votes vote down vote up
public void btnAnimatorSet(final View view){
    ObjectAnimator animator1 = ObjectAnimator.ofFloat(view, "translationX", 300f);
    ObjectAnimator animator2 = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f, 1f);
    ObjectAnimator animator3 = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f, 1f);
    AnimatorSet set = new AnimatorSet();
    set.setDuration(1000);
    set.playTogether(animator1, animator2, animator3);
    set.start();
}
 
Example 19
Source File: SecretMediaViewer.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void toggleActionBar(boolean show, final boolean animated) {
    if (show) {
        actionBar.setVisibility(View.VISIBLE);
    }
    actionBar.setEnabled(show);
    isActionBarVisible = show;

    if (animated) {
        ArrayList<Animator> arrayList = new ArrayList<>();
        arrayList.add(ObjectAnimator.ofFloat(actionBar, "alpha", show ? 1.0f : 0.0f));
        currentActionBarAnimation = new AnimatorSet();
        currentActionBarAnimation.playTogether(arrayList);
        if (!show) {
            currentActionBarAnimation.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (currentActionBarAnimation != null && currentActionBarAnimation.equals(animation)) {
                        actionBar.setVisibility(View.GONE);
                        currentActionBarAnimation = null;
                    }
                }
            });
        }

        currentActionBarAnimation.setDuration(200);
        currentActionBarAnimation.start();
    } else {
        actionBar.setAlpha(show ? 1.0f : 0.0f);
        if (!show) {
            actionBar.setVisibility(View.GONE);
        }
    }
}
 
Example 20
Source File: ActionBarLayout.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void movePreviewFragment(float dy) {
    if (!inPreviewMode || transitionAnimationPreviewMode) {
        return;
    }
    float currentTranslation = containerView.getTranslationY();
    float nextTranslation = -dy;
    if (nextTranslation > 0) {
        nextTranslation = 0;
    } else if (nextTranslation < -AndroidUtilities.dp(60)) {
        previewOpenAnimationInProgress = true;
        inPreviewMode = false;
        nextTranslation = 0;

        BaseFragment prevFragment = fragmentsStack.get(fragmentsStack.size() - 2);
        BaseFragment fragment = fragmentsStack.get(fragmentsStack.size() - 1);

        if (Build.VERSION.SDK_INT >= 21) {
            fragment.fragmentView.setOutlineProvider(null);
            fragment.fragmentView.setClipToOutline(false);
        }
        FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) fragment.fragmentView.getLayoutParams();
        layoutParams.topMargin = layoutParams.bottomMargin = layoutParams.rightMargin = layoutParams.leftMargin = 0;
        fragment.fragmentView.setLayoutParams(layoutParams);

        presentFragmentInternalRemoveOld(false, prevFragment);

        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(
                ObjectAnimator.ofFloat(fragment.fragmentView, View.SCALE_X, 1.0f, 1.05f, 1.0f),
                ObjectAnimator.ofFloat(fragment.fragmentView, View.SCALE_Y, 1.0f, 1.05f, 1.0f));
        animatorSet.setDuration(200);
        animatorSet.setInterpolator(new CubicBezierInterpolator(0.42, 0.0, 0.58, 1.0));
        animatorSet.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                previewOpenAnimationInProgress = false;
            }
        });
        animatorSet.start();
        performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);

        fragment.setInPreviewMode(false);
    }
    if (currentTranslation != nextTranslation) {
        containerView.setTranslationY(nextTranslation);
        invalidate();
    }
}