Пример #1
0
  /**
   * Refreshes the content of the parent list view while maintaining the current vertical position
   * in the list view.
   */
  private void refreshListView(ViewGroup parent, Group updatedGroup) {

    // Get position of first and last visible list items
    AbsListView parentListView = (AbsListView) parent.findViewById(android.R.id.list);
    int firstVisible = parentListView.getFirstVisiblePosition();
    int lastVisible = parentListView.getLastVisiblePosition();

    // Populate list view
    mItems.clear();
    List<Group> groups = Group.getAllSortedByDisplayOrder();
    for (Group group : groups) {
      mItems.add(group.name);
    }
    notifyDataSetChanged();

    // Handle case where item is at visible top and moved up.
    if (firstVisible >= updatedGroup.getDisplayOrder()) {
      parentListView.setSelection(updatedGroup.getDisplayOrder() - 1);
      // Handle case where item is at visible bottom and moved down.
    } else if (lastVisible < updatedGroup.getDisplayOrder()) {
      parentListView.setSelection(firstVisible + 1);
      // Handle move cases in the middle of viewable listview.
    } else {
      parentListView.setSelection(firstVisible);
    }
  }
Пример #2
0
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   if (view.getLastVisiblePosition() >= totalItemCount - 5 && !searchBusy) {
     if (searchMode == Var.SEARCH_YOUTUBE) searchYoutube();
     // if(searchMode == Var.SEARCH_TWITTER) searchTwitter();
   }
 }
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
     // 判断是否滚动到底部
     if (view.getLastVisiblePosition() == view.getCount() - 1) {
       getResource();
     }
   }
 }
  @Override
  public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (scrollState == SCROLL_STATE_IDLE
        && view.getLastVisiblePosition() >= view.getCount() - THRESHOLD
        && !mLoding) {
      mLoding = true;

      loadPhotos();
    }
  }
 @Override
 public void onScrollStateChanged(AbsListView listView, int scrollState) {
   if (scrollState == SCROLL_STATE_IDLE) {
     // load 3 (4-1) items before we reach the end of the list
     if (listView.getLastVisiblePosition() >= listView.getCount() - 4) {
       currentPage++;
       getLoaderManager().restartLoader(0, null, this);
     }
   }
 }
Пример #6
0
 @Override
 public void onScroll(
     AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
   mFirstVisibleItem = firstVisibleItem;
   if (view.getFirstVisiblePosition() == 1) {
     mIsTop = true;
   } else if (view.getLastVisiblePosition() == view.getCount() - 1) {
     mIsBottom = true;
   } else {
     mIsTop = false;
     mIsBottom = false;
   }
 }
Пример #7
0
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   // Toast.makeText(context, "state change End", Toast.LENGTH_SHORT).show();
   if (scrollState != SCROLL_STATE_FLING
       && lastScrollState == SCROLL_STATE_FLING
       && view.getLastVisiblePosition() == getCount() - 1
       && scrollCheck) {
     // Toast.makeText(context, "call", Toast.LENGTH_SHORT).show();
     // avoid duplicate calls
     scrollCheck = false;
     // call next page data
     makePaginationCall();
   }
   lastScrollState = scrollState;
 }
Пример #8
0
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   switch (scrollState) {
       // 当不滚动时
     case AbsListView.OnScrollListener.SCROLL_STATE_IDLE:
       // 判断滚动到底部
       if (view.getLastVisiblePosition() == (view.getCount() - 1)) {
         Log.d("---'", "到底啦!" + isLoading);
         Story b = adapter.getLast();
         if (b != null) {
           getBefore(b.getId());
         }
       }
       break;
   }
 }
Пример #9
0
 @Override
 public void onScrollStateChanged(AbsListView listView, int scrollState) {
   if (autoLoadMore) {
     if (hasMoreData) {
       if (!isLoading()) {
         if (scrollState == OnScrollListener.SCROLL_STATE_IDLE
             && listView.getLastVisiblePosition() + 1 == listView.getCount()) { // 如果滚动到最后一行
           // 如果网络可以用
           if (needCheckNetwork && !NetworkUtils.hasNetwork(context)) {
             mLoadMoreView.showFail();
           } else {
             loadMore();
           }
         }
       }
     }
   }
 }
 public boolean canChildScrollDown() {
   if (android.os.Build.VERSION.SDK_INT < 14) {
     if (mTarget instanceof AbsListView) {
       final AbsListView absListView = (AbsListView) mTarget;
       View lastChild = absListView.getChildAt(absListView.getChildCount() - 1);
       if (lastChild != null) {
         return (absListView.getLastVisiblePosition() == (absListView.getCount() - 1))
             && lastChild.getBottom() > absListView.getPaddingBottom();
       } else {
         return false;
       }
     } else {
       return mTarget.getHeight() - mTarget.getScrollY() > 0;
     }
   } else {
     return ViewCompat.canScrollVertically(mTarget, 1);
   }
 }
