Search in sources :

Example 31 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project Carbon by ZieIony.

the class BottomSheetLayout method updateRecycler.

private void updateRecycler() {
    if (menu == null)
        return;
    recycler.setLayoutManager(style == Style.List ? new LinearLayoutManager(getContext()) : new GridLayoutManager(getContext(), 3));
    ArrayList<Serializable> items = new ArrayList<>();
    for (int i = 0; i < menu.size(); i++) {
        if (menu.getItem(i).isVisible())
            items.add(new Item(menu.getItem(i)));
    }
    if (style == Style.List) {
        for (int i = 0; i < recycler.getItemDecorationCount(); i++) recycler.removeItemDecorationAt(0);
        ViewItemDecoration dividerItemDecoration = new ViewItemDecoration(getContext(), R.layout.carbon_menustrip_hseparator_item);
        dividerItemDecoration.setDrawAfter(position -> position < items.size() - 1 && items.get(position) instanceof NavigationView.Item && items.get(position + 1) instanceof NavigationView.Item && ((NavigationView.Item) items.get(position)).getGroupId() != ((NavigationView.Item) items.get(position + 1)).getGroupId());
        recycler.addItemDecoration(dividerItemDecoration);
        ViewItemDecoration paddingItemDecoration = new ViewItemDecoration(getContext(), R.layout.carbon_row_padding);
        paddingItemDecoration.setDrawAfter(position -> position == items.size() - 1);
        recycler.addItemDecoration(paddingItemDecoration);
    }
    RowListAdapter<Serializable> adapter = new RowListAdapter<>();
    adapter.putFactory(Item.class, style == Style.List ? BottomSheetRow::new : BottomSheetCell::new);
    adapter.setItems(items);
    recycler.setAdapter(adapter);
}
Also used : MenuItem(android.view.MenuItem) Serializable(java.io.Serializable) NavigationView(carbon.widget.NavigationView) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) ViewItemDecoration(carbon.recycler.ViewItemDecoration) ArrayList(java.util.ArrayList) RowListAdapter(carbon.recycler.RowListAdapter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 32 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project PhotoView by chrisbanes.

the class ActivityTransitionActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_transition);
    RecyclerView list = findViewById(R.id.list);
    list.setLayoutManager(new GridLayoutManager(this, 2));
    ImageAdapter imageAdapter = new ImageAdapter(new ImageAdapter.Listener() {

        @Override
        public void onImageClicked(View view) {
            transition(view);
        }
    });
    list.setAdapter(imageAdapter);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 33 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project OneSignal-Android-SDK by OneSignal.

the class MainActivityViewModel method setupInAppMessagingLayout.

private void setupInAppMessagingLayout() {
    recyclerViewBuilder.setupRecyclerView(inAppMessagingRecyclerView, 4, false, true);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(getActivity(), 2);
    inAppMessagingRecyclerView.setLayoutManager(gridLayoutManager);
    inAppMessagingRecyclerViewAdapter = new InAppMessageRecyclerViewAdapter(context, InAppMessage.values());
    inAppMessagingRecyclerView.setAdapter(inAppMessagingRecyclerViewAdapter);
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) InAppMessageRecyclerViewAdapter(com.onesignal.sdktest.adapter.InAppMessageRecyclerViewAdapter)

Example 34 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project AntennaPod by AntennaPod.

the class TagSettingsDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    ArrayList<FeedPreferences> feedPreferencesList = (ArrayList<FeedPreferences>) getArguments().getSerializable(ARG_FEED_PREFERENCES);
    Set<String> commonTags = new HashSet<>(feedPreferencesList.get(0).getTags());
    for (FeedPreferences preference : feedPreferencesList) {
        commonTags.retainAll(preference.getTags());
    }
    displayedTags = new ArrayList<>(commonTags);
    displayedTags.remove(FeedPreferences.TAG_ROOT);
    viewBinding = EditTagsDialogBinding.inflate(getLayoutInflater());
    viewBinding.tagsRecycler.setLayoutManager(new GridLayoutManager(getContext(), 2));
    viewBinding.tagsRecycler.addItemDecoration(new ItemOffsetDecoration(getContext(), 4));
    adapter = new TagSelectionAdapter();
    adapter.setHasStableIds(true);
    viewBinding.tagsRecycler.setAdapter(adapter);
    viewBinding.rootFolderCheckbox.setChecked(commonTags.contains(FeedPreferences.TAG_ROOT));
    viewBinding.newTagButton.setOnClickListener(v -> addTag(viewBinding.newTagEditText.getText().toString().trim()));
    loadTags();
    viewBinding.newTagEditText.setThreshold(1);
    viewBinding.newTagEditText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            viewBinding.newTagEditText.showDropDown();
            viewBinding.newTagEditText.requestFocus();
            return false;
        }
    });
    if (feedPreferencesList.size() > 1) {
        viewBinding.commonTagsInfo.setVisibility(View.VISIBLE);
    }
    AlertDialog.Builder dialog = new AlertDialog.Builder(getContext());
    dialog.setView(viewBinding.getRoot());
    dialog.setTitle(R.string.feed_tags_label);
    dialog.setPositiveButton(android.R.string.ok, (d, input) -> {
        addTag(viewBinding.newTagEditText.getText().toString().trim());
        updatePreferencesTags(feedPreferencesList, commonTags);
    });
    dialog.setNegativeButton(R.string.cancel_label, null);
    return dialog.create();
}
Also used : FeedPreferences(de.danoeh.antennapod.model.feed.FeedPreferences) AlertDialog(androidx.appcompat.app.AlertDialog) ArrayList(java.util.ArrayList) ItemOffsetDecoration(de.danoeh.antennapod.view.ItemOffsetDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MotionEvent(android.view.MotionEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) HashSet(java.util.HashSet) NonNull(androidx.annotation.NonNull)

Example 35 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class GridActivity 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 GridLayoutManager(this, 3));
    mRecyclerView.addItemDecoration(new BorderItemDecoration(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
                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(GridActivity.this, message, Toast.LENGTH_LONG).show();
            }
        }
    });
    mAdapter = new ExpandedAdapter(this);
    mRecyclerView.setAdapter(mAdapter);
    refresh();
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) OnItemClickListener(com.yanzhenjie.recyclerview.OnItemClickListener) ExpandedAdapter(com.yanzhenjie.recyclerview.sample.adapter.ExpandedAdapter) SwipeRecyclerView(com.yanzhenjie.recyclerview.SwipeRecyclerView) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar) BorderItemDecoration(com.yanzhenjie.recyclerview.widget.BorderItemDecoration)

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