Search in sources :

Example 61 with GridLayoutManager

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());
}
Also used : MainAdapter(com.yanzhenjie.recyclerview.sample.adapter.MainAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 62 with GridLayoutManager

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;
            }
        });
    }
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 63 with GridLayoutManager

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);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Example 64 with GridLayoutManager

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);
}
Also used : Context(android.content.Context) Arrays(java.util.Arrays) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) FrameLayout(android.widget.FrameLayout) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) StorageUtil(org.thoughtcrime.securesms.util.StorageUtil) List(java.util.List) Nullable(androidx.annotation.Nullable) AttributeSet(android.util.AttributeSet) Media(org.thoughtcrime.securesms.mediasend.Media) View(android.view.View) InputAwareLayout(org.thoughtcrime.securesms.components.InputAwareLayout) Predicate(com.annimon.stream.function.Predicate) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 65 with GridLayoutManager

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));
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Optional(java.util.Optional) EmojiNoResultsModel(org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter.EmojiNoResultsModel) Drawable(android.graphics.drawable.Drawable) EmojiHeader(org.thoughtcrime.securesms.components.emoji.EmojiPageViewGridAdapter.EmojiHeader)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)122 RecyclerView (androidx.recyclerview.widget.RecyclerView)63 View (android.view.View)45 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)16 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)13 ImageView (android.widget.ImageView)12 Nullable (androidx.annotation.Nullable)11 Toolbar (androidx.appcompat.widget.Toolbar)10 ViewGroup (android.view.ViewGroup)7 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 SuppressLint (android.annotation.SuppressLint)6 Context (android.content.Context)6 ArrayList (java.util.ArrayList)6 NonNull (androidx.annotation.NonNull)5 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)5 List (java.util.List)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 Drawable (android.graphics.drawable.Drawable)4 Handler (android.os.Handler)3