Java Code Examples for android.animation.Animator#AnimatorListener

The following examples show how to use android.animation.Animator#AnimatorListener . 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: NotificationView.java    From Android-Notification with Apache License 2.0 6 votes vote down vote up
/**
 * Move the contentView to x position with animation.
 *
 * @param x
 * @param alpha
 * @param listener
 * @param duration
 */
public void animateContentViewTranslationX(float x, float alpha,
                                           Animator.AnimatorListener listener,
                                           int duration) {

    if (DBG) Log.v(TAG, "animateContentViewTranslationX - " +
                   "x=" + x + ", alpha=" + alpha);

    mContentView.animate().cancel();
    mContentView.animate()
        .alpha(alpha)
        .translationX(x)
        .setListener(listener)
        .setDuration(duration)
        .start();
}
 
Example 2
Source File: FragmentTransactionExtended.java    From Kernel-Tuner with GNU General Public License v3.0 6 votes vote down vote up
private void switchFragments() {
    ((Activity) this.mContext).getFragmentManager().addOnBackStackChangedListener(this);

    if (mIsAnimating) {
        return;
    }
    mIsAnimating = true;
    if (mDidSlideOut) {
        mDidSlideOut = false;
        ((Activity) mContext).getFragmentManager().popBackStack();
    } else {
        mDidSlideOut = true;
        Animator.AnimatorListener listener = new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator arg0) {
                mFragmentTransaction.setCustomAnimations(R.animator.slide_fragment_in, 0, 0, R.animator.slide_fragment_out);
                mFragmentTransaction.add(mContainerID, mSecondFragment);
                mFragmentTransaction.addToBackStack(null);
                mFragmentTransaction.commit();
            }
        };
        slideBack(listener);
    }
}
 
Example 3
Source File: OvercastType.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(1, -1);
    animator.setDuration(1000);
    animator.setRepeatCount(0);
    animator.setInterpolator(new AccelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            hillTransFactor = (float) animation.getAnimatedValue();
        }
    });
    if (listener != null) {
        animator.addListener(listener);
    }
    animator.start();
}
 
Example 4
Source File: WXAnimationModule.java    From weex-uikit with MIT License 6 votes vote down vote up
public static
@Nullable
Animator.AnimatorListener createAnimatorListener(final WXSDKInstance mWXSDKInstance, @Nullable final String callBack) {
  if (!TextUtils.isEmpty(callBack)) {
    return new AnimatorListenerAdapter() {
      @Override
      public void onAnimationEnd(Animator animation) {
        if (mWXSDKInstance == null) {
          WXLogUtils.e("WXRenderStatement-onAnimationEnd mWXSDKInstance == null NPE");
        } else {
          WXSDKManager.getInstance().callback(mWXSDKInstance.getInstanceId(),
                                              callBack,
                                              new HashMap<String, Object>());
        }
      }
    };
  } else {
    return null;
  }
}
 
Example 5
Source File: MaterialMenuDrawable.java    From HaiNaBaiChuan with Apache License 2.0 5 votes vote down vote up
public void setAnimationListener(Animator.AnimatorListener listener) {
    if (animatorListener != null) {
        transformation.removeListener(animatorListener);
    }

    if (listener != null) {
        transformation.addListener(listener);
    }

    animatorListener = listener;
}
 
Example 6
Source File: AnimatorUtils.java    From MousePaint with MIT License 5 votes vote down vote up
public static Animator animViewFadeOut(View paramView, long paramLong, Animator.AnimatorListener paramAnimatorListener) {
    ObjectAnimator localObjectAnimator = ObjectAnimator.ofFloat(paramView, "alpha", new float[]{1.0F, 0.0F});
    localObjectAnimator.setDuration(paramLong);
    if (paramAnimatorListener != null)
        localObjectAnimator.addListener(paramAnimatorListener);
    localObjectAnimator.start();
    return localObjectAnimator;
}
 
Example 7
Source File: ChangeTranslation.java    From Noyze with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to handle creating and running the Animator.
 */
