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

The following examples show how to use android.support.v7.widget.RecyclerView. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: RxTools-master   Author: duboAndroid   File: PinnedHeaderDecoration.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    createPinnedHeader(parent);

    if (mPinnedHeaderView != null) {
        int headerEndAt = mPinnedHeaderView.getTop() + mPinnedHeaderView.getHeight();
        View v = parent.findChildViewUnder(c.getWidth() / 2, headerEndAt + 1);

        if (isPinnedView(parent, v)) {
            mPinnedHeaderTop = v.getTop() - mPinnedHeaderView.getHeight();
        } else {
            mPinnedHeaderTop = 0;
        }

        mClipBounds = c.getClipBounds();
        mClipBounds.top = mPinnedHeaderTop + mPinnedHeaderView.getHeight();
        c.clipRect(mClipBounds);
    }
}
 
Example #2
Source Project: ReSwipeCard   Author: JerryChan123   File: ReItemTouchHelper.java    License: Apache License 2.0 6 votes vote down vote up
private void addChildDrawingOrderCallback() {
    if (Build.VERSION.SDK_INT >= 21) {
        return;// we use elevation on Lollipop
    }
    if (mChildDrawingOrderCallback == null) {
        mChildDrawingOrderCallback = new RecyclerView.ChildDrawingOrderCallback() {
            @Override
            public int onGetChildDrawingOrder(int childCount, int i) {
                if (mOverdrawChild == null) {
                    return i;
                }
                int childPosition = mOverdrawChildPosition;
                if (childPosition == -1) {
                    childPosition = mRecyclerView.indexOfChild(mOverdrawChild);
                    mOverdrawChildPosition = childPosition;
                }
                if (i == childCount - 1) {
                    return childPosition;
                }
                return i < childPosition ? i : i + 1;
            }
        };
    }
    mRecyclerView.setChildDrawingOrderCallback(mChildDrawingOrderCallback);
}
 
Example #3
Source Project: LRecyclerView   Author: jdsjlzx   File: LuGridItemDecoration.java    License: Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    LuRecyclerViewAdapter adapter = (LuRecyclerViewAdapter) parent.getAdapter();
    for (int i = 0; i < childCount; i++) {
        if (adapter.isHeader(i) || adapter.isFooter(i)) {
            c.drawRect(0, 0, 0, 0, mPaint);
        } else {
            final View child = parent.getChildAt(i);
            final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
            final int top = child.getTop();
            final int bottom = child.getBottom() + verticalSpace;
            final int left = child.getRight() + params.rightMargin;
            final int right = left + horizontalSpace;
            c.drawRect(left, top, right, bottom, mPaint);
        }

    }
}
 
Example #4
Source Project: Mover   Author: Codetail   File: MoverRecycleFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean onItemLongClick(RecyclerView parent, View view, int position, long id) {

    int viewType = mWatchMeAdapter.getItemViewType(position);

    switch (viewType){
        case WatchMeAdapterNew.TYPE_HEADER_FIRST:
            getJobManager().addJob(new FetchAvailableVideoQualities("p3xpwfHm"));
            return true;

        case WatchMeAdapterNew.TYPE_VIDEO:
        case WatchMeAdapterNew.TYPE_VIDEO_LAST:

            mSelectedVideoPosition = position;

            PopupMenu popupMenu = new PopupMenu(view.getContext(), view, Gravity.TOP);
            popupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
            popupMenu.inflate(R.menu.video_item_menu);
            popupMenu.show();
            return true;
    }

    return false;
}
 
Example #5
Source Project: AndroidUiKit   Author: yangjiantao   File: MultiTypeLoadMoreAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
    loadMoreDelegate.attach(recyclerView);
    final RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager == null) {
        Log.e(TAG, "Cannot setSpanSizeLookup on a null LayoutManager Object. " +
                "Call setLayoutManager with a non-null argument.");
        return;
    }

    if (layoutManager instanceof GridLayoutManager) {
        ((GridLayoutManager) layoutManager).setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                Object obj = getItems().get(position);
                return obj.getClass().equals(LoadMoreItem.class) ? ((GridLayoutManager) layoutManager).getSpanCount() : 1;
            }
        });
    }
}
 
Example #6
Source Project: AutoRecycleView   Author: GaoGersy   File: SmartRecycleView.java    License: Apache License 2.0 6 votes vote down vote up
public SmartRecycleView setLayoutManger(LayoutManagerType layoutManagerType, int orientation, int spanCout) {
    RecyclerView.LayoutManager layoutManager = null;
    if (layoutManagerType == LayoutManagerType.LINEAR_LAYOUT) {
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(orientation);
        layoutManager = linearLayoutManager;
    } else if (layoutManagerType == LayoutManagerType.GRID_LAYOUT) {
        GridLayoutManager gridLayoutManager = new GridLayoutManager(mContext, spanCout);
        gridLayoutManager.setOrientation(orientation);
        layoutManager = gridLayoutManager;
    } else if (layoutManagerType == LayoutManagerType.STAGGER_LAYOUT) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(spanCout, orientation);
        layoutManager = staggeredGridLayoutManager;
    }
    mRecyclerView.setLayoutManager(layoutManager);
    return this;
}
 
Example #7
Source Project: LiveSourceCode   Author: yanzhenjie   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    findViewById(R.id.btn_request).setOnClickListener(onClickListener);
    findViewById(R.id.btn_select_image).setOnClickListener(onClickListener);
    mTvResult = (TextView) findViewById(R.id.tv_result);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(5, 5, 5, 5);
        }
    });
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));

    int size = measureSize();
    mAdapter = new AlbumPreviewAdapter(this, size);
    mRecyclerView.setAdapter(mAdapter);
}
 
Example #8
Source Project: kute   Author: scorelab   File: MyRoutesRecyclerAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    switch (holder.getItemViewType())
    {
        case header:
            configureRecyclerHead((HeaderRecyclerViewHolder)holder);
            break;
        case general_list_item:
            configureGeneralItem((MyRoutesItemViewHolder)holder,position);
            break;
        default:
            configureGeneralItem((MyRoutesItemViewHolder)holder,position);
            break;
    }

}
 
Example #9
Source Project: vlayout   Author: alibaba   File: ExposeLinearLayoutManagerEx.java    License: MIT License 6 votes vote down vote up
/**
 * @return The final offset amount for children
 */
private int fixLayoutEndGapExpose(int endOffset, RecyclerView.Recycler recycler,
                                  RecyclerView.State state, boolean canOffsetChildren) {
    int gap = mOrientationHelper.getEndAfterPadding() - endOffset;
    int fixOffset = 0;
    if (gap > 0) {
        fixOffset = -scrollInternalBy(-gap, recycler, state);
    } else {
        return 0; // nothing to fix
    }
    // move offset according to scroll amount
    endOffset += fixOffset;
    if (canOffsetChildren) {
        // re-calculate gap, see if we could fix it
        gap = mOrientationHelper.getEndAfterPadding() - endOffset;
        if (gap > 0) {
            mOrientationHelper.offsetChildren(gap);
            return gap + fixOffset;
        }
    }
    return fixOffset;
}
 
Example #10
Source Project: ChipsLayoutManager   Author: BelooS   File: RecyclerViewEspressoFactory.java    License: Apache License 2.0 6 votes vote down vote up
private static Matcher<View> orderMatcher() {
    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("with correct position order");
        }

        @Override
        public boolean matchesSafely(View v) {
            RecyclerView view = (RecyclerView) v;
            if (view.getLayoutManager() == null) return false;
            ChildViewsIterable childViews = new ChildViewsIterable(view.getLayoutManager());
            int pos = view.getChildAdapterPosition(childViews.iterator().next());
            for (View child : childViews) {
                if (pos != view.getChildAdapterPosition(child)) {
                    return false;
                }
                pos ++;
            }
            return true;
        }
    };
}
 
Example #11
Source Project: luckly_recyclerview   Author: MrGaoGang   File: LRecyclerView.java    License: MIT License 6 votes vote down vote up
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManager instanceof GridLayoutManager) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
        final int spanCount = gridLayoutManager.getSpanCount();
        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                // 如果当前是footer的位置,那么该item占据一行的个单元格,正常情况下占据1个单元格
                if (getItemViewType(position) == FOOTER_TYPE) {
                    return spanCount;
                } else if (isRefreshHeader(position) || getItemViewType(position) == getHeaderTypeByPosition(position - 1)) {
                    return spanCount;
                } else {
                    return 1;
                }
            }
        });
    }
    mAdapter.onAttachedToRecyclerView(recyclerView);
}
 
