@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 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);
     }
   }
 }
  @Override
  public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (scrollState == SCROLL_STATE_IDLE
        && view.getLastVisiblePosition() >= view.getCount() - THRESHOLD
        && !mLoding) {
      mLoding = true;

      loadPhotos();
    }
  }
 @Override
 public boolean isScrolledToTop(View view) {
   AbsListView absListView = (AbsListView) view;
   if (absListView.getCount() == 0) {
     return true;
   } else if (absListView.getFirstVisiblePosition() == 0) {
     final View firstVisibleChild = absListView.getChildAt(0);
     return firstVisibleChild != null && firstVisibleChild.getTop() >= 0;
   }
   return false;
 }
Пример #5
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;
   }
 }
Пример #6
0
 /**
  * Copy From AbsListView (API Level >= 19)
  *
  * @param absListView AbsListView
  * @param direction Negative to check scrolling up, positive to check scrolling down.
  * @return true if the list can be scrolled in the specified direction, false otherwise
  */
 private boolean absListViewCanScrollList(AbsListView absListView, int direction) {
   final int childCount = absListView.getChildCount();
   if (childCount == 0) {
     return false;
   }
   final int firstPosition = absListView.getFirstVisiblePosition();
   if (direction > 0) { // can scroll down
     final int lastBottom = absListView.getChildAt(childCount - 1).getBottom();
     final int lastPosition = firstPosition + childCount;
     return lastPosition < absListView.getCount()
         || lastBottom > absListView.getHeight() - absListView.getPaddingTop();
   } else { // can scroll  up
     final int firstTop = absListView.getChildAt(0).getTop();
     return firstPosition > 0 || firstTop < absListView.getPaddingTop();
   }
 }
Пример #7
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;
   }
 }
Пример #8
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);
   }
 }
Пример #10
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;
   }
 }
 @Override
 public void onScrollStateChanged(AbsListView view, int scrollState) {
   if (view.getCount() == 0) return;
   switch (scrollState) {
     case SCROLL_STATE_IDLE:
       {
         mListScrollStarted = false;
         break;
       }
     case SCROLL_STATE_TOUCH_SCROLL:
       {
         final View firstChild = view.getChildAt(0);
         mFirstVisibleItem = view.getFirstVisiblePosition();
         mFirstVisibleTop = firstChild.getTop();
         mFirstVisibleBottom = firstChild.getBottom();
         mFirstVisibleHeight = firstChild.getHeight();
         mListScrollStarted = true;
         mTotalScrollDistance = 0;
         break;
       }
   }
 }
Пример #12
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);
       }
     }
   }
 }
Пример #13
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;
      }
    }