Search in sources :

Example 1 with SnapHelper

use of android.support.v7.widget.SnapHelper in project Horizontal-Calendar by Mulham-Raee.

the class HorizontalCalendar method loadHorizontalCalendar.

/* Init Calendar View */
private void loadHorizontalCalendar() {
    dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
    mListDays = new ArrayList<>();
    calendarView = (HorizontalCalendarView) rootView.findViewById(calendarId);
    calendarView.setHasFixedSize(true);
    calendarView.setHorizontalScrollBarEnabled(false);
    calendarView.setHorizontalCalendar(this);
    LinearSnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(calendarView);
    hide();
    new InitializeDatesList().execute();
}
Also used : LinearSnapHelper(android.support.v7.widget.LinearSnapHelper) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with SnapHelper

use of android.support.v7.widget.SnapHelper in project SmartRefreshLayout by scwang90.

the class SnapHelperExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_snaphelper);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    // 初始化列表和监听
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(new BaseRecyclerAdapter<Integer>(loadModels(), R.layout.listitem_example_snaphelper) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Integer model, int position) {
                holder.image(R.id.imageView, model);
            }
        });
        SnapHelper snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(recyclerView);
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) RecyclerView(android.support.v7.widget.RecyclerView) SnapHelper(android.support.v7.widget.SnapHelper) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with SnapHelper

use of android.support.v7.widget.SnapHelper in project Shuttle by timusus.

the class QueuePagerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_queue_pager, container, false);
    unbinder = ButterKnife.bind(this, rootView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    if (ShuttleUtils.isLandscape()) {
        textProtectionScrim.setVisibility(View.GONE);
    }
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(viewModelAdapter);
    SnapHelper snapHelper = new PagerSnapHelper() {

        @Override
        public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
            int snapPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
            if (snapPosition < viewModelAdapter.items.size()) {
                Observable.defer(() -> {
                    if (MusicUtils.getQueuePosition() != snapPosition) {
                        MusicUtils.setQueuePosition(snapPosition);
                    }
                    return Observable.empty();
                }).delaySubscription(150, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.io()).subscribe();
            }
            return snapPosition;
        }
    };
    snapHelper.attachToRecyclerView(recyclerView);
    recyclerView.addOnScrollListener(new RecyclerViewPreloader<>(new ListPreloader.PreloadModelProvider<QueuePagerItemView>() {

        @Override
        public List<QueuePagerItemView> getPreloadItems(int position) {
            QueuePagerItemView queuePagerItemView = (QueuePagerItemView) viewModelAdapter.items.get(position);
            return Collections.singletonList(queuePagerItemView);
        }

        @Override
        public GenericRequestBuilder getPreloadRequestBuilder(QueuePagerItemView item) {
            return requestManager.load(item.song).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(PlaceholderProvider.getInstance().getPlaceHolderDrawable(item.song.name, true));
        }
    }, (item, adapterPosition, perItemPosition) -> imageSize, 3));
    recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            // This null check doesn't make sense to me, but there was an NPE here..
            if (recyclerView != null) {
                imageSize = new int[] { recyclerView.getWidth(), recyclerView.getHeight() };
                recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
            }
            return false;
        }
    });
    return rootView;
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) SnapHelper(android.support.v7.widget.SnapHelper) ButterKnife(butterknife.ButterKnife) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) BindView(butterknife.BindView) Inject(javax.inject.Inject) GenericRequestBuilder(com.bumptech.glide.GenericRequestBuilder) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) RequestManager(com.bumptech.glide.RequestManager) ListPreloader(com.bumptech.glide.ListPreloader) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) View(android.view.View) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Unbinder(butterknife.Unbinder) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) QueuePagerView(com.simplecity.amp_library.ui.views.QueuePagerView) LayoutInflater(android.view.LayoutInflater) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewGroup(android.view.ViewGroup) RecyclerViewPreloader(com.simplecity.amp_library.glide.preloader.RecyclerViewPreloader) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) FragmentModule(com.simplecity.amp_library.dagger.module.FragmentModule) ViewTreeObserver(android.view.ViewTreeObserver) QueuePagerPresenter(com.simplecity.amp_library.ui.presenters.QueuePagerPresenter) Collections(java.util.Collections) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) QueuePagerView(com.simplecity.amp_library.ui.views.QueuePagerView) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) SnapHelper(android.support.v7.widget.SnapHelper) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) ViewTreeObserver(android.view.ViewTreeObserver)

Example 4 with SnapHelper

use of android.support.v7.widget.SnapHelper in project mvpanimation by androidMVP.

the class ExpandingActivity method initView.

