ppamorim

Untitled

Jul 27th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.74 KB | None | 0 0
  1. package com.Tag_Interativa.vejo_ao_vivo.app.core.layout;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.Map;
  6. import java.util.Map.Entry;
  7.  
  8. import android.graphics.Rect;
  9. import android.util.Log;
  10.  
  11. import com.comcast.freeflow.core.FreeFlowItem;
  12. import com.comcast.freeflow.core.Section;
  13. import com.comcast.freeflow.layouts.FreeFlowLayoutBase;
  14.  
  15. public class ListLayout extends FreeFlowLayoutBase {
  16.  
  17.     private static final String TAG = "ListLayout";
  18.     private HashMap<Object, FreeFlowItem> map;
  19.     private Section s;
  20.  
  21.     private int itemHeight = 250;
  22.  
  23.     public ListLayout() {}
  24.  
  25.     @Override
  26.     public Map<Object, FreeFlowItem> getItemProxies(int viewPortLeft,
  27.                                                     int viewPortTop) {
  28.         Rect viewport = new Rect(viewPortLeft, viewPortTop, viewPortLeft
  29.                 + width, viewPortTop + height);
  30.         HashMap<Object, FreeFlowItem> ret = new HashMap<Object, FreeFlowItem>();
  31.  
  32.         Iterator<Entry<Object, FreeFlowItem>> it = map.entrySet().iterator();
  33.         while (it.hasNext()) {
  34.             Entry<Object, FreeFlowItem> pairs = it.next();
  35.             FreeFlowItem p = (FreeFlowItem) pairs.getValue();
  36.             if (Rect.intersects(p.frame, viewport)) {
  37.                 ret.put(pairs.getKey(), p);
  38.             }
  39.         }
  40.         return ret;
  41.     }
  42.  
  43.     @Override
  44.     public void setLayoutParams(FreeFlowLayoutParams params) {}
  45.  
  46.     @Override
  47.     public void prepareLayout() {
  48.  
  49.         Log.d(TAG, "prepare layout!!!");
  50.         map = new HashMap<Object, FreeFlowItem>();
  51.         s = itemsAdapter.getSection(0);
  52.         Log.d(TAG, "prepare layout for: " + s.getDataCount());
  53.         for (int i = 0; i < s.getDataCount(); i++) {
  54.  
  55.             Rect r = new Rect();
  56.             FreeFlowItem p = new FreeFlowItem();
  57.  
  58.             p.isHeader = false;
  59.             p.itemIndex = i;
  60.             p.itemSection = 0;
  61.             p.data = s.getDataAtIndex(i);
  62.  
  63.             switch (i % 6) {
  64.  
  65.                 case (0):
  66.                     r.left = 0;
  67.                     r.right = width;
  68.                     r.top = i / 6 * (4 * itemHeight);
  69.                     r.bottom = r.top + itemHeight;
  70.                     break;
  71.  
  72.                 case (1):
  73.                     r.left = 0;
  74.                     r.right = width / 2;
  75.                     r.top = i / 6 * (4 * itemHeight) + itemHeight;
  76.                     r.bottom = r.top + itemHeight;
  77.                     break;
  78.  
  79.                 case (2):
  80.                     r.left = width / 2;
  81.                     r.right = width;
  82.                     r.top = i / 6 * (4 * itemHeight) + itemHeight;
  83.                     r.bottom = r.top + itemHeight;
  84.                     break;
  85.  
  86.                 case (3):
  87.                     r.left = 0;
  88.                     r.right = width / 2;
  89.                     r.top = i / 6 * (4 * itemHeight) + 2 * itemHeight;
  90.                     r.bottom = r.top + itemHeight;
  91.                     break;
  92.  
  93.                 case (4):
  94.  
  95.                     r.left = width / 2;
  96.                     r.right = width;
  97.                     r.top = i / 6 * (4 * itemHeight) + 2 * itemHeight;
  98.                     r.bottom = r.top + itemHeight;
  99.                     break;
  100.  
  101.                 case (5):
  102.                     r.left = 0;
  103.                     r.right = width;
  104.                     r.top = i / 6 * (4 * itemHeight) + 3 * itemHeight;
  105.                     r.bottom = r.top + itemHeight;
  106.                     break;
  107.  
  108.                 case (6):
  109.  
  110.                     r.left = width / 2;
  111.                     r.right = width;
  112.                     r.top = i / 6 * (4 * itemHeight) + 4 * itemHeight;
  113.                     r.bottom = r.top + itemHeight;
  114.                     break;
  115.  
  116.                 default:
  117.                     break;
  118.             }
  119.             p.frame = r;
  120.             map.put(s.getDataAtIndex(i), p);
  121.         }
  122.     }
  123.  
  124.     @Override
  125.     public FreeFlowItem getFreeFlowItemForItem(Object item) {
  126.         return map.get(item);
  127.     }
  128.  
  129.     @Override
  130.     public boolean horizontalScrollEnabled() {
  131.         return false;
  132.     }
  133.  
  134.     @Override
  135.     public boolean verticalScrollEnabled() {
  136.         return true;
  137.     }
  138.  
  139.     @Override
  140.     public int getContentWidth() {
  141.         return 0;
  142.     }
  143.  
  144.     @Override
  145.     public int getContentHeight() {
  146.  
  147.         int additional = 0;
  148.         if((s.getDataCount() * 4) % 6 != 0){
  149.             additional = 1;
  150.         }
  151.  
  152.         int val =  ((s.getDataCount() * 4 / 6 )+additional) *itemHeight;
  153.         Log.d(TAG, "items: "+s.getDataCount()+"/  "+itemHeight+": "+val);
  154.  
  155.         return val;
  156.     }
  157.  
  158.     @Override
  159.     public FreeFlowItem getItemAt(float x, float y) {
  160.         // TODO Auto-generated method stub
  161.         return null;
  162.     }
  163.  
  164.     }
Advertisement
Add Comment
Please, Sign In to add comment