Search in sources :

Example 1 with TwoWayView

use of com.marshalchen.common.uimodule.twowayview.widget.TwoWayView in project UltimateAndroid by cymcsg.

the class LayoutFragment method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Activity activity = getActivity();
    mToast = Toast.makeText(activity, "", Toast.LENGTH_SHORT);
    mToast.setGravity(Gravity.CENTER, 0, 0);
    mRecyclerView = (TwoWayView) view.findViewById(R.id.list);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLongClickable(true);
    mPositionText = (TextView) view.getRootView().findViewById(R.id.position);
    mCountText = (TextView) view.getRootView().findViewById(R.id.count);
    mStateText = (TextView) view.getRootView().findViewById(R.id.state);
    updateState(SCROLL_STATE_IDLE);
    final ItemClickSupport itemClick = ItemClickSupport.addTo(mRecyclerView);
    itemClick.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(RecyclerView parent, View child, int position, long id) {
            mToast.setText("Item clicked: " + position);
            mToast.show();
        }
    });
    itemClick.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(RecyclerView parent, View child, int position, long id) {
            mToast.setText("Item long pressed: " + position);
            mToast.show();
            return true;
        }
    });
    mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
            updateState(scrollState);
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int i, int i2) {
            mPositionText.setText("First: " + mRecyclerView.getFirstVisiblePosition());
            mCountText.setText("Count: " + mRecyclerView.getChildCount());
        }
    });
    final Drawable divider = getResources().getDrawable(R.drawable.two_way_view_divider);
    mRecyclerView.addItemDecoration(new DividerItemDecoration(divider));
    mRecyclerView.setAdapter(new LayoutAdapter(activity, mRecyclerView, mLayoutId));
}
Also used : OnItemClickListener(com.marshalchen.common.uimodule.twowayview.ItemClickSupport.OnItemClickListener) Drawable(android.graphics.drawable.Drawable) Activity(android.app.Activity) DividerItemDecoration(com.marshalchen.common.uimodule.twowayview.widget.DividerItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) TwoWayView(com.marshalchen.common.uimodule.twowayview.widget.TwoWayView) OnItemLongClickListener(com.marshalchen.common.uimodule.twowayview.ItemClickSupport.OnItemLongClickListener) RecyclerView(android.support.v7.widget.RecyclerView) ItemClickSupport(com.marshalchen.common.uimodule.twowayview.ItemClickSupport)

Aggregations

Activity (android.app.Activity)1 Drawable (android.graphics.drawable.Drawable)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 ItemClickSupport (com.marshalchen.common.uimodule.twowayview.ItemClickSupport)1 OnItemClickListener (com.marshalchen.common.uimodule.twowayview.ItemClickSupport.OnItemClickListener)1 OnItemLongClickListener (com.marshalchen.common.uimodule.twowayview.ItemClickSupport.OnItemLongClickListener)1 DividerItemDecoration (com.marshalchen.common.uimodule.twowayview.widget.DividerItemDecoration)1 TwoWayView (com.marshalchen.common.uimodule.twowayview.widget.TwoWayView)1