Example #12
Source Project: RecyclerViewHelper   Author: vihuela   File: WRLinearLayoutManager.java    License: MIT License 6 votes vote down vote up
private void measureScrapChild(RecyclerView.Recycler recycler, int position, int widthSpec,
                               int heightSpec, int[] measuredDimension) {

    View view = recycler.getViewForPosition(position);

    // For adding Item Decor Insets to view
    super.measureChildWithMargins(view, 0, 0);
    RecyclerView.LayoutParams p = (RecyclerView.LayoutParams) view.getLayoutParams();
    int childWidthSpec = ViewGroup.getChildMeasureSpec(widthSpec,
            getPaddingLeft() + getPaddingRight() + getDecoratedLeft(view) + getDecoratedRight(view), p.width);
    int childHeightSpec = ViewGroup.getChildMeasureSpec(heightSpec,
            getPaddingTop() + getPaddingBottom() + getPaddingBottom() + getDecoratedBottom(view), p.height);
    view.measure(childWidthSpec, childHeightSpec);

    // Get decorated measurements
    measuredDimension[0] = getDecoratedMeasuredWidth(view) + p.leftMargin + p.rightMargin;
    measuredDimension[1] = getDecoratedMeasuredHeight(view) + p.bottomMargin + p.topMargin;
    recycler.recycleView(view);
}
 
Example #13
Source Project: Jide-Note   Author: Null-Ouwenjie   File: ListFragment.java    License: MIT License 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.fragment_list, container, false);
    fab = (ButtonFloat) view.findViewById(R.id.new_edit_fab);
    fab.setOnClickListener(this);

    recyclerView = (RecyclerView) view.findViewById(R.id.list_recyclerview);
    initRecyclerView();

    LogUtils.e("onCreateView");
    return view;
}
 
Example #14
Source Project: OpenHub   Author: ThirtyDegreesRay   File: ListFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
    protected void initFragment(Bundle savedInstanceState) {
        refreshLayout.setOnRefreshListener(this);
        refreshLayout.setColorSchemeColors(ViewUtils.getRefreshLayoutColors(getContext()));

        recyclerView.setLayoutManager(new CatchableLinearLayoutManager(getActivity()));
        adapter.setOnItemLongClickListener(this);
        adapter.setOnItemClickListener(this);
        recyclerView.setAdapter(adapter);

        layTip.setVisibility(View.GONE);

        //adapter 数据观察者,当数据为空时,显示空提示
        observer = new RecyclerView.AdapterDataObserver() {
            @Override
            public void onChanged() {
                super.onChanged();
                int itemCount = adapter.getItemCount();
                if (itemCount == 0) {
                    refreshLayout.setVisibility(View.GONE);
                    layTip.setVisibility(View.VISIBLE);
                    tvTip.setText(getEmptyTip());
                    errorImage.setVisibility(View.GONE);
                } else {
                    refreshLayout.setVisibility(View.VISIBLE);
                    layTip.setVisibility(View.GONE);
                    itemCount -= getHeaderSize();
                    if(loadMoreEnable && autoJudgeCanLoadMoreEnable){
                        canLoadMore = itemCount % getPagerSize() == 0 ;
//                        curPage = itemCount % getPagerSize() == 0 ?
//                                itemCount / getPagerSize() : (itemCount / getPagerSize()) + 1;
                    }
                }
            }
        };
        adapter.registerAdapterDataObserver(observer);
        recyclerView.setOnScrollListener(new ScrollListener());
        refreshLayout.setRefreshing(true);
        initScrollListener();
    }
 
Example #15
Source Project: ChatKit   Author: stfalcon-studio   File: RecyclerScrollMoreListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView view, int dx, int dy) {
    if (loadMoreListener != null) {
        int lastVisibleItemPosition = 0;
        int totalItemCount = mLayoutManager.getItemCount();

        if (mLayoutManager instanceof StaggeredGridLayoutManager) {
            int[] lastVisibleItemPositions = ((StaggeredGridLayoutManager) mLayoutManager).findLastVisibleItemPositions(null);
            lastVisibleItemPosition = getLastVisibleItem(lastVisibleItemPositions);
        } else if (mLayoutManager instanceof LinearLayoutManager) {
            lastVisibleItemPosition = ((LinearLayoutManager) mLayoutManager).findLastVisibleItemPosition();
        } else if (mLayoutManager instanceof GridLayoutManager) {
            lastVisibleItemPosition = ((GridLayoutManager) mLayoutManager).findLastVisibleItemPosition();
        }

        if (totalItemCount < previousTotalItemCount) {
            this.currentPage = 0;
            this.previousTotalItemCount = totalItemCount;
            if (totalItemCount == 0) {
                this.loading = true;
            }
        }

        if (loading && (totalItemCount > previousTotalItemCount)) {
            loading = false;
            previousTotalItemCount = totalItemCount;
        }

        int visibleThreshold = 5;
        if (!loading && (lastVisibleItemPosition + visibleThreshold) > totalItemCount) {
            currentPage++;
            loadMoreListener.onLoadMore(loadMoreListener.getMessagesCount(), totalItemCount);
            loading = true;
        }
    }
}
 
Example #16
Source Project: BitkyShop   Author: bitkylin   File: HomeFragment.java    License: MIT License 5 votes vote down vote up
private void initRecyclerView() {
    recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_home_fragment);
    if (recyclerAdapter == null) {
        initRecyclerViewData(new ArrayList<Commodity>());
    }
    recyclerView.setAdapter(recyclerAdapter);
    recyclerView.setLayoutManager(
        new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    presenter.refreshRecyclerAdapterData(RefreshType.Refresh);
}
 
Example #17
Source Project: NoNonsense-FilePicker   Author: spacecowboy   File: AbstractFilePickerFragment.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Checks if a divider drawable has been defined in the current theme. If it has, will apply
 * an item decoration with the divider. If no divider has been specified, then does nothing.
 */
protected void configureItemDecoration(@NonNull LayoutInflater inflater,
                                       @NonNull RecyclerView recyclerView) {
    final TypedArray attributes =
            getActivity().obtainStyledAttributes(new int[]{R.attr.nnf_list_item_divider});
    Drawable divider = attributes.getDrawable(0);
    attributes.recycle();

    if (divider != null) {
        recyclerView.addItemDecoration(new DividerItemDecoration(divider));
    }
}
 
Example #18
Source Project: photo-editor-android   Author: eventtus   File: EmojiFragment.java    License: MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main_photo_edit_emoji, container, false);

    emojiRecyclerView = (RecyclerView) rootView.findViewById(R.id.fragment_main_photo_edit_emoji_rv);
    emojiRecyclerView.setHasFixedSize(true);
    emojiRecyclerView.setLayoutManager(new GridLayoutManager(photoEditorActivity, 4));
    EmojiAdapter adapter = new EmojiAdapter(photoEditorActivity, emojiIds);
    adapter.setOnEmojiClickListener(this);
    emojiRecyclerView.setAdapter(adapter);

    return rootView;
}
 
