Java Code Examples for android.animation.ValueAnimator#addListener()

The following examples show how to use android.animation.ValueAnimator#addListener() . 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: FloatingView.java    From text_converter with GNU General Public License v3.0 6 votes vote down vote up
void run() {
    if (mDynamicUpdate == null) {
        mDraggableIcon.animate()
                .translationX(mDestX)
                .translationY(mDestY)
                .setDuration(mDuration)
                .setInterpolator(mInterpolator)
                .setListener(mAnimationFinishedListener);
    } else {
        ValueAnimator animator = ValueAnimator.ofInt(0, 100);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                float percent = valueAnimator.getAnimatedFraction();
                mDraggableIcon.setTranslationX(mDynamicUpdate.getTranslationX(percent));
                mDraggableIcon.setTranslationY(mDynamicUpdate.getTranslationY(percent));
            }
        });
        animator.setDuration(mDuration);
        animator.setInterpolator(mInterpolator);
        animator.addListener(mAnimationFinishedListener);
        animator.start();
    }
}
 
Example 2
Source File: SnowType.java    From FakeWeather with Apache License 2.0 6 votes vote down vote up
@Override
public void endAnimation(DynamicWeatherView dynamicWeatherView, Animator.AnimatorListener listener) {
    super.endAnimation(dynamicWeatherView, listener);
    ValueAnimator animator = ValueAnimator.ofFloat(getWidth() - bitmap.getWidth() * 0.25f, getWidth());
    animator.setDuration(1000);
    animator.setRepeatCount(0);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            transFactor = (float) animation.getAnimatedValue();
        }
    });
    if (listener != null) {
        animator.addListener(listener);
    }
    animator.start();
}
 
Example 3
Source File: SplashActivity.java    From likequanmintv with Apache License 2.0 6 votes vote down vote up
private void start() {
    rootView = findViewById(R.id.main_root);
    final View viewById = findViewById(R.id.tt);
    ValueAnimator valueAnimator=ValueAnimator.ofFloat(0.3f,1.0f);
    valueAnimator.setDuration(1500);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float alpha = (float) animation.getAnimatedValue();
            rootView.setAlpha(alpha);
            viewById.setScaleX(alpha);
            viewById.setScaleY(alpha);

        }
    });
    valueAnimator.addListener(this);
    valueAnimator.start();
}
 
Example 4
Source File: HoldingButton.java    From HoldingButton with Apache License 2.0 6 votes vote down vote up
private ValueAnimator createCollapseValueAnimator() {
    ValueAnimator animator = ValueAnimator.ofFloat(1f, 0f);
    animator.setDuration(DEFAULT_ANIMATION_DURATION_COLLAPSE);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            mExpandedScaleFactor[0] = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            notifyCollapsed();
        }
    });
    return animator;
}
 
Example 5
Source File: SwipeDismissTouchListener.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
private void performDismiss() {
  // Animate the dismissed view to zero-height and then fire the dismiss callback.
  // This triggers layout on each animation frame; in the future we may want to do something
  // smarter and more performant.

  final ViewGroup.LayoutParams lp = mView.getLayoutParams();
  final int originalHeight = mView.getHeight();

  ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

  animator.addListener(
      new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
          mDismissCallbacks.onDismiss(mView, mToken);
          // Reset view presentation
          mView.setAlpha(1f);
          mView.setTranslationX(0);
          lp.height = originalHeight;
          mView.setLayoutParams(lp);
        }
      });

  animator.addUpdateListener(
      new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
          lp.height = (Integer) valueAnimator.getAnimatedValue();
          mView.setLayoutParams(lp);
        }
      });

  animator.start();
}
 
Example 6
Source File: AnimProcessor.java    From AgentWebX5 with Apache License 2.0 5 votes vote down vote up
public void animLayoutByTime(int start, int end, AnimatorUpdateListener listener, AnimatorListener animatorListener) {
        ValueAnimator va = ValueAnimator.ofInt(start, end);
        va.setInterpolator(new DecelerateInterpolator());
        va.addUpdateListener(listener);
        va.addListener(animatorListener);
        va.setDuration((int) (Math.abs(start - end) * animFraction));
        va.start();
//        offerToQueue(va);
    }
 
