Search in sources :

Example 6 with FreeFlowItem

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

the class DefaultLayoutAnimator method getItemsMovedAnimation.

protected AnimatorSet getItemsMovedAnimation(List<Pair<FreeFlowItem, Rect>> moved) {
    AnimatorSet anim = new AnimatorSet();
    ArrayList<Animator> moves = new ArrayList<Animator>();
    for (Pair<FreeFlowItem, Rect> item : moved) {
        FreeFlowItem proxy = FreeFlowItem.clone(item.first);
        View v = proxy.view;
        proxy.frame.left -= callback.getViewportLeft();
        proxy.frame.top -= callback.getViewportTop();
        proxy.frame.right -= callback.getViewportLeft();
        proxy.frame.bottom -= callback.getViewportTop();
        moves.add(transitionToFrame(item.second, proxy, v));
    }
    anim.playTogether(moves);
    return anim;
}
Also used : Rect(android.graphics.Rect) 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) View(android.view.View)

Example 7 with FreeFlowItem

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

the class FreeFlowPhotoGridActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.free_flow_photo_grid_activity);
    FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLayout);
    final ImageAdapter adapter = new ImageAdapter();
    container = new FreeFlowContainer(this);
    DefaultLayoutAnimator anim = (DefaultLayoutAnimator) container.getLayoutAnimator();
    anim.animateAllSetsSequentially = false;
    anim.animateIndividualCellsSequentially = false;
    container.requestFocus();
    hLayout = new HLayout();
    hLayout.setLayoutParams(new HLayout.LayoutParams(100, 150, 600));
    vLayout = new VLayout();
    vLayout.setLayoutParams(new VLayout.LayoutParams(100, 600, 150));
    vGridLayout = new VGridLayout();
    vGridLayout.setLayoutParams(new VGridLayout.LayoutParams(200, 200, 600, 100));
    hGridLayout = new HGridLayout();
    hGridLayout.setLayoutParams(new HGridLayout.LayoutParams(200, 200, 100, 600));
    layouts = new FreeFlowLayout[] { vLayout, hLayout, vGridLayout, hGridLayout };
    container.setAdapter(adapter);
    container.setLayout(layouts[currentLayoutIndex]);
    frameLayout.addView(container);
    changeButton = ((Button) frameLayout.findViewById(R.id.transitionButton));
    changeButton.setText("Layout");
    changeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            currentLayoutIndex++;
            if (currentLayoutIndex == layouts.length) {
                currentLayoutIndex = 0;
            }
            container.setLayout(layouts[currentLayoutIndex]);
        }
    });
    jumpButton = (Button) findViewById(R.id.jumpButton);
    jumpButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int section = (int) (adapter.getNumberOfSections() * Math.random());
            int index = (int) (adapter.getSection(section).getDataCount() * Math.random());
            String s = "section = " + section + ", index = " + index;
            Toast.makeText(FreeFlowPhotoGridActivity.this, s, Toast.LENGTH_SHORT).show();
            container.scrollToItem(section, index, false);
        }
    });
    jumpButtonAnim = (Button) findViewById(R.id.jumpButtonAnim);
    jumpButtonAnim.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int section = (int) (adapter.getNumberOfSections() * Math.random());
            int index = (int) (adapter.getSection(section).getDataCount() * Math.random());
            String s = "section = " + section + ", index = " + index;
            Toast.makeText(FreeFlowPhotoGridActivity.this, s, Toast.LENGTH_SHORT).show();
            container.scrollToItem(section, index, true);
        }
    });
    container.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AbsLayoutContainer parent, FreeFlowItem proxy) {
            Log.d("Test", "container item: " + proxy.itemSection + " /  " + proxy.itemIndex);
        }
    });
    changeButton.bringToFront();
    jumpButton.bringToFront();
    jumpButtonAnim.bringToFront();
}
Also used : OnItemClickListener(com.marshalchen.common.uimodule.freeflow.core.AbsLayoutContainer.OnItemClickListener) HGridLayout(com.marshalchen.common.uimodule.freeflow.layouts.HGridLayout) View(android.view.View) TextView(android.widget.TextView) DefaultLayoutAnimator(com.marshalchen.common.uimodule.freeflow.animations.DefaultLayoutAnimator) VGridLayout(com.marshalchen.common.uimodule.freeflow.layouts.VGridLayout) HLayout(com.marshalchen.common.uimodule.freeflow.layouts.HLayout) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) VLayout(com.marshalchen.common.uimodule.freeflow.layouts.VLayout) FreeFlowContainer(com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer) OnClickListener(android.view.View.OnClickListener) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) AbsLayoutContainer(com.marshalchen.common.uimodule.freeflow.core.AbsLayoutContainer)

