Search in sources :

Example 1 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 2 with FreeFlowItem

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

the class HGridLayout 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)

Example 3 with FreeFlowItem

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

the class HGridLayout method prepareLayout.

public void prepareLayout() {
    proxies.clear();
    int rows = height / itemHeight;
    int leftStart = 0;
    for (int i = 0; i < itemsAdapter.getNumberOfSections(); i++) {
        Section s = itemsAdapter.getSection(i);
        if (itemsAdapter.shouldDisplaySectionHeaders()) {
            FreeFlowItem header = new FreeFlowItem();
            Rect hframe = new Rect();
            header.itemSection = i;
            header.itemIndex = -1;
            header.isHeader = true;
            hframe.left = leftStart;
            hframe.top = 0;
            hframe.right = leftStart + headerWidth;
            hframe.bottom = headerHeight;
            header.frame = hframe;
            header.data = s.getHeaderData();
            proxies.put(header.data, header);
            leftStart += headerWidth;
        }
        for (int j = 0; j < s.getDataCount(); j++) {
            FreeFlowItem descriptor = new FreeFlowItem();
            Rect frame = new Rect();
            descriptor.itemSection = i;
            descriptor.itemIndex = j;
            frame.left = (j / rows) * itemWidth + leftStart;
            frame.top = (j % rows) * itemHeight;
            frame.right = frame.left + itemWidth;
            frame.bottom = frame.top + itemHeight;
            descriptor.frame = frame;
            descriptor.data = s.getDataAtIndex(j);
            proxies.put(descriptor.data, descriptor);
        }
        int mod = 0;
        if (s.getDataCount() % rows != 0)
            mod = 1;
        leftStart += ((s.getDataCount() / rows) + mod) * itemWidth;
    }
}
Also used : Rect(android.graphics.Rect) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) Section(com.marshalchen.common.uimodule.freeflow.core.Section)

Example 4 with FreeFlowItem

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

the class HLayout method prepareLayout.

public void prepareLayout() {
    if (itemWidth < 0) {
        throw new IllegalStateException("itemWidth not set");
    }
    proxies.clear();
    int leftStart = 0;
    for (int i = 0; i < itemsAdapter.getNumberOfSections(); i++) {
        Section s = itemsAdapter.getSection(i);
        if (itemsAdapter.shouldDisplaySectionHeaders()) {
            if (headerWidth < 0) {
                throw new IllegalStateException("headerWidth not set");
            }
            if (headerHeight < 0) {
                throw new IllegalStateException("headerHeight not set");
            }
            FreeFlowItem header = new FreeFlowItem();
            Rect hframe = new Rect();
            header.itemSection = i;
            header.itemIndex = -1;
            header.isHeader = true;
            hframe.left = leftStart;
            hframe.top = 0;
            hframe.right = leftStart + headerWidth;
            hframe.bottom = headerHeight;
            header.frame = hframe;
            header.data = s.getHeaderData();
            proxies.put(header.data, header);
            leftStart += headerWidth;
        }
        for (int j = 0; j < s.getDataCount(); j++) {
            FreeFlowItem descriptor = new FreeFlowItem();
            Rect frame = new Rect();
            descriptor.itemSection = i;
            descriptor.itemIndex = j;
            frame.left = j * itemWidth + leftStart;
            frame.top = 0;
            frame.right = frame.left + itemWidth;
            frame.bottom = height;
            descriptor.frame = frame;
            descriptor.data = s.getDataAtIndex(j);
            proxies.put(descriptor.data, descriptor);
        }
        leftStart += s.getDataCount() * itemWidth;
    }
}
Also used : Rect(android.graphics.Rect) FreeFlowItem(com.marshalchen.common.uimodule.freeflow.core.FreeFlowItem) Section(com.marshalchen.common.uimodule.freeflow.core.Section)

Example 5 with FreeFlowItem

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

the class VGridLayout method getContentHeight.

@Override
public int getContentHeight() {
    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);
    if (fd == null) {
        return 0;
    }
    return (fd.frame.top + fd.frame.height());
}
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