Java Code Examples for android.animation.Animator#cancel()

The following examples show how to use android.animation.Animator#cancel() . 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: CircleIndicator.java    From SuperIndicator with Apache License 2.0 6 votes vote down vote up
private void addIndicator(@DrawableRes int backgroundDrawableId, Animator animator) {
    if (animator.isRunning()) {
        animator.end();
        animator.cancel();
    }

    View Indicator = new View(getContext());
    Indicator.setBackgroundResource(backgroundDrawableId);
    addView(Indicator, mIndicatorWidth, mIndicatorHeight);
    LayoutParams lp = (LayoutParams) Indicator.getLayoutParams();
    lp.leftMargin = mIndicatorMargin;
    lp.rightMargin = mIndicatorMargin;
    Indicator.setLayoutParams(lp);

    animator.setTarget(Indicator);
    animator.start();
}
 
Example 2
Source File: Transition.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * This method cancels a transition that is currently running.
 *
 * @hide
 */
protected void cancel() {
    int numAnimators = mCurrentAnimators.size();
    for (int i = numAnimators - 1; i >= 0; i--) {
        Animator animator = mCurrentAnimators.get(i);
        animator.cancel();
    }
    if (mListeners != null && mListeners.size() > 0) {
        ArrayList<TransitionListener> tmpListeners =
                (ArrayList<TransitionListener>) mListeners.clone();
        int numListeners = tmpListeners.size();
        for (int i = 0; i < numListeners; ++i) {
            tmpListeners.get(i).onTransitionCancel(this);
        }
    }
}
 
Example 3
Source File: SwipeHelper.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called when a view is updated to be non-dismissable, if the view was being dismissed before
 * the update this will handle snapping it back into place.
 *
 * @param view the view to snap if necessary.
 * @param animate whether to animate the snap or not.
 * @param targetLeft the target to snap to.
 */
public void snapChildIfNeeded(final View view, boolean animate, float targetLeft) {
    if ((mDragging && mCurrView == view) || mSnappingChild) {
        return;
    }
    boolean needToSnap = false;
    Animator dismissPendingAnim = mDismissPendingMap.get(view);
    if (dismissPendingAnim != null) {
        needToSnap = true;
        dismissPendingAnim.cancel();
    } else if (getTranslation(view) != 0) {
        needToSnap = true;
    }
    if (needToSnap) {
        if (animate) {
            snapChild(view, targetLeft, 0.0f /* velocity */);
        } else {
            snapChildInstantly(view);
        }
    }
}
 
Example 4
Source File: ViewPropertyAnimator.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Cancels all property animations that are currently running or pending.
 */
public void cancel() {
    if (mAnimatorMap.size() > 0) {
        HashMap<Animator, PropertyBundle> mAnimatorMapCopy =
                (HashMap<Animator, PropertyBundle>)mAnimatorMap.clone();
        Set<Animator> animatorSet = mAnimatorMapCopy.keySet();
        for (Animator runningAnim : animatorSet) {
            runningAnim.cancel();
        }
    }
    mPendingAnimations.clear();
    mPendingSetupAction = null;
    mPendingCleanupAction = null;
    mPendingOnStartAction = null;
    mPendingOnEndAction = null;
    mView.removeCallbacks(mAnimationStarter);
    if (mRTBackend != null) {
        mRTBackend.cancelAll();
    }
}
 
Example 5
Source File: DynamicGridView.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void stopWobble(boolean resetRotation) {
    for (Animator wobbleAnimator : mWobbleAnimators) {
        wobbleAnimator.cancel();
    }
    mWobbleAnimators.clear();
    for (int i = 0; i < getChildCount(); i++) {
        View v = getChildAt(i);
        if (v != null) {
            if (resetRotation) v.setRotation(0);
            v.setTag(R.id.dynamic_grid_wobble_tag, false);
        }
    }
}
 
Example 6
Source File: LauncherAnimUtils.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
public static void onDestroyActivity() {
    HashSet<Animator> animators = new HashSet<Animator>(sAnimators.keySet());
    for (Animator a : animators) {
        if (a.isRunning()) {
            a.cancel();
        }
        sAnimators.remove(a);
    }
}
 