private Animator createAnimation(View view, float[] startTranslation, float[] endTranslation,
                                 Animator.AnimatorListener listener, TimeInterpolator interpolator) {
    if (startTranslation == null || endTranslation == null ||
            startTranslation.length != endTranslation.length || equals(startTranslation, endTranslation)) {
        // run listener if we're noop'ing the animation, to get the end-state results now
        if (listener != null) {
            listener.onAnimationEnd(null);
        }
        return null;
    }

    final AnimatorSet anim = new AnimatorSet();
    ObjectAnimator animX = null, animY = null;

    if ((mTranslationDirection & X) != 0) {
        animX = ObjectAnimator.ofFloat(view, View.X,
                startTranslation[0], endTranslation[0]);
    }

    if ((mTranslationDirection & Y) != 0) {
        animY = ObjectAnimator.ofFloat(view, View.Y,
                startTranslation[1], endTranslation[1]);
    }

    if (null != animX && null == animY) anim.play(animX);
    if (null == animX && null != animY) anim.play(animY);
    if (null != animX && null != animY) anim.playTogether(animX, animY);
    if (null == animX && null == animY) return null;

    if (listener != null) {
        anim.addListener(listener);
    }

    anim.setInterpolator(interpolator);
    return anim;
}
 
Example 8
Source File: ViewUtils.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public static void animateFabJump(View fab, Animator.AnimatorListener listener) {
    try {
        ObjectAnimator animation = ObjectAnimator.ofFloat(fab, "translationY", -10f, -5f, 0f, 5f, 10f, 5f, 0f, -5f, -10f, -5f, 0f);
        animation.setDuration(350);
        animation.addListener(listener);
        animation.start();
    } catch (Exception e) {
        // Some devices crash at runtime when using the ObjectAnimator
    }
}
 
Example 9
Source File: AnimationEngine.java    From TikTok with Apache License 2.0 5 votes vote down vote up
public void startTogetherByLink(Animator.AnimatorListener listener, AnimatorValue...animatorValues){
	if(animationSet==null){
		Log.d(TAG, "δ�ܳ�ʼ��");
		return;
	}
	animationSet.removeAllListeners();
	if(listener!=null){
		animationSet.addListener(listener);
	}
	if (animatorValues != null) {
		AnimatorSet.Builder lastBuilder=null;
           for (int i = 0; i < animatorValues.length; i++) {
           	AnimatorSet.Builder curBuilder = animationSet.play(animatorValues[i].getAnimator());
               if(animatorValues[i].getBeforeAnimator()!=null){
               	curBuilder.after(animatorValues[i].getBeforeAnimator());
               }else if(lastBuilder!=null){
               	lastBuilder.with(animatorValues[i].getAnimator());		
               }
               	lastBuilder=curBuilder;
           }
       }else{
       	Log.d(TAG, "���������ǿ�");
		return;
       }
	//animationSet.setDuration(duration/animatorValues.length);
	animationSet.setInterpolator(interpolator);
	animationSet.start();
}
 
Example 10
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 11
Source File: ViewTooltip.java    From styT with Apache License 2.0 4 votes vote down vote up
@Override
public void animateEnter(View view, Animator.AnimatorListener animatorListener) {
    view.setAlpha(0);
    view.animate().alpha(1).setDuration(fadeDuration).setListener(animatorListener);
}
 
Example 12
Source File: BaseAdditiveAnimator.java    From android_additive_animations with Apache License 2.0 4 votes vote down vote up
public T addListener(Animator.AnimatorListener listener) {
    getValueAnimator().addListener(listener);
    return self();
}
 
Example 13
Source File: MetroViewBorderHandler.java    From TVSample with Apache License 2.0 4 votes vote down vote up
public void removeAnimatorListener(Animator.AnimatorListener animatorListener) {
    this.mAnimatorListener.remove(animatorListener);
}
 
Example 14
Source File: LauncherViewPropertyAnimator.java    From Trebuchet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ArrayList<Animator.AnimatorListener> getListeners() {
    return mListeners;
}
 
Example 15
Source File: MetroViewBorderHandler.java    From TVSample with Apache License 2.0 4 votes vote down vote up
public void removeAnimatorListener(Animator.AnimatorListener animatorListener) {
    this.mAnimatorListener.remove(animatorListener);
}
 
Example 16
Source File: HTBaseRecyclerViewImpl.java    From ht-refreshrecyclerview with MIT License 4 votes vote down vote up
/**
 * 隐藏刷新空间带动画
 */
