Search in sources :

Example 1 with FreeFlowItem

use of com.comcast.freeflow.core.FreeFlowItem in project FreeFlow by Comcast.

the class VLayout method prepareLayout.

public void prepareLayout() {
    if (itemHeight < 0) {
        throw new IllegalStateException("itemHeight not set");
    }
    proxies.clear();
    int topStart = 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 = 0;
            hframe.top = topStart;
            hframe.right = headerWidth;
            hframe.bottom = topStart + headerHeight;
            header.frame = hframe;
            header.data = s.getHeaderData();
            proxies.put(header.data, header);
            topStart += headerHeight;
        }
        for (int j = 0; j < s.getDataCount(); j++) {
            FreeFlowItem descriptor = new FreeFlowItem();
            Rect frame = new Rect();
            descriptor.itemSection = i;
            descriptor.itemIndex = j;
            frame.left = 0;
            frame.top = j * itemHeight + topStart;
            frame.right = width;
            frame.bottom = frame.top + itemHeight;
            descriptor.frame = frame;
            descriptor.data = s.getDataAtIndex(j);
            proxies.put(descriptor.data, descriptor);
        }
        topStart += (s.getDataCount()) * itemHeight;
    }
}
Also used : Rect(android.graphics.Rect) FreeFlowItem(com.comcast.freeflow.core.FreeFlowItem) Section(com.comcast.freeflow.core.Section)

Example 2 with FreeFlowItem

use of com.comcast.freeflow.core.FreeFlowItem in project FreeFlow by Comcast.

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.comcast.freeflow.core.FreeFlowItem)

Example 3 with FreeFlowItem

use of com.comcast.freeflow.core.FreeFlowItem in project FreeFlow by Comcast.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    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(MainActivity.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(MainActivity.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.comcast.freeflow.core.AbsLayoutContainer.OnItemClickListener) HGridLayout(com.comcast.freeflow.layouts.HGridLayout) View(android.view.View) TextView(android.widget.TextView) DefaultLayoutAnimator(com.comcast.freeflow.animations.DefaultLayoutAnimator) VGridLayout(com.comcast.freeflow.layouts.VGridLayout) HLayout(com.comcast.freeflow.layouts.HLayout) Button(android.widget.Button) FrameLayout(android.widget.FrameLayout) VLayout(com.comcast.freeflow.layouts.VLayout) FreeFlowContainer(com.comcast.freeflow.core.FreeFlowContainer) OnClickListener(android.view.View.OnClickListener) FreeFlowItem(com.comcast.freeflow.core.FreeFlowItem) AbsLayoutContainer(com.comcast.freeflow.core.AbsLayoutContainer)

Example 4 with FreeFlowItem

use of com.comcast.freeflow.core.FreeFlowItem in project FreeFlow by Comcast.

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.comcast.freeflow.core.FreeFlowItem) Section(com.comcast.freeflow.core.Section)

Example 5 with FreeFlowItem

use of com.comcast.freeflow.core.FreeFlowItem in project FreeFlow by Comcast.

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.comcast.freeflow.core.FreeFlowItem) Section(com.comcast.freeflow.core.Section)

Aggregations

FreeFlowItem (com.comcast.freeflow.core.FreeFlowItem)18 Rect (android.graphics.Rect)8 Section (com.comcast.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.comcast.freeflow.core.AbsLayoutContainer)2 OnItemClickListener (com.comcast.freeflow.core.AbsLayoutContainer.OnItemClickListener)2 FreeFlowContainer (com.comcast.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.comcast.freeflow.animations.DefaultLayoutAnimator)1 OnScrollListener (com.comcast.freeflow.core.FreeFlowContainer.OnScrollListener)1 DefaultSectionAdapter (com.comcast.freeflow.helpers.DefaultSectionAdapter)1