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();
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations