android.support.v7.widget.LinearSnapHelper Java Examples

The following examples show how to use android.support.v7.widget.LinearSnapHelper. 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: RecyclerWheelPicker.java    From RecyclerWheelPicker with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    initSound();

    setOverScrollMode(OVER_SCROLL_NEVER);
    setHasFixedSize(true);

    mDecorationPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mUnitTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mDecorationRect = new Rect();
    mDecoration = new DefaultDecoration();

    mAdapter = new WheelAdapter(context);
    super.setAdapter(mAdapter);
    mLayoutManager = new WheelPickerLayoutManager(this);
    super.setLayoutManager(mLayoutManager);
    new LinearSnapHelper().attachToRecyclerView(this);

    mCamera = new Camera();
    mMatrix = new Matrix();
}
 
Example #2
Source File: MainActivity.java    From BetterWay with Apache License 2.0 6 votes vote down vote up
/**
 * 初始化菜单等
 */
private void init() {
    LogUtil.d(TAG, "init");
    setSupportActionBar(mToolbar);
    mBlurFragment.setOnTouchListener(this);
    LinearLayoutManager linearLayoutManager =
            new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    scheduleAdapter = new ScheduleAdapter(mScheduleList);
    mRecyclerView.setLayoutManager(linearLayoutManager);
    if (mScheduleList.size() ==0) {
        mRecyclerView.setNestedScrollingEnabled(true);
    } else {
        mRecyclerView.setNestedScrollingEnabled(false);
    }
    new LinearSnapHelper().attachToRecyclerView(mRecyclerView);
    mRecyclerView.setAdapter(scheduleAdapter);
    scheduleAdapter.setAgency(new ScheduleAdapter.Agency() {
        @Override
        public void toDetails(int position) {
            mMainPresenterImpel.choseSchedule(position);
        }
    });
}
 
Example #3
Source File: MainActivity.java    From HorizontalPicker with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    rv = (RecyclerView) findViewById(R.id.rv);

    PickerLayoutManager pickerLayoutManager = new PickerLayoutManager(this, PickerLayoutManager.HORIZONTAL, false);
    pickerLayoutManager.setChangeAlpha(true);
    pickerLayoutManager.setScaleDownBy(0.99f);
    pickerLayoutManager.setScaleDownDistance(0.8f);

    adapter = new PickerAdapter(this, getData(100), rv);
    SnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(rv);
    rv.setLayoutManager(pickerLayoutManager);
    rv.setAdapter(adapter);

    pickerLayoutManager.setOnScrollStopListener(new PickerLayoutManager.onScrollStopListener() {
        @Override
        public void selectedView(View view) {
            Toast.makeText(MainActivity.this, ("Selected value : "+((TextView) view).getText().toString()), Toast.LENGTH_SHORT).show();
        }
    });
}
 
Example #4
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 #5
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 #6
Source File: CameraButtonRecyclerView.java    From CameraButton with Apache License 2.0 5 votes vote down vote up
public RecyclerView.OnScrollListener attach() {
    if (mSnap) {
        new LinearSnapHelper().attachToRecyclerView(mRecyclerView);
    }
    RecyclerView.OnScrollListener listener = new HorizontalCenterScrollListener(mCameraButton);
    mRecyclerView.addOnScrollListener(listener);
    return listener;
}
 
Example #7
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 #8
Source File: CharacterActivity.java    From Villains-and-Heroes with Apache License 2.0 5 votes vote down vote up
private void setupSectionView(RecyclerView recyclerView, @SectionVO.Type int type) {
    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setHasFixedSize(true);
    SectionAdapter adapter = new SectionAdapter(this, type, this);
    recyclerView.setAdapter(adapter);
    SnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(recyclerView);
}
 
