use of android.support.v7.widget.RecyclerView in project platform_frameworks_base by android.
the class FocusManager method findTargetPosition.
/**
* Finds the destination position where the focus should land for a given navigation event.
*
* @param view The view that received the event.
* @param keyCode The key code for the event.
* @param event
* @return The adapter position of the destination item. Could be RecyclerView.NO_POSITION.
*/
private int findTargetPosition(View view, int keyCode, KeyEvent event) {
switch(keyCode) {
case KeyEvent.KEYCODE_MOVE_HOME:
return 0;
case KeyEvent.KEYCODE_MOVE_END:
return mAdapter.getItemCount() - 1;
case KeyEvent.KEYCODE_PAGE_UP:
case KeyEvent.KEYCODE_PAGE_DOWN:
return findPagedTargetPosition(view, keyCode, event);
}
// Find a navigation target based on the arrow key that the user pressed.
int searchDir = -1;
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_UP:
searchDir = View.FOCUS_UP;
break;
case KeyEvent.KEYCODE_DPAD_DOWN:
searchDir = View.FOCUS_DOWN;
break;
}
if (inGridMode()) {
int currentPosition = mView.getChildAdapterPosition(view);
// Left and right arrow keys only work in grid mode.
switch(keyCode) {
case KeyEvent.KEYCODE_DPAD_LEFT:
if (currentPosition > 0) {
// Stop backward focus search at the first item, otherwise focus will wrap
// around to the last visible item.
searchDir = View.FOCUS_BACKWARD;
}
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
if (currentPosition < mAdapter.getItemCount() - 1) {
// Stop forward focus search at the last item, otherwise focus will wrap
// around to the first visible item.
searchDir = View.FOCUS_FORWARD;
}
break;
}
}
if (searchDir != -1) {
// Focus search behaves badly if the parent RecyclerView is focused. However, focusable
// shouldn't be unset on RecyclerView, otherwise focus isn't properly restored after
// events that cause a UI rebuild (like rotating the device). Compromise: turn focusable
// off while performing the focus search.
// TODO: Revisit this when RV focus issues are resolved.
mView.setFocusable(false);
View targetView = view.focusSearch(searchDir);
mView.setFocusable(true);
// of the list.
if (targetView != null) {
// Ignore navigation targets that aren't items in the RecyclerView.
if (targetView.getParent() == mView) {
return mView.getChildAdapterPosition(targetView);
}
}
}
return RecyclerView.NO_POSITION;
}
use of android.support.v7.widget.RecyclerView in project android-design-support-lib-demo by sagar-viradiya.
the class CollapsingToolbarFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_collapsing_toolbar, container, false);
toolbar = (Toolbar) view.findViewById(R.id.toolbar);
setupToolbar();
((CollapsingToolbarLayout) view.findViewById(R.id.collapsing_toolbar)).setTitle(getString(R.string.collapsing_toolbar_fragment_title));
recyclerView = (RecyclerView) view.findViewById(R.id.recycler_view);
setupRecyclerView();
return view;
}
use of android.support.v7.widget.RecyclerView in project android-design-support-lib-demo by sagar-viradiya.
the class FabFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_fab, container, false);
toolbar = (Toolbar) view.findViewById(R.id.fab_toolbar);
setupToolbar();
floatingActionButton = (FloatingActionButton) view.findViewById(R.id.fab);
fixFloatingActionButtonMargin();
recyclerView = (RecyclerView) view.findViewById(R.id.fab_recycler_view);
setupRecyclerView();
return view;
}
use of android.support.v7.widget.RecyclerView in project Android-MaterialRefreshLayout by android-cjj.
the class SimpleActivity method setupRecyclerView.
private void setupRecyclerView(RecyclerView recyclerView) {
recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(SimpleActivity.this));
recyclerView.setItemAnimator(new DefaultItemAnimator());
}
use of android.support.v7.widget.RecyclerView in project Android-MaterialRefreshLayout by android-cjj.
the class SimpleActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple);
initsToolbar();
materialRefreshLayout = (MaterialRefreshLayout) findViewById(R.id.refresh);
materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {
@Override
public void onRefresh(final MaterialRefreshLayout materialRefreshLayout) {
materialRefreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
materialRefreshLayout.finishRefresh();
}
}, 3000);
materialRefreshLayout.finishRefreshLoadMore();
}
@Override
public void onfinish() {
Toast.makeText(SimpleActivity.this, "finish", Toast.LENGTH_LONG).show();
}
});
RecyclerView rv = (RecyclerView) findViewById(R.id.recyclerview);
setupRecyclerView(rv);
}
Aggregations