Search in sources :

Example 1 with VLayout

use of com.comcast.freeflow.layouts.VLayout in project FreeFlow by Comcast.

the class FreeFlowContainerTest method testSourceCannotModifyFreeFlowContainerReferences.

/**
	 * Tests that changing an attached layout cannot change 
	 * the internal map of the item proxies insode a container
	 * 
	 * @throws InterruptedException
	 */
public void testSourceCannotModifyFreeFlowContainerReferences() throws InterruptedException {
    final CountDownLatch lock = new CountDownLatch(1);
    main.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final FreeFlowContainer container = new FreeFlowContainer(main);
            final VLayout vLayout = new VLayout();
            vLayout.setLayoutParams(new VLayout.LayoutParams(300, 200, 10));
            container.setLayout(vLayout);
            final DefaultSectionAdapter adapter = new DefaultSectionAdapter(main, 1, 2);
            container.setAdapter(adapter);
            main.setContentView(container);
            container.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

                @Override
                public boolean onPreDraw() {
                    int frameCount = container.getFrames().size();
                    adapter.setData(5, 10);
                    // setItems will force new frames to be generated, but not set 
                    vLayout.setAdapter(adapter);
                    vLayout.prepareLayout();
                    //assertEquals("Layout frames did not generate as expected", 5*(10+1), vLayout.getAllProxies().size());
                    assertEquals("FreeFlowContainer frames changed unexpectedly with data", frameCount, container.getFrames().size());
                    lock.countDown();
                    return false;
                }
            });
        }
    });
    lock.await(5000, TimeUnit.MILLISECONDS);
}
Also used : VLayout(com.comcast.freeflow.layouts.VLayout) DefaultSectionAdapter(com.comcast.freeflow.helpers.DefaultSectionAdapter) CountDownLatch(java.util.concurrent.CountDownLatch) OnPreDrawListener(android.view.ViewTreeObserver.OnPreDrawListener)

Example 2 with VLayout

use of com.comcast.freeflow.layouts.VLayout in project FreeFlow by Comcast.

the class FreeFlowContainerTest method testAllViewsAreGeneratedByFirstLayout.

/**
	 * Tests that all items are generated by the time predraw kicks in
	 * 
	 * @throws InterruptedException
	 */
public void testAllViewsAreGeneratedByFirstLayout() throws InterruptedException {
    final CountDownLatch lock = new CountDownLatch(1);
    main.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            final FreeFlowContainer container = new FreeFlowContainer(main);
            DefaultSectionAdapter adapter = new DefaultSectionAdapter(main, 1, 2);
            container.setAdapter(adapter);
            VLayout vLayout = new VLayout();
            vLayout.setLayoutParams(new VLayout.LayoutParams(300, 200, 10));
            container.setLayout(vLayout);
            container.addFreeFlowEventListener(new FreeFlowEventListener() {

                @Override
                public void onLayoutChanging(FreeFlowLayout oldLayout, FreeFlowLayout newLayout) {
                }

                @Override
                public void layoutComputed() {
                }

                @Override
                public void layoutComplete(boolean areTransitionAnimationsPlaying) {
                    assertEquals("Correct number of children were not created", 3, container.getChildCount());
                }

                @Override
                public void dataChanged() {
                }

                @Override
                public void animationsStarted() {
                }

                @Override
                public void layoutChangeAnimationsComplete() {
                }
            });
            main.setContentView(container);
        }
    });
    lock.await(5000, TimeUnit.MILLISECONDS);
}
Also used : DefaultSectionAdapter(com.comcast.freeflow.helpers.DefaultSectionAdapter) VLayout(com.comcast.freeflow.layouts.VLayout) CountDownLatch(java.util.concurrent.CountDownLatch) FreeFlowLayout(com.comcast.freeflow.layouts.FreeFlowLayout)

Example 3 with VLayout

use of com.comcast.freeflow.layouts.VLayout in project FreeFlow by Comcast.

the class ArtbookActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_artbook);
    container = (FreeFlowContainer) findViewById(R.id.container);
    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    findViewById(R.id.load_more).setOnClickListener(this);
    //Our new layout
    custom = new ArtbookLayout();
    //Grid Layout
    grid = new VGridLayout();
    VGridLayout.LayoutParams params = new VGridLayout.LayoutParams(size.x / 2, size.x / 2);
    grid.setLayoutParams(params);
    //Vertical Layout
    VLayout vlayout = new VLayout();
    VLayout.LayoutParams params2 = new VLayout.LayoutParams(size.x);
    vlayout.setLayoutParams(params2);
    //HLayout
    HLayout hlayout = new HLayout();
    hlayout.setLayoutParams(new HLayout.LayoutParams(size.x));
    layouts = new FreeFlowLayout[] { custom, grid, vlayout, hlayout };
    adapter = new DribbbleDataAdapter(this);
    container.setLayout(layouts[currLayoutIndex]);
    container.setAdapter(adapter);
    fetch = new DribbbleFetch();
    fetch.load(this, itemsPerPage, pageIndex);
}
Also used : VGridLayout(com.comcast.freeflow.layouts.VGridLayout) ArtbookLayout(com.comcast.freeflow.examples.artbook.layouts.ArtbookLayout) HLayout(com.comcast.freeflow.layouts.HLayout) LayoutParams(com.comcast.freeflow.layouts.VGridLayout.LayoutParams) DribbbleFetch(com.comcast.freeflow.examples.artbook.models.DribbbleFetch) VLayout(com.comcast.freeflow.layouts.VLayout) Point(android.graphics.Point) LayoutParams(com.comcast.freeflow.layouts.VGridLayout.LayoutParams) DribbbleDataAdapter(com.comcast.freeflow.examples.artbook.data.DribbbleDataAdapter) Display(android.view.Display)

Example 4 with VLayout

use of com.comcast.freeflow.layouts.VLayout 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)

Aggregations

VLayout (com.comcast.freeflow.layouts.VLayout)4 DefaultSectionAdapter (com.comcast.freeflow.helpers.DefaultSectionAdapter)2 HLayout (com.comcast.freeflow.layouts.HLayout)2 VGridLayout (com.comcast.freeflow.layouts.VGridLayout)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Point (android.graphics.Point)1 Display (android.view.Display)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 OnPreDrawListener (android.view.ViewTreeObserver.OnPreDrawListener)1 Button (android.widget.Button)1 FrameLayout (android.widget.FrameLayout)1 TextView (android.widget.TextView)1 DefaultLayoutAnimator (com.comcast.freeflow.animations.DefaultLayoutAnimator)1 AbsLayoutContainer (com.comcast.freeflow.core.AbsLayoutContainer)1 OnItemClickListener (com.comcast.freeflow.core.AbsLayoutContainer.OnItemClickListener)1 FreeFlowContainer (com.comcast.freeflow.core.FreeFlowContainer)1 FreeFlowItem (com.comcast.freeflow.core.FreeFlowItem)1 DribbbleDataAdapter (com.comcast.freeflow.examples.artbook.data.DribbbleDataAdapter)1 ArtbookLayout (com.comcast.freeflow.examples.artbook.layouts.ArtbookLayout)1