Search in sources :

Example 31 with RecyclerView

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;
}
Also used : View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Example 32 with RecyclerView

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;
}
Also used : CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 33 with RecyclerView

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;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 34 with RecyclerView

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());
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 35 with RecyclerView

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);
}
Also used : MaterialRefreshListener(com.cjj.MaterialRefreshListener) MaterialRefreshLayout(com.cjj.MaterialRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)978 View (android.view.View)671 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)574 TextView (android.widget.TextView)213 GridLayoutManager (android.support.v7.widget.GridLayoutManager)143 ImageView (android.widget.ImageView)128 ArrayList (java.util.ArrayList)100 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)73 Toolbar (android.support.v7.widget.Toolbar)68 ViewGroup (android.view.ViewGroup)66 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)61 Intent (android.content.Intent)54 Bundle (android.os.Bundle)50 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)49 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)49 Context (android.content.Context)46 Nullable (android.support.annotation.Nullable)45 Rect (android.graphics.Rect)41 Handler (android.os.Handler)39 LayoutInflater (android.view.LayoutInflater)38