Search in sources :

Example 11 with FreeFlowItem

use of com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem in project UltimateAndroid by cymcsg.

the class DefaultLayoutAnimator method getItemsRemovedAnimation.

/**
     * The animation to run on the items being removed
     *
     * @param removed An ArrayList of <code>FreeFlowItems</code> removed
     * @return The AnimatorSet of the removed objects
     */
protected AnimatorSet getItemsRemovedAnimation(List<FreeFlowItem> removed) {
    AnimatorSet disappearingSet = new AnimatorSet();
    ArrayList<Animator> fades = new ArrayList<Animator>();
    for (FreeFlowItem proxy : removed) {
        fades.add(ObjectAnimator.ofFloat(proxy.view, "alpha", 0));
    }
    disappearingSet.setDuration(oldCellsRemovalAnimationDuration);
    disappearingSet.setStartDelay(oldCellsRemovalAnimationStartDelay);
    if (animateIndividualCellsSequentially)
        disappearingSet.playSequentially(fades);
    else
        disappearingSet.playTogether(fades);
    return disappearingSet;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem)

Example 12 with FreeFlowItem

use of com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem in project UltimateAndroid by cymcsg.

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.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) Comparator(java.util.Comparator)

Example 13 with FreeFlowItem

use of com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem in project UltimateAndroid by cymcsg.

the class DefaultLayoutAnimator method getItemsAddedAnimation.

/**
     *
     */
protected AnimatorSet getItemsAddedAnimation(List<FreeFlowItem> added) {
    AnimatorSet appearingSet = new AnimatorSet();
    ArrayList<Animator> fadeIns = new ArrayList<Animator>();
    for (FreeFlowItem proxy : added) {
        proxy.view.setAlpha(0);
        fadeIns.add(ObjectAnimator.ofFloat(proxy.view, "alpha", 1));
    }
    if (animateIndividualCellsSequentially)
        appearingSet.playSequentially(fadeIns);
    else
        appearingSet.playTogether(fadeIns);
    appearingSet.setStartDelay(newCellsAdditionAnimationStartDelay);
    appearingSet.setDuration(newCellsAdditionAnimationDurationPerCell);
    return appearingSet;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem)

Example 14 with FreeFlowItem

use of com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem in project UltimateAndroid by cymcsg.

the class NoAnimationLayoutAnimator method animateChanges.

@Override
public void animateChanges(LayoutChangeset changes, FreeFlowContainer callback) {
    this.changes = changes;
    for (Pair<FreeFlowItem, Rect> item : changes.getMoved()) {
        Rect r = item.first.frame;
        View v = item.first.view;
        int wms = MeasureSpec.makeMeasureSpec(r.right - r.left, MeasureSpec.EXACTLY);
        int hms = MeasureSpec.makeMeasureSpec(r.bottom - r.top, MeasureSpec.EXACTLY);
        v.measure(wms, hms);
        v.layout(r.left, r.top, r.right, r.bottom);
    }
    callback.onLayoutChangeAnimationsCompleted(this);
}
Also used : Rect(android.graphics.Rect) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) View(android.view.View)

Example 15 with FreeFlowItem

use of com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem in project UltimateAndroid by cymcsg.

the class HLayout method getContentWidth.

@Override
public int getContentWidth() {
    if (itemsAdapter == null || itemsAdapter.getNumberOfSections() <= 0) {
        return 0;
    }
    int sectionIndex = itemsAdapter.getNumberOfSections() - 1;
    Section s = itemsAdapter.getSection(sectionIndex);
    if (s.getDataCount() == 0)
        return 0;
    Object lastFrameData = s.getDataAtIndex(s.getDataCount() - 1);
    FreeFlowItem fd = proxies.get(lastFrameData);
    return (fd.frame.left + fd.frame.width());
}
Also used : FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) Section(com.marshalchen.common.uimodule.freeflow.core.Section)

Aggregations

FreeFlowItem (com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem)17 Rect (android.graphics.Rect)8 Section (com.marshalchen.common.uimodule.freeflow.core.Section)8 Animator (android.animation.Animator)4 AnimatorSet (android.animation.AnimatorSet)4 ObjectAnimator (android.animation.ObjectAnimator)4 ValueAnimator (android.animation.ValueAnimator)4 View (android.view.View)3 ArrayList (java.util.ArrayList)3 AbsLayoutContainer (com.marshalchen.common.uimodule.freeflow.core.AbsLayoutContainer)2 OnItemClickListener (com.marshalchen.common.uimodule.freeflow.core.AbsLayoutContainer.OnItemClickListener)2 FreeFlowContainer (com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer)2 AnimatorListener (android.animation.Animator.AnimatorListener)1 OnClickListener (android.view.View.OnClickListener)1 Button (android.widget.Button)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 DefaultLayoutAnimator (com.marshalchen.common.uimodule.freeflow.animations.DefaultLayoutAnimator)1 OnScrollListener (com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.OnScrollListener)1 HGridLayout (com.marshalchen.common.uimodule.freeflow.layouts.HGridLayout)1