android.support.v7.widget.PagerSnapHelper Java Examples

The following examples show how to use android.support.v7.widget.PagerSnapHelper. 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: SuntimesActivity.java    From SuntimesWidget with GNU General Public License v3.0 6 votes vote down vote up
/**
 * initialize the card flipper and associated views
 * @param context a context used to access resources
 */
private void initCardViews(Context context)
{
    card_adapter = new CardAdapter(context);
    card_adapter.setCardAdapterListener(cardAdapterListener);

    card_view = (RecyclerView) findViewById(R.id.info_time_flipper1);
    card_view.setHasFixedSize(true);
    card_view.setItemViewCacheSize(7);
    card_view.setLayoutManager(card_layout = new CardLayoutManager(this));
    card_view.addItemDecoration(new CardAdapter.CardViewDecorator(this));

    card_view.setAdapter(card_adapter);
    card_view.scrollToPosition(CardAdapter.TODAY_POSITION);

    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(card_view);
    card_scroller = new CardAdapter.CardViewScroller(context);
    card_view.setOnScrollListener(onCardScrollListener);
}
 
Example #2
Source File: ViewPagerActivity.java    From recyclerviewItemDecorations with MIT License 6 votes vote down vote up
@Override
public void onCreateRecyclerView(Bundle savedInstanceState) {
  int backgroundColor = 0xFF665F30;
  Context context = this;
  recyclerView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
  recyclerView.setBackgroundColor(backgroundColor);

  SimpleViewAdapter adapter = new SimpleViewAdapter(5, R.layout.item_view_pager_page);

  recyclerView.setAdapter(adapter);
  recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));

  // add pager behavior
  PagerSnapHelper snapHelper = new PagerSnapHelper();
  snapHelper.attachToRecyclerView(recyclerView);

  // pager indicator
  recyclerView.addItemDecoration(new LinePagerIndicatorDecoration());

}
 
Example #3
Source File: LoopBanner.java    From LoopBanner with Apache License 2.0 5 votes vote down vote up
private void setupViewPager(final RecyclerView viewPager) {

        mLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
        viewPager.setLayoutManager(mLayoutManager);

        initFirstWidth();

        mSnapHelper = new PagerSnapHelper();
        mSnapHelper.attachToRecyclerView(viewPager);
        viewPager.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                final int cur = findCurPosition();
                if (cur != mLastPosition) {
                    Tools.logI(TAG, "onPageSelected: " + cur);
                    mCurrentIndex = cur;
                    notifySelectChange(cur);
                    updateIndicators(cur, mLastPosition);
                    mLastPosition = cur;
                }
                switch (newState) {
                    case SCROLL_STATE_DRAGGING:
                        stopInternal();
                        break;
                    case SCROLL_STATE_IDLE:
                        startInternal(false);
                        break;
                    default:
                }
            }
        });


//        if (mLrScale > 0 && mLrScale < 1) {
//            viewPager.setPageTransformer(false, new ScalePageTransformer(mLrScale));
//        }
    }
 
Example #4
Source File: PreviewActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
private void initRecyclerView() {
    rvPhotos = (RecyclerView) findViewById(R.id.rv_photos);
    adapter = new PreviewPhotosAdapter(this, photos, this);
    lm = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    rvPhotos.setLayoutManager(lm);
    rvPhotos.setAdapter(adapter);
    rvPhotos.scrollToPosition(index);
    toggleSelector();
    snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(rvPhotos);
    rvPhotos.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);

            View view = snapHelper.findSnapView(lm);
            if (view == null) {
                return;
            }
            int position = lm.getPosition(view);
            if (lastPosition == position) {
                return;
            }
            lastPosition = position;
            previewFragment.setSelectedPosition(-1);
            tvNumber.setText(getString(R.string.preview_current_number_easy_photos, lastPosition + 1, photos.size()));
            toggleSelector();
            PreviewPhotosAdapter.PreviewPhotosViewHolder holder = (PreviewPhotosAdapter.PreviewPhotosViewHolder) rvPhotos.getChildViewHolder(view);
            if (holder == null || holder.ivPhoto == null) {
                return;
            }
            if (holder.ivPhoto.getScale() != 1f) {
                holder.ivPhoto.setScale(1f, true);


            }
        }
    });
    tvNumber.setText(getString(R.string.preview_current_number_easy_photos, index + 1, photos.size()));
}
 