Example 7
Source File: AnimationUtils.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
public static void addBookmarkWithAnimation(@NonNull final View bookmarkImage, Animator.AnimatorListener animatorListener) {
    bookmarkImage.setPivotY(0);
    ValueAnimator moveAnim = ObjectAnimator.ofFloat(bookmarkImage, View.SCALE_Y, 0, 1);
    moveAnim.setDuration(1000);
    moveAnim.setInterpolator(new OvershootInterpolator(BOOKMARK_ANIMATING_OVERSHOOT_TENSION));
    moveAnim.addListener(animatorListener);
    moveAnim.start();
}
 
Example 8
Source File: SimpleAnimationUtils.java    From SimpleSearchView with Apache License 2.0 5 votes vote down vote up
public static Animator verticalSlideView(@NonNull View view, int fromHeight, int toHeight, int duration, @Nullable final AnimationListener listener) {
    ValueAnimator anim = ValueAnimator
            .ofInt(fromHeight, toHeight);

    anim.addUpdateListener(animation -> {
        view.getLayoutParams().height = (int) (Integer) animation.getAnimatedValue();
        view.requestLayout();
    });

    anim.addListener(new DefaultActionAnimationListener(view, listener));

    anim.setDuration(duration);
    anim.setInterpolator(getDefaultInterpolator());
    return anim;
}
 
Example 9
Source File: SwipeDismissTouchListener.java    From androidpn-client with Apache License 2.0 5 votes vote down vote up
private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}
 
Example 10
Source File: SwipeDismissTouchListenerLeftRight.java    From SwipeableCard with Apache License 2.0 5 votes vote down vote up
private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}
 
Example 11
Source File: VRefreshLayout.java    From BaseProject with Apache License 2.0 5 votes vote down vote up
private void moveAnimation(int star, int end, int duration, Animator.AnimatorListener animatorListener) {
    ValueAnimator valueAnimator = ValueAnimator.ofInt(star, end);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int value = (int) animation.getAnimatedValue();
            moveTo(value);
        }
    });
    if (animatorListener != null) {
        valueAnimator.addListener(animatorListener);
    }
    valueAnimator.setDuration(duration);
    valueAnimator.start();
}
 
Example 12
Source File: DefaultClusterRenderer.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
public void perform() {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
    valueAnimator.setInterpolator(ANIMATION_INTERP);
    valueAnimator.addUpdateListener(this);
    valueAnimator.addListener(this);
    valueAnimator.start();
}
 
Example 13
Source File: DynamicListLayout.java    From dynamiclistview with MIT License 5 votes vote down vote up
private void animate(float fromY, float toY, AnimatorListener listener) {
    ValueAnimator animator = ValueAnimator.ofFloat(fromY, toY);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setDuration(200);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float val = (Float) animation.getAnimatedValue();
            mListFrame.scrollTo(0, (int) val);
            checkPullingState(mListFrame.getScrollY());
        }
    });
    animator.addListener(listener);
    animator.start();
}
 
Example 14
Source File: EditVideoActivity.java    From WeiXinRecordedDemo with MIT License 5 votes vote down vote up
/**
 * 执行文字编辑区域动画
 */
private void startAnim(float start, float end, AnimatorListenerAdapter listenerAdapter) {

    ValueAnimator va = ValueAnimator.ofFloat(start, end).setDuration(200);
    va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            rl_edit_text.setY(value);
        }
    });
    if (listenerAdapter != null) va.addListener(listenerAdapter);
    va.start();
}
 
Example 15
Source File: ExpandedScreen.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
private void applyShowActionBar(boolean show) {
	ActionBar actionBar = activity.getActionBar();
	if (fullScreenLayoutEnabled) {
		boolean showing = isActionBarShowing();
		ValueAnimator foregroundAnimator = ExpandedScreen.this.foregroundAnimator;
		if (foregroundAnimator != null) {
			foregroundAnimator.cancel();
		}
		if (showing != show) {
			if (toolbarView != null) {
				actionBar.show();
			}
			foregroundAnimator = ValueAnimator.ofFloat(show ? 0f : 1f, show ? 1f : 0f);
			ForegroundAnimatorListener listener = new ForegroundAnimatorListener(show);
			foregroundAnimator.setInterpolator(AnimationUtils.ACCELERATE_DECELERATE_INTERPOLATOR);
			foregroundAnimator.setDuration(ACTION_BAR_ANIMATION_TIME);
			foregroundAnimator.addListener(listener);
			foregroundAnimator.addUpdateListener(listener);
			foregroundAnimator.start();
			ExpandedScreen.this.foregroundAnimator = foregroundAnimator;
			foregroundAnimatorShow = show;
		}
	}
	if (toolbarView == null) {
		if (show) {
			actionBar.show();
		} else {
			actionBar.hide();
		}
	}
}
 
