コード例 #1
0
  public void setLoadingMore(boolean loading) {
    isLoading = loading;
    if (loading) {

      if (isRefreshing()) {
        return;
      }
      if (mListView.getFooterViewsCount() == 0) {
        mListView.addFooterView(mListViewFooter);
      }
      mListView.setSelection(mListView.getAdapter().getCount() - 1);
      showMaterialProgressBar();
      //            if (isRefreshing()) {
      //                setRefreshing(false);
      //            }
      //            if (mListView.getFooterViewsCount() == 0) {
      //                mListView.addFooterView(mListViewFooter);
      //                mListView.setSelection(mListView.getAdapter().getCount() - 1);
      //            } else {
      //                mListViewFooter.setVisibility(VISIBLE);
      //                showMaterialProgressBar();
      //                //mListView.addFooterView(mListViewFooter);
      //            }
    } else {
      //            if (mListView.getAdapter() instanceof HeaderViewListAdapter) {
      //                mListView.removeFooterView(mListViewFooter);
      //            } else {
      //                mListViewFooter.setVisibility(View.GONE);
      //            }
      mListView.removeFooterView(mListViewFooter);
      mYDown = 0;
      mLastY = 0;
    }
  }
コード例 #2
0
 /** 展示搜索到的词书列表 */
 private void showResultList(SearchResultBooksInfo booksInfo) {
   mHasMeasured = false;
   ResultBooksAdapter resultBooksAdapter = new ResultBooksAdapter(this, booksInfo);
   if (mResultBooksListView.getFooterViewsCount() == 0) {
     mResultBooksListView.addFooterView(
         View.inflate(SearchActivity.this, R.layout.footer_search_result, null));
   }
   mResultBooksListView.setAdapter(resultBooksAdapter);
   mResultBooksCountTextView.setText(booksInfo.getBooksCount() + "条搜索结果");
 }
コード例 #3
0
 private void updateList() {
   View footerView = getFooterView();
   if (mListView.getFooterViewsCount() == 0) {
     mListView.addFooterView(footerView);
   }
   if (mSongAdapter == null) {
     mSongAdapter = new SongAdapter();
     mListView.setEmptyView(getEmptyView());
     mListView.setAdapter(mSongAdapter);
   } else {
     mSongAdapter.notifyDataSetChanged();
   }
 }
コード例 #4
0
  public static void CreateView() {
    Button btnLoadMore = new Button(context);
    btnLoadMore.setText("Load More");
    if (listView.getFooterViewsCount() == 0) listView.addFooterView(btnLoadMore);
    adapter = new MyCustomBaseAdapter(context, searchResults);
    listView.setAdapter(adapter);

    btnLoadMore.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View arg0) {
            if (ShowMore) {
              // progress.show();
              pageCount++;
              SearchOnDailyMotion(searchTerm, pageCount);
            } else {
              Toast.makeText(context, "More results not available", Toast.LENGTH_SHORT).show();
            }
          }
        });

    listView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> a, View v, int position, long id) {
            Object o = listView.getItemAtPosition(position);
            SearchResults fullObject = (SearchResults) o;
            if (fullObject.getProvider().compareTo("DailyMotion") == 0) {
              Intent myIntent = new Intent(context, MainActivity.class);
              myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              myIntent.putExtra("key", fullObject.getId());
              myIntent.putExtra("title", fullObject.getTitle());
              myIntent.putExtra("player", "DM");
              context.startActivity(myIntent);
            } else if (fullObject.getProvider().compareTo("Youtube") == 0) {
              Intent intent = new Intent(context, YTPlayerActivity.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              intent.putExtra("VIDEO_ID", fullObject.getId());
              context.startActivity(intent);
            } else if (fullObject.getProvider().compareTo("Vimeo") == 0) {
              Intent intent = new Intent(context, MainActivity.class);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              intent.putExtra("key", fullObject.getId());
              intent.putExtra("player", "Vimeo");
              context.startActivity(intent);
            }
          }
        });
  }
コード例 #5
0
  private void clearHistory() {
    if (!getHistoryOfSearchedLocations().isEmpty()) {
      getHistoryOfSearchedLocations().clear();

      // Save
      app.clearSearchedDestinations();

      if (historyListView.getFooterViewsCount() == 0) {
        historyListView.addFooterView(getEmptyHistoryFooter());
      }

      getDestionationHistoryAdapter().notifyDataSetChanged();

      showToast(res.getString(R.string.search_history_cleared));
    }
  }
コード例 #6
0
  private void removeFromHistory(cgDestination destination) {
    if (getHistoryOfSearchedLocations().contains(destination)) {
      getHistoryOfSearchedLocations().remove(destination);

      // Save
      app.removeSearchedDestinations(destination);

      if (getHistoryOfSearchedLocations().isEmpty()) {
        if (historyListView.getFooterViewsCount() == 0) {
          historyListView.addFooterView(getEmptyHistoryFooter());
        }
      }

      getDestionationHistoryAdapter().notifyDataSetChanged();

      showToast(res.getString(R.string.search_remove_destination));
    }
  }
コード例 #7
0
  private void updateListView() {
    if (mAdapter != null) {
      mAdapter.notifyDataSetChanged();
    }
    if (mWeiboList == null || mWeiboList.size() == 0) {

      return;
    }
    mListView.setVisibility(View.VISIBLE);
    if (mAdapter != null) {
      mAdapter.notifyDataSetChanged();
    }

    mAdapter = new MyFavoriteListAdapter(mContext, mWeiboList);
    if (mListView.getFooterViewsCount() == 0) {
      mFootView =
          (LinearLayout) LayoutInflater.from(this).inflate(R.layout.hometab_listview_footer, null);
      ProgressBar pb = (ProgressBar) mFootView.findViewById(R.id.hometab_addmore_progressbar);
      pb.setVisibility(View.GONE);
      mListView.addFooterView(mFootView);
    }

    mListView.setAdapter(mAdapter);
  }
コード例 #8
0
  @Override
  public boolean onTouch(View view, MotionEvent motionEvent) {
    if (mViewWidth < 2) {
      mViewWidth = mListView.getWidth();
    }

    switch (motionEvent.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        {
          if (mPaused) {
            return false;
          }

          if (mSwiping) {
            return true;
          }

          // TODO: ensure this is a finger, and set a flag

          // Find the child view that was touched (perform a hit test)
          Rect rect = new Rect();
          int childCount = mListView.getChildCount();
          int headerCount = mListView.getHeaderViewsCount();
          int footerCount = mListView.getFooterViewsCount();
          int[] listViewCoords = new int[2];
          mListView.getLocationOnScreen(listViewCoords);
          int x = (int) motionEvent.getRawX() - listViewCoords[0];
          int y = (int) motionEvent.getRawY() - listViewCoords[1];
          View child = null;
          for (int i = headerCount; i < (childCount - footerCount); i++) {
            child = mListView.getChildAt(i);
            child.getHitRect(rect);
            if (rect.contains(x, y)) {
              mDownView = child;
              break;
            }
          }

          if (mDownView != null) {

            mDownX = motionEvent.getRawX();
            mDownY = motionEvent.getRawY();
            mDownPosition = mListView.getPositionForView(mDownView);
            if (mDownPosition != ListView.INVALID_POSITION
                && mDownPosition < mListView.getAdapter().getCount()) {
              if (mListView.getAdapter().getItem(mDownPosition) instanceof Card) {
                if (mCallbacks.canDismiss(
                    mDownPosition, (Card) mListView.getAdapter().getItem(mDownPosition))) {
                  mVelocityTracker = VelocityTracker.obtain();
                  mVelocityTracker.addMovement(motionEvent);
                } else {
                  mDownView = null;
                }
              } else {
                mDownView = null;
              }
            } else {
              mDownView = null;
            }
          }
          view.onTouchEvent(motionEvent);
          return true;
          // return false;
        }

      case MotionEvent.ACTION_UP:
        {
          if (mVelocityTracker == null) {
            break;
          }

          float deltaX = motionEvent.getRawX() - mDownX;
          mVelocityTracker.addMovement(motionEvent);
          mVelocityTracker.computeCurrentVelocity(1000);
          float velocityX = mVelocityTracker.getXVelocity();
          float absVelocityX = Math.abs(velocityX);
          float absVelocityY = Math.abs(mVelocityTracker.getYVelocity());
          boolean dismiss = false;
          boolean dismissRight = false;
          if (Math.abs(deltaX) > mViewWidth / swipeDistanceDivisor && mSwiping) {
            dismiss = true;
            dismissRight = deltaX > 0;
          } else if (mMinFlingVelocity <= absVelocityX
              && absVelocityX <= mMaxFlingVelocity
              && absVelocityY < absVelocityX
              && mSwiping) {
            // dismiss only if flinging in the same direction as dragging
            dismiss = (velocityX < 0) == (deltaX < 0);
            dismissRight = mVelocityTracker.getXVelocity() > 0;
          }
          if (dismiss && mDownPosition != ListView.INVALID_POSITION) {
            // dismiss
            dismiss(mDownView, mDownPosition - mListView.getHeaderViewsCount(), dismissRight);

          } else {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(1)
                .setDuration(mAnimationTime)
                .setListener(null);
          }

          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          if (mSwiping) {
            // To prevent onClick event with a fast swipe
            mSwiping = false;
            return true;
          }
          mSwiping = false;
          break;
        }

      case MotionEvent.ACTION_CANCEL:
        {
          if (mVelocityTracker == null) {
            break;
          }

          if (mDownView != null) {
            // cancel
            mDownView
                .animate()
                .translationX(0)
                .alpha(1)
                .setDuration(mAnimationTime)
                .setListener(null);
          }
          mVelocityTracker.recycle();
          mVelocityTracker = null;
          mDownX = 0;
          mDownY = 0;
          mDownView = null;
          mDownPosition = ListView.INVALID_POSITION;
          mSwiping = false;
          break;
        }

      case MotionEvent.ACTION_MOVE:
        {
          if (mVelocityTracker == null || mPaused) {
            break;
          }

          mVelocityTracker.addMovement(motionEvent);
          float deltaX = motionEvent.getRawX() - mDownX;
          float deltaY = motionEvent.getRawY() - mDownY;
          boolean movementAllowed = isSwipeMovementAllowed(deltaX);
          if (Math.abs(deltaX) > mSlop
              && Math.abs(deltaY) < Math.abs(deltaX) / 2
              && movementAllowed) {
            mSwiping = true;
            mSwipingSlop = (deltaX > 0 ? mSlop : -mSlop);
            mListView.requestDisallowInterceptTouchEvent(true);

            // Cancel ListView's touch (un-highlighting the item)
            MotionEvent cancelEvent = MotionEvent.obtain(motionEvent);
            cancelEvent.setAction(
                MotionEvent.ACTION_CANCEL
                    | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT));
            mListView.onTouchEvent(cancelEvent);
            view.onTouchEvent(cancelEvent);
            cancelEvent.recycle();
          }

          if (mSwiping) {
            mDownView.setTranslationX(deltaX - mSwipingSlop);
            mDownView.setAlpha(Math.max(0f, Math.min(1f, 1f - 2f * Math.abs(deltaX) / mViewWidth)));
            return true;
          }
          break;
        }
    }
    return false;
  }
コード例 #9
0
 private void removeFootView(PullToRefreshListView plv, View footView) {
   ListView lv = plv.getRefreshableView();
   if (lv.getFooterViewsCount() > 1) {
     lv.removeFooterView(footView);
   }
 }
コード例 #10
0
 private void addFootView(PullToRefreshListView plv, View footView) {
   ListView lv = plv.getRefreshableView();
   if (lv.getFooterViewsCount() == 1) {
     lv.addFooterView(footView);
   }
 }
コード例 #11
0
ファイル: ViewUtils.java プロジェクト: hak/Rebuild
 public static void addFooterView(ListView listView, View view) {
   if (listView == null || listView.getFooterViewsCount() != 0 || view == null) {
     return;
   }
   listView.addFooterView(view, null, false);
 }