private void initView() {
    List<Integer> lists = new ArrayList<Integer>();
    lists.add(1);
    lists.add(2);
    lists.add(3);
    lists.add(4);
    lists.add(5);
    lists.add(6);
    lists.add(7);
    lists.add(8);
    lists.add(9);
    RecyclerView recyclerView = findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    ExpandingAdapter cardAdapter = new ExpandingAdapter(lists);
    recyclerView.setAdapter(cardAdapter);
    SnapHelper snapHelper = new LinearSnapHelper();
    snapHelper.attachToRecyclerView(recyclerView);
}
Also used : ArrayList(java.util.ArrayList) LinearSnapHelper(android.support.v7.widget.LinearSnapHelper) RecyclerView(android.support.v7.widget.RecyclerView) LinearSnapHelper(android.support.v7.widget.LinearSnapHelper) SnapHelper(android.support.v7.widget.SnapHelper) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 5 with SnapHelper

use of android.support.v7.widget.SnapHelper in project Andela-Med-Manager by jumaallan.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActivityMainBinding binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
    User user = new User(Long.valueOf("1"), "Data Binding", "User");
    binding.setUser(user);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ButterKnife.bind(this);
    profileDialog = ProfileDialog.newInstance(((dialog, which) -> logout()));
    calendar = Calendar.getInstance();
    simpleDateFormat = new SimpleDateFormat("EEEE, MMM d, yyyy");
    String currentDate = simpleDateFormat.format(calendar.getTime());
    date.setText(currentDate);
    menuViewList = getMenuOptions();
    recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    ItemOffsetDecoration itemDecoration = new ItemOffsetDecoration(this, R.dimen.item_offset);
    recyclerView.addItemDecoration(itemDecoration);
    MainDashboardAdapter mainDashboardAdapter = new MainDashboardAdapter(this, menuViewList, (v, position) -> {
        MenuView role = menuViewList.get(position);
        String menuName = role.getName();
        switch(menuName) {
            case "Add Medicine":
                Intent addMedicine = new Intent(getApplicationContext(), AddMedicineActivity.class);
                startActivity(addMedicine);
                break;
            case "Profile":
                break;
            case "Reminders":
                break;
            case "Monthly Intake":
                break;
            default:
                Toast.makeText(MainActivity.this, "Sorry, It's Under development", Toast.LENGTH_SHORT).show();
                break;
        }
    });
    recyclerView.setAdapter(mainDashboardAdapter);
    DailyMedicineStatisticsAdapter dailyMedicineStatisticsAdapter = new DailyMedicineStatisticsAdapter(this, new ArrayList<>());
    recyclerViewDailyMedicineStatistics.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
    // add pager behavior
    PagerSnapHelper snapHelper = new PagerSnapHelper();
    snapHelper.attachToRecyclerView(recyclerViewDailyMedicineStatistics);
    // pager indicator
    recyclerViewDailyMedicineStatistics.addItemDecoration(new CirclePagerIndicatorDecoration());
    recyclerViewDailyMedicineStatistics.setAdapter(dailyMedicineStatisticsAdapter);
// MedicineViewModel medicineViewModel = ViewModelProviders.of(this).get(MedicineViewModel.class);
// medicineViewModel.getMedicineList().observe(MainActivity.this, dailyMedicineStatisticsAdapter::addItems);
}
Also used : User(com.androidstudy.medmanager.data.model.User) DailyMedicineStatisticsAdapter(com.androidstudy.medmanager.ui.adapter.DailyMedicineStatisticsAdapter) Intent(android.content.Intent) ItemOffsetDecoration(com.androidstudy.medmanager.util.ItemOffsetDecoration) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GridLayoutManager(android.support.v7.widget.GridLayoutManager) MainDashboardAdapter(com.androidstudy.medmanager.ui.adapter.MainDashboardAdapter) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) MenuView(com.androidstudy.medmanager.data.model.MenuView) CirclePagerIndicatorDecoration(com.androidstudy.medmanager.util.CirclePagerIndicatorDecoration) ActivityMainBinding(com.androidstudy.medmanager.databinding.ActivityMainBinding) SimpleDateFormat(java.text.SimpleDateFormat) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 PagerSnapHelper (android.support.v7.widget.PagerSnapHelper)5 RecyclerView (android.support.v7.widget.RecyclerView)3 SnapHelper (android.support.v7.widget.SnapHelper)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 LinearSnapHelper (android.support.v7.widget.LinearSnapHelper)2 Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 SimpleDateFormat (java.text.SimpleDateFormat)2 PendingIntent (android.app.PendingIntent)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LayoutInflater (android.view.LayoutInflater)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 Unbinder (butterknife.Unbinder)1