Example 16
Source File: ButtonSpinnerDrawable.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
private ValueAnimator createStartAnimator() {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(1.0f, 0.02f);
    valueAnimator.setDuration(700);
    valueAnimator.setInterpolator(new AccelerateInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fillValue = (float) animation.getAnimatedValue();
        }
    });
    valueAnimator.addListener(this);
    fillValue = 0.02f;
    return valueAnimator;
}
 
Example 17
Source File: LinePieChartView.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private Animator b()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        0.0F, 1.0F
    });
    valueanimator.addListener(new l(this));
    valueanimator.addUpdateListener(new m(this));
    valueanimator.setDuration(3500L);
    valueanimator.setInterpolator(new LinearInterpolator());
    valueanimator.setRepeatMode(1);
    valueanimator.setRepeatCount(-1);
    return valueanimator;
}
 
Example 18
Source File: SwipeDismissTouchListener.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void performDismiss() {
    // Animate the dismissed view to zero-height and then fire the dismiss callback.
    // This triggers layout on each animation frame; in the future we may want to do something
    // smarter and more performant.

    final ViewGroup.LayoutParams lp = mView.getLayoutParams();
    final int originalHeight = mView.getHeight();

    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);

    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            mCallbacks.onDismiss(mView, mToken);
            // Reset view presentation
            mView.setAlpha(1f);
            mView.setTranslationX(0);
            lp.height = originalHeight;
            mView.setLayoutParams(lp);
        }
    });

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            mView.setLayoutParams(lp);
        }
    });

    animator.start();
}
 
Example 19
Source File: SwitchThemeAnimView.java    From DanDanPlayForAndroid with MIT License 4 votes vote down vote up
private ValueAnimator getAnimator() {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, mMaxRadius).setDuration(mDuration);
    valueAnimator.addUpdateListener(mAnimatorUpdateListener);
    valueAnimator.addListener(mAnimatorListener);
    return valueAnimator;
}
 
Example 20
Source File: ViewPropertyAnimator.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Starts the underlying Animator for a set of properties. We use a single animator that
 * simply runs from 0 to 1, and then use that fractional value to set each property
 * value accordingly.
 */
private void startAnimation() {
    if (mRTBackend != null && mRTBackend.startAnimation(this)) {
        return;
    }
    mView.setHasTransientState(true);
    ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
    ArrayList<NameValuesHolder> nameValueList =
            (ArrayList<NameValuesHolder>) mPendingAnimations.clone();
    mPendingAnimations.clear();
    int propertyMask = 0;
    int propertyCount = nameValueList.size();
    for (int i = 0; i < propertyCount; ++i) {
        NameValuesHolder nameValuesHolder = nameValueList.get(i);
        propertyMask |= nameValuesHolder.mNameConstant;
    }
    mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList));
    if (mPendingSetupAction != null) {
        mAnimatorSetupMap.put(animator, mPendingSetupAction);
        mPendingSetupAction = null;
    }
    if (mPendingCleanupAction != null) {
        mAnimatorCleanupMap.put(animator, mPendingCleanupAction);
        mPendingCleanupAction = null;
    }
    if (mPendingOnStartAction != null) {
        mAnimatorOnStartMap.put(animator, mPendingOnStartAction);
        mPendingOnStartAction = null;
    }
    if (mPendingOnEndAction != null) {
        mAnimatorOnEndMap.put(animator, mPendingOnEndAction);
        mPendingOnEndAction = null;
    }
    animator.addUpdateListener(mAnimatorEventListener);
    animator.addListener(mAnimatorEventListener);
    if (mStartDelaySet) {
        animator.setStartDelay(mStartDelay);
    }
    if (mDurationSet) {
        animator.setDuration(mDuration);
    }
    if (mInterpolatorSet) {
        animator.setInterpolator(mInterpolator);
    }
    animator.start();
}