List of usage examples for android.animation Animator removeListener
public void removeListener(AnimatorListener listener)
From source file:com.keylesspalace.tusky.fragment.ViewMediaFragment.java
private void onToolbarVisibilityChange(boolean visible) { isDescriptionVisible = showingDescription && visible; final int visibility = isDescriptionVisible ? View.VISIBLE : View.INVISIBLE; int alpha = isDescriptionVisible ? 1 : 0; descriptionView.animate().alpha(alpha).setListener(new AnimatorListenerAdapter() { @Override/*w w w.j av a2s. co m*/ public void onAnimationEnd(Animator animation) { descriptionView.setVisibility(visibility); animation.removeListener(this); } }).start(); }
From source file:com.keylesspalace.tusky.ViewMediaActivity.java
@Override public void onPhotoTap() { isToolbarVisible = !isToolbarVisible; for (ToolbarVisibilityListener listener : toolbarVisibilityListeners) { listener.onToolbarVisiblityChanged(isToolbarVisible); }//from w w w. ja va 2 s . c o m final int visibility = isToolbarVisible ? View.VISIBLE : View.INVISIBLE; int alpha = isToolbarVisible ? 1 : 0; toolbar.animate().alpha(alpha).setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { toolbar.setVisibility(visibility); animation.removeListener(this); } }).start(); }
From source file:com.quanliren.quan_one.pull.swipe.SwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false;/*w ww. j a va2 s .com*/ } if (!isEnabled() || mReturningToStart || canChildScrollUp()) { // Fail fast if we're not in a state where a swipe is possible return false; } switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; break; case MotionEvent.ACTION_MOVE: { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex < 0) { Log.e(LOG_TAG, "Got ACTION_MOVE event but have an invalid active pointer id."); return false; } final float y = MotionEventCompat.getY(ev, pointerIndex); final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; if (mIsBeingDragged) { mProgress.showArrow(true); float originalDragPercent = overscrollTop / mTotalDragDistance; if (originalDragPercent < 0) { return false; } float dragPercent = Math.min(1f, Math.abs(originalDragPercent)); float adjustedPercent = (float) Math.max(dragPercent - .4, 0) * 5 / 3; float extraOS = Math.abs(overscrollTop) - mTotalDragDistance; float slingshotDist = mUsingCustomStart ? mSpinnerFinalOffset - mOriginalOffsetTop : mSpinnerFinalOffset; float tensionSlingshotPercent = Math.max(0, Math.min(extraOS, slingshotDist * 2) / slingshotDist); float tensionPercent = (float) ((tensionSlingshotPercent / 4) - Math.pow((tensionSlingshotPercent / 4), 2)) * 2f; float extraMove = (slingshotDist) * tensionPercent * 2; int targetY = mOriginalOffsetTop + (int) ((slingshotDist * dragPercent) + extraMove); // where 1.0f is a full circle if (mCircleView.getVisibility() != View.VISIBLE) { mCircleView.setVisibility(View.VISIBLE); } if (!mScale) { ViewCompat.setScaleX(mCircleView, 1f); ViewCompat.setScaleY(mCircleView, 1f); } if (overscrollTop < mTotalDragDistance) { if (mScale) { setAnimationProgress(overscrollTop / mTotalDragDistance); } if (mProgress.getAlpha() > STARTING_PROGRESS_ALPHA && !isAnimationRunning(mAlphaStartAnimation)) { // Animate the alpha startProgressAlphaStartAnimation(); } float strokeStart = adjustedPercent * .8f; mProgress.setStartEndTrim(0f, Math.min(MAX_PROGRESS_ANGLE, strokeStart)); mProgress.setArrowScale(Math.min(1f, adjustedPercent)); } else { if (mProgress.getAlpha() < MAX_ALPHA && !isAnimationRunning(mAlphaMaxAnimation)) { // Animate the alpha startProgressAlphaMaxAnimation(); } } float rotation = (-0.25f + .4f * adjustedPercent + tensionPercent * 2) * .5f; mProgress.setProgressRotation(rotation); setTargetOffsetTopAndBottom(targetY - mCurrentTargetOffsetTop, true /* requires update */); } break; } case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { if (mActivePointerId == INVALID_POINTER) { if (action == MotionEvent.ACTION_UP) { Log.e(LOG_TAG, "Got ACTION_UP event but don't have an active pointer id."); } return false; } final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float y = MotionEventCompat.getY(ev, pointerIndex); final float overscrollTop = (y - mInitialMotionY) * DRAG_RATE; mIsBeingDragged = false; if (overscrollTop > mTotalDragDistance) { setRefreshing(true, true /* notify */); } else { // cancel refresh mRefreshing = false; mProgress.setStartEndTrim(0f, 0f); AnimatorListenerAdapter listener = null; if (!mScale) { listener = new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { animation.removeListener(this); if (!mScale) { startScaleDownAnimation(null); } } }; } animateOffsetToStartPosition(mCurrentTargetOffsetTop, listener); mProgress.showArrow(false); } mActivePointerId = INVALID_POINTER; return false; } } return true; }
From source file:com.appsummary.luoxf.myappsummary.navigationtabstrip.NavigationTabStrip.java
public void setOnTabStripSelectedIndexListener( final OnTabStripSelectedIndexListener onTabStripSelectedIndexListener) { mOnTabStripSelectedIndexListener = onTabStripSelectedIndexListener; if (mAnimatorListener == null) mAnimatorListener = new Animator.AnimatorListener() { @Override//w w w . j av a 2 s.c o m public void onAnimationStart(final Animator animation) { if (mOnTabStripSelectedIndexListener != null) mOnTabStripSelectedIndexListener.onStartTabSelected(mTitles[mIndex], mIndex); animation.removeListener(this); animation.addListener(this); } @Override public void onAnimationEnd(final Animator animation) { if (mIsViewPagerMode) return; animation.removeListener(this); animation.addListener(this); if (mOnTabStripSelectedIndexListener != null) mOnTabStripSelectedIndexListener.onEndTabSelected(mTitles[mIndex], mIndex); } @Override public void onAnimationCancel(final Animator animation) { } @Override public void onAnimationRepeat(final Animator animation) { } }; mAnimator.removeListener(mAnimatorListener); mAnimator.addListener(mAnimatorListener); }
From source file:com.gigamole.navigationtabstrip.NavigationTabStrip.java
public void setOnTabStripSelectedIndexListener( final OnTabStripSelectedIndexListener onTabStripSelectedIndexListener) { mOnTabStripSelectedIndexListener = onTabStripSelectedIndexListener; if (mAnimatorListener == null) mAnimatorListener = new AnimatorListenerAdapter() { @Override//from w w w .java2 s.c om public void onAnimationStart(final Animator animation) { if (mOnTabStripSelectedIndexListener != null) mOnTabStripSelectedIndexListener.onStartTabSelected(mTitles[mIndex], mIndex); animation.removeListener(this); animation.addListener(this); } @Override public void onAnimationEnd(final Animator animation) { if (mIsViewPagerMode) return; animation.removeListener(this); animation.addListener(this); if (mOnTabStripSelectedIndexListener != null) mOnTabStripSelectedIndexListener.onEndTabSelected(mTitles[mIndex], mIndex); } }; mAnimator.removeListener(mAnimatorListener); mAnimator.addListener(mAnimatorListener); }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) private void animateRemoveImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mRemoveAnimations.add(holder);/* w w w .j a v a 2s .c o m*/ // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; // get the initial radius for the clipping circle int initialRadius = view.getWidth(); // create the animation (the final radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initialRadius, 0); anim.setDuration(getRemoveDuration()); // make the view invisible when the animation is done anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); view.setVisibility(View.VISIBLE); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // start the animation anim.start(); // animation.setDuration(getRemoveDuration()) // .alpha(0).setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchRemoveStarting(holder); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // ViewCompat.setAlpha(view, 1); // dispatchRemoveFinished(holder); // mRemoveAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:android.support.transition.TransitionPort.java
/** * This is a utility method used by subclasses to handle standard parts of * setting up and running an Animator: it sets the {@link #getDuration() * duration} and the {@link #getStartDelay() startDelay}, starts the * animation, and, when the animator ends, calls {@link #end()}. * * @param animator The Animator to be run during this transition. * @hide//from ww w .j av a 2 s . c o m */ @RestrictTo(GROUP_ID) protected void animate(Animator animator) { // TODO: maybe pass auto-end as a boolean parameter? if (animator == null) { end(); } else { if (getDuration() >= 0) { animator.setDuration(getDuration()); } if (getStartDelay() >= 0) { animator.setStartDelay(getStartDelay()); } if (getInterpolator() != null) { animator.setInterpolator(getInterpolator()); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { end(); animation.removeListener(this); } }); animator.start(); } }
From source file:com.github.huajianjiang.expandablerecyclerview.sample.anim.CircularRevealItemAnimator.java
void animateAddImpl(final RecyclerView.ViewHolder holder) { Logger.e(TAG, "<<<animateAddImpl>>" + holder); final View view = holder.itemView; // final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view); mAddAnimations.add(holder);//from www. j a va2 s . co m // get the center for the clipping circle int cx = (view.getLeft() + view.getRight()) / 2; int cy = view.getHeight() / 2; Logger.e(TAG, "cx=" + cx + ",cy=" + cy); // get the final radius for the clipping circle int finalRadius = Math.max(view.getWidth(), view.getHeight()); Logger.e(TAG, "width=" + view.getWidth() + ",height=" + view.getHeight() + ",finalRadius=" + finalRadius); // create the animator for this view (the start radius is zero) final Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, 0, finalRadius); anim.setDuration(getAddDuration()); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { dispatchAddStarting(holder); } @Override public void onAnimationCancel(Animator animation) { view.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { anim.removeListener(this); dispatchAddFinished(holder); mAddAnimations.remove(holder); dispatchFinishedWhenDone(); } }); // make the view visible and start the animation view.setVisibility(View.VISIBLE); anim.start(); // animation.alpha(1).setDuration(getAddDuration()). // setListener(new CircularRevealItemAnimator.VpaListenerAdapter() { // @Override // public void onAnimationStart(View view) { // dispatchAddStarting(holder); // } // @Override // public void onAnimationCancel(View view) { // ViewCompat.setAlpha(view, 1); // } // // @Override // public void onAnimationEnd(View view) { // animation.setListener(null); // dispatchAddFinished(holder); // mAddAnimations.remove(holder); // dispatchFinishedWhenDone(); // } // }).start(); }
From source file:org.tomahawk.tomahawk_android.activities.TomahawkMainActivity.java
@Override public void onPanelSlide(View view, float v) { mSlidingOffset = v;//from w w w . ja v a 2s. c om if (v > 0.5f) { hideActionbar(); } else if (v < 0.5f && v > 0f) { showActionBar(true); } final View topPanel = mSlidingUpPanelLayout.findViewById(R.id.top_buttonpanel); if (v > 0.15f) { AnimationUtils.fade(topPanel, 0f, 1f, AnimationUtils.DURATION_PLAYBACKTOPPANEL, true, new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { topPanel.findViewById(R.id.imageButton_repeat).setVisibility(View.VISIBLE); topPanel.findViewById(R.id.close_button).setVisibility(View.VISIBLE); topPanel.findViewById(R.id.imageButton_shuffle).setVisibility(View.VISIBLE); animation.removeListener(this); } @Override public void onAnimationEnd(Animator animation) { } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); } else if (v < 0.15f) { AnimationUtils.fade(mSlidingUpPanelLayout.findViewById(R.id.top_buttonpanel), 1f, 0f, AnimationUtils.DURATION_PLAYBACKTOPPANEL, false, new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { topPanel.findViewById(R.id.imageButton_repeat).setVisibility(View.GONE); topPanel.findViewById(R.id.close_button).setVisibility(View.GONE); topPanel.findViewById(R.id.imageButton_shuffle).setVisibility(View.GONE); animation.removeListener(this); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); } int position = Math.min(10000, Math.max(0, (int) ((v - 0.8f) * 10000f / (1f - 0.8f)))); mPlaybackPanel.animate(position); sendSlidingLayoutChangedEvent(); }
From source file:android.support.transition.Transition.java
/** * This is a utility method used by subclasses to handle standard parts of * setting up and running an Animator: it sets the {@link #getDuration() * duration} and the {@link #getStartDelay() startDelay}, starts the * animation, and, when the animator ends, calls {@link #end()}. * * @param animator The Animator to be run during this transition. * * @hide/*ww w. j a v a 2 s .c o m*/ */ protected void animate(Animator animator) { // TODO: maybe pass auto-end as a boolean parameter? if (animator == null) { end(); } else { if (getDuration() >= 0) { animator.setDuration(getDuration()); } if (getStartDelay() >= 0) { animator.setStartDelay(getStartDelay()); } if (getInterpolator() != null) { animator.setInterpolator(getInterpolator()); } animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { end(); animation.removeListener(this); } }); animator.start(); } }