Search in sources :

Example 11 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project sticky-headers-recyclerview by timehop.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview);
    Button button = (Button) findViewById(R.id.button_update);
    final ToggleButton isReverseButton = (ToggleButton) findViewById(R.id.button_is_reverse);
    // Set adapter populated with example dummy data
    final AnimalsHeadersAdapter adapter = new AnimalsHeadersAdapter();
    adapter.add("Animals below!");
    adapter.addAll(getDummyDataSet());
    recyclerView.setAdapter(adapter);
    // Set button to update all views one after another (Test for the "Dance")
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Handler handler = new Handler(Looper.getMainLooper());
            for (int i = 0; i < adapter.getItemCount(); i++) {
                final int index = i;
                handler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        adapter.notifyItemChanged(index);
                    }
                }, 50);
            }
        }
    });
    // Set layout manager
    int orientation = getLayoutManagerOrientation(getResources().getConfiguration().orientation);
    final LinearLayoutManager layoutManager = new LinearLayoutManager(this, orientation, isReverseButton.isChecked());
    recyclerView.setLayoutManager(layoutManager);
    // Add the sticky headers decoration
    final StickyRecyclerHeadersDecoration headersDecor = new StickyRecyclerHeadersDecoration(adapter);
    recyclerView.addItemDecoration(headersDecor);
    // Add decoration for dividers between list items
    recyclerView.addItemDecoration(new DividerDecoration(this));
    // Add touch listeners
    StickyRecyclerHeadersTouchListener touchListener = new StickyRecyclerHeadersTouchListener(recyclerView, headersDecor);
    touchListener.setOnHeaderClickListener(new StickyRecyclerHeadersTouchListener.OnHeaderClickListener() {

        @Override
        public void onHeaderClick(View header, int position, long headerId) {
            Toast.makeText(MainActivity.this, "Header position: " + position + ", id: " + headerId, Toast.LENGTH_SHORT).show();
        }
    });
    recyclerView.addOnItemTouchListener(touchListener);
    recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this, new RecyclerItemClickListener.OnItemClickListener() {

        @Override
        public void onItemClick(View view, int position) {
            adapter.remove(adapter.getItem(position));
        }
    }));
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            headersDecor.invalidateHeaders();
        }
    });
    isReverseButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean isChecked = isReverseButton.isChecked();
            isReverseButton.setChecked(isChecked);
            layoutManager.setReverseLayout(isChecked);
            adapter.notifyDataSetChanged();
        }
    });
}
Also used : ToggleButton(android.widget.ToggleButton) Handler(android.os.Handler) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) StickyRecyclerHeadersTouchListener(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersTouchListener) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) StickyRecyclerHeadersDecoration(com.timehop.stickyheadersrecyclerview.StickyRecyclerHeadersDecoration) Button(android.widget.Button) ToggleButton(android.widget.ToggleButton) RecyclerView(android.support.v7.widget.RecyclerView)

Example 12 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project BGARefreshLayout-Android by bingoogolapple.

the class RefreshStaggeredRecyclerViewFragment method processLogic.

@Override
protected void processLogic(Bundle savedInstanceState) {
    mRefreshLayout.setCustomHeaderView(DataEngine.getCustomHeaderView(mApp), true);
    mRefreshLayout.setRefreshViewHolder(new BGANormalRefreshViewHolder(mApp, true));
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
    mDataRv.setLayoutManager(layoutManager);
    mDataRv.setAdapter(mAdapter);
}
Also used : BGANormalRefreshViewHolder(cn.bingoogolapple.refreshlayout.BGANormalRefreshViewHolder) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager)

Example 13 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project glide by bumptech.

the class RecyclerToListViewScrollListener method onScrolled.

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
    int firstVisible = layoutManager.findFirstVisibleItemPosition();
    int visibleCount = Math.abs(firstVisible - layoutManager.findLastVisibleItemPosition());
    int itemCount = recyclerView.getAdapter().getItemCount();
    if (firstVisible != lastFirstVisible || visibleCount != lastVisibleCount || itemCount != lastItemCount) {
        scrollListener.onScroll(null, firstVisible, visibleCount, itemCount);
        lastFirstVisible = firstVisible;
        lastVisibleCount = visibleCount;
        lastItemCount = itemCount;
    }
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 14 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project plaid by nickbutcher.

the class DesignerNewsStory method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_designer_news_story);
    ButterKnife.bind(this);
    story = getIntent().getParcelableExtra(EXTRA_STORY);
    fab.setOnClickListener(fabClick);
    chromeFader = new ElasticDragDismissFrameLayout.SystemChromeFader(this);
    markdown = new Bypass(this, new Bypass.Options().setBlockQuoteLineColor(ContextCompat.getColor(this, R.color.designer_news_quote_line)).setBlockQuoteLineWidth(// dps
    2).setBlockQuoteLineIndent(// dps
    8).setPreImageLinebreakHeight(//dps
    4).setBlockQuoteIndentSize(TypedValue.COMPLEX_UNIT_DIP, 2f).setBlockQuoteTextColor(ContextCompat.getColor(this, R.color.designer_news_quote)));
    circleTransform = new CircleTransform(this);
    designerNewsPrefs = DesignerNewsPrefs.get(this);
    layoutManager = new LinearLayoutManager(this);
    commentsList.setLayoutManager(layoutManager);
    commentsList.setItemAnimator(new CommentAnimator(getResources().getInteger(R.integer.comment_expand_collapse_duration)));
    header = getLayoutInflater().inflate(R.layout.designer_news_story_description, commentsList, false);
    bindDescription();
    // setup title/toolbar
    if (collapsingToolbar != null) {
        // narrow device: collapsing toolbar
        collapsingToolbar.addOnLayoutChangeListener(titlebarLayout);
        collapsingToolbar.setTitle(story.title);
        final Toolbar toolbar = (Toolbar) findViewById(R.id.story_toolbar);
        toolbar.setNavigationOnClickListener(backClick);
        commentsList.addOnScrollListener(headerScrollListener);
        setEnterSharedElementCallback(new SharedElementCallback() {

            @Override
            public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(getIntent(), collapsingToolbar);
            }

            @Override
            public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements, List<View> sharedElementSnapshots) {
                ReflowText.setupReflow(collapsingToolbar);
            }
        });
    } else {
        // w600dp configuration: content card scrolls over title bar
        final TextView title = (TextView) findViewById(R.id.story_title);
        title.setText(story.title);
        findViewById(R.id.back).setOnClickListener(backClick);
    }
    final View enterCommentView = setupCommentField();
    if (story.comment_count > 0) {
        // flatten the comments from a nested structure {@see Comment#comments} to a
        // list appropriate for our adapter (using the depth attribute).
        List<Comment> flattened = new ArrayList<>(story.comment_count);
        unnestComments(story.comments, flattened);
        commentsAdapter = new DesignerNewsCommentsAdapter(header, flattened, enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    } else {
        commentsAdapter = new DesignerNewsCommentsAdapter(header, new ArrayList<Comment>(0), enterCommentView);
        commentsList.setAdapter(commentsAdapter);
    }
    customTab = new CustomTabActivityHelper();
    customTab.setConnectionCallback(customTabConnect);
}
Also used : ActivityOptions(android.app.ActivityOptions) Comment(io.plaidapp.data.api.designernews.model.Comment) ArrayList(java.util.ArrayList) CircleTransform(io.plaidapp.util.glide.CircleTransform) SpannableString(android.text.SpannableString) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) PinnedOffsetView(io.plaidapp.ui.widget.PinnedOffsetView) RecyclerView(android.support.v7.widget.RecyclerView) ElasticDragDismissFrameLayout(io.plaidapp.ui.widget.ElasticDragDismissFrameLayout) CustomTabActivityHelper(io.plaidapp.util.customtabs.CustomTabActivityHelper) Bypass(in.uncod.android.bypass.Bypass) AuthorTextView(io.plaidapp.ui.widget.AuthorTextView) TextView(android.widget.TextView) SharedElementCallback(android.app.SharedElementCallback) Toolbar(android.widget.Toolbar)

Example 15 with LayoutManager

use of android.support.v7.widget.RecyclerView.LayoutManager in project ListenerMusicPlayer by hefuyicoder.

the class PlaylistFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    injectDependences();
    mPresenter.attachView(this);
    mPreferences = PreferencesUtility.getInstance(getActivity());
    isGrid = mPreferences.getPlaylistView() == Constants.PLAYLIST_VIEW_GRID;
    mAdapter = new PlaylistAdapter(this, null);
    if (isGrid) {
        layoutManager = new GridLayoutManager(getActivity(), 2);
    } else {
        layoutManager = new GridLayoutManager(getActivity(), 1);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) PlaylistAdapter(io.hefuyi.listener.ui.adapter.PlaylistAdapter)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)205 RecyclerView (android.support.v7.widget.RecyclerView)202 View (android.view.View)151 GridLayoutManager (android.support.v7.widget.GridLayoutManager)73 TextView (android.widget.TextView)66 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)47 ImageView (android.widget.ImageView)44 Bundle (android.os.Bundle)24 Nullable (android.support.annotation.Nullable)24 BindView (butterknife.BindView)22 ArrayList (java.util.ArrayList)21 ViewGroup (android.view.ViewGroup)20 Context (android.content.Context)17 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)16 Intent (android.content.Intent)15 Handler (android.os.Handler)15 Toolbar (android.support.v7.widget.Toolbar)15 List (java.util.List)12 Point (android.graphics.Point)10 Drawable (android.graphics.drawable.Drawable)10