Java Code Examples for android.support.v7.widget.RecyclerView

The following are top voted examples for showing how to use android.support.v7.widget.RecyclerView. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GxIconAndroid   File: SearchActivity.java   View source code 6 votes vote down vote up
private void init() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    int[] gridNumAndWidth = calculateGridNumAndWidth();
    recyclerView.setLayoutManager(new GridLayoutManager(this, gridNumAndWidth[0]));

    adapter = new IconAdapter(this, gridNumAndWidth[1]);
    adapter.setMode(IconAdapter.MODE_ICON_LABEL);
    adapter.setOnItemClickListener(new IconAdapter.OnItemClickListener() {
        @Override
        public void onClick(int pos, IconBean bean) {
            searchView.clearFocus();
            IconDialog.newInstance(bean, false).show(getSupportFragmentManager(), "iconDialog");
        }
    });
    recyclerView.setAdapter(adapter);
}
 
Example 2
Project: minu-poska-android   File: AssignmentsFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_assignments, container, false);
    vSwipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeContainer);
    vSwipeRefreshLayout.setOnRefreshListener(this);
    vSwipeRefreshLayout.setColorSchemeColors(getResources().getColor(R.color.primary));

    vRecyclerView = (RecyclerView) view.findViewById(R.id.cardList);
    vRecyclerView.setHasFixedSize(false);
    final LinearLayoutManager llm = new LinearLayoutManager(getActivity());
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    vRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            // So the user didn't accidentally refresh on pulling up
            vSwipeRefreshLayout.setEnabled(llm.findFirstCompletelyVisibleItemPosition() == 0);
        }
    });
    vRecyclerView.setLayoutManager(llm);
    return view;
}
 
Example 3
Project: Paprika   File: RecipesItemAnimator.java   View source code 6 votes vote down vote up
@Override
public boolean animateChange(@NonNull RecyclerView.ViewHolder oldHolder,
                             @NonNull RecyclerView.ViewHolder newHolder,
                             @NonNull ItemHolderInfo preInfo,
                             @NonNull ItemHolderInfo postInfo) {

    if (preInfo instanceof RecipesItemHolderInfo) {
        RecipesItemHolderInfo recipesItemHolderInfo = (RecipesItemHolderInfo) preInfo;
        RecipesAdapter.RecipeViewHolder holder = (RecipesAdapter.RecipeViewHolder) newHolder;

        animateHeartButton(holder);
        if (RecipesAdapter.ACTION_LIKE_IMAGE_DOUBLE_CLICKED.equals(recipesItemHolderInfo.updateAction)) {
            animatePhotoLike(holder);
        }

    }

    return false;
}
 
Example 4
Project: Tourguideapp   File: AroundFragment.java   View source code 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.place_list, container, false);

    // Create a list of words
    final ArrayList<Place> places = new ArrayList<Place>();
    places.add(new Place(R.string.name_Paris, R.string.Paris_title,
            R.drawable.paris_france_logo));
    places.add(new Place(R.string.paris_plage, R.string.argu_p_p,
            R.drawable.paris_plage));
    places.add(new Place(R.string.shopping, R.string.argu_shopping,
            R.drawable.shopping_paris));

    PlaceRecyclerViewAdapter adapter = new PlaceRecyclerViewAdapter(places);

    RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.list);
    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

    return rootView;
}
 
Example 5
Project: GitHub   File: RecyclerToListViewScrollListener.java   View source code 6 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
  int listViewState;
  switch (newState) {
    case RecyclerView.SCROLL_STATE_DRAGGING:
      listViewState = ListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL;
      break;
    case RecyclerView.SCROLL_STATE_IDLE:
      listViewState = ListView.OnScrollListener.SCROLL_STATE_IDLE;
      break;
    case RecyclerView.SCROLL_STATE_SETTLING:
      listViewState = ListView.OnScrollListener.SCROLL_STATE_FLING;
      break;
    default:
      listViewState = UNKNOWN_SCROLL_STATE;
  }

  scrollListener.onScrollStateChanged(null /*view*/, listViewState);
}
 