Example #9
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 #10
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 #11
Source File: TVShowDetailActivity.java    From PopCorn with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tvshow_detail);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    setTitle("");

    Intent receivedIntent = getIntent();
    mTVShowId = receivedIntent.getIntExtra(Constants.TV_SHOW_ID, -1);

    if (mTVShowId == -1) finish();

    mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
    mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);

    mPosterWidth = (int) (getResources().getDisplayMetrics().widthPixels * 0.25);
    mPosterHeight = (int) (mPosterWidth / 0.66);
    mBackdropWidth = getResources().getDisplayMetrics().widthPixels;
    mBackdropHeight = (int) (mBackdropWidth / 1.77);

    mTVShowTabLayout = (ConstraintLayout) findViewById(R.id.layout_toolbar_tv_show);
    mTVShowTabLayout.getLayoutParams().height = mBackdropHeight + (int) (mPosterHeight * 0.9);

    mPosterImageView = (ImageView) findViewById(R.id.image_view_poster);
    mPosterImageView.getLayoutParams().width = mPosterWidth;
    mPosterImageView.getLayoutParams().height = mPosterHeight;
    mPosterProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_poster);
    mPosterProgressBar.setVisibility(View.GONE);

    mBackdropImageView = (ImageView) findViewById(R.id.image_view_backdrop);
    mBackdropImageView.getLayoutParams().height = mBackdropHeight;
    mBackdropProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_backdrop);
    mBackdropProgressBar.setVisibility(View.GONE);

    mTitleTextView = (TextView) findViewById(R.id.text_view_title_tv_show_detail);
    mGenreTextView = (TextView) findViewById(R.id.text_view_genre_tv_show_detail);
    mYearTextView = (TextView) findViewById(R.id.text_view_year_tv_show_detail);

    mBackImageButton = (ImageButton) findViewById(R.id.image_button_back_tv_show_detail);
    mBackImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });
    mFavImageButton = (ImageButton) findViewById(R.id.image_button_fav_tv_show_detail);
    mShareImageButton = (ImageButton) findViewById(R.id.image_button_share_tv_show_detail);

    mRatingLayout = (LinearLayout) findViewById(R.id.layout_rating_tv_show_detail);
    mRatingTextView = (TextView) findViewById(R.id.text_view_rating_tv_show_detail);

    mOverviewTextView = (TextView) findViewById(R.id.text_view_overview_tv_show_detail);
    mOverviewReadMoreTextView = (TextView) findViewById(R.id.text_view_read_more_tv_show_detail);
    mDetailsLayout = (LinearLayout) findViewById(R.id.layout_details_tv_show_detail);
    mDetailsTextView = (TextView) findViewById(R.id.text_view_details_tv_show_detail);

    mVideosTextView = (TextView) findViewById(R.id.text_view_trailer_tv_show_detail);
    mVideosRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_trailers_tv_show_detail);
    (new LinearSnapHelper()).attachToRecyclerView(mVideosRecyclerView);
    mVideos = new ArrayList<>();
    mVideosAdapter = new VideoAdapter(TVShowDetailActivity.this, mVideos);
    mVideosRecyclerView.setAdapter(mVideosAdapter);
    mVideosRecyclerView.setLayoutManager(new LinearLayoutManager(TVShowDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));

    mHorizontalLine = (View) findViewById(R.id.view_horizontal_line);

    mCastTextView = (TextView) findViewById(R.id.text_view_cast_tv_show_detail);
    mCastRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_cast_tv_show_detail);
    mCasts = new ArrayList<>();
    mCastAdapter = new TVShowCastAdapter(TVShowDetailActivity.this, mCasts);
    mCastRecyclerView.setAdapter(mCastAdapter);
    mCastRecyclerView.setLayoutManager(new LinearLayoutManager(TVShowDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));

    mSimilarTVShowsTextView = (TextView) findViewById(R.id.text_view_similar_tv_show_detail);
    mSimilarTVShowsRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_similar_tv_show_detail);
    mSimilarTVShows = new ArrayList<>();
    mSimilarTVShowsAdapter = new TVShowBriefsSmallAdapter(TVShowDetailActivity.this, mSimilarTVShows);
    mSimilarTVShowsRecyclerView.setAdapter(mSimilarTVShowsAdapter);
    mSimilarTVShowsRecyclerView.setLayoutManager(new LinearLayoutManager(TVShowDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));

    if (NetworkConnection.isConnected(TVShowDetailActivity.this)) {
        isActivityLoaded = true;
        loadActivity();
    }

}
 