Пример #11
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();
  }
Пример #12
0
 @Override
 public void onScrollStateChanged(AbsListView listview, int scrollState) {
   switch (scrollState) {
       // 当不滚动时
     case OnScrollListener.SCROLL_STATE_IDLE:
       // 判断滚动到底部
       if (!isLoadingMore) {
         if (listview.getLastVisiblePosition() == (listview.getCount() - 1)) {
           if (currentPageNum < pageCount) {
             currentPageNum++;
             isLoadingMore = true;
             loadReferenceList();
           } else {
             handler.sendEmptyMessageDelayed(NORE_MORE_DATA, 100);
           }
         }
       }
       break;
   }
 }
Пример #13
0
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   if (scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
     // 判断是否滚动到底部
     int lastIndex = view.getLastVisiblePosition();
     int count = view.getCount();
     if (lastIndex == count - 1 || lastIndex == count - 2) {
       footer.setVisibility(View.VISIBLE);
       if (((lastIndex - 1) % 10 == 0 || lastIndex % 10 == 0) && count > 2) {
         footer.findViewById(R.id.footer_progressBar).setVisibility(View.VISIBLE);
         footer.findViewById(R.id.footer_hint).setVisibility(View.GONE);
         if (footerState != LOADING_MORE) {
           refreshListener.onShowNextPage();
           footerState = LOADING_MORE;
         }
       } else {
         footer.findViewById(R.id.footer_progressBar).setVisibility(View.GONE);
         footer.findViewById(R.id.footer_hint).setVisibility(View.VISIBLE);
       }
     }
   }
 }