Example 7
Source File: KeyButtonRipple.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void cancelAnimations() {
    mTmpArray.addAll(mRunningAnimations);
    int size = mTmpArray.size();
    for (int i = 0; i < size; i++) {
        Animator a = mTmpArray.get(i);
        a.cancel();
    }
    mTmpArray.clear();
    mRunningAnimations.clear();
}
 
Example 8
Source File: ChatListItemAnimator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
protected boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
    if (BuildVars.LOGS_ENABLED) {
        FileLog.d("end change if necessary");
    }
    Animator a = animators.remove(item);
    if (a != null) {
        a.cancel();
    }

    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    item.itemView.setAlpha(1);
    if (item.itemView instanceof ChatMessageCell) {
        ((ChatMessageCell) item.itemView).setAnimationOffsetX(0);
        ((ChatMessageCell) item.itemView).getTransitionParams().resetAnimation();
    } else {
        item.itemView.setTranslationX(0);
    }
    item.itemView.setTranslationY(0);
    dispatchChangeFinished(item, oldItem);

    return true;
}
 
Example 9
Source File: ProgressIndicatorView.java    From 920-text-editor-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * make animation to start or end when target
 * view was be Visible or Gone or Invisible.
 * make animation to cancel when target view
 * be onDetachedFromWindow.
 *
 * @param animStatus
 */
public void setAnimationStatus(AnimStatus animStatus) {
    if (mAnimators == null) {
        return;
    }
    int count = mAnimators.size();
    for (int i = 0; i < count; i++) {
        Animator animator = mAnimators.get(i);
        boolean isRunning = animator.isRunning();
        switch (animStatus) {
            case START:
                if (!isRunning) {
                    animator.start();
                }
                break;
            case END:
                if (isRunning) {
                    animator.end();
                }
                break;
            case CANCEL:
                if (isRunning) {
                    animator.cancel();
                }
                break;
        }
    }
}
 
Example 10
Source File: LauncherAnimUtils.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
public static void onDestroyActivity() {
    HashSet<Animator> animators = new HashSet<Animator>(sAnimators.keySet());
    for (Animator a : animators) {
        if (a.isRunning()) {
            a.cancel();
        }
        sAnimators.remove(a);
    }
}
 
Example 11
Source File: TextSelectionHelper.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void cancelAllAnimators() {
    for (int i = 0; i < animatorSparseArray.size(); i++) {
        Animator animator = animatorSparseArray.get(animatorSparseArray.keyAt(i));
        animator.cancel();
    }
    animatorSparseArray.clear();
}
 
Example 12
Source File: FlipMenuView.java    From timecat with Apache License 2.0 5 votes vote down vote up
private void dismiss() {
    for (Animator animator : mTotalAnimList) {
        animator.cancel();
    }

    if (!mAlphaAnim.isRunning()) {
        mAlphaAnim.start();
    }
}
 
Example 13
Source File: TextSelectionHelper.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void cancelAllAnimators() {
    for (int i = 0; i < animatorSparseArray.size(); i++) {
        Animator animator = animatorSparseArray.get(animatorSparseArray.keyAt(i));
        animator.cancel();
    }
    animatorSparseArray.clear();
}
 
Example 14
Source File: SupportAnimatorLollipop.java    From fab-transformation with MIT License 5 votes vote down vote up
@Override
public void cancel() {
    Animator a = mAnimator.get();
    if (a != null) {
        a.cancel();
    }
}
 
Example 15
Source File: StateAnimator.java    From Carbon with Apache License 2.0 5 votes vote down vote up
private void clearTarget() {
    final AnimatedView view = getTarget();
    final int size = mTuples.size();
    for (int i = 0; i < size; i++) {
        Animator anim = mTuples.get(i).animation;
        if (view.getAnimator() == anim) {
            anim.cancel();
        }
    }
    viewRef = null;
    lastMatch = null;
    runningAnimation = null;
}
 
Example 16
Source File: BaseIndicatorController.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * make animation to start or end when target
 * view was be Visible or Gone or Invisible.
 * make animation to cancel when target view
 * be onDetachedFromWindow.
 * @param animStatus
 */
public void setAnimationStatus(AnimStatus animStatus){
    if (mAnimators==null){
        return;
    }
    int count=mAnimators.size();
    for (int i = 0; i < count; i++) {
        Animator animator=mAnimators.get(i);
        boolean isRunning=animator.isRunning();
        switch (animStatus){
            case START:
                if (!isRunning){
                    animator.start();
                }
                break;
            case END:
                if (isRunning){
                    animator.end();
                }
                break;
            case CANCEL:
                if (isRunning){
                    animator.cancel();
                }
                break;
        }
    }
}
 
Example 17
Source File: ChatListItemAnimator.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void endAnimation(RecyclerView.ViewHolder item) {
    Animator animator = animators.remove(item);
    if (animator != null) {
        animator.cancel();
    }
    super.endAnimation(item);
    if (BuildVars.LOGS_ENABLED) {
        FileLog.d("end animation");
    }
}
 
Example 18
Source File: ViewPropertyAnimator.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Utility function, called by animateProperty() and animatePropertyBy(), which handles the
 * details of adding a pending animation and posting the request to start the animation.
 *
 * @param constantName The specifier for the property being animated
 * @param startValue The starting value of the property
 * @param byValue The amount by which the property will change
 */
private void animatePropertyBy(int constantName, float startValue, float byValue) {
    // First, cancel any existing animations on this property
    if (mAnimatorMap.size() > 0) {
        Animator animatorToCancel = null;
        Set<Animator> animatorSet = mAnimatorMap.keySet();
        for (Animator runningAnim : animatorSet) {
            PropertyBundle bundle = mAnimatorMap.get(runningAnim);
            if (bundle.cancel(constantName)) {
                // property was canceled - cancel the animation if it's now empty
                // Note that it's safe to break out here because every new animation
                // on a property will cancel a previous animation on that property, so
                // there can only ever be one such animation running.
                if (bundle.mPropertyMask == NONE) {
                    // the animation is no longer changing anything - cancel it
                    animatorToCancel = runningAnim;
                    break;
                }
            }
        }
        if (animatorToCancel != null) {
            animatorToCancel.cancel();
        }
    }

    NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue);
    mPendingAnimations.add(nameValuePair);
    mView.removeCallbacks(mAnimationStarter);
    mView.postOnAnimation(mAnimationStarter);
}
 
Example 19
Source File: AnimatorUtils.java    From Transitions-Everywhere with Apache License 2.0 4 votes vote down vote up
@Override
public void pause(@NonNull Animator animator) {
    animator.cancel();
}
 
Example 20
Source File: Transition.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Called by TransitionManager to play the transition. This calls
 * createAnimators() to set things up and create all of the animations and then
 * runAnimations() to actually start the animations.
 */
void playTransition(ViewGroup sceneRoot) {
    mStartValuesList = new ArrayList<TransitionValues>();
    mEndValuesList = new ArrayList<TransitionValues>();
    matchStartAndEnd(mStartValues, mEndValues);

    ArrayMap<Animator, AnimationInfo> runningAnimators = getRunningAnimators();
    int numOldAnims = runningAnimators.size();
    WindowId windowId = sceneRoot.getWindowId();
    for (int i = numOldAnims - 1; i >= 0; i--) {
        Animator anim = runningAnimators.keyAt(i);
        if (anim != null) {
            AnimationInfo oldInfo = runningAnimators.get(anim);
            if (oldInfo != null && oldInfo.view != null && oldInfo.windowId == windowId) {
                TransitionValues oldValues = oldInfo.values;
                View oldView = oldInfo.view;
                TransitionValues startValues = getTransitionValues(oldView, true);
                TransitionValues endValues = getMatchedTransitionValues(oldView, true);
                if (startValues == null && endValues == null) {
                    endValues = mEndValues.viewValues.get(oldView);
                }
                boolean cancel = (startValues != null || endValues != null) &&
                        oldInfo.transition.isTransitionRequired(oldValues, endValues);
                if (cancel) {
                    if (anim.isRunning() || anim.isStarted()) {
                        if (DBG) {
                            Log.d(LOG_TAG, "Canceling anim " + anim);
                        }
                        anim.cancel();
                    } else {
                        if (DBG) {
                            Log.d(LOG_TAG, "removing anim from info list: " + anim);
                        }
                        runningAnimators.remove(anim);
                    }
                }
            }
        }
    }

    createAnimators(sceneRoot, mStartValues, mEndValues, mStartValuesList, mEndValuesList);
    runAnimators();
}