Example #5
Source File: HomeActivity.java    From Cinema-App-Concept with MIT License 5 votes vote down vote up
public void init(){

        //Changing the font throughout the activity

        regular = Typeface.createFromAsset(getAssets(), "fonts/product_san_regular.ttf");
        bold = Typeface.createFromAsset(getAssets(),"fonts/product_sans_bold.ttf");
        regularFontChanger = new FontChanger(regular);
        boldFontChanger = new FontChanger(bold);
        moviesRV = findViewById(R.id.moviesRV);
        movieList = new ArrayList<>();
        movieAdapter = new MovieAdapter(movieList,HomeActivity.this);
        layoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
        snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(moviesRV);
        moviesRV.setLayoutManager(layoutManager);
        moviesRV.addItemDecoration(new LinePagerIndicatorDecoration(HomeActivity.this));
        moviesRV.setAdapter(movieAdapter);

        backdropIV = findViewById(R.id.backdropIV);
        MiddleItemFinder.MiddleItemCallback callback =
                new MiddleItemFinder.MiddleItemCallback() {
                    @Override
                    public void scrollFinished(int middleElement) {
                        // interaction with middle item
                        onActiveCardChange(middleElement);
                    }
                };
        moviesRV.addOnScrollListener(
                new MiddleItemFinder(getApplicationContext(), layoutManager,
                        callback, RecyclerView.SCROLL_STATE_IDLE));




    }
 
Example #6
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 #7
Source File: EquinoxView.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void init(Context context, AttributeSet attrs)
{
    initLocale(context);
    themeViews(context);
    LayoutInflater.from(context).inflate(R.layout.layout_view_equinox, this, true);

    if (attrs != null)
    {
        LinearLayout.LayoutParams lp = generateLayoutParams(attrs);
        options.centered = ((lp.gravity == Gravity.CENTER) || (lp.gravity == Gravity.CENTER_HORIZONTAL));
    }

    empty = (TextView)findViewById(R.id.txt_empty);

    card_view = (RecyclerView)findViewById(R.id.info_equinoxsolstice_flipper1);
    card_view.setHasFixedSize(true);
    card_view.setItemViewCacheSize(7);
    card_view.setLayoutManager(card_layout = new CardLayoutManager(context));
    //card_view.addItemDecoration(new CardAdapter.CardViewDecorator(context));

    card_adapter = new EquinoxViewAdapter(context, options);
    card_adapter.setEquinoxViewListener(cardListener);
    card_view.setAdapter(card_adapter);
    card_view.scrollToPosition(EquinoxViewAdapter.CENTER_POSITION);

    SnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(card_view);
    card_scroller = new CardAdapter.CardViewScroller(context);

    boolean minimized = isMinimized();
    if (!minimized) {
        card_view.setOnScrollListener(onCardScrollListener);
    }
    card_view.setLayoutFrozen(minimized);

    if (isInEditMode()) {
        updateViews(context);
    }
}
 
Example #8
Source File: PagerLayoutManager.java    From DouYinWu with MIT License 4 votes vote down vote up
private void init() {
    mPagerSnapHelper = new PagerSnapHelper();
}
 