Example #12
Source File: MovieDetailActivity.java    From PopCorn with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie_detail);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(mToolbar);

    setTitle("");

    Intent receivedIntent = getIntent();
    mMovieId = receivedIntent.getIntExtra(Constants.MOVIE_ID, -1);

    if (mMovieId == -1) finish();

    mCollapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar_layout);
    mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar);

    mPosterWidth = (int) (getResources().getDisplayMetrics().widthPixels * 0.25);
    mPosterHeight = (int) (mPosterWidth / 0.66);
    mBackdropWidth = getResources().getDisplayMetrics().widthPixels;
    mBackdropHeight = (int) (mBackdropWidth / 1.77);

    mMovieTabLayout = (ConstraintLayout) findViewById(R.id.layout_toolbar_movie);
    mMovieTabLayout.getLayoutParams().height = mBackdropHeight + (int) (mPosterHeight * 0.9);

    mPosterImageView = (ImageView) findViewById(R.id.image_view_poster);
    mPosterImageView.getLayoutParams().width = mPosterWidth;
    mPosterImageView.getLayoutParams().height = mPosterHeight;
    mPosterProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_poster);
    mPosterProgressBar.setVisibility(View.GONE);

    mBackdropImageView = (ImageView) findViewById(R.id.image_view_backdrop);
    mBackdropImageView.getLayoutParams().height = mBackdropHeight;
    mBackdropProgressBar = (AVLoadingIndicatorView) findViewById(R.id.progress_bar_backdrop);
    mBackdropProgressBar.setVisibility(View.GONE);

    mTitleTextView = (TextView) findViewById(R.id.text_view_title_movie_detail);
    mGenreTextView = (TextView) findViewById(R.id.text_view_genre_movie_detail);
    mYearTextView = (TextView) findViewById(R.id.text_view_year_movie_detail);

    mBackImageButton = (ImageButton) findViewById(R.id.image_button_back_movie_detail);
    mBackImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            onBackPressed();
        }
    });
    mFavImageButton = (ImageButton) findViewById(R.id.image_button_fav_movie_detail);
    mShareImageButton = (ImageButton) findViewById(R.id.image_button_share_movie_detail);

    mRatingLayout = (LinearLayout) findViewById(R.id.layout_rating_movie_detail);
    mRatingTextView = (TextView) findViewById(R.id.text_view_rating_movie_detail);

    mOverviewTextView = (TextView) findViewById(R.id.text_view_overview_movie_detail);
    mOverviewReadMoreTextView = (TextView) findViewById(R.id.text_view_read_more_movie_detail);
    mDetailsLayout = (LinearLayout) findViewById(R.id.layout_details_movie_detail);
    mDetailsTextView = (TextView) findViewById(R.id.text_view_details_movie_detail);

    mTrailerTextView = (TextView) findViewById(R.id.text_view_trailer_movie_detail);
    mTrailerRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_trailers_movie_detail);
    (new LinearSnapHelper()).attachToRecyclerView(mTrailerRecyclerView);
    mTrailers = new ArrayList<>();
    mTrailerAdapter = new VideoAdapter(MovieDetailActivity.this, mTrailers);
    mTrailerRecyclerView.setAdapter(mTrailerAdapter);
    mTrailerRecyclerView.setLayoutManager(new LinearLayoutManager(MovieDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));

    mHorizontalLine = (View) findViewById(R.id.view_horizontal_line);

    mCastTextView = (TextView) findViewById(R.id.text_view_cast_movie_detail);
    mCastRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_cast_movie_detail);
    mCasts = new ArrayList<>();
    mCastAdapter = new MovieCastsAdapter(MovieDetailActivity.this, mCasts);
    mCastRecyclerView.setAdapter(mCastAdapter);
    mCastRecyclerView.setLayoutManager(new LinearLayoutManager(MovieDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));

    mSimilarMoviesTextView = (TextView) findViewById(R.id.text_view_similar_movie_detail);
    mSimilarMoviesRecyclerView = (RecyclerView) findViewById(R.id.recycler_view_similar_movie_detail);
    mSimilarMovies = new ArrayList<>();
    mSimilarMoviesAdapter = new MovieBriefsSmallAdapter(MovieDetailActivity.this, mSimilarMovies);
    mSimilarMoviesRecyclerView.setAdapter(mSimilarMoviesAdapter);
    mSimilarMoviesRecyclerView.setLayoutManager(new LinearLayoutManager(MovieDetailActivity.this, LinearLayoutManager.HORIZONTAL, false));

    if (NetworkConnection.isConnected(MovieDetailActivity.this)) {
        isActivityLoaded = true;
        loadActivity();
    }

}
 
Example #13
Source File: SimpleRecyclerView.java    From SimpleRecyclerView with Apache License 2.0 4 votes vote down vote up
public void enableSnappy(@NonNull SnapAlignment alignment) {
  SnapHelper snapHelper = alignment.equals(SnapAlignment.CENTER) ?
    new LinearSnapHelper() : new StartSnapHelper(spacing);
  snapHelper.attachToRecyclerView(this);
}
 
Example #14
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 #15
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 #16
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 #17
Source File: HomeBaseAdapter.java    From MangoBloggerAndroidApp with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    HomeGroup snap = mSnaps.get(position);
    holder.snapTextView.setText(snap.getText());

    if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
                .recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
        holder.recyclerView.setOnFlingListener(null);
        new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
    } else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL) {
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
                .recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ?
                LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
        holder.recyclerView.setOnFlingListener(null);
        new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
    } else if (snap.getGravity() == Gravity.CENTER) { // Pager snap
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
                .recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
        holder.recyclerView.setOnFlingListener(null);
        new PagerSnapHelper().attachToRecyclerView(holder.recyclerView);
    } else { // Top / Bottom
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder
                .recyclerView.getContext()));
        holder.recyclerView.setOnFlingListener(null);
        new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
    }

    HomeItemAdapter itemAdapter = new HomeItemAdapter(mContext, snap.getCardSize(), snap.getApps());
    holder.recyclerView.setAdapter(itemAdapter);
    itemAdapter.setOnItemClickListener(new HomeItemAdapter.OnItemClickListener() {
        @Override
        public void itemClick(HomeItem item, int Position) {
            if(mContext instanceof HomeActivity) {
                if(item.isWebView()) {
                    ((HomeActivity) mContext).attachFragment(WebFragment.newInstance(item.getUrl(), item.getName()), true);
                } else {
                    ((HomeActivity) mContext).attachFragment(FirebaseListFragment.newInstance(item.getUrl(), item.getExtra()), true);
                }
            }
        }
    });

}