Example #19
Source Project: GalleryLayoutManager   Author: BCsl   File: GalleryLayoutManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Layout the item view witch position special by {@link GalleryLayoutManager#mInitialSelectedPosition} first and then layout the other
 *
 * @param recycler
 * @param state
 */
private void firstFillWithVertical(RecyclerView.Recycler recycler, RecyclerView.State state) {
    detachAndScrapAttachedViews(recycler);
    int topEdge = getOrientationHelper().getStartAfterPadding();
    int bottomEdge = getOrientationHelper().getEndAfterPadding();
    int startPosition = mInitialSelectedPosition;
    int scrapWidth, scrapHeight;
    Rect scrapRect = new Rect();
    int width = getHorizontalSpace();
    int leftOffset;
    //layout the init position view
    View scrap = recycler.getViewForPosition(mInitialSelectedPosition);
    addView(scrap, 0);
    measureChildWithMargins(scrap, 0, 0);
    scrapWidth = getDecoratedMeasuredWidth(scrap);
    scrapHeight = getDecoratedMeasuredHeight(scrap);
    leftOffset = (int) (getPaddingLeft() + (width - scrapWidth) / 2.0f);
    int top = (int) (getPaddingTop() + (getVerticalSpace() - scrapHeight) / 2.f);
    scrapRect.set(leftOffset, top, leftOffset + scrapWidth, top + scrapHeight);
    layoutDecorated(scrap, scrapRect.left, scrapRect.top, scrapRect.right, scrapRect.bottom);
    if (getState().mItemsFrames.get(startPosition) == null) {
        getState().mItemsFrames.put(startPosition, scrapRect);
    } else {
        getState().mItemsFrames.get(startPosition).set(scrapRect);
    }
    mFirstVisiblePosition = mLastVisiblePos = startPosition;
    int topStartOffset = getDecoratedTop(scrap);
    int bottomStartOffset = getDecoratedBottom(scrap);
    //fill left of center
    fillTop(recycler, mInitialSelectedPosition - 1, topStartOffset, topEdge);
    //fill right of center
    fillBottom(recycler, mInitialSelectedPosition + 1, bottomStartOffset, bottomEdge);
}
 
Example #20
Source Project: Ouroboros   Author: Luorrak   File: ThreadNetworkFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
public InsertThreadIntoDatabaseTask(Activity activity, InfiniteDbHelper infiniteDbHelper, String boardName, String resto, int threadPosition, boolean firstRequest, RecyclerView recyclerView, ThreadAdapter threadAdapter) {
    onAttach(activity);
    this.infiniteDbHelper = infiniteDbHelper;
    this.boardName = boardName;
    this.resto = resto;
    this.threadAdapter = threadAdapter;
    this.recyclerView = recyclerView;
    this.threadPosition = threadPosition;
    this.firstRequest = firstRequest;
}
 
Example #21
Source Project: RecyclerViewPager   Author: lsjwzh   File: TabLayoutSupport.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    TabLayout tabLayout = this.mTabLayoutRef.get();
    final RecyclerViewPager viewPager = (RecyclerViewPager) recyclerView;
    final int pagerWidth = recyclerView.getWidth()
            - recyclerView.getPaddingLeft()
            - recyclerView.getPaddingRight();
    final View centerXChild = ViewUtils.getCenterXChild(viewPager);
    if (centerXChild == null) {
        return;
    }
    int centerChildPosition = viewPager.getChildAdapterPosition(centerXChild);
    float offset = mPagerLeftBeforeScroll - centerXChild.getLeft()
            + pagerWidth * (centerChildPosition - mPositionBeforeScroll);
    final float positionOffset = offset * 1f / pagerWidth;
    if (tabLayout != null) {
        if (positionOffset < 0) {
            try {
                tabLayout.setScrollPosition(mPositionBeforeScroll
                        + (int) Math.floor(positionOffset),
                    positionOffset - (int) Math.floor(positionOffset),
                    false);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        } else {
            tabLayout.setScrollPosition(mPositionBeforeScroll + (int) (positionOffset),
                    positionOffset - (int) (positionOffset),
                    false);
        }
    }
    Log.d("test", "dx:" + positionOffset);
}
 
Example #22
Source Project: CrawlerForReader   Author: smuyyh   File: DividerItemDecoration.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void getItemOffsets(Rect outRect, int itemPosition, RecyclerView parent) {
    if (mOrientation == VERTICAL) {
        outRect.set(0, 0, 0, 1);
    } else {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
    }
}
 
Example #23
Source Project: Social   Author: devallever   File: RecyclerViewItemClickListener.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
    View childView = view.findChildViewUnder(e.getX(), e.getY());
    if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
        mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
    }
    return false;
}
 
Example #24
Source Project: VideoDemoJava   Author: zzh12138   File: LineItemDecoration.java    License: MIT License 5 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
    int count = parent.getChildCount();
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();
    for (int i = 0; i < count - 1; i++) {
        View view = parent.getChildAt(i);
        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
        int top = view.getBottom() + params.bottomMargin;
        int bottom = top + mDrawable.getIntrinsicHeight();
        mDrawable.setBounds(left, top, right, bottom);
        mDrawable.draw(c);
    }
}
 
