List of usage examples for android.animation ObjectAnimator ofFloat
public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, float... values)
From source file:com.androidinspain.deskclock.timer.TimerFragment.java
/** * @param toView one of {@link #mTimersView} or {@link #mCreateTimerView} * @param timerToRemove the timer to be removed during the animation; {@code null} if no timer * should be removed//from w ww . j a va 2 s. com * @param animateDown {@code true} if the views should animate upwards, otherwise downwards */ private void animateToView(final View toView, final Timer timerToRemove, final boolean animateDown) { if (mCurrentView == toView) { return; } final boolean toTimers = toView == mTimersView; if (toTimers) { mTimersView.setVisibility(VISIBLE); } else { mCreateTimerView.setVisibility(VISIBLE); } // Avoid double-taps by enabling/disabling the set of buttons active on the new view. updateFab(BUTTONS_DISABLE); final long animationDuration = UiDataModel.getUiDataModel().getLongAnimationDuration(); final ViewTreeObserver viewTreeObserver = toView.getViewTreeObserver(); viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (viewTreeObserver.isAlive()) { viewTreeObserver.removeOnPreDrawListener(this); } final View view = mTimersView.findViewById(com.androidinspain.deskclock.R.id.timer_time); final float distanceY = view != null ? view.getHeight() + view.getY() : 0; final float translationDistance = animateDown ? distanceY : -distanceY; toView.setTranslationY(-translationDistance); mCurrentView.setTranslationY(0f); toView.setAlpha(0f); mCurrentView.setAlpha(1f); final Animator translateCurrent = ObjectAnimator.ofFloat(mCurrentView, TRANSLATION_Y, translationDistance); final Animator translateNew = ObjectAnimator.ofFloat(toView, TRANSLATION_Y, 0f); final AnimatorSet translationAnimatorSet = new AnimatorSet(); translationAnimatorSet.playTogether(translateCurrent, translateNew); translationAnimatorSet.setDuration(animationDuration); translationAnimatorSet.setInterpolator(AnimatorUtils.INTERPOLATOR_FAST_OUT_SLOW_IN); final Animator fadeOutAnimator = ObjectAnimator.ofFloat(mCurrentView, ALPHA, 0f); fadeOutAnimator.setDuration(animationDuration / 2); fadeOutAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); // The fade-out animation and fab-shrinking animation should run together. updateFab(FAB_AND_BUTTONS_SHRINK); } @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (toTimers) { showTimersView(FAB_AND_BUTTONS_EXPAND); // Reset the state of the create view. mCreateTimerView.reset(); } else { showCreateTimerView(FAB_AND_BUTTONS_EXPAND); } if (timerToRemove != null) { DataModel.getDataModel().removeTimer(timerToRemove); Events.sendTimerEvent(com.androidinspain.deskclock.R.string.action_delete, com.androidinspain.deskclock.R.string.label_deskclock); } // Update the fab and button states now that the correct view is visible and // before the animation to expand the fab and buttons starts. updateFab(FAB_AND_BUTTONS_IMMEDIATE); } }); final Animator fadeInAnimator = ObjectAnimator.ofFloat(toView, ALPHA, 1f); fadeInAnimator.setDuration(animationDuration / 2); fadeInAnimator.setStartDelay(animationDuration / 2); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(fadeOutAnimator, fadeInAnimator, translationAnimatorSet); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); mTimersView.setTranslationY(0f); mCreateTimerView.setTranslationY(0f); mTimersView.setAlpha(1f); mCreateTimerView.setAlpha(1f); } }); animatorSet.start(); return true; } }); }
From source file:co.ceryle.radiorealbutton.library.RadioRealButtonGroup.java
private ObjectAnimator createAnimator(View view, String property, float value, boolean hasDelay, boolean hasDuration) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, property, value); animator.setInterpolator(interpolatorSelector); if (hasDuration) animator.setDuration(animateSelectorDuration); else/* w w w. j av a 2 s.co m*/ animator.setDuration(0); if (hasDelay) animator.setStartDelay(animateSelectorDelay); return animator; }
From source file:com.android.calculator2.Calculator.java
private void reveal(View sourceView, int colorRes, AnimatorListener listener) { final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) getWindow().getDecorView().getOverlay(); final Rect displayRect = new Rect(); mDisplayView.getGlobalVisibleRect(displayRect); // Make reveal cover the display and status bar. final View revealView = new View(this); revealView.setBottom(displayRect.bottom); revealView.setLeft(displayRect.left); revealView.setRight(displayRect.right); revealView.setBackgroundColor(getResources().getColor(colorRes)); groupOverlay.add(revealView);// ww w . j a v a 2 s.c om final int[] clearLocation = new int[2]; sourceView.getLocationInWindow(clearLocation); clearLocation[0] += sourceView.getWidth() / 2; clearLocation[1] += sourceView.getHeight() / 2; final int revealCenterX = clearLocation[0] - revealView.getLeft(); final int revealCenterY = clearLocation[1] - revealView.getTop(); final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2); final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2); final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2); final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX, revealCenterY, 0.0f, revealRadius); revealAnimator.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); revealAnimator.addListener(listener); final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f); alphaAnimator.setDuration(getResources().getInteger(android.R.integer.config_mediumAnimTime)); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(revealAnimator).before(alphaAnimator); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animator) { groupOverlay.remove(revealView); mCurrentAnimator = null; } }); mCurrentAnimator = animatorSet; animatorSet.start(); }
From source file:com.b44t.ui.ActionBar.BottomSheet.java
private void startOpenAnimation() { containerView.setVisibility(View.VISIBLE); if (!onCustomOpenAnimation()) { if (Build.VERSION.SDK_INT >= 20) { container.setLayerType(View.LAYER_TYPE_HARDWARE, null); }//from www .j a v a2 s . com containerView.setTranslationY(containerView.getMeasuredHeight()); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(ObjectAnimator.ofFloat(containerView, "translationY", 0), ObjectAnimator.ofInt(backDrawable, "alpha", 51)); animatorSet.setDuration(200); animatorSet.setStartDelay(20); animatorSet.setInterpolator(new DecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapterProxy() { @Override public void onAnimationEnd(Animator animation) { if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) { currentSheetAnimation = null; if (delegate != null) { delegate.onOpenAnimationEnd(); } container.setLayerType(View.LAYER_TYPE_NONE, null); } } @Override public void onAnimationCancel(Animator animation) { if (currentSheetAnimation != null && currentSheetAnimation.equals(animation)) { currentSheetAnimation = null; } } }); animatorSet.start(); currentSheetAnimation = animatorSet; } }
From source file:com.google.samples.apps.sergio.ui.BaseActivity.java
private void setupAccountBoxToggle() { int selfItem = getSelfNavDrawerItem(); if (mDrawerLayout == null || selfItem == NAVDRAWER_ITEM_INVALID) { // this Activity does not have a nav drawer return;//from ww w . ja v a2 s. co m } mExpandAccountBoxIndicator.setImageResource(mAccountBoxExpanded ? R.drawable.ic_drawer_accounts_collapse : R.drawable.ic_drawer_accounts_expand); int hideTranslateY = -mAccountListContainer.getHeight() / 4; // last 25% of animation if (mAccountBoxExpanded && mAccountListContainer.getTranslationY() == 0) { // initial setup mAccountListContainer.setAlpha(0); mAccountListContainer.setTranslationY(hideTranslateY); } AnimatorSet set = new AnimatorSet(); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDrawerItemsListContainer.setVisibility(mAccountBoxExpanded ? View.INVISIBLE : View.VISIBLE); mAccountListContainer.setVisibility(mAccountBoxExpanded ? View.VISIBLE : View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } }); if (mAccountBoxExpanded) { mAccountListContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 1) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.playSequentially(ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet); set.start(); } else { mDrawerItemsListContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, hideTranslateY) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.playSequentially(subSet, ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 1) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.start(); } set.start(); }
From source file:com.tt.engtrain.showcontent.ContentListItemActivity.java
/** * Animate.//ww w.j a v a 2 s . c o m * * @param progressBar * the progress bar * @param listener * the listener */ private void animate(final HoloCircularProgressBar progressBar, final AnimatorListener listener, final float progress, final int duration) { mProgressBarAnimator = ObjectAnimator.ofFloat(progressBar, "progress", progress); mProgressBarAnimator.setDuration(duration); mProgressBarAnimator.addListener(new AnimatorListener() { @Override public void onAnimationCancel(final Animator animation) { } @Override public void onAnimationEnd(final Animator animation) { progressBar.setProgress(progress); } @Override public void onAnimationRepeat(final Animator animation) { } @Override public void onAnimationStart(final Animator animation) { } }); if (listener != null) { mProgressBarAnimator.addListener(listener); } mProgressBarAnimator.reverse(); mProgressBarAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(final ValueAnimator animation) { progressBar.setProgress((Float) animation.getAnimatedValue()); } }); progressBar.setMarkerProgress(progress); mProgressBarAnimator.start(); }
From source file:com.google.samples.apps.iosched.ui.BaseActivity.java
private void setupAccountBoxToggle() { int selfItem = getSelfNavDrawerItem(); if (mDrawerLayout == null || selfItem == NAVDRAWER_ITEM_INVALID) { // this Activity does not have a nav drawer return;/*from w ww . j a v a2 s. c o m*/ } mExpandAccountBoxIndicator.setImageResource(mAccountBoxExpanded ? R.drawable.ic_navview_accounts_collapse : R.drawable.ic_navview_accounts_expand); int hideTranslateY = -mAccountListContainer.getHeight() / 4; // last 25% of animation if (mAccountBoxExpanded && mAccountListContainer.getTranslationY() == 0) { // initial setup mAccountListContainer.setAlpha(0); mAccountListContainer.setTranslationY(hideTranslateY); } AnimatorSet set = new AnimatorSet(); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDrawerItemsListContainer.setVisibility(mAccountBoxExpanded ? View.INVISIBLE : View.VISIBLE); mAccountListContainer.setVisibility(mAccountBoxExpanded ? View.VISIBLE : View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } }); if (mAccountBoxExpanded) { mAccountListContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 1) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.playSequentially(ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet); set.start(); } else { mDrawerItemsListContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, hideTranslateY) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.playSequentially(subSet, ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 1) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.start(); } set.start(); }
From source file:com.b44t.ui.ActionBar.BottomSheet.java
public void dismissWithButtonClick(final int item) { if (dismissed) { return;// w w w. j av a 2 s . c o m } dismissed = true; cancelSheetAnimation(); AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( ObjectAnimator.ofFloat(containerView, "translationY", containerView.getMeasuredHeight() + AndroidUtilities.dp(10)), ObjectAnimator.ofInt(backDrawable, "alpha", 0)); 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; if (onClickListener != null) { onClickListener.onClick(BottomSheet.this, item); } AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { try { BottomSheet.super.dismiss(); } 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:com.saarang.samples.apps.iosched.ui.BaseActivity.java
private void setupAccountBoxToggle() { int selfItem = getSelfNavDrawerItem(); if (mDrawerLayout == null || selfItem == NAVDRAWER_ITEM_INVALID) { // this Activity does not have a nav drawer return;/*ww w . j av a 2s. c om*/ } mExpandAccountBoxIndicator.setImageResource( mAccountBoxExpanded ? com.saarang.samples.apps.iosched.R.drawable.ic_drawer_accounts_collapse : com.saarang.samples.apps.iosched.R.drawable.ic_drawer_accounts_expand); int hideTranslateY = -mAccountListContainer.getHeight() / 4; // last 25% of animation if (mAccountBoxExpanded && mAccountListContainer.getTranslationY() == 0) { // initial setup mAccountListContainer.setAlpha(0); mAccountListContainer.setTranslationY(hideTranslateY); } AnimatorSet set = new AnimatorSet(); set.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mDrawerItemsListContainer.setVisibility(mAccountBoxExpanded ? View.INVISIBLE : View.VISIBLE); mAccountListContainer.setVisibility(mAccountBoxExpanded ? View.VISIBLE : View.INVISIBLE); } @Override public void onAnimationCancel(Animator animation) { onAnimationEnd(animation); } }); if (mAccountBoxExpanded) { mAccountListContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 1) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.playSequentially(ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), subSet); set.start(); } else { mDrawerItemsListContainer.setVisibility(View.VISIBLE); AnimatorSet subSet = new AnimatorSet(); subSet.playTogether( ObjectAnimator.ofFloat(mAccountListContainer, View.ALPHA, 0) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION), ObjectAnimator.ofFloat(mAccountListContainer, View.TRANSLATION_Y, hideTranslateY) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.playSequentially(subSet, ObjectAnimator.ofFloat(mDrawerItemsListContainer, View.ALPHA, 1) .setDuration(ACCOUNT_BOX_EXPAND_ANIM_DURATION)); set.start(); } set.start(); }
From source file:com.b44t.ui.ActionBar.BottomSheet.java
@Override public void dismiss() { if (dismissed) { return;//from w ww . j a v a2s . c om } 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; } }