use of androidx.recyclerview.widget.LinearLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class ListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scroll);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
assert actionBar != null;
actionBar.setDisplayHomeAsUpEnabled(true);
mRecyclerView = findViewById(R.id.recycler_view);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
mRecyclerView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View itemView, int position) {
// 根据原position判断该item是否是parent item
if (mAdapter.isParentItem(position)) {
// 换取parent position
final int parentPosition = mAdapter.parentItemPosition(position);
// 判断parent是否打开了二级菜单
if (mAdapter.isExpanded(parentPosition)) {
mDataList.get(parentPosition).setExpanded(false);
mAdapter.notifyParentChanged(parentPosition);
// 关闭该parent下的二级菜单
mAdapter.collapseParent(parentPosition);
} else {
mDataList.get(parentPosition).setExpanded(true);
mAdapter.notifyParentChanged(parentPosition);
// 打开该parent下的二级菜单
mAdapter.expandParent(parentPosition);
}
} else {
// 换取parent position
int parentPosition = mAdapter.parentItemPosition(position);
// 换取child position
int childPosition = mAdapter.childItemPosition(position);
String message = String.format("我是%1$d爸爸的%2$d儿子", parentPosition, childPosition);
Toast.makeText(ListActivity.this, message, Toast.LENGTH_LONG).show();
}
}
});
mAdapter = new ExpandedAdapter(this);
mRecyclerView.setAdapter(mAdapter);
refresh();
}
use of androidx.recyclerview.widget.LinearLayoutManager in project epoxy by airbnb.
the class Carousel method setInitialPrefetchItemCount.
/**
* If you are using a Linear or Grid layout manager you can use this to set the item prefetch
* count. Only use this if you are not using {@link #setNumViewsToShowOnScreen(float)}
*
* @see #setNumViewsToShowOnScreen(float)
* @see LinearLayoutManager#setInitialPrefetchItemCount(int)
*/
@ModelProp(group = "prefetch")
public void setInitialPrefetchItemCount(int numItemsToPrefetch) {
if (numItemsToPrefetch < 0) {
throw new IllegalStateException("numItemsToPrefetch must be greater than 0");
}
// Use the linearlayoutmanager default of 2 if the user did not specify one
int prefetchCount = numItemsToPrefetch == 0 ? 2 : numItemsToPrefetch;
LayoutManager layoutManager = getLayoutManager();
if (layoutManager instanceof LinearLayoutManager) {
((LinearLayoutManager) layoutManager).setInitialPrefetchItemCount(prefetchCount);
}
}
use of androidx.recyclerview.widget.LinearLayoutManager in project xabber-android by redsolution.
the class ServerInfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_server_info);
final Intent intent = getIntent();
AccountJid account = getAccount(intent);
if (account == null) {
finish();
return;
}
accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
Application.getInstance().onError(R.string.NO_SUCH_ACCOUNT);
finish();
return;
}
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_default);
toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
toolbar.setTitle(accountItem.getConnection().getXMPPServiceDomain());
BarPainter barPainter = new BarPainter(this, toolbar);
barPainter.updateWithAccountName(account);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.server_info_recycler_view);
serverInfoAdapter = new ServerInfoAdapter();
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setAdapter(serverInfoAdapter);
progressBar = findViewById(R.id.server_info_progress_bar);
requestServerInfo();
}
use of androidx.recyclerview.widget.LinearLayoutManager in project xabber-android by redsolution.
the class MessageVH method setupForwarded.
protected void setupForwarded(MessageItem messageItem, MessagesAdapter.MessageExtraData extraData) {
String[] forwardedIDs = messageItem.getForwardedIdsAsArray();
if (!Arrays.asList(forwardedIDs).contains(null)) {
RealmResults<MessageItem> forwardedMessages = MessageDatabaseManager.getInstance().getRealmUiThread().where(MessageItem.class).in(MessageItem.Fields.UNIQUE_ID, forwardedIDs).findAllSorted(MessageItem.Fields.TIMESTAMP, Sort.ASCENDING);
if (forwardedMessages.size() > 0) {
RecyclerView recyclerView = forwardLayout.findViewById(R.id.recyclerView);
ForwardedAdapter adapter = new ForwardedAdapter(forwardedMessages, extraData);
recyclerView.setLayoutManager(new LinearLayoutManager(extraData.getContext()));
recyclerView.setAdapter(adapter);
forwardLayout.setBackgroundColor(ColorManager.getColorWithAlpha(R.color.forwarded_background_color, 0.2f));
forwardLeftBorder.setBackgroundColor(extraData.getAccountMainColor());
forwardLayout.setVisibility(View.VISIBLE);
}
}
}
use of androidx.recyclerview.widget.LinearLayoutManager in project xabber-android by redsolution.
the class FileMessageVH method setUpFile.
private void setUpFile(RealmList<Attachment> attachments, Context context) {
RealmList<Attachment> fileAttachments = new RealmList<>();
for (Attachment attachment : attachments) {
if (!attachment.isImage())
fileAttachments.add(attachment);
}
if (fileAttachments.size() > 0) {
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context);
rvFileList.setLayoutManager(layoutManager);
FilesAdapter adapter = new FilesAdapter(fileAttachments, this);
rvFileList.setAdapter(adapter);
fileLayout.setVisibility(View.VISIBLE);
}
}
Aggregations