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;
}
}
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;
}
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();
}
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;
}
}
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;
}
}
Aggregations