use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class HeaderViewActivity method onCreate.
@Override
protected void onCreate(@Nullable 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);
SwipeRecyclerView recyclerView = findViewById(R.id.recycler_view);
recyclerView.setOnItemClickListener(this);
recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
recyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
// HeaderView。
View headerView = getLayoutInflater().inflate(R.layout.layout_header, recyclerView, false);
headerView.findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "HeaderView", Toast.LENGTH_SHORT).show();
}
});
recyclerView.addHeaderView(headerView);
// FooterView。
View footerView = getLayoutInflater().inflate(R.layout.layout_footer, recyclerView, false);
footerView.findViewById(R.id.btn_start).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(v.getContext(), "FooterView", Toast.LENGTH_SHORT).show();
}
});
recyclerView.addFooterView(footerView);
MainAdapter mainAdapter = new MainAdapter(this);
recyclerView.setAdapter(mainAdapter);
mainAdapter.notifyDataSetChanged(createDataList());
}
use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.
the class ExpandableAdapter method onAttachedToRecyclerView.
@Override
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
if (lm instanceof GridLayoutManager) {
final GridLayoutManager glm = (GridLayoutManager) lm;
final GridLayoutManager.SpanSizeLookup originLookup = glm.getSpanSizeLookup();
glm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (isParentItem(position))
return glm.getSpanCount();
if (originLookup != null)
return originLookup.getSpanSize(position);
return 1;
}
});
}
}
use of androidx.recyclerview.widget.GridLayoutManager in project Signal-Android by WhisperSystems.
the class StickerPackPreviewActivity method initView.
private void initView() {
this.coverImage = findViewById(R.id.sticker_install_cover);
this.stickerTitle = findViewById(R.id.sticker_install_title);
this.stickerAuthor = findViewById(R.id.sticker_install_author);
this.installButton = findViewById(R.id.sticker_install_button);
this.removeButton = findViewById(R.id.sticker_install_remove_button);
this.stickerList = findViewById(R.id.sticker_install_list);
this.shareButton = findViewById(R.id.sticker_install_share_button);
this.shareButtonImage = findViewById(R.id.sticker_install_share_button_image);
this.adapter = new StickerPackPreviewAdapter(GlideApp.with(this), this, DeviceProperties.shouldAllowApngStickerAnimation(this));
this.layoutManager = new GridLayoutManager(this, 2);
this.touchListener = new StickerRolloverTouchListener(this, GlideApp.with(this), this, this);
onScreenWidthChanged(getScreenWidth());
stickerList.setLayoutManager(layoutManager);
stickerList.addOnItemTouchListener(touchListener);
stickerList.setAdapter(adapter);
}
use of androidx.recyclerview.widget.GridLayoutManager in project Signal-Android by WhisperSystems.
the class AttachmentKeyboard method init.
private void init(@NonNull Context context) {
inflate(context, R.layout.attachment_keyboard, this);
this.container = findViewById(R.id.attachment_keyboard_container);
this.mediaList = findViewById(R.id.attachment_keyboard_media_list);
this.permissionText = findViewById(R.id.attachment_keyboard_permission_text);
this.permissionButton = findViewById(R.id.attachment_keyboard_permission_button);
RecyclerView buttonList = findViewById(R.id.attachment_keyboard_button_list);
mediaAdapter = new AttachmentKeyboardMediaAdapter(GlideApp.with(this), media -> {
if (callback != null) {
callback.onAttachmentMediaClicked(media);
}
});
buttonAdapter = new AttachmentKeyboardButtonAdapter(button -> {
if (callback != null) {
callback.onAttachmentSelectorClicked(button);
}
});
mediaList.setAdapter(mediaAdapter);
buttonList.setAdapter(buttonAdapter);
mediaList.setLayoutManager(new GridLayoutManager(context, 1, GridLayoutManager.HORIZONTAL, false));
buttonList.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
buttonAdapter.setButtons(DEFAULT_BUTTONS);
}
use of androidx.recyclerview.widget.GridLayoutManager in project Signal-Android by WhisperSystems.
the class EmojiPageView method initialize.
public void initialize(@NonNull EmojiEventListener emojiSelectionListener, @NonNull VariationSelectorListener variationSelectorListener, boolean allowVariations, @NonNull LinearLayoutManager layoutManager, @LayoutRes int displayEmojiLayoutResId, @LayoutRes int displayEmoticonLayoutResId) {
this.variationSelectorListener = variationSelectorListener;
this.layoutManager = layoutManager;
this.scrollDisabler = new ScrollDisabler();
this.popup = new EmojiVariationSelectorPopup(getContext(), emojiSelectionListener);
this.adapterFactory = () -> new EmojiPageViewGridAdapter(popup, emojiSelectionListener, this, allowVariations, displayEmojiLayoutResId, displayEmoticonLayoutResId);
if (this.layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayout = (GridLayoutManager) this.layoutManager;
gridLayout.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
if (getAdapter() != null) {
Optional<MappingModel<?>> model = getAdapter().getModel(position);
if (model.isPresent() && (model.get() instanceof EmojiHeader || model.get() instanceof EmojiNoResultsModel)) {
return gridLayout.getSpanCount();
}
}
return 1;
}
});
}
setLayoutManager(layoutManager);
Drawable drawable = DrawableUtil.tint(ContextUtil.requireDrawable(getContext(), R.drawable.triangle_bottom_right_corner), ContextCompat.getColor(getContext(), R.color.signal_button_secondary_text_disabled));
addItemDecoration(new EmojiItemDecoration(allowVariations, drawable));
}
Aggregations