Example #25
Source Project: FancyAdapters   Author: MikiLoz92   File: SuperSelectableAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
    if (actionState == 2) { // Drag start
        dragging = true;
        draggedElementPos = viewHolder.getLayoutPosition();
        elementMoved = false;
    } else if (actionState == 1) {
        swiping = true;
        swipedElementPos = viewHolder.getLayoutPosition();
    } else if (actionState == 0) { // Drop
        if (dragging) {
            dragging = false;
            if (!elementMoved && triggerOnDrop) {
                //VH vh = (VH) recyclerView.findViewHolderForAdapterPosition(draggedElementPos);
                //triggerSelectionMode(vh, draggedElementPos);
                VH vh;
                for (VH v: viewHolders) {
                    if (v.getAdapterPosition() == draggedElementPos) {
                        vh = v;
                        triggerSelectionMode(vh, draggedElementPos);
                        break;
                    }
                }
            }
        } else if (swiping) {
            swiping = false;
        }

    }
}
 
Example #26
Source Project: xDrip-plus   Author: jamorham   File: Reminders.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reminders);
    setTheme(R.style.AppThemeToolBarLite); // for toolbar mode

    //setSupportActionBar((Toolbar)findViewById(R.id.reminder_toolbar));
    JoH.fixActionBar(this);

    setTitle(getString(R.string.xdrip_reminders));
    // TODO subtitle with summary
    recyclerView = (RecyclerView) findViewById(R.id.reminder_recycler);
    floatingsnooze = (CardView) findViewById(R.id.floatingsnooze);
    floaterText = (TextView) findViewById(R.id.floaterText);

    floatingsnooze.setVisibility(View.GONE);

    mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    mProximity = mSensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

    mAdapter = new RecyclerAdapter(this, reminders);

    if (selectedSound == null) {
        if (PersistentStore.getString("reminders-last-sound").length() > 5)
            selectedSound = PersistentStore.getString("reminders-last-sound");
    }

    reloadList();

    postOnCreate();

    final Bundle bundle = getIntent().getExtras();
    processIncomingBundle(bundle);


    if (reminders.size() == 0) {
        //JoH.static_toast_long("No reminders yet, add one!"); // replace with showcase?
        showcase(this, Home.SHOWCASE_REMINDER1);
    }
}
 
Example #27
Source Project: RecyclerViewDemo   Author: kymjs   File: Divider.java    License: Apache License 2.0 5 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    final int top = parent.getPaddingTop() + topMargin;
    final int bottom = parent.getHeight() - parent.getPaddingBottom() - bottomMargin;

    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 left = child.getRight() + params.rightMargin + leftMargin;
        final int right = left + width;
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
Example #28
Source Project: Awesome-WanAndroid   Author: JsonChao   File: NavigationFragment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Right recyclerView linkage left tabLayout
 * SCROLL_STATE_IDLE just call once
 *
 * @param newState RecyclerView new scroll state
 */
private void rightLinkageLeft(int newState) {
    if (newState == RecyclerView.SCROLL_STATE_IDLE) {
        if (isClickTab) {
            isClickTab = false;
            return;
        }
        int firstPosition = mManager.findFirstVisibleItemPosition();
        if (index != firstPosition) {
            index = firstPosition;
            setChecked(index);
        }
    }
}
 
Example #29
Source Project: Rocko-Android-Demos   Author: zhengxiaopeng   File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void init() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);
    setTitle(R.string.app_name);
    mToolbar.setTitleTextColor(Color.WHITE);

    mFabButton = (ImageButton) findViewById(R.id.fab);
    mFabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "FAB", Toast.LENGTH_SHORT).show();
        }
    });

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    RecyclerAdapter recyclerAdapter = new RecyclerAdapter(createItemList());
    recyclerView.setAdapter(recyclerAdapter);
    recyclerView.setOnScrollListener(new HidingScrollListener() {
        @Override
        public void onHide() {
            hideViews();
        }

        @Override
        public void onShow() {
            showViews();
        }
    });

}
 
Example #30
Source Project: YCBanner   Author: yangchong211   File: SevenActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_seven);
    mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    mRecyclerView2 = (RecyclerView) findViewById(R.id.recyclerView2);
    mRecyclerView3 = (RecyclerView) findViewById(R.id.recyclerView3);
    mRecyclerView4 = (RecyclerView) findViewById(R.id.recyclerView4);
    initRecyclerView();
    initRecyclerView2();
    initRecyclerView3();
    initRecyclerView4();
}