Example 8 with FreeFlowItem

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

the class ArtbookLayout method prepareLayout.

@Override
public void prepareLayout() {
    Log.d(TAG, "prepare layout!!!");
    map = new HashMap<Object, FreeFlowItem>();
    s = itemsAdapter.getSection(0);
    int rowIndex;
    Log.d(TAG, "prepare layout for: " + s.getDataCount());
    for (int i = 0; i < s.getDataCount(); i++) {
        rowIndex = i / 5;
        FreeFlowItem p = new FreeFlowItem();
        p.isHeader = false;
        p.itemIndex = i;
        p.itemSection = 0;
        p.data = s.getDataAtIndex(i);
        Rect r = new Rect();
        switch(i % 5) {
            case (0):
                r.left = 0;
                r.top = rowIndex * largeItemSide;
                r.right = largeItemSide;
                r.bottom = r.top + largeItemSide;
                if (rowIndex % 2 != 0) {
                    r.offset(largeItemSide, 0);
                }
                break;
            case (1):
                r.left = largeItemSide;
                r.right = largeItemSide + regularItemSide;
                r.top = rowIndex * largeItemSide;
                r.bottom = r.top + regularItemSide;
                if (rowIndex % 2 != 0) {
                    r.offset(-largeItemSide, 0);
                }
                break;
            case (2):
                r.left = 3 * regularItemSide;
                r.right = width;
                r.top = rowIndex * largeItemSide;
                r.bottom = r.top + regularItemSide;
                if (rowIndex % 2 != 0) {
                    r.offset(-largeItemSide, 0);
                }
                break;
            case (3):
                r.left = largeItemSide;
                r.right = largeItemSide + regularItemSide;
                r.top = rowIndex * largeItemSide + regularItemSide;
                r.bottom = r.top + regularItemSide;
                if (rowIndex % 2 != 0) {
                    r.offset(-largeItemSide, 0);
                }
                break;
            case (4):
                r.left = 3 * regularItemSide;
                r.right = width;
                r.top = rowIndex * largeItemSide + regularItemSide;
                r.bottom = r.top + regularItemSide;
                if (rowIndex % 2 != 0) {
                    r.offset(-largeItemSide, 0);
                }
                break;
            default:
                break;
        }
        p.frame = r;
        map.put(s.getDataAtIndex(i), p);
    }
}
Also used : Rect(android.graphics.Rect) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem)

Example 9 with FreeFlowItem

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

the class FreeFlowArtbookActivity method onDataLoaded.

public void onDataLoaded(DribbbleFeed feed) {
    Log.d(TAG, "photo: " + feed.getShots().get(0).getImage_teaser_url());
    adapter.update(feed);
    container.dataInvalidated();
    container.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AbsLayoutContainer parent, FreeFlowItem proxy) {
        }
    });
    container.addScrollListener(new OnScrollListener() {

        @Override
        public void onScroll(FreeFlowContainer container) {
            Log.d(TAG, "scroll percent " + container.getScrollPercentY());
        }
    });
}
Also used : OnItemClickListener(com.marshalchen.common.uimodule.freeflow.core.AbsLayoutContainer.OnItemClickListener) OnScrollListener(com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer.OnScrollListener) FreeFlowContainer(com.marshalchen.common.uimodule.freeflow.core.FreeFlowContainer) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) AbsLayoutContainer(com.marshalchen.common.uimodule.freeflow.core.AbsLayoutContainer)

Example 10 with FreeFlowItem

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

the class ArtbookLayout method getItemProxies.

@Override
public HashMap<Object, FreeFlowItem> getItemProxies(int viewPortLeft, int viewPortTop) {
    Rect viewport = new Rect(viewPortLeft, viewPortTop, viewPortLeft + width, viewPortTop + height);
    //Log.d(TAG, "Viewport: "+viewPortLeft+", "+viewPortTop+", "+viewport.width()+","+viewport.height());
    HashMap<Object, FreeFlowItem> ret = new HashMap<Object, FreeFlowItem>();
    Iterator<Entry<Object, FreeFlowItem>> it = map.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Object, FreeFlowItem> pairs = it.next();
        FreeFlowItem p = (FreeFlowItem) pairs.getValue();
        if (Rect.intersects(p.frame, viewport)) {
            ret.put(pairs.getKey(), p);
        }
    }
    return ret;
}
Also used : Rect(android.graphics.Rect) Entry(java.util.Map.Entry) HashMap(java.util.HashMap) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem)

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