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();
}
});
}
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);
}
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;
}
}
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);
}
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);
}
}
Aggregations