Esempio n. 1
0
  @Override
  public void getItemOffsets(
      Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int position = parent.getChildAdapterPosition(view);
    outRect.left = mSpace;
    outRect.right = mSpace;
    outRect.top = 0;
    outRect.bottom = mSpace;

    if (parent.getLayoutManager() instanceof StaggeredGridLayoutManager) {
      outRect.left = 0;
      outRect.right = 0;
      outRect.top = 0;
      outRect.bottom = 0;
      if (position < ((StaggeredGridLayoutManager) parent.getLayoutManager()).getSpanCount()) {
        // 利用item的margin配合RecyclerView的margin值使得间隔相等,这里只需设第一行item的相对顶部的高度
        outRect.top = mSpace;
      }
    } else if (parent.getLayoutManager() instanceof GridLayoutManager) {
      if (position < ((GridLayoutManager) parent.getLayoutManager()).getSpanCount()) {
        // 保证第一行有相对顶部有高度
        outRect.top = mSpace;
      }
    } else if (parent.getLayoutManager() instanceof LinearLayoutManager) {
      if (position == 0) {
        // 保证第一行有相对顶部有高度
        outRect.top = mSpace;
      }
    }
  }
Esempio n. 2
0
 @Override
 public void onItemClicked(ItemAdapter itemAdapter, RssItem rssItem) {
   int positionToExpand = -1;
   int positionToContract = -1;
   if (itemAdapter.getExpandedItem() != null) {
     positionToContract = currentItems.indexOf(itemAdapter.getExpandedItem());
     View viewToContract = recyclerView.getLayoutManager().findViewByPosition(positionToContract);
     if (viewToContract == null) {
       positionToContract = -1;
     }
   }
   if (itemAdapter.getExpandedItem() != rssItem) {
     positionToExpand = currentItems.indexOf(rssItem);
     itemAdapter.setExpandedItem(rssItem);
   } else {
     itemAdapter.setExpandedItem(null);
   }
   if (positionToContract > -1) {
     itemAdapter.notifyItemChanged(positionToContract);
   }
   if (positionToExpand > -1) {
     itemAdapter.notifyItemChanged(positionToExpand);
     delegate.get().onItemExpanded(this, itemAdapter.getExpandedItem());
   } else {
     delegate.get().onItemContracted(this, rssItem);
     return;
   }
   View viewToExpand = recyclerView.getLayoutManager().findViewByPosition(positionToExpand);
   int lessToScroll = 0;
   if (positionToContract > -1 && positionToContract < positionToExpand) {
     lessToScroll = itemAdapter.getExpandedItemHeight() - itemAdapter.getCollapsedItemHeight();
   }
   recyclerView.smoothScrollBy(0, viewToExpand.getTop() - lessToScroll);
 }
Esempio n. 3
0
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

          super.onScrolled(recyclerView, dx, dy);

          int visibleItemCount = mRecycler.getLayoutManager().getChildCount();
          int totalItemCount = mRecycler.getLayoutManager().getItemCount();
          int pastVisibleItems =
              ((GridLayoutManager) mRecycler.getLayoutManager()).findFirstVisibleItemPosition();

          if ((visibleItemCount + pastVisibleItems) >= totalItemCount
              && !MainActivity.mEventsPresenter.isLoading()) {
            MainActivity.mEventsPresenter.onEndListReached();
          }

          // Is scrolling up
          if (dy > 10) {

            if (!flag) {
              // showToolbar();
              flag = true;
            }

            // Is scrolling down
          } else if (dy < -10) {

            if (flag) {
              // hideToolbar();
              flag = false;
            }
          }
        }
  public DataAdapter(List<Student> students, RecyclerView recyclerView) {
    studentList = students;

    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {

      final LinearLayoutManager linearLayoutManager =
          (LinearLayoutManager) recyclerView.getLayoutManager();

      recyclerView.addOnScrollListener(
          new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);

              totalItemCount = linearLayoutManager.getItemCount();
              lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
              if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) {
                // End has been reached
                // Do something
                if (onLoadMoreListener != null) {
                  onLoadMoreListener.onLoadMore();
                }
                loading = true;
              }
            }
          });
    }
  }
  public SurveysRcvAdapter(final List<SurveyData> data, RecyclerView recyclerView, String type) {
    this.data = data;
    this.type = type;

    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
      final LinearLayoutManager linearLayoutManager =
          (LinearLayoutManager) recyclerView.getLayoutManager();

      recyclerView.addOnScrollListener(
          new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);
              if (onSwipe) {
                pages = 1;
                isLoading = false;
              }
              totalItemCount = linearLayoutManager.getItemCount();
              lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
              //                    Log.e(debugTag, "Is Loading: "+isLoading+" Total items:
              // "+totalItemCount+" Last visible item: "+lastVisibleItem+" Visible Threshold:
              // "+visibleThreshold);
              if (!isLoading && totalItemCount <= lastVisibleItem + visibleThreshold) {
                if (onLoadMoreListener != null) {
                  onLoadMoreListener.onLoadMore(pages * 20);
                  pages++;
                }
                isLoading = true;
              }
              onSwipe = false;
            }
          });
    }
  }
Esempio n. 6
0
  /**
   * Constructor.
   *
   * @param pPhotoList the initial list of photos.
   * @param pFragmentType the type of fragment using the adapter.
   * @param pPhotoAdapterListener the listener for events on the photo cards.
   * @param recyclerView the RecyclerView.
   * @param fragment the fragment using the adapter.
   */
  public PhotoAdapter(
      List<PhotoInfo> pPhotoList,
      AbelanaClient.PhotoListType pFragmentType,
      PhotoAdapterListener pPhotoAdapterListener,
      RecyclerView recyclerView,
      PicturesFragment fragment) {
    this.mPhotoList = pPhotoList;
    this.mFragmentType = pFragmentType;
    this.mListener = pPhotoAdapterListener;
    this.mFragment = fragment;

    if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) {

      final LinearLayoutManager linearLayoutManager =
          (LinearLayoutManager) recyclerView.getLayoutManager();
      recyclerView.setOnScrollListener(
          new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
              super.onScrolled(recyclerView, dx, dy);

              mTotalItemCount = linearLayoutManager.getItemCount();
              mLastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
              if (!mLoading && mTotalItemCount <= (mLastVisibleItem + mVisibleThreshold)) {
                // End has been reached
                // Do something
                if (mOnLoadMoreListener != null) {
                  mOnLoadMoreListener.onLoadMore();
                }
                mLoading = true;
              }
            }
          });
    }
  }
 private int getOrientation(RecyclerView parent) {
   if (parent.getLayoutManager() instanceof LinearLayoutManager) {
     LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
     return layoutManager.getOrientation();
   } else {
     throw new IllegalStateException(
         "ColorDividerItemDecoration can only be used with a LinearLayoutManager.");
   }
 }
  /**
   * Sets the content spans of grid count of this view
   *
   * @param span
   */
  public void setContentSpan(int span) {
    if (span < 1) return;
    if (mContentWrapper.getLayoutManager() == null) return;

    RecyclerView.LayoutManager lManager = mContentWrapper.getLayoutManager();
    if (lManager instanceof GridLayoutManager) {
      ((GridLayoutManager) lManager).setSpanCount(span);
      mContentWrapper.invalidate();
    }
  }
Esempio n. 9
0
  private void goUp() {
    if (adapter.dataSet.posts != null) {

      int position = 0;
      int currentOrientation = getResources().getConfiguration().orientation;
      RecyclerView.SmoothScroller smoothScroller = null;
      if (rv.getLayoutManager() instanceof LinearLayoutManager
          && currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
        position = ((LinearLayoutManager) rv.getLayoutManager()).findFirstVisibleItemPosition();
        smoothScroller = new TopSnappedSmoothScroller(rv.getContext(), rv.getLayoutManager());

      } else if (rv.getLayoutManager() instanceof CatchStaggeredGridLayoutManager) {
        int[] firstVisibleItems = null;
        firstVisibleItems =
            ((CatchStaggeredGridLayoutManager) rv.getLayoutManager())
                .findFirstVisibleItemPositions(firstVisibleItems);
        if (firstVisibleItems != null && firstVisibleItems.length > 0) {
          position = firstVisibleItems[0];
          (rv.getLayoutManager())
              .smoothScrollToPosition(rv, new RecyclerView.State(), position - 1);
          return;
        }
      } else {
        position =
            ((PreCachingLayoutManager) rv.getLayoutManager())
                .findFirstCompletelyVisibleItemPosition();
        smoothScroller = new TopSnappedSmoothScroller(rv.getContext(), rv.getLayoutManager());
      }

      if (smoothScroller != null) {
        smoothScroller.setTargetPosition(position - 1);
        (rv.getLayoutManager()).startSmoothScroll(smoothScroller);
      }
    }
  }
Esempio n. 10
0
  /**
   * Sets the orientation of content display of this view
   *
   * @param orientation
   */
  public void setContentOrientation(int orientation) {
    if (orientation != CONTENT_ORIENTATION_HORIZONTAL
        && orientation != CONTENT_ORIENTATION_VERTICAL) return;
    if (mContentWrapper.getLayoutManager() == null) return;

    RecyclerView.LayoutManager lManager = mContentWrapper.getLayoutManager();
    if (lManager instanceof GridLayoutManager) {
      ((GridLayoutManager) lManager).setOrientation(orientation);
      mContentOrientation = orientation;
      mContentWrapper.invalidate();
    }
  }
 public int findFirstVisibleItemPosition() {
   switch (type) {
     case LinearLayout:
       return ((LinearLayoutManager) recyclerView.getLayoutManager())
           .findFirstVisibleItemPosition();
     case Grid:
       return ((GridLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
     case LinearLayoutWithHeaders:
       return ((LayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
     default:
       throw new IllegalStateException(
           "Type of layoutManager unknown." + "In this case this method needs to be overridden");
   }
 }
Esempio n. 12
0
  /*
  One simple method
   */
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int firstVisibleItem =
        ((LinearLayoutManager) recyclerView.getLayoutManager()).findFirstVisibleItemPosition();
    if (firstVisibleItem == 0) {
      if (!controlsVisible) {
        onShow();
        controlsVisible = true;
      }
    } else {
      if (scrolledDistance < -HIDE_THRESHOLD && !controlsVisible) {
        onShow();
        scrolledDistance = 0;
        controlsVisible = true;
      } else if (scrolledDistance > HIDE_THRESHOLD && controlsVisible) {
        onHide();
        controlsVisible = false;
        scrolledDistance = 0;
      }
    }

    if ((controlsVisible && dy > 0) || (!controlsVisible && dy < 0)) {
      scrolledDistance += dy;
    }
  }
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
          if (dy == 0 || recyclerView.getChildCount() <= 0) return;

          LinearLayoutManager linearLayoutManager =
              (LinearLayoutManager) recyclerView.getLayoutManager();
          int firstVisibleItem = linearLayoutManager.findFirstVisibleItemPosition();
          int lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
          int visibleItemCount = lastVisibleItem - firstVisibleItem;
          int totalItemCount = recyclerView.getAdapter().getItemCount();

          NewsListRecyclerAdapter adapter = (NewsListRecyclerAdapter) recyclerView.getAdapter();

          // Set the item at top to read
          ViewHolder vh =
              (ViewHolder) recyclerView.findViewHolderForLayoutPosition(firstVisibleItem);
          if (vh != null && !vh.shouldStayUnread()) {
            adapter.ChangeReadStateOfItem(vh, true);
          }

          // Check if Listview is scrolled to bottom
          if (lastVisibleItem == (totalItemCount - 1)
              && recyclerView.getChildAt(visibleItemCount).getBottom()
                  <= recyclerView.getHeight()) {
            for (int i = firstVisibleItem + 1; i <= lastVisibleItem; i++) {
              vh = (ViewHolder) recyclerView.findViewHolderForLayoutPosition(i);
              if (vh != null && !vh.shouldStayUnread()) {
                adapter.ChangeReadStateOfItem(vh, true);
              }
            }
          }
        }
  @Override
  public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
    visibleItemCount = recyclerView.getChildCount();
    totalItemCount = gridLayoutManager.getItemCount();
    firstVisibleItem = gridLayoutManager.findFirstVisibleItemPosition();

    if (isVisible && scrollDist > MINIMUM) {
      onHideShow(true);
      scrollDist = 0;
      isVisible = false;
    } else if (!isVisible && scrollDist < -MINIMUM) {
      onHideShow(false);
      scrollDist = 0;
      isVisible = true;
    }
    if ((isVisible && dy > 0) || (!isVisible && dy < 0)) {
      scrollDist += dy;
    }

    if (loading) {
      if (totalItemCount > previousTotal + 1) {
        loading = false;
        previousTotal = totalItemCount;
      }
    }
    if (!loading && (totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold)) {
      // End has been reached
      // Do something
      current_page++;
      onLoadMore(current_page, totalItemCount);
      loading = true;
    }
  }
  /**
   * 设置每个条目占用的列数
   *
   * @param recyclerView recycleView
   */
  private void setSpanCount(RecyclerView recyclerView) {
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManager == null) {
      Log.e(TAG, "LayoutManager 为空,请先设置 recycleView.setLayoutManager(...)");
    }

    // 网格布局
    if (layoutManager instanceof GridLayoutManager) {
      final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
      gridLayoutManager.setSpanSizeLookup(
          new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
              int type = getItemViewType(position);
              if (type == TYPE_NORMAL_ITEM) {
                return 1;
              } else {
                return gridLayoutManager.getSpanCount();
              }
            }
          });
    }

    // 瀑布流布局
    if (layoutManager instanceof StaggeredGridLayoutManager) {
      mStaggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
    }
  }
Esempio n. 16
0
 public void saveScrollPosition() {
   if (crumb == null) return;
   crumb.setScrollPosition(
       ((GridLayoutManager) mRecyclerView.getLayoutManager()).findFirstVisibleItemPosition());
   final View firstChild = mRecyclerView.getChildAt(0);
   if (firstChild != null) crumb.setScrollOffset((int) firstChild.getY());
 }
Esempio n. 17
0
 private boolean isLastRow(RecyclerView parent, int pos, int spanCount, int childCount) {
   RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
   if (layoutManager instanceof GridLayoutManager) {
     childCount = childCount - childCount % spanCount;
     if (pos >= childCount) {
       return true;
     }
   } else if (layoutManager instanceof StaggeredGridLayoutManager) {
     int orentation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
     if (orentation == StaggeredGridLayoutManager.HORIZONTAL) { // 水平
       if ((pos + 1) % spanCount == 0) {
         return true;
       }
     } else { // 垂直
       childCount = childCount - childCount % spanCount;
       if (pos >= childCount) {
         return true;
       }
     }
   } else if (layoutManager instanceof LinearLayoutManager) {
     if (pos + 1 == childCount) {
       return true;
     }
   }
   return false;
 }
  private void FadingOutOtherItems(PopupMenu popupMenu) {
    // Dim out all the other list items if they exist
    LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
    int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
    int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
    for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) {
      if (i == mHolder.getLayoutPosition()) continue;
      RecyclerViewHolder viewHolder =
          (RecyclerViewHolder) mRecyclerView.findViewHolderForLayoutPosition(i);
      View itemView = viewHolder.getItemView();
      itemView.clearAnimation();
      itemView.startAnimation(mFadeOut);
    }

    // Make sure to bring them back to normal after the menu is gone
    popupMenu.setOnDismissListener(
        new PopupMenu.OnDismissListener() {
          @Override
          public void onDismiss(PopupMenu popupMenu) {
            LinearLayoutManager layoutManager =
                (LinearLayoutManager) mRecyclerView.getLayoutManager();
            int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();
            int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition();
            for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) {
              if (i == mHolder.getLayoutPosition()) continue;
              RecyclerViewHolder viewHolder =
                  (RecyclerViewHolder) mRecyclerView.findViewHolderForLayoutPosition(i);
              View itemView = viewHolder.getItemView();
              viewHolder.getLayoutPosition();
              itemView.clearAnimation();
              itemView.startAnimation(mFadeIn);
            }
          }
        });
  }
 @Override
 public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
   super.onScrolled(recyclerView, dx, dy);
   LinearLayoutManager mLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
   lastVisibleItem = mLayoutManager.findLastVisibleItemPosition();
   pulldown = (dy > 0);
 }
  public boolean shouldHandleRecyclerViewLoadingMore(RecyclerView recyclerView) {
    if (mIsLoadingMore
        || mCurrentRefreshStatus == RefreshStatus.REFRESHING
        || mLoadMoreFooterView == null
        || mDelegate == null
        || recyclerView.getAdapter() == null
        || recyclerView.getAdapter().getItemCount() == 0) {
      return false;
    }

    RecyclerView.LayoutManager manager = recyclerView.getLayoutManager();
    if (manager == null || manager.getItemCount() == 0) {
      return false;
    }

    if (manager instanceof LinearLayoutManager) {
      LinearLayoutManager layoutManager = (LinearLayoutManager) manager;
      if (layoutManager.findLastCompletelyVisibleItemPosition()
          == recyclerView.getAdapter().getItemCount() - 1) {
        return true;
      }
    } else if (manager instanceof StaggeredGridLayoutManager) {
      StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) manager;

      int[] out = layoutManager.findLastCompletelyVisibleItemPositions(null);
      int lastPosition = layoutManager.getItemCount() - 1;
      for (int position : out) {
        if (position == lastPosition) {
          return true;
        }
      }
    }
    return false;
  }
Esempio n. 21
0
 private void restoreScrollPosition() {
   if (crumb == null) return;
   final int scrollY = crumb.getScrollPosition();
   if (scrollY > -1 && scrollY < getAdapter().getItemCount()) {
     ((GridLayoutManager) mRecyclerView.getLayoutManager())
         .scrollToPositionWithOffset(scrollY, crumb.getScrollOffset());
   }
 }
Esempio n. 22
0
  @Override
  public void onLoadFinished(android.support.v4.content.Loader<Cursor> loader, Cursor cursor) {
    mAdapter.changeCursor(cursor);
    mRecyclerView.getLayoutManager().scrollToPosition(0);

    mEmptyView.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.insert_first_item));
    if (mAdapter.getItemCount() != 0) mEmptyView.clearAnimation();
  }
  /**
   * Computes the offsets based on the vertical and horizontal spacing values. The spacing
   * computation has to ensure that the lane sizes are the same after applying the offsets. This
   * means we have to shift the spacing unevenly across items depending on their position in the
   * layout.
   */
  public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
    final BaseLayoutManager lm = (BaseLayoutManager) parent.getLayoutManager();

    lm.getLaneForPosition(mTempLaneInfo, itemPosition, TwoWayLayoutManager.Direction.END);
    final int lane = mTempLaneInfo.startLane;
    final int laneSpan = lm.getLaneSpanForPosition(itemPosition);
    final int laneCount = lm.getLanes().getCount();
    final int itemCount = parent.getAdapter().getItemCount();

    final boolean isVertical = lm.isVertical();

    final boolean firstLane = (lane == 0);
    final boolean secondLane = isSecondLane(lm, itemPosition, lane);

    final boolean lastLane = (lane + laneSpan == laneCount);
    final boolean beforeLastLane = (lane + laneSpan == laneCount - 1);

    final int laneSpacing = (isVertical ? mHorizontalSpacing : mVerticalSpacing);

    final int laneOffsetStart;
    final int laneOffsetEnd;

    if (firstLane) {
      laneOffsetStart = 0;
    } else if (lastLane && !secondLane) {
      laneOffsetStart = (int) (laneSpacing * 0.75);
    } else if (secondLane && !lastLane) {
      laneOffsetStart = (int) (laneSpacing * 0.25);
    } else {
      laneOffsetStart = (int) (laneSpacing * 0.5);
    }

    if (lastLane) {
      laneOffsetEnd = 0;
    } else if (firstLane && !beforeLastLane) {
      laneOffsetEnd = (int) (laneSpacing * 0.75);
    } else if (beforeLastLane && !firstLane) {
      laneOffsetEnd = (int) (laneSpacing * 0.25);
    } else {
      laneOffsetEnd = (int) (laneSpacing * 0.5);
    }

    final boolean isFirstInLane = isFirstChildInLane(lm, itemPosition);
    final boolean isLastInLane =
        !mAddSpacingAtEnd && isLastChildInLane(lm, itemPosition, itemCount);

    if (isVertical) {
      outRect.left = laneOffsetStart;
      outRect.top = (isFirstInLane ? 0 : mVerticalSpacing / 2);
      outRect.right = laneOffsetEnd;
      outRect.bottom = (isLastInLane ? 0 : mVerticalSpacing / 2);
    } else {
      outRect.left = (isFirstInLane ? 0 : mHorizontalSpacing / 2);
      outRect.top = laneOffsetStart;
      outRect.right = (isLastInLane ? 0 : mHorizontalSpacing / 2);
      outRect.bottom = laneOffsetEnd;
    }
  }
Esempio n. 24
0
 @Override
 public void onFocusChange(View v, boolean hasFocus) {
   if (v instanceof TextView) {
     if (hasFocus) {
     } else {
       mRecyclerView.getLayoutManager().findViewByPosition(0).requestFocus();
     }
   }
 }
Esempio n. 25
0
 // 返回列数
 private int getSpanCount(RecyclerView parent) {
   int spanCount = 1;
   RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
   if (layoutManager instanceof StaggeredGridLayoutManager) {
     spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
   } else if (layoutManager instanceof GridLayoutManager) {
     spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
   }
   return spanCount;
 }
Esempio n. 26
0
 // This method would check that the recyclerview scroll has reached the bottom or not
 private boolean isLastItemDisplaying(RecyclerView recyclerView) {
   if (recyclerView.getAdapter().getItemCount() != 0) {
     int lastVisibleItemPosition =
         ((LinearLayoutManager) recyclerView.getLayoutManager())
             .findLastCompletelyVisibleItemPosition();
     if (lastVisibleItemPosition != RecyclerView.NO_POSITION
         && lastVisibleItemPosition == recyclerView.getAdapter().getItemCount() - 1) return true;
   }
   return false;
 }
 private boolean isLayoutManagerReversed(RecyclerView recycler) {
   boolean reversed = false;
   RecyclerView.LayoutManager manager = recycler.getLayoutManager();
   if (manager instanceof LinearLayoutManager) {
     reversed = ((LinearLayoutManager) manager).getReverseLayout();
   } else if (manager instanceof StaggeredGridLayoutManager) {
     reversed = ((StaggeredGridLayoutManager) manager).getReverseLayout();
   }
   return reversed;
 }
Esempio n. 28
0
 void handleDragScroll(RecyclerView rv, DragInfo dragInfo) {
   if (rv.getLayoutManager().canScrollHorizontally()) {
     if (rv.canScrollHorizontally(-1) && dragInfo.shouldScrollLeft()) {
       rv.scrollBy(-SCROLL_AMOUNT, 0);
       dragManager.clearNextMove();
     } else if (rv.canScrollHorizontally(1) && dragInfo.shouldScrollRight(rv.getWidth())) {
       rv.scrollBy(SCROLL_AMOUNT, 0);
       dragManager.clearNextMove();
     }
   } else if (rv.getLayoutManager().canScrollVertically()) {
     if (rv.canScrollVertically(-1) && dragInfo.shouldScrollUp()) {
       rv.scrollBy(0, -SCROLL_AMOUNT);
       dragManager.clearNextMove();
     } else if (rv.canScrollVertically(1) && dragInfo.shouldScrollDown(rv.getHeight())) {
       rv.scrollBy(0, SCROLL_AMOUNT);
       dragManager.clearNextMove();
     }
   }
 }
Esempio n. 29
0
  public void sendMessage(View v) {
    final String newMessageTmp = mNewMessage.getText().toString().trim();

    if (newMessageTmp.length() > 0) {
      // Criando uma nova mensagem
      final Message tmpMsg = new Message(mNumeroChatAtivo, newMessageTmp, 1, 1);

      // Salvando no SQLite
      ContentValues contentValues = new ContentValues();
      contentValues.put("numero", tmpMsg.getNumber());
      contentValues.put("msg", tmpMsg.getMessage());
      contentValues.put("lida", tmpMsg.getWasRead());
      contentValues.put("ehMinha", tmpMsg.getIsMine());

      long insertId = mBD.insert("mensagens", contentValues);

      // Adicionando o id insertado na tmpMsg
      tmpMsg.setId(insertId);

      // Limpando o editText
      mNewMessage.setText("");

      // Adicionando a nova mensagem
      ((ChatAdapter) mRecyclerView.getAdapter()).addItemList(tmpMsg, mListMessage.size());
      mRecyclerView
          .getLayoutManager()
          .scrollToPosition(mRecyclerView.getAdapter().getItemCount() - 1);

      // Escondendo o textview "NÃO HÁ CONVERSA RECENTE"
      if (findViewById(R.id.empty).getVisibility() == View.VISIBLE)
        findViewById(R.id.empty).setVisibility(View.INVISIBLE);

      // Adicionando a mensagem no firebase
      Firebase userRef = mFirebase.child(mNumeroChatAtivo);

      Map<String, String> users = new HashMap<String, String>();
      users.put("de", "5522999355171");
      users.put("msg", tmpMsg.getMessage());
      userRef
          .push()
          .setValue(
              users,
              new Firebase.CompletionListener() {

                @Override
                public void onComplete(FirebaseError firebaseError, Firebase firebase) {
                  if (firebaseError != null) {
                    System.out.println("A mensagem não foi salva: " + firebaseError.getMessage());
                  } else {
                    System.out.println("A mensagem foi salva");
                  }
                }
              });
    }
  }
Esempio n. 30
0
  @Override
  public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();

    if (layoutManager instanceof LinearLayoutManager) {
      drawHorizontal(c, parent);
    } else {
      drawHorizontal(c, parent);
      drawVertical(c, parent);
    }
  }