@Override
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   super.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
   if (mTimeLineText.getVisibility() == View.VISIBLE) {
     int index =
         firstVisibleItem + 1 == view.getAdapter().getCount()
             ? view.getAdapter().getCount() - 1
             : firstVisibleItem + 1;
     Image image = (Image) view.getAdapter().getItem(index);
     if (image != null) {
       mTimeLineText.setText(TimeUtil.formatPhotoDate(image.path));
     }
   }
 }
Ejemplo n.º 2
0
  public boolean shouldHandleAbsListViewLoadingMore(AbsListView absListView) {
    if (mIsLoadingMore
        || mCurrentRefreshStatus == RefreshStatus.REFRESHING
        || mLoadMoreFooterView == null
        || mDelegate == null
        || absListView == null
        || absListView.getAdapter() == null
        || absListView.getAdapter().getCount() == 0) {
      return false;
    }

    int lastChildBottom = 0;
    if (absListView.getChildCount() > 0) {
      // 如果AdapterView的子控件数量不为0,获取最后一个子控件的bottom
      lastChildBottom = absListView.getChildAt(absListView.getChildCount() - 1).getBottom();
    }
    return absListView.getLastVisiblePosition() == absListView.getAdapter().getCount() - 1
        && lastChildBottom <= absListView.getMeasuredHeight();
  }
  @SuppressWarnings("unchecked")
  public void onScroll(
      AbsListView absListView, int firstVisible, int visibleCount, int totalCount) {

    boolean loadMore = /* maybe add a padding */ firstVisible + visibleCount >= totalCount - 1;

    //        Log.d("onScroll:","loadMore f=" + firstVisible + ", vc=" + visibleCount + ", tc="
    // +totalCount);
    if (loadMore) {
      // Debug.startMethodTracing("list" + firstVisible);
      ListAdapter adapter = absListView.getAdapter();
      if (adapter instanceof StatusAdapter) {
        StatusAdapter sta = (StatusAdapter) adapter;
        if (totalCount > 0) {
          Object item = sta.getItem(totalCount - 1);
          int i = 0;
          if (item instanceof DirectMessage) {
            DirectMessage message = (DirectMessage) item;

            List<DirectMessage> messages = th.getDirectsFromDb(message.getId(), 7);
            for (DirectMessage direct : messages) {
              sta.insert(direct, totalCount + i);
              directs.add(direct);
              i++;
            }
          } else if (item instanceof Status) {
            Status last = (Status) item;
            if (statuses == null) statuses = new ArrayList<Status>();

            List<Status> newStatuses = th.getStatuesFromDb(last.getId(), 7, list_id);
            // TODO add checking for old
            List<Long> readIds = obtainReadIds(newStatuses);
            sta.readIds.addAll(readIds);
            for (Status status : newStatuses) {
              if (!matchesFilter(status)) {
                sta.insert(status, totalCount + i);
                statuses.add(status);
                i++;
              }
            }
          }
          sta.notifyDataSetChanged();
        }
      }
      // Debug.stopMethodTracing();
    }
  }
Ejemplo n.º 4
0
  /**
   * get AbsListView height according to every children
   *
   * @param view
   * @return
   */
  public static int getAbsListViewHeightBasedOnChildren(AbsListView view) {
    ListAdapter adapter;
    if (view == null || (adapter = view.getAdapter()) == null) {
      return 0;
    }

    int height = 0;
    for (int i = 0; i < adapter.getCount(); i++) {
      View item = adapter.getView(i, null, view);
      if (item instanceof ViewGroup) {
        item.setLayoutParams(
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
      }
      item.measure(0, 0);
      height += item.getMeasuredHeight();
    }
    height += view.getPaddingTop() + view.getPaddingBottom();
    return height;
  }
Ejemplo n.º 5
0
  protected Object getContextMenuSource(final View v, final ContextMenuInfo menuInfo) {
    Object source = null;

    if (menuInfo instanceof AdapterContextMenuInfo) {
      final AbsListView list = (AbsListView) v;
      final AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo;
      source = list.getAdapter().getItem(mi.position);
    } else if (menuInfo instanceof ExpandableListContextMenuInfo) {
      final ExpandableListView list = (ExpandableListView) v;
      final ExpandableListAdapter adapter = list.getExpandableListAdapter();
      final ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) menuInfo;
      final long pp = mi.packedPosition;
      final int group = ExpandableListView.getPackedPositionGroup(pp);
      final int child = ExpandableListView.getPackedPositionChild(pp);
      if (child >= 0) {
        source = adapter.getChild(group, child);
      } else {
        source = adapter.getGroup(group);
      }
    }
    return source;
  }