Example #9
Source File: MovieDetailsActivity.java    From Cinema-App-Concept with MIT License 4 votes vote down vote up
public void init(){



        postponeEnterTransition();
        descCV = findViewById(R.id.descCV);
        //Changing the font throughout the activity
        regular = Typeface.createFromAsset(getAssets(), "fonts/product_san_regular.ttf");
        bold = Typeface.createFromAsset(getAssets(),"fonts/product_sans_bold.ttf");
        regularFontChanger = new FontChanger(regular);
        boldFontChanger = new FontChanger(bold);
        movieNameTV = findViewById(R.id.movieNameTV);
        genreTV = findViewById(R.id.genreTV);
        descTV = findViewById(R.id.descriptionTV);
        backdropIV = findViewById(R.id.backdropIV);
        sessionLL = findViewById(R.id.sessionLL);
        timeSelectionLL = findViewById(R.id.timeSelectionLL);
        detailsLL = findViewById(R.id.detailsLL);
        sessionTimeButton = findViewById(R.id.sessionTimeBTN);
        picturesRV = findViewById(R.id.picturesRV);
        ptMovieList = new ArrayList<>();
        ptAdapter = new PTAdapter(ptMovieList,MovieDetailsActivity.this);
        bookTicketsBTN = findViewById(R.id.bookTicketsBTN);
        layoutManager = new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL,false);
        snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(picturesRV);
        picturesRV.setLayoutManager(layoutManager);
        picturesRV.addItemDecoration(new LinePagerIndicatorDecoration(MovieDetailsActivity.this));
        picturesRV.setAdapter(ptAdapter);
        picturesRV.post(new Runnable() {
            @Override
            public void run() {
                supportStartPostponedEnterTransition();


            }
        });


        MiddleItemFinder.MiddleItemCallback callback =
                new MiddleItemFinder.MiddleItemCallback() {
                    @Override
                    public void scrollFinished(int middleElement) {
                        // interaction with middle item
                        currentPosition = middleElement;

                    }
                };
        picturesRV.addOnScrollListener(
                new MiddleItemFinder(getApplicationContext(), layoutManager,
                        callback, RecyclerView.SCROLL_STATE_IDLE));

        picturesRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                System.out.println("Testing "+dx);

            }
        });

        movieTimeRV = findViewById(R.id.movieTimeRV);
        movieTimeList = new ArrayList<>();
        timeSelectionAdapter = new TimeSelectionAdapter(movieTimeList,MovieDetailsActivity.this);
        LinearLayoutManager layoutManager1 = new LinearLayoutManager(MovieDetailsActivity.this,LinearLayoutManager.HORIZONTAL,false);
        movieTimeRV.setLayoutManager(layoutManager1);
        movieTimeRV.setAdapter(timeSelectionAdapter);

        movieTimeList.add(new MovieTime("7:00 am",300,250));
        movieTimeList.add(new MovieTime("11:00 am",300,120));
        movieTimeList.add(new MovieTime("3:00 pm",300,60));
        movieTimeList.add(new MovieTime("6:45 pm",300,50));
        movieTimeList.add(new MovieTime("10:00 pm",300,170));
        timeSelectionAdapter.notifyDataSetChanged();

    }
 
Example #10
Source File: GalleryLayoutManager.java    From YCGallery with Apache License 2.0 4 votes vote down vote up
private void init() {
    mSnapHelper = new PagerSnapHelper();
}
 
Example #11
Source File: EyepetizerFragment.java    From Ency with Apache License 2.0 4 votes vote down vote up
@Override
protected void initialize() {
    swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
    swipeRefreshLayout.setRefreshing(true);
    swipeRefreshLayout.setOnRefreshListener(this);

    mPresenter.getVideoData(page, Constants.EYEPETIZER_UDID,"weekly", "256", "XXX");
    mPresenter.getPTP();

    View headerView = getActivity().getLayoutInflater().inflate(R.layout.header_eyepetizer, null);
    recyclerViewTop = headerView.findViewById(R.id.recyclerview_eyepetizer_top);
    tvHot = headerView.findViewById(R.id.txt_hot);
    tvLike = headerView.findViewById(R.id.txt_like);
    llMore = headerView.findViewById(R.id.layout_more);

    llMore.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(mContext, EyepetizerHotActivity.class);
            intent.putExtra("data", hotVideoBean);
            mContext.startActivity(intent);
        }
    });

    hotAdapter = new Eyepetizer2Adapter();
    hotAdapter.setOnItemClickListener(this);
    recyclerViewTop.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false));
    recyclerViewTop.setAdapter(hotAdapter);
    recyclerViewTop.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            switch (newState) {
                case RecyclerView.SCROLL_STATE_DRAGGING:
                    swipeRefreshLayout.setEnabled(false);
                    break;
                case RecyclerView.SCROLL_STATE_IDLE:
                    swipeRefreshLayout.setEnabled(true);
                    break;
            }
        }
    });
    new PagerSnapHelper().attachToRecyclerView(recyclerViewTop);

    dailyAdapter = new EyepetizerAdapter();
    dailyAdapter.setOnItemClickListener(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
    recyclerView.setAdapter(dailyAdapter);
    dailyAdapter.addHeaderView(headerView);
    dailyAdapter.setOnLoadMoreListener(this, recyclerView);
}
 
Example #12
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);
                }
            }
        }
    });

}