Java Code Examples for android.support.v7.widget.LinearSnapHelper#attachToRecyclerView()

The following examples show how to use android.support.v7.widget.LinearSnapHelper#attachToRecyclerView() . 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 File: ReelSearchView.java    From reel-search-android with MIT License 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();


    // Ensuring child count and throwing exception otherwise
    if (getChildCount() != 2) {
        throw new IllegalStateException("Must have exactly 2 children");
    }

    View temp = getChildAt(0);

    if (temp instanceof RecyclerView) {
        mRecyclerView = (RecyclerView) temp;
    } else {
        throw new IllegalStateException("First child must be a RecyclerView or its descendant");
    }

    temp = getChildAt(1);

    if (temp instanceof EditText) {
        mEditText = (EditText) temp;
    } else {
        throw new IllegalStateException("Second child must be an EditText or its descendant");
    }

    // Initializing all members
    mLayoutManager = new CenteredLayoutManager();
    mLayoutManager.setChildTransformer(new AlphaChildTransformer());
    mRecyclerView.setLayoutManager(mLayoutManager);
    mLinearSnapHelper = new LinearSnapHelper();
    mLinearSnapHelper.attachToRecyclerView(mRecyclerView);
}
 
Example 2
Source File: SevenActivity.java    From YCBanner with Apache License 2.0 5 votes vote down vote up
private void initRecyclerView2() {
    LinearLayoutManager manager = new LinearLayoutManager(this);
    manager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mRecyclerView2.setLayoutManager(manager);
    LinearSnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(mRecyclerView2);
    SnapAdapter adapter = new SnapAdapter(this);
    mRecyclerView2.setAdapter(adapter);
    adapter.addAll(getData());
}
 
Example 3
Source File: ScrollManager.java    From Recyclerview-Gallery with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化SnapHelper
 *
 * @param helper int
 */
public void initSnapHelper(int helper) {
    switch (helper) {
        case GalleryRecyclerView.LINEAR_SNAP_HELPER:
            LinearSnapHelper mLinearSnapHelper = new LinearSnapHelper();
            mLinearSnapHelper.attachToRecyclerView(mGalleryRecyclerView);
            break;
        case GalleryRecyclerView.PAGER_SNAP_HELPER:
            PagerSnapHelper mPagerSnapHelper = new PagerSnapHelper();
            mPagerSnapHelper.attachToRecyclerView(mGalleryRecyclerView);
            break;
        default:
            break;
    }
}
 
Example 4
Source File: DailyGankFragment.java    From GankLock with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void initView() {
    mActivity = (AppCompatActivity) mContext;
    mToolbar = mContext.findViewById(R.id.toolbar_daily_fragment);
    mActivity.setSupportActionBar(mToolbar);
    mActivity.setTitle(R.string.bottom_bar_gank);
    mToolbar.inflateMenu(R.menu.main_menu);
    mRecyclerView = mContext.findViewById(R.id.daily_recycler_view);
    LinearLayoutManager manager = new LinearLayoutManager(mContext);
    manager.setOrientation(LinearLayoutManager.HORIZONTAL);
    mRecyclerView.setLayoutManager(manager);
    mRecyclerView.setItemAnimator(new DefaultItemAnimator());
    mSnapHelper = new LinearSnapHelper();
    if (mRecyclerView.getOnFlingListener() == null) {
        mSnapHelper.attachToRecyclerView(mRecyclerView);
    }
    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            LinearLayoutManager layoutManager
                = (LinearLayoutManager) recyclerView.getLayoutManager();
            int totalItemCount = layoutManager.getItemCount();
            int lastVisibleItem = layoutManager.findLastVisibleItemPosition();
            if (totalItemCount <= lastVisibleItem + 1) {
                loadDailyData(mPage+=1);
            }

        }
    });
    mProgressBar = mContext.findViewById(R.id.daily_loading_progress_bar);
    mFailureTextView = mContext.findViewById(R.id.daily_get_failure_tip);
}
 
Example 5
Source File: Slider.java    From Virtualview-Android with MIT License 4 votes vote down vote up
public Slider(VafContext context, ViewCache viewCache) {
    super(context, viewCache);

    LinearSnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(mNative);
}
 
Example 6
Source File: HomeFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void showRecents() {
    final RootInfo root = roots.getRecentsRoot();
    recents.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openRoot(root);
        }
    });

    mRecentsAdapter = new RecentsAdapter(getActivity(), null);
    mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
            openDocument(item.mDocumentInfo);
        }
    });
    mRecentsRecycler.setAdapter(mRecentsAdapter);
    LinearSnapHelper helper = new LinearSnapHelper();
    helper.attachToRecyclerView(mRecentsRecycler);

    final BaseActivity.State state = getDisplayState(this);
    mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {

        @Override
        public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
            final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
            return new RecentLoader(getActivity(), roots, state);
        }

        @Override
        public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
            if (!isAdded())
                return;
            if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
                recents_container.setVisibility(View.GONE);
            } else {
                //recents_container.setVisibility(View.VISIBLE);
                mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
            }
        }

        @Override
        public void onLoaderReset(Loader<DirectoryResult> loader) {
            mRecentsAdapter.swapCursor(null);
        }
    };
    getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
 
Example 7
Source File: HomeFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void showRecents() {
    final RootInfo root = roots.getRecentsRoot();
    recents.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openRoot(root);
        }
    });

    mRecentsAdapter = new RecentsAdapter(getActivity(), null);
    mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
            openDocument(item.mDocumentInfo);
        }
    });
    mRecentsRecycler.setAdapter(mRecentsAdapter);
    LinearSnapHelper helper = new LinearSnapHelper();
    helper.attachToRecyclerView(mRecentsRecycler);

    final BaseActivity.State state = getDisplayState(this);
    mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {

        @Override
        public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
            final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
            return new RecentLoader(getActivity(), roots, state);
        }

        @Override
        public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
            if (!isAdded())
                return;
            if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
                recents_container.setVisibility(View.GONE);
            } else {
                //recents_container.setVisibility(View.VISIBLE);
                mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
            }
        }

        @Override
        public void onLoaderReset(Loader<DirectoryResult> loader) {
            mRecentsAdapter.swapCursor(null);
        }
    };
    getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
 
Example 8
Source File: HomeFragment.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
private void showRecents() {
    final RootInfo root = roots.getRecentsRoot();
    recents.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            openRoot(root);
        }
    });

    mRecentsAdapter = new RecentsAdapter(getActivity(), null);
    mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
            openDocument(item.mDocumentInfo);
        }
    });
    mRecentsRecycler.setAdapter(mRecentsAdapter);
    LinearSnapHelper helper = new LinearSnapHelper();
    helper.attachToRecyclerView(mRecentsRecycler);

    final BaseActivity.State state = getDisplayState(this);
    mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {

        @Override
        public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
            final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
            return new RecentLoader(getActivity(), roots, state);
        }

        @Override
        public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
            if (!isAdded())
                return;
            if(null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
                recents_container.setVisibility(View.GONE);
            } else {
                //recents_container.setVisibility(View.VISIBLE);
                mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
            }
        }

        @Override
        public void onLoaderReset(Loader<DirectoryResult> loader) {
            mRecentsAdapter.swapCursor(null);
        }
    };
    getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}