Пример #14
0
  /**
   * 子控件为ListView等时,ACTION_MOVE执行几次后this.disallowIntercept=true;
   * 造成的影响:用户体验不好!(如果从中间滑到顶部或底部是不会进入onInterceptTouchEvent方法的,拦截不到事件,不能执行刷新加载相关功能)
   * 解决办法:重写requestDisallowInterceptTouchEvent,过滤disallowIntercept=true。
   * 缺点:这样会导致子控件调用parent.requestDisallowInterceptTouchEvent(true)失效。
   *
   * <p>ViewGroup类dispatchTouchEvent方法关键代码: final boolean disallowIntercept = (mGroupFlags &
   * FLAG_DISALLOW_INTERCEPT) != 0; if (!disallowIntercept) { intercepted =
   * onInterceptTouchEvent(ev); }
   *
   * @param ev
   * @return
   */
  @Override
  public boolean onInterceptTouchEvent(MotionEvent ev) {
    printLog("parent onInterceptTouchEvent:" + ev.getAction());
    int action = ev.getAction();
    if (pullView.doMainType == pullView.NONE && action == MotionEvent.ACTION_DOWN) {
      reset();
    }
    if (pullView.doMainType == pullView.REFRESHING || pullView.doMainType == pullView.LOADING) {
      printLog("parent onInterceptTouchEvent result:" + !refreshingOrLoadingOverScrollEnabled);
      return !refreshingOrLoadingOverScrollEnabled;
    }
    printLog("parent onInterceptTouchEvent result:" + isGetFinalDirection);
    if (isGetFinalDirection) {
      //            getParent().requestDisallowInterceptTouchEvent(true);
      return true;
    }
    // 得到可能的方向
    if (this.direction.type == Direction.NONE && this.directionEnable.type != Direction.NONE) {
      this.startY = ev.getY();
      printLog("startY:" + startY);
      for (View view : conditionChildViews) {
        printLog(view.getClass().getSimpleName());
        if (view instanceof AbsListView) {
          AbsListView absListView = (AbsListView) view;
          Direction direction = new Direction();
          View firstView = absListView.getChildAt(0);
          View lastView = absListView.getChildAt(absListView.getChildCount() - 1);
          if (firstView == null
              || (absListView.getFirstVisiblePosition() == 0
                  && firstView.getTop() >= view.getTop())) {
            printLog("顶部");
            direction.addDirection(Direction.DOWN_PULL);
          }
          if (lastView == null
              || (absListView.getLastVisiblePosition() == (absListView.getCount() - 1)
                  && lastView.getBottom() <= view.getBottom())) {
            printLog("底部");
            direction.addDirection(Direction.UP_PULL);
          }
          if (direction.type == Direction.NONE) {
            this.direction.type = Direction.NONE;
            printLog("NONE");
            break;
          }
          this.direction.configDirection(direction.type);
        } else if (view instanceof ScrollView) {
          ScrollView scrollView = (ScrollView) view;
          Direction direction = new Direction();
          int scrollY = view.getScrollY();
          int height = view.getHeight();
          int scrollViewMeasuredHeight = scrollView.getChildAt(0).getMeasuredHeight();
          if (scrollY == 0) {
            printLog("顶部");
            direction.addDirection(Direction.DOWN_PULL);
          }
          if ((scrollY + height) == scrollViewMeasuredHeight) {
            printLog("底部");
            direction.addDirection(Direction.UP_PULL);
          }
          if (direction.type == Direction.NONE) {
            this.direction.type = Direction.NONE;
            printLog("NONE");
            break;
          }
          this.direction.configDirection(direction.type);
        } else {
          if (view.getScrollY() == 0) {
            printLog("顶部");
            direction.addDirection(Direction.DOWN_PULL);
          }
          if (true) { // TODO 哈哈(待修改)
            printLog("底部");
            direction.addDirection(Direction.UP_PULL);
          }
          if (direction.type == Direction.NONE) {
            this.direction.type = Direction.NONE;
            printLog("NONE");
            break;
          }
          this.direction.configDirection(direction.type);
        }
      }
      this.direction.takeIntersection(this.directionEnable);
    }
    // 得到最终方向
    else if (this.direction.type != Direction.NONE) {
      findFinalDirection(ev);
    }

    return false;
  }
    @Override
    public void onScrollStateChanged(final AbsListView view, int scrollState) {
      super.onScrollStateChanged(view, scrollState);
      if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
        int currentFirstVisiblePosition = view.getFirstVisiblePosition();
        if (currentFirstVisiblePosition == 0) {
          // 滚动到顶部
          View v = (View) view.getChildAt(0);
          int[] location = new int[2];
          // 获取在整个屏幕内的绝对坐标
          v.getLocationOnScreen(location);
          int y = location[1];
          if (currentFirstVisiblePosition != firstVisiblePosition && firstLocationY != y) {
            // 第一次拖至顶部
            firstVisiblePosition = currentFirstVisiblePosition;
            firstLocationY = y;
            return;
          } else if (currentFirstVisiblePosition == firstVisiblePosition && firstLocationY == y) {
            User firstUser = personList.get(0);
            // 第二次拖至顶部
            logic.queryUser(
                queryType,
                queryValue,
                ORDER_BY_NEWEST,
                firstUser.getLastLoginTime(),
                8,
                createUIEventListener(
                    new EventListener() {
                      @Override
                      public void onEvent(EventId id, EventArgs args) {
                        stopLoading();
                        UserEventArgs result = (UserEventArgs) args;
                        OperErrorCode errCode = result.getErrCode();
                        if (errCode == OperErrorCode.Success) {
                          List<User> userList = result.getUserList();
                          if (userList != null && userList.size() > 0) {
                            personList.addAll(0, userList);
                            imageAdapter.notifyDataSetChanged();
                            personsGridView.smoothScrollToPosition(0);
                          }
                        }
                      }
                    }));
            startLoading();
          }
        } else {
          int currentLastVisiblePosition = view.getLastVisiblePosition();
          if (currentLastVisiblePosition == (view.getCount() - 1)) {
            // 滚动到底部
            View v = (View) view.getChildAt(view.getChildCount() - 1);
            int[] location = new int[2];
            // 获取在整个屏幕内的绝对坐标
            v.getLocationOnScreen(location);
            int y = location[1];
            if (currentLastVisiblePosition != lastVisiblePosition && lastLocationY != y) {
              // 第一次拖至底部
              lastVisiblePosition = currentLastVisiblePosition;
              lastLocationY = y;
              return;
            } else if (currentLastVisiblePosition == lastVisiblePosition && lastLocationY == y) {
              // 第二次拖至底部
              User lastUser = personList.get(personList.size() - 1);
              // 第二次拖至顶部
              logic.queryUser(
                  queryType,
                  queryValue,
                  ORDER_BY_EARLIEST,
                  lastUser.getLastLoginTime(),
                  8,
                  createUIEventListener(
                      new EventListener() {
                        @Override
                        public void onEvent(EventId id, EventArgs args) {
                          stopLoading();
                          UserEventArgs result = (UserEventArgs) args;
                          OperErrorCode errCode = result.getErrCode();
                          if (errCode == OperErrorCode.Success) {
                            List<User> userList = result.getUserList();
                            if (userList != null && userList.size() > 0) {
                              personList.addAll(userList);
                              imageAdapter.notifyDataSetChanged();
                              personsGridView.smoothScrollToPosition(view.getCount());
                            }
                          }
                        }
                      }));
              startLoading();
            }
          }
        }

        // 未滚动到顶部
        firstVisiblePosition = -1;
        firstLocationY = 0;
        // 未滚动到底部
        lastVisiblePosition = 0;
        lastLocationY = 0;
      }
    }