protected void changeLoadMoreViewPositionWithAnimation(int targetPosition, @Nullable Animator.AnimatorListener animatorListener) {
    int startValue = 0;
    switch (mHTOrientation) {
        case HTOrientation.VERTICAL_DOWN:
            startValue = mLoadMoreContainerView.getPaddingBottom();
            break;
        case HTOrientation.VERTICAL_UP:
            startValue = mLoadMoreContainerView.getPaddingTop();
            break;
        case HTOrientation.HORIZONTAL_LEFT:
            startValue = mLoadMoreContainerView.getPaddingLeft();
            break;
        case HTOrientation.HORIZONTAL_RIGHT:
            startValue = mLoadMoreContainerView.getPaddingRight();
            break;
    }
    if (startValue <= -mLoadMoreViewSize) return;
    if (mLoadMoreAnimator != null && mLoadMoreAnimator.isRunning()) {
        mLoadMoreAnimator.end();
    }
    mLoadMoreAnimator = ValueAnimator.ofInt(startValue, targetPosition);
    mLoadMoreAnimator.setDuration(mHTViewHolder.getAnimationTime());
    mLoadMoreAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int padding = (int) animation.getAnimatedValue();
            mLoadMoreContainerView.setPadding(
                    mHTOrientation == HTOrientation.HORIZONTAL_LEFT ? padding : 0,
                    mHTOrientation == HTOrientation.VERTICAL_UP ? padding : 0,
                    mHTOrientation == HTOrientation.HORIZONTAL_RIGHT ? padding : 0,
                    mHTOrientation == HTOrientation.VERTICAL_DOWN ? padding : 0);
        }
    });
    if (animatorListener != null) {
        mLoadMoreAnimator.addListener(animatorListener);
    }
    post(new Runnable() {
        public void run() {
            mLoadMoreAnimator.start();
        }
    });
}
 
Example 17
Source File: AnimatedVectorDrawableWrapper.java    From Bop with Apache License 2.0 4 votes vote down vote up
public AnimatorListenerWrapperM(Animator animator, Animator.AnimatorListener listener) {
    mAnimator = animator;
    mListener = listener;
}
 
Example 18
Source File: LogicCalculatorActivity.java    From ncalc with GNU General Public License v3.0 4 votes vote down vote up
/**
 * only use animate on device lollipop
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void animateRipple(View sourceView, int color, final Animator.AnimatorListener listener) {
    // Make animateRipple cover the display
    final RevealView revealView = new RevealView(this);
    revealView.setLayoutParams(mLayoutParams);
    revealView.setRevealColor(color);
    mDisplayForeground.addView(revealView);

    final Animator revealAnimator;
    final int[] clearLocation = new int[2];
    if (sourceView != null) {
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;
    } else {
        clearLocation[0] = mDisplayForeground.getWidth() / 2;
        clearLocation[1] = mDisplayForeground.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));

    revealAnimator = ViewAnimationUtils.createCircularReveal(revealView,
            revealCenterX, revealCenterY, 0.0f, revealRadius);
    revealAnimator.setDuration(
            getResources().getInteger(android.R.integer.config_shortAnimTime));
    revealAnimator.addListener(listener);

    final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
    alphaAnimator.setDuration(getResources()
            .getInteger(android.R.integer.config_shortAnimTime));
    alphaAnimator.addListener(new AnimationFinishedListener() {
        @Override
        public void onAnimationFinished() {
            mDisplayForeground.removeView(revealView);
        }
    });

    revealAnimator.addListener(new AnimationFinishedListener() {
        @Override
        public void onAnimationFinished() {
            playAnimation(alphaAnimator);
        }
    });
    playAnimation(revealAnimator);
}
 
Example 19
Source File: Titanic.java    From android2048 with Apache License 2.0 4 votes vote down vote up
public void setAnimatorListener(Animator.AnimatorListener animatorListener) {
    this.animatorListener = animatorListener;
}
 
Example 20
Source File: BarChartProgressView.java    From SlidePager with MIT License 2 votes vote down vote up
/**
 * Sets the animation listener on {@link #mBarView}
 *
 * @param listener
 */
public void addAnimationListener(Animator.AnimatorListener listener) {
    mBarView.removeAllListeners();
    mBarView.addListener(listener);
}