use of androidx.recyclerview.widget.LinearLayoutManager in project Carbon by ZieIony.
the class SampleListActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences preferences = getSharedPreferences("samples", Context.MODE_PRIVATE);
allPreferences = (Map<String, String>) preferences.getAll();
RecyclerView recyclerView = findViewById(R.id.recycler);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
adapter = new RowListAdapter<>();
adapter.putFactory(SampleActivityGroup.class, parent -> new DataBindingComponent<>(parent, R.layout.row_main));
adapter.putFactory(SampleActivityItem.class, parent -> {
return new DataBindingComponent<SampleActivityItem>(parent, R.layout.row_sample) {
@Override
public void bind(SampleActivityItem data) {
super.bind(data);
getView().findViewById(R.id.star).setOnClickListener(v -> {
data.setStarred(!data.isStarred());
if (data.isStarred()) {
preferences.edit().putString(data.getActivityClass().getName(), getString(data.getName())).commit();
} else {
preferences.edit().remove(data.getActivityClass().getName()).commit();
}
for (int i = 0; i < adapter.getItemCount(); i++) {
if (adapter.getItems().get(i) == data) {
adapter.notifyItemChanged(i);
break;
}
}
});
}
};
});
adapter.putFactory(String.class, parent -> new DataBindingComponent<>(parent, R.layout.row_description));
adapter.setOnItemClickedListener((view, item, position) -> {
if (item instanceof SampleActivityGroup) {
Class activityClass = ((SampleActivityGroup) item).getActivityClass();
Intent intent = new Intent(view.getContext(), activityClass);
startActivity(intent);
}
});
recyclerView.setAdapter(adapter);
ViewItemDecoration itemDecoration = new ViewItemDecoration(this, R.layout.carbon_row_padding);
itemDecoration.setDrawBefore(position -> position == 0);
itemDecoration.setDrawAfter(position -> position == adapter.getItemCount() - 1);
recyclerView.addItemDecoration(itemDecoration);
}
use of androidx.recyclerview.widget.LinearLayoutManager in project Carbon by ZieIony.
the class ExpandableRecyclerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initToolbar();
final ExpandableRecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
final ExpandableFruitAdapter fruitAdapter = new ExpandableFruitAdapter(fruits);
recyclerView.setAdapter(fruitAdapter);
DividerItemDecoration decoration = new DividerItemDecoration(this);
decoration.setDrawBefore(position -> position > 0 && fruits.contains(fruitAdapter.getItem(position)));
recyclerView.addItemDecoration(decoration);
}
use of androidx.recyclerview.widget.LinearLayoutManager in project MaterialDateTimePicker by wdullaer.
the class GravitySnapHelper method findEndView.
private View findEndView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int lastChild = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
if (lastChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(lastChild);
float visibleWidth;
if (isRtlHorizontal) {
visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child);
}
// If we're at the start of the list, we shouldn't snap
// to avoid having the first item not completely visible.
boolean startOfList = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() == 0;
if (visibleWidth > 0.5f && !startOfList) {
return child;
} else if (startOfList) {
return null;
} else {
// If the child wasn't returned, we need to return the previous view
return layoutManager.findViewByPosition(lastChild - 1);
}
}
return null;
}
use of androidx.recyclerview.widget.LinearLayoutManager in project MaterialDateTimePicker by wdullaer.
the class GravitySnapHelper method findStartView.
/**
* Returns the first view that we should snap to.
*
* @param layoutManager the recyclerview's layout manager
* @param helper orientation helper to calculate view sizes
* @return the first view in the LayoutManager to snap to
*/
private View findStartView(RecyclerView.LayoutManager layoutManager, OrientationHelper helper) {
if (layoutManager instanceof LinearLayoutManager) {
int firstChild = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
if (firstChild == RecyclerView.NO_POSITION) {
return null;
}
View child = layoutManager.findViewByPosition(firstChild);
float visibleWidth;
// In a RTL configuration, we need to check the start point and in LTR the end point
if (isRtlHorizontal) {
visibleWidth = (float) (helper.getTotalSpace() - helper.getDecoratedStart(child)) / helper.getDecoratedMeasurement(child);
} else {
visibleWidth = (float) helper.getDecoratedEnd(child) / helper.getDecoratedMeasurement(child);
}
// If we're at the end of the list, we shouldn't snap
// to avoid having the last item not completely visible.
boolean endOfList = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;
if (visibleWidth > 0.5f && !endOfList) {
return child;
} else if (endOfList) {
return null;
} else {
// the next view close to the start.
return layoutManager.findViewByPosition(firstChild + 1);
}
}
return null;
}
use of androidx.recyclerview.widget.LinearLayoutManager in project OneSignal-Android-SDK by OneSignal.
the class MainActivityViewModel method setupTriggerRecyclerView.
private void setupTriggerRecyclerView() {
recyclerViewBuilder.setupRecyclerView(triggersRecyclerView, 20, false, true);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
triggersRecyclerView.setLayoutManager(linearLayoutManager);
triggerPairRecyclerViewAdapter = new PairRecyclerViewAdapter(context, triggerArrayList, key -> {
OneSignal.removeTriggerForKey(key);
triggerSet.remove(key);
refreshTriggerRecyclerView();
toaster.makeCustomViewToast("Deleted trigger " + key, ToastType.SUCCESS);
});
triggersRecyclerView.setAdapter(triggerPairRecyclerViewAdapter);
}
Aggregations