Example 6
Project: TPlayer   File: FeatureAdapter.java   View source code 6 votes vote down vote up
/**
 * 当RecyclerView在windows活动时获取StaggeredGridLayoutManager布局管理器,修正header和footer显示整行
 *
 * @param holder the RecyclerView.ViewHolder
 */
@Override
public void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();
    if (lp != null && lp instanceof StaggeredGridLayoutManager.LayoutParams) {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;
        if (BEHAVIOR_MODE == ONLY_HEADER) {
            p.setFullSpan(holder.getLayoutPosition() == 0);
        } else if (BEHAVIOR_MODE == ONLY_FOOTER) {
            p.setFullSpan(holder.getLayoutPosition() == mItems.size() + 1);
        } else if (BEHAVIOR_MODE == BOTH_HEADER_FOOTER) {
            if (holder.getLayoutPosition() == 0 || holder.getLayoutPosition() == mItems.size() + 1) {
                p.setFullSpan(true);
            }
        }
    }
}
 
Example 7
Project: Coin-Tracker   File: RVDividerItemDecoration.java   View source code 6 votes vote down vote up
@Override
public void onDraw(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    int dividerLeft = parent.getPaddingLeft();
    int dividerRight = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++) {
        View child = parent.getChildAt(i);

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int dividerTop = child.getBottom() + params.bottomMargin;
        int dividerBottom = dividerTop + mDivider.getIntrinsicHeight();

        mDivider.setBounds(dividerLeft, dividerTop, dividerRight, dividerBottom);
        mDivider.draw(canvas);
    }
}
 
Example 8
Project: Android-Wear-Projects   File: HistoryActivity.java   View source code 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_history);
    // Calling the RecyclerView
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setHasFixedSize(true);

    Realm.init(this);
    realm = Realm.getDefaultInstance();
    RealmResults<StepCounts> results = realm.where(StepCounts.class).findAll();
    // The number of Columns
    mLayoutManager = new GridLayoutManager(this, 1);
    mRecyclerView.setLayoutManager(mLayoutManager);

    mAdapter = new HistoryAdapter(results,HistoryActivity.this);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example 9
Project: Tusky   File: AccountListFragment.java   View source code 6 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    BaseActivity activity = (BaseActivity) getActivity();

    /* MastodonApi on the base activity is only guaranteed to be initialised after the parent
     * activity is created, so everything needing to access the api object has to be delayed
     * until here. */
    api = activity.mastodonApi;
    // Just use the basic scroll listener to load more accounts.
    scrollListener = new EndlessOnScrollListener(layoutManager) {
        @Override
        public void onLoadMore(int page, int totalItemsCount, RecyclerView view) {
            AccountListFragment.this.onLoadMore(view);
        }
    };

    recyclerView.addOnScrollListener(scrollListener);
}
 
Example 10
Project: UltimateRecyclerView   File: UltimateRecyclerViewAdapter.java   View source code 6 votes vote down vote up
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                if (mSpanSizeLookup == null) {
                    return (isHeader(position) || isFooter(position) || isRefreshHeader(position))
                            ? gridLayoutManager.getSpanCount() : 1;
                } else {
                    return (isHeader(position) || isFooter(position) ||
                            isRefreshHeader(position)) ? gridLayoutManager.getSpanCount() :
                            mSpanSizeLookup.getSpanSize(gridLayoutManager,
                                    (position - (getHeaderViewCount() + 1)));
                }
            }
        });
    }
    mInnerAdapter.onAttachedToRecyclerView(recyclerView);
}
 
Example 11
Project: TestChat   File: MultiFuncRecyclerView.java   View source code 6 votes vote down vote up
public void setAdapter(final RecyclerView.Adapter adapter) {
                if (adapter != null) {
                        adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
                                @Override
                                public void onChanged() {
                                        LogUtil.e("数据改变了 ");
//                                        当数据插入完成后
                                        isLoading = false;
                                        if (moreLoadView.getVisibility() == VISIBLE) {
                                                moreLoadView.setVisibility(GONE);
                                        }
                                        if (adapter.getItemCount() == 0 && emptyView != null) {
                                                LogUtil.e("数据为空时,显示空view");
                                                emptyView.setVisibility(VISIBLE);
                                        } else if (emptyView != null) {
                                                emptyView.setVisibility(GONE);
                                        }
                                }
                        });
                        display.setAdapter(adapter);
                }
        }
 
Example 12
Project: GitHub   File: FullyGridLayoutManager.java   View source code 6 votes vote down vote up
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                               int heightSpec, int[] measuredDimension) {
    if (position < getItemCount()) {
        try {
            View view = recycler.getViewForPosition(position);//fix 动态添加时报IndexOutOfBoundsException
            if (view != null) {
                RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
                int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
                        getPaddingLeft() + getPaddingRight(), p.width);
                int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
                        getPaddingTop() + getPaddingBottom(), p.height);
                view.measure(childWidthSpec, childHeightSpec);
                measuredDimension[0] = view.getMeasuredWidth() + p.leftMargin + p.rightMargin;
                measuredDimension[1] = view.getMeasuredHeight() + p.bottomMargin + p.topMargin;
                recycler.recycleView(view);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
Example 13
Project: gmlrva   File: DecoratorDrawableDividerHelper.java   View source code 6 votes vote down vote up
/**
 * Procedure meant to handle the drawing of the intended {@link SimpleDividerItemDecoration}'s divider
 * on start / left of the parent's {@link RecyclerView} item.
 * @param canvas the {@link Canvas} object where the divider will be drawn.
 * @param parent the parent {@link RecyclerView} for the applied {@link SimpleDividerItemDecoration}.
 * @param mDivider the divider's target {@link Drawable} value.
 */
protected void drawDrawableDividerPositionStart(@NonNull final Canvas canvas, @NonNull final RecyclerView parent,
                                                @NonNull final Drawable mDivider) {
    final int top = parent.getPaddingTop();
    final int bottom = parent.getHeight() - parent.getPaddingBottom();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View view = parent.getChildAt(i);
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        final int left = view.getLeft() + params.leftMargin;
        final int right = left + mDivider.getIntrinsicWidth();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(canvas);
    }
}
 
Example 14
Project: NovelReader   File: DividerGridItemDecoration.java   View source code 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getTop() - params.topMargin;
        final int bottom = child.getBottom() + params.bottomMargin;
        final int left = child.getRight() + params.rightMargin;
        final int right = left + mHeightDivider.getIntrinsicWidth();

        mHeightDivider.setBounds(left, top, right, bottom);
        mHeightDivider.draw(c);
    }
}
 
Example 15
Project: VanGogh   File: VanMediaAdapter.java   View source code 6 votes vote down vote up
@Override
public void onCheckViewClicked(CheckView checkView, MediaInfo mediaInfo, RecyclerView.ViewHolder holder) {
    if (mSelectionSpec.countable) {
        int checkedNum = mSelectedCollection.checkedNumOf(mediaInfo);
        if (checkedNum == CheckView.UNCHECKED) {
            if (assertAddSelection(holder.itemView.getContext(), mediaInfo)) {
                mSelectedCollection.add(mediaInfo);
                notifyCheckStateChanged();
            }
        } else {
            mSelectedCollection.remove(mediaInfo);
            notifyCheckStateChanged();
        }
    } else {
        if (mSelectedCollection.isSelected(mediaInfo)) {
            mSelectedCollection.remove(mediaInfo);
            notifyCheckStateChanged();
        } else {
            if (assertAddSelection(holder.itemView.getContext(), mediaInfo)) {
                mSelectedCollection.add(mediaInfo);
                notifyCheckStateChanged();
            }
        }
    }
}
 
Example 16
Project: SmartChart   File: WrapperUtils.java   View source code 6 votes vote down vote up
public static void onAttachedToRecyclerView(RecyclerView.Adapter innerAdapter, RecyclerView recyclerView, final SpanSizeCallback callback) {
    innerAdapter.onAttachedToRecyclerView(recyclerView);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();

        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return callback.getSpanSize(gridLayoutManager, spanSizeLookup, position);
            }
        });
        gridLayoutManager.setSpanCount(gridLayoutManager.getSpanCount());
    }
}
 
Example 17
Project: baselibrary-master   File: HeaderAndFooterWrapper.java   View source code 6 votes vote down vote up
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView)
{
    WrapperUtils.onAttachedToRecyclerView(mInnerAdapter, recyclerView, new WrapperUtils.SpanSizeCallback()
    {
        @Override
        public int getSpanSize(GridLayoutManager layoutManager, GridLayoutManager.SpanSizeLookup oldLookup, int position)
        {
            int viewType = getItemViewType(position);
            if (mHeaderViews.get(viewType) != null)
            {
                return layoutManager.getSpanCount();
            } else if (mFootViews.get(viewType) != null)
            {
                return layoutManager.getSpanCount();
            }
            if (oldLookup != null)
                return oldLookup.getSpanSize(position);
            return 1;
        }
    });
}
 
Example 18
Project: RecyclerViewEvent   File: DividerGridItemDecoration.java   View source code 6 votes vote down vote up
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
        } else
        // StaggeredGridLayoutManager 且横向滚动
        {
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example 19
Project: AndroidTvDemo   File: AbsFocusBorder.java   View source code 6 votes vote down vote up
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState)
{
    if (newState == RecyclerView.SCROLL_STATE_IDLE)
    {
        final AbsFocusBorder border = mFocusBorder.get();
        final View focused = recyclerView.getFocusedChild();
        if (null != border && null != focused)
        {
            if (border.mReAnim || mScrolledX != 0 || mScrolledY != 0)
            {
                border.runBorderAnimation(focused, Options.OptionsHolder.INSTANCE);
            }
        }
        mScrolledX = mScrolledY = 0;
    }
}
 
Example 20
Project: MultiTypeRecyclerViewAdapter   File: MainActivity.java   View source code 5 votes vote down vote up
private void initView() {

        mToolbar = (Toolbar) findViewById(R.id.toolbar);
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        mSearchView = (MaterialSearchView) findViewById(R.id.search);
        mTitle = (TextView) findViewById(R.id.title);
        mAppBar = (AppBarLayout) findViewById(R.id.appbar);
    }
 
Example 21
Project: NoPaginate   File: ScrollUtils.java   View source code 5 votes vote down vote up
static boolean isOnBottom(RecyclerView recyclerView, int loadingTriggerThreshold) {
    final int visibleItemCount = recyclerView.getChildCount();
    final int totalItemCount = recyclerView.getLayoutManager().getItemCount();
    final int firstVisibleItemPosition = getFirstVisibleItemPositionByLayoutManager(recyclerView.getLayoutManager());
    // Check if end of the list is reached (counting threshold) or if there is no items at all
    return (totalItemCount - visibleItemCount) <= (firstVisibleItemPosition + loadingTriggerThreshold)
            || totalItemCount == 0;

}
 
Example 22
Project: GitHub   File: DefaultAdapter.java   View source code 5 votes vote down vote up
/**
 * 遍历所有hodler,释放他们需要释放的资源
 *
 * @param recyclerView
 */
public static void releaseAllHolder(RecyclerView recyclerView) {
    if (recyclerView == null) return;
    for (int i = recyclerView.getChildCount() - 1; i >= 0; i--) {
        final View view = recyclerView.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = recyclerView.getChildViewHolder(view);
        if (viewHolder != null && viewHolder instanceof BaseHolder) {
            ((BaseHolder) viewHolder).onRelease();
        }
    }
}
 
Example 23
Project: CoordinatorLayoutExample-master   File: LoadMoreWrapper.java   View source code 5 votes vote down vote up
private void setFullSpan(RecyclerView.ViewHolder holder) {
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

    if (lp != null
            && lp instanceof StaggeredGridLayoutManager.LayoutParams) {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams)
                lp;

        p.setFullSpan(true);
    }
}
 
Example 24
Project: BaseAdapterRel   File: LoadMoreWrapper.java   View source code 5 votes vote down vote up
private void setFullSpan(RecyclerView.ViewHolder holder)
{
    ViewGroup.LayoutParams lp = holder.itemView.getLayoutParams();

    if (lp != null
            && lp instanceof StaggeredGridLayoutManager.LayoutParams)
    {
        StaggeredGridLayoutManager.LayoutParams p = (StaggeredGridLayoutManager.LayoutParams) lp;

        p.setFullSpan(true);
    }
}
 
Example 25
Project: android-study   File: SimpleItemTouchHelperCallback.java   View source code 5 votes vote down vote up
/**
 * 当条目停止移动时调用
 */
@Override public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
  super.clearView(recyclerView, viewHolder);
  viewHolder.itemView.setAlpha(1.0f);
  if (viewHolder instanceof ItemTouchHelperViewHolder) {
    ItemTouchHelperViewHolder holder = (ItemTouchHelperViewHolder) viewHolder;
    holder.onItemClear();
  }
}
 
Example 26
Project: AndroidDigIn   File: RecyclerFragment.java   View source code 5 votes vote down vote up
/**
     * Provide the cursor for the recycler view.
     */
    public void setRecyclerAdapter(RecyclerView.Adapter adapter) {
//        boolean hadAdapter = mAdapter != null;
        mAdapter = adapter;
        if (mRecyclerView != null) {
            mRecyclerView.setAdapter(adapter);
        }
    }
 
Example 27
Project: ClassifyView   File: BaseMainAdapter.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void onStartMergeAnimation(RecyclerView parent, int selectedPosition, int targetPosition,int duration) {
    VH selectedViewHolder = (VH) parent.findViewHolderForAdapterPosition(selectedPosition);
    VH targetViewHolder = (VH) parent.findViewHolderForAdapterPosition(targetPosition);
    if(selectedViewHolder == null || targetViewHolder == null) return;
    onStartMergeAnimation(selectedViewHolder, targetViewHolder, selectedPosition, targetPosition,duration);
}
 
Example 28
Project: android-study   File: GravitySnapHelper.java   View source code 5 votes vote down vote up
@Override public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
    throws IllegalStateException {
  if (recyclerView != null) {
    mIsRtl = false;
  }
  super.attachToRecyclerView(recyclerView);
}
 
Example 29
Project: Android-Infrastructure   File: NotesActivity.java   View source code 5 votes vote down vote up
private void setup(){
    recyclerView = (RecyclerView) findViewById(R.id.recycler);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(new NotesAdapter(this));
    findViewById(R.id.addbutton).setOnClickListener(this);
    noteET = (EditText) findViewById(R.id.editText);
    progressBar = (ProgressBar)findViewById(R.id.progressBar);
}
 
Example 30
Project: ContactsList   File: FloatingBarItemDecoration.java   View source code 5 votes vote down vote up
private void drawTitleArea(Canvas c, int left, int right, View child,
                           RecyclerView.LayoutParams params, int position) {
    final int rectBottom = child.getTop() - params.topMargin;
    c.drawRect(left, rectBottom - mTitleHeight, right,
            rectBottom, mBackgroundPaint);
    c.drawText(mList.get(position), child.getPaddingLeft() + mTextStartMargin,
            rectBottom - (mTitleHeight - mTextHeight) / 2 - mTextBaselineOffset, mTextPaint);
}
 
Example 31
Project: RvAdapter   File: StickyRecyclerHeadersTouchListener.java   View source code 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    if (this.mOnHeaderClickListener != null) {
        boolean tapDetectorResponse = this.mTapDetector.onTouchEvent(e);
        if (tapDetectorResponse) {
            // Don't return false if a single tap is detected
            return true;
        }
        if (e.getAction() == MotionEvent.ACTION_DOWN) {
            int position = mDecor.findHeaderPositionUnder((int) e.getX(), (int) e.getY());
            return position != -1;
        }
    }
    return false;
}
 
Example 32
Project: vlayout   File: StaggeredGridLayoutHelper.java   View source code 5 votes vote down vote up
@Override
public void onScrollStateChanged(int state, int startPosition,
                                 int endPosition, LayoutManagerHelper helper) {
    if (startPosition > getRange().getUpper() || endPosition < getRange().getLower()) {
        return;
    }

    if (state == RecyclerView.SCROLL_STATE_IDLE) {
        checkForGaps();
    }
}
 
Example 33
Project: SmartChart   File: EmptyWrapper.java   View source code 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (isEmpty()) {
        return;
    }
    mInnerAdapter.onBindViewHolder(holder, position);
}
 
Example 34
Project: Tangram-Android   File: BaseTangramEngine.java   View source code 5 votes vote down vote up
/**
 * @return Return the recyclerView binded to Tangram, do not call this method after {@link #destroy()}, since it
 * will recreate a recyclerView instance. Also it is suggested to call {@link #bindView(RecyclerView)} first
 * before call this method, since the recyclerView created in this method is a default one and may not meet up to
 * your case.
 */
public RecyclerView getContentView() {
    if (mContentView == null) {
        RecyclerView recyclerView = new RecyclerView(mContext);
        bindView(recyclerView);
        Preconditions.checkState(mContentView != null, "mContentView is still null after call bindView()");
    }

    return mContentView;
}
 
Example 35
Project: popomusic   File: JKActivity.java   View source code 5 votes vote down vote up
@Override
public void initView() {
    recyclerView=(RecyclerView)findViewById(R.id.recycler_JK);
    mAdapter=new LocalMusicAdapter(this);
    mLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(mAdapter);
    LogUtils.d("LocalMusicActivity","initView()");
    srfLayout=(SwipeRefreshLayout)findViewById(R.id.swipe);
    mPresenter=new JKPresenter((JKMusicData.View)this);
    mBtnPlay.setImageResource(R.mipmap.bar_play);
}
 
Example 36
Project: CoordinatorLayoutExample-master   File: EmptyWrapper.java   View source code 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (isEmpty()) {
        return;
    }
    mInnerAdapter.onBindViewHolder(holder, position);
}
 
Example 37
Project: 2017.1-Trezentos   File: ExamsFragment.java   View source code 5 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    ExamsFragment.ViewHolder holder = (ExamsFragment.ViewHolder) viewHolder;

    Exam exam  = exams.get(position) ;
    holder.className.setText(exam.getNameExam());
}
 
Example 38
Project: androidadvanced   File: RecipesAdapterTest.java   View source code 5 votes vote down vote up
@Override
public void setUp() throws Exception {
    super.setUp();
    URL = "http://galileo.edu";
    when(recipe.getSourceURL()).thenReturn(URL);

    adapter = new RecipesAdapter(recipeList, imageLoader, onItemClickListener);
    shadowAdapter = (ShadowRecyclerViewAdapter) ShadowExtractor.extract(adapter);

    Activity activity = Robolectric.setupActivity(Activity.class);
    RecyclerView recyclerView = new RecyclerView(activity);
    recyclerView.setLayoutManager(new LinearLayoutManager(activity));

    recyclerView.setAdapter(adapter);
}
 
Example 39
Project: Hands-On-Android-UI-Development   File: OverviewActivity.java   View source code 5 votes vote down vote up
@Override
public void onSwiped(
        final RecyclerView.ViewHolder viewHolder,
        final int direction) {

    final DataBoundViewHolder<?, ClaimItem> holder = (DataBoundViewHolder<?, ClaimItem>) viewHolder;
    new DeleteClaimItemCommand(holder.getItem()).exec(null);
}
 
Example 40
Project: SuperRecyclerViewAdapter   File: Btn2LayoutActivity.java   View source code 5 votes vote down vote up
private void initView() {

        mRv = (RecyclerView) findViewById(R.id.rv);

        mAdapter = new SuperRecyclerAdapter<String>(this, mList) {
            @Override
            public void convert(SuperRecyclerHolder holder, final String s, int layoutType,
                final int position) {
                //只有一种布局,不使用layoutType来区分type了
                holder//
                    .setText(R.id.tv_content, s)
                    .setOnItemClickListenner(new View.OnClickListener() {
                        @Override public void onClick(View v) {
                            Toast.makeText(Btn2LayoutActivity.this, "item被点击", Toast.LENGTH_SHORT)
                                .show();
                        }
                    });
            }

            @Override public int getLayoutAsViewType(String s, int position) {
                return R.layout.recycler_item_btn2;
            }
        };

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        mRv.setLayoutManager(layoutManager);
        mRv.setAdapter(mAdapter);
    }