@Override
 public int getCount() {
   // total together all sections, plus one for each section header
   int total = 0;
   for (Adapter adapter : this.sections.values()) total += adapter.getCount() + 1;
   return total;
 }
Ejemplo n.º 2
0
 private void postViewSwitched(int direction) {
   if (direction != 0) {
     if (direction > 0) {
       mCurrentAdapterIndex++;
       mCurrentBufferIndex++;
       mLazyInit.remove(LazyInit.LEFT);
       mLazyInit.add(LazyInit.RIGHT);
       if (mCurrentAdapterIndex > mBufferedItemCount) {
         recycleView(mLoadedViews.removeFirst());
         mCurrentBufferIndex--;
       }
       int newBufferIndex = mCurrentAdapterIndex + mBufferedItemCount;
       if (newBufferIndex < mAdapter.getCount())
         mLoadedViews.addLast(makeAndAddView(newBufferIndex, true));
     } else {
       mCurrentAdapterIndex--;
       mCurrentBufferIndex--;
       mLazyInit.add(LazyInit.LEFT);
       mLazyInit.remove(LazyInit.RIGHT);
       if (mAdapter.getCount() - 1 - mCurrentAdapterIndex > mBufferedItemCount) {
         recycleView(mLoadedViews.removeLast());
       }
       int newBufferIndex = mCurrentAdapterIndex - mBufferedItemCount;
       if (newBufferIndex > -1) {
         mLoadedViews.addFirst(makeAndAddView(newBufferIndex, false));
         mCurrentBufferIndex++;
       }
     }
     requestLayout();
     setVisibleView(mCurrentBufferIndex, true);
     if (viewSwitchListener != null) {
       viewSwitchListener.onSwitched(mLoadedViews.get(mCurrentBufferIndex), mCurrentAdapterIndex);
     }
   }
 }
 @Override
 public int getViewTypeCount() {
   // assume that headers count as one, then total all sections
   int total = 1;
   for (Adapter adapter : this.sections.values()) total += adapter.getViewTypeCount();
   return total;
 }
Ejemplo n.º 4
0
 /*
  *(non-Javadoc)
  * @see android.widget.AdapterView#setSelection(int)
  */
 @Override
 public void setSelection(int position) {
   mNextScreen = INVALID_SCREEN;
   mScroller.forceFinished(true);
   if (mAdapter != null) {
     position = Math.max(position, 0);
     position = Math.min(position, mAdapter.getCount() - 1);
     recycleViews();
     View currentView = makeAndAddView(position, true);
     mLoadedViews.addLast(currentView);
     for (int offset = 1; mBufferedItemCount - offset >= 0; offset++) {
       int leftIndex = position - offset;
       int rightIndex = position + offset;
       if (leftIndex >= 0) {
         mLoadedViews.addFirst(makeAndAddView(leftIndex, false));
       }
       if (rightIndex < mAdapter.getCount()) {
         mLoadedViews.addLast(makeAndAddView(rightIndex, true));
       }
     }
     mCurrentBufferIndex = mLoadedViews.indexOf(currentView);
     mCurrentAdapterIndex = position;
     requestLayout();
     setVisibleView(mCurrentBufferIndex, false);
     if (viewSwitchListener != null) {
       viewSwitchListener.onSwitched(currentView, mCurrentAdapterIndex);
     }
   }
 }
 @Implementation
 public long getItemIdAtPosition(int position) {
   Adapter adapter = getAdapter();
   return (adapter == null || position < 0)
       ? AdapterView.INVALID_ROW_ID
       : adapter.getItemId(position);
 }
  private boolean isFirstItemVisible() {
    final Adapter adapter = mRefreshableView.getAdapter();

    if (null == adapter || adapter.isEmpty()) {
      if (DEBUG) {
        Log.d(LOG_TAG, "isFirstItemVisible. Empty View.");
      }
      return true;

    } else {

      /**
       * This check should really just be: mRefreshableView.getFirstVisiblePosition() == 0, but
       * PtRListView internally use a HeaderView which messes the positions up. For now we'll just
       * add one to account for it and rely on the inner condition which checks getTop().
       */
      if (mRefreshableView.getFirstVisiblePosition() <= 1) {
        final View firstVisibleChild = mRefreshableView.getChildAt(0);
        if (firstVisibleChild != null) {
          return firstVisibleChild.getTop() >= mRefreshableView.getTop();
        }
      }
    }

    return false;
  }
Ejemplo n.º 7
0
 private boolean walkTree(View view, Condition<TextView> condition) {
   if (view instanceof TextView) {
     if (condition.matches((TextView) view)) {
       return true;
     }
   } else if (view instanceof AdapterView) {
     Adapter adapter = ((AdapterView) view).getAdapter();
     for (int i = 0; i < adapter.getCount(); i++) {
       View adapterView = adapter.getView(i, null, null);
       if (walkTree(adapterView, condition)) {
         return true;
       }
     }
   } else if (view instanceof ViewGroup) {
     ViewGroup viewGroup = (ViewGroup) view;
     for (int i = 0; i < viewGroup.getChildCount(); i++) {
       View childView = viewGroup.getChildAt(i);
       if (childView instanceof ViewGroup) {
         if (walkTree(childView, condition)) {
           return true;
         }
       }
     }
   }
   return false;
 }
 private int getPositionForItem(Adapter adapter, String item) {
   for (int i = 0; i < adapter.getCount(); i++) {
     if (adapter.getItem(i).equals(item)) {
       return i;
     }
   }
   return -1;
 }
Ejemplo n.º 9
0
 public int getCount() {
   // total together all sections, plus one for each section header (except if the section is
   // empty)
   int total = 0;
   for (Adapter adapter : this.sections.values())
     total += ((adapter.getCount() > 0) ? adapter.getCount() + 1 : 0);
   return total;
 }
Ejemplo n.º 10
0
 /** {@inheritDoc} */
 @Override
 public int getViewTypeCount() {
   // assume that mHeaders count as one, then total all mSections
   int total = 1;
   for (final Adapter adapter : mSections.values()) {
     total += adapter.getViewTypeCount();
   }
   return total;
 }
Ejemplo n.º 11
0
 /** {@inheritDoc} */
 @Override
 public int getCount() {
   // total together all mSections, plus one for each section header
   int total = 0;
   for (final Adapter adapter : mSections.values()) {
     total += adapter.getCount() + 1;
   }
   return total;
 }
  public void testChangeInConversationNotifyAdapter() {
    DataSetObserver observer = Mockito.mock(DataSetObserver.class);

    Adapter adapter = mMessageList.getAdapter();
    adapter.registerDataSetObserver(observer);

    mActivity.onConversationChanged(mConversation.getId());

    Mockito.verify(observer, Mockito.times(1)).onChanged();
  }
Ejemplo n.º 13
0
    public Object getItem(int position) {
      for (Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        if (position == 0) return section;
        if (position < size) return adapter.getItem(position - 1);

        position -= size;
      }
      return null;
    }
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    // Show a toast
    Adapter adapter = parent.getAdapter();
    String website = adapter.getItem(position).toString();
    Toast.makeText(this, website, Toast.LENGTH_SHORT).show();

    // Dismiss the drawer
    if (mDrawerLayout.isDrawerOpen(mDrawerListView)) {
      mDrawerLayout.closeDrawer(mDrawerListView);
    }
  }
Ejemplo n.º 15
0
 /*
  *(non-Javadoc)
  * @see android.widget.AdapterView#setAdapter(android.widget.Adapter)
  */
 @Override
 public void setAdapter(Adapter adapter) {
   if (mAdapter != null) {
     mAdapter.unregisterDataSetObserver(mDataSetObserver);
   }
   mAdapter = adapter;
   if (mAdapter != null) {
     mDataSetObserver = new AdapterDataSetObserver();
     mAdapter.registerDataSetObserver(mDataSetObserver);
   }
   if (mAdapter != null && mAdapter.getCount() > 0) {
     setSelection(0);
   }
 }
Ejemplo n.º 16
0
    public int getItemViewType(int position) {
      int type = 1;
      for (Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        if (position == 0) return TYPE_SECTION_HEADER;
        if (position < size) return type + adapter.getItemViewType(position - 1);

        position -= size;
        type += adapter.getViewTypeCount();
      }
      return -1;
    }
Ejemplo n.º 17
0
  public void setAdapter(Adapter adapter) {
    this.adapter = adapter;
    adapter.registerDataSetObserver(adapterObserver);

    // setViewsFromAdapter(adapter);

    this.removeAllViews();
    for (int i = 0; i < adapter.getCount(); i++) {
      View temp_view = adapter.getView(i, null, null);
      TextView temp_txt = (TextView) temp_view.findViewById(R.id.gridsearch_text);

      quilt.addPatch(temp_view);
    }
  }
  @Override
  public void setAdapter(Adapter adapter) {
    if (mAdapter != null && mDataSetObserver != null) {
      mAdapter.unregisterDataSetObserver(mDataSetObserver);
      mDataSetObserver = null;
    }

    mAdapter = adapter;

    if (mAdapter != null && mDataSetObserver == null) {
      mDataSetObserver = new AdapterDataSetObserver();
      mAdapter.registerDataSetObserver(mDataSetObserver);
    }
  }
Ejemplo n.º 19
0
  public Object getItem(int position) {
    for (Object section : this.sections.keySet()) {
      Adapter adapter = sections.get(section);
      int size = adapter.getCount() + 1;

      // check if position inside this section
      if (position == 0) return section;
      if (position < size) return adapter.getItem(position - 1);

      // otherwise jump into next section
      position -= size;
    }
    return null;
  }
Ejemplo n.º 20
0
  public String getSectionOfItem(int position) {
    int sectionnum = 0;
    for (Object section : this.sections.keySet()) {
      Adapter adapter = sections.get(section);
      int size = adapter.getCount() + 1;

      // check if position inside this section
      if (position < size) return headers.getItem(sectionnum);

      // otherwise jump into next section
      position -= size;
      sectionnum++;
    }
    return null;
  }
Ejemplo n.º 21
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      int sectionnum = 0;
      for (Object section : this.sections.keySet()) {
        Adapter adapter = sections.get(section);
        int size = adapter.getCount() + 1;

        if (position == 0) return headers.getView(sectionnum, convertView, parent);
        if (position < size) return adapter.getView(position - 1, convertView, parent);

        position -= size;
        sectionnum++;
      }
      return null;
    }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);
    try {
      // if we don't have an adapter, we don't need to do anything
      if (mAdapter == null) {
        return;
      }

      mInLayout = true;
      final int adapterCount = mAdapter.getCount();
      System.out.println(adapterCount + " /// ");
      if (adapterCount == 0) {
        removeAllViewsInLayout();
      } else {
        View topCard = getChildAt(LAST_OBJECT_IN_STACK);
        if (mActiveCard != null && topCard != null && topCard == mActiveCard) {
          removeViewsInLayout(0, LAST_OBJECT_IN_STACK);
          layoutChildren(1, adapterCount);
        } else {
          // Reset the UI and set top view listener
          removeAllViewsInLayout();
          layoutChildren(0, adapterCount);
          setTopView();
        }
      }

      mInLayout = false;

      if (adapterCount < MAX_VISIBLE) mFlingListener.onAdapterAboutToEmpty(adapterCount);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 23
0
 public void previous() {
   if (mCurrentScreen > 0) {
     snapToScreen(mCurrentScreen - 1);
   } else {
     setSelection(mAdapter.getCount() - 1);
   }
 }
Ejemplo n.º 24
0
  public int getItemViewType(int position) {
    int type = 1;
    for (Object section : this.sections.keySet()) {
      Adapter adapter = sections.get(section);
      int size = adapter.getCount() + 1;

      // check if position inside this section
      if (position == 0) return TYPE_SECTION_HEADER;
      if (position < size) return type + adapter.getItemViewType(position - 1);

      // otherwise jump into next section
      position -= size;
      type += adapter.getViewTypeCount();
    }
    return -1;
  }
Ejemplo n.º 25
0
  // @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    int sectionnum = 0;
    for (Object section : this.sections.keySet()) {
      Adapter adapter = sections.get(section);
      int size = adapter.getCount() + 1;

      // check if position inside this section
      if (position == 0) return headers.getView(sectionnum, convertView, parent);
      if (position < size) return adapter.getView(position - 1, convertView, parent);

      // otherwise jump into next section
      position -= size;
      sectionnum++;
    }
    return null;
  }
  private void reloadAdapter() {
    if (null != mAdapter) {
      mItemTypeCount = mAdapter.getViewTypeCount();
      mItemCount = mAdapter.getCount();

      mRecycleBin = Collections.synchronizedList(new ArrayList<Queue<View>>());
      for (int i = 0; i < mItemTypeCount; i++) {
        mRecycleBin.add(new LinkedList<View>());
      }
    } else {
      mItemCount = 0;
    }

    mDataChanged = true;
    requestLayout();
  }
  public void setAdapter(Adapter adapter) {

    if (mAdapter != null) {
      mAdapter.unregisterDataSetObserver(mObserver);
      mAdapter = null;
    }

    mAdapter = adapter;
    resetList();

    if (mAdapter != null) {
      mObserver = new WorkspaceDataSetObserver();
      mAdapter.registerDataSetObserver(mObserver);
    }

    reloadAdapter();
  }
  public void setAdapter(Adapter adapter) {

    if (mAdapter != null) {
      mAdapter.unregisterDataSetObserver(mObserver);
      mAdapter = null;
    }

    mAdapter = adapter;
    resetList();

    mObserver = new WorkspaceDataSetObserver();
    mAdapter.registerDataSetObserver(mObserver);

    mDataChanged = true;
    mItemCount = adapter.getCount();
    requestLayout();
  }
Ejemplo n.º 29
0
  @Override
  public long getItemId(int position) {
    for (int i = 0; i < headers.getCount(); i++) {
      String section = headers.getItem(i);
      Adapter adapter = sections.get(section);
      if (adapter.getCount() > 0) {
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position < size) return adapter.getItemId(position - 1);

        // otherwise jump into next section
        position -= size;
      }
    }
    return -1;
  }
Ejemplo n.º 30
0
  public String getSectionForPosition(int position) {
    int curPos = 0;
    for (int i = 0; i < headers.getCount(); i++) {
      String section = headers.getItem(i);
      Adapter adapter = sections.get(section);
      if (adapter.getCount() > 0) {
        int size = adapter.getCount() + 1;

        // check if position inside this section
        if (position >= curPos && position < (curPos + size)) return section.toString();

        // otherwise jump into next section
        curPos += size;
      }
    }
    return null;
  }