Search in sources :

Example 21 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project atlas by alibaba.

the class DefaultProgressDrawable method setupAnimations.

private void setupAnimations() {
    this.mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, this.mAngleProperty, new float[] { 360.0F });
    this.mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR);
    this.mObjectAnimatorAngle.setDuration(2000L);
    this.mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART);
    this.mObjectAnimatorAngle.setRepeatCount(-1);
    this.mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, this.mSweepProperty, new float[] { 300.0F });
    this.mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR);
    this.mObjectAnimatorSweep.setDuration(600L);
    this.mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART);
    this.mObjectAnimatorSweep.setRepeatCount(-1);
    this.mObjectAnimatorSweep.addListener(new AnimatorListener() {

        public void onAnimationStart(Animator animation) {
        }

        public void onAnimationEnd(Animator animation) {
        }

        public void onAnimationCancel(Animator animation) {
        }

        public void onAnimationRepeat(Animator animation) {
            DefaultProgressDrawable.this.toggleAppearingMode();
        }
    });
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator)

Example 22 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project FreeFlow by Comcast.

the class DefaultLayoutAnimator method animateChanges.

@Override
public void animateChanges(LayoutChangeset changeSet, final FreeFlowContainer callback) {
    this.changeSet = changeSet;
    this.callback = callback;
    cancel();
    mIsRunning = true;
    disappearingSet = null;
    appearingSet = null;
    movingSet = null;
    Comparator<FreeFlowItem> cmp = new Comparator<FreeFlowItem>() {

        @Override
        public int compare(FreeFlowItem lhs, FreeFlowItem rhs) {
            return (lhs.itemSection * 1000 + lhs.itemIndex) - (rhs.itemSection * 1000 + rhs.itemIndex);
        }
    };
    List<FreeFlowItem> removed = changeSet.getRemoved();
    if (removed.size() > 0) {
        Collections.sort(removed, cmp);
        disappearingSet = getItemsRemovedAnimation(changeSet.getRemoved());
    }
    List<FreeFlowItem> added = changeSet.getAdded();
    if (added.size() > 0) {
        Collections.sort(added, cmp);
        appearingSet = getItemsAddedAnimation(added);
    }
    if (changeSet.getMoved().size() > 0) {
        movingSet = getItemsMovedAnimation(changeSet.getMoved());
    }
    AnimatorSet all = getAnimationSequence();
    if (all == null) {
        mIsRunning = false;
        callback.onLayoutChangeAnimationsCompleted(this);
    } else {
        all.addListener(new AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                mIsRunning = false;
                callback.onLayoutChangeAnimationsCompleted(DefaultLayoutAnimator.this);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }
        });
        all.start();
    }
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorSet(android.animation.AnimatorSet) FreeFlowItem(com.comcast.freeflow.core.FreeFlowItem) Comparator(java.util.Comparator)

Example 23 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project android_frameworks_base by AOSPA.

the class QSDetail method handleShowingDetail.

private void handleShowingDetail(final QSTile.DetailAdapter adapter, int x, int y) {
    final boolean showingDetail = adapter != null;
    setClickable(showingDetail);
    if (showingDetail) {
        mQsDetailHeaderTitle.setText(adapter.getTitle());
        final Boolean toggleState = adapter.getToggleState();
        if (toggleState == null) {
            mQsDetailHeaderSwitch.setVisibility(INVISIBLE);
            mQsDetailHeader.setClickable(false);
        } else {
            mQsDetailHeaderSwitch.setVisibility(VISIBLE);
            handleToggleStateChanged(toggleState, adapter.getToggleEnabled());
            mQsDetailHeader.setClickable(true);
            mQsDetailHeader.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    boolean checked = !mQsDetailHeaderSwitch.isChecked();
                    mQsDetailHeaderSwitch.setChecked(checked);
                    adapter.setToggleState(checked);
                }
            });
        }
        if (!mFullyExpanded) {
            mTriggeredExpand = true;
            mHost.animateToggleQSExpansion();
        } else {
            mTriggeredExpand = false;
        }
        mOpenX = x;
        mOpenY = y;
    } else {
        // Ensure we collapse into the same point we opened from.
        x = mOpenX;
        y = mOpenY;
        if (mTriggeredExpand) {
            mHost.animateToggleQSExpansion();
            mTriggeredExpand = false;
        }
    }
    boolean visibleDiff = (mDetailAdapter != null) != (adapter != null);
    // already in right state
    if (!visibleDiff && mDetailAdapter == adapter)
        return;
    AnimatorListener listener = null;
    if (adapter != null) {
        int viewCacheIndex = adapter.getMetricsCategory();
        View detailView = adapter.createDetailView(mContext, mDetailViews.get(viewCacheIndex), mDetailContent);
        if (detailView == null)
            throw new IllegalStateException("Must return detail view");
        final Intent settingsIntent = adapter.getSettingsIntent();
        mDetailSettingsButton.setVisibility(settingsIntent != null ? VISIBLE : GONE);
        mDetailSettingsButton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                mHost.startActivityDismissingKeyguard(settingsIntent);
            }
        });
        mDetailContent.removeAllViews();
        mDetailContent.addView(detailView);
        mDetailViews.put(viewCacheIndex, detailView);
        MetricsLogger.visible(mContext, adapter.getMetricsCategory());
        announceForAccessibility(mContext.getString(R.string.accessibility_quick_settings_detail, adapter.getTitle()));
        mDetailAdapter = adapter;
        listener = mHideGridContentWhenDone;
        setVisibility(View.VISIBLE);
    } else {
        if (mDetailAdapter != null) {
            MetricsLogger.hidden(mContext, mDetailAdapter.getMetricsCategory());
        }
        mClosingDetail = true;
        mDetailAdapter = null;
        listener = mTeardownDetailWhenDone;
        mHeader.setVisibility(View.VISIBLE);
        mQsPanel.setGridContentVisibility(true);
        mQsPanelCallback.onScanStateChanged(false);
    }
    sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
    if (visibleDiff) {
        mAnimatingOpen = adapter != null;
        if (mFullyExpanded || mDetailAdapter != null) {
            setAlpha(1);
            mClipper.animateCircularClip(x, y, mDetailAdapter != null, listener);
        } else {
            animate().alpha(0).setDuration(FADE_DURATION).setListener(listener).start();
        }
    }
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 24 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project android_frameworks_base by AOSPA.

the class SettingsButton method startAccelSpin.

protected void startAccelSpin() {
    cancelAnimation();
    mAnimator = ObjectAnimator.ofFloat(this, View.ROTATION, 0, 360);
    mAnimator.setInterpolator(AnimationUtils.loadInterpolator(mContext, android.R.interpolator.accelerate_quad));
    mAnimator.setDuration(ACCEL_LENGTH);
    mAnimator.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            startContinuousSpin();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    mAnimator.start();
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator)

Example 25 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project XobotOS by xamarin.

the class Tweener method to.

public static Tweener to(Object object, long duration, Object... vars) {
    long delay = 0;
    AnimatorUpdateListener updateListener = null;
    AnimatorListener listener = null;
    TimeInterpolator interpolator = null;
    // Iterate through arguments and discover properties to animate
    ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length / 2);
    for (int i = 0; i < vars.length; i += 2) {
        if (!(vars[i] instanceof String)) {
            throw new IllegalArgumentException("Key must be a string: " + vars[i]);
        }
        String key = (String) vars[i];
        Object value = vars[i + 1];
        if ("simultaneousTween".equals(key)) {
        // TODO
        } else if ("ease".equals(key)) {
            // TODO: multiple interpolators?
            interpolator = (TimeInterpolator) value;
        } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
            updateListener = (AnimatorUpdateListener) value;
        } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
            listener = (AnimatorListener) value;
        } else if ("delay".equals(key)) {
            delay = ((Number) value).longValue();
        } else if ("syncWith".equals(key)) {
        // TODO
        } else if (value instanceof float[]) {
            props.add(PropertyValuesHolder.ofFloat(key, ((float[]) value)[0], ((float[]) value)[1]));
        } else if (value instanceof Number) {
            float floatValue = ((Number) value).floatValue();
            props.add(PropertyValuesHolder.ofFloat(key, floatValue));
        } else {
            throw new IllegalArgumentException("Bad argument for key \"" + key + "\" with value " + value.getClass());
        }
    }
    // Re-use existing tween, if present
    Tweener tween = sTweens.get(object);
    ObjectAnimator anim = null;
    if (tween == null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(object, props.toArray(new PropertyValuesHolder[props.size()]));
        tween = new Tweener(anim);
        sTweens.put(object, tween);
        if (DEBUG)
            Log.v(TAG, "Added new Tweener " + tween);
    } else {
        anim = sTweens.get(object).animator;
        // Cancel all animators for given object
        replace(props, object);
    }
    if (interpolator != null) {
        anim.setInterpolator(interpolator);
    }
    // Update animation with properties discovered in loop above
    anim.setStartDelay(delay);
    anim.setDuration(duration);
    if (updateListener != null) {
        // There should be only one
        anim.removeAllUpdateListeners();
        anim.addUpdateListener(updateListener);
    }
    if (listener != null) {
        // There should be only one.
        anim.removeAllListeners();
        anim.addListener(listener);
    }
    anim.addListener(mCleanupListener);
    anim.start();
    return tween;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator) AnimatorListener(android.animation.Animator.AnimatorListener) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Aggregations

AnimatorListener (android.animation.Animator.AnimatorListener)32 ObjectAnimator (android.animation.ObjectAnimator)25 Animator (android.animation.Animator)24 AnimatorSet (android.animation.AnimatorSet)10 ValueAnimator (android.animation.ValueAnimator)8 View (android.view.View)8 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 BaseItemAnimator (com.dk.animation.effect.BaseItemAnimator)6 SegmentAnimator (com.dk.animation.effect.SegmentAnimator)6 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)5 Intent (android.content.Intent)5 ArrayList (java.util.ArrayList)4 PropertyValuesHolder (android.animation.PropertyValuesHolder)3 TimeInterpolator (android.animation.TimeInterpolator)3 ArgbEvaluator (android.animation.ArgbEvaluator)2 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)2 Comparator (java.util.Comparator)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1