Search in sources :

Example 1 with SwipeMenuRecyclerView

use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.

the class MenuCardActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    mContext = this;
    List<String> dataList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        dataList.add("我是第" + i + "个菜单");
    }
    mMenuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    // 布局管理器。
    mMenuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mMenuRecyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.set(10, 10, 10, 10);
        }
    });
    MenuCardAdapter menuCardAdapter = new MenuCardAdapter(dataList);
    menuCardAdapter.setOnItemClickListener(onItemClickListener);
    mMenuRecyclerView.setAdapter(menuCardAdapter);
}
Also used : Rect(android.graphics.Rect) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) MenuCardAdapter(com.yanzhenjie.swiperecyclerview.adapter.MenuCardAdapter)

Example 2 with SwipeMenuRecyclerView

use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.

the class MenuViewTypeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    mContext = this;
    // 这里只是模拟数据,模拟Item的ViewType,根据ViewType决定显示什么菜单,到时候你可以根据你的数据来决定ViewType。
    mViewTypeBeanList = new ArrayList<>();
    for (int i = 0, j = 0; i < 30; i++, j++) {
        ViewTypeBean viewTypeBean = new ViewTypeBean();
        if (j == 0) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_NONE);
            viewTypeBean.setContent("我没有菜单");
        } else if (j == 1) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_SINGLE);
            viewTypeBean.setContent("我有1个菜单");
        } else if (j == 2) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_MULTI);
            viewTypeBean.setContent("我有2个菜单");
        } else if (j == 3) {
            viewTypeBean.setViewType(MenuViewTypeAdapter.VIEW_TYPE_MENU_LEFT);
            viewTypeBean.setContent("我的左边有菜单,右边没有");
            j = -1;
        }
        mViewTypeBeanList.add(viewTypeBean);
    }
    SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    menuRecyclerView.addItemDecoration(new ListViewDecoration());
    menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
    menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
    MenuViewTypeAdapter menuAdapter = new MenuViewTypeAdapter(mViewTypeBeanList);
    menuAdapter.setOnItemClickListener(onItemClickListener);
    menuRecyclerView.setAdapter(menuAdapter);
}
Also used : ListViewDecoration(com.yanzhenjie.swiperecyclerview.view.ListViewDecoration) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) MenuViewTypeAdapter(com.yanzhenjie.swiperecyclerview.adapter.MenuViewTypeAdapter) ViewTypeBean(com.yanzhenjie.swiperecyclerview.entity.ViewTypeBean) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with SwipeMenuRecyclerView

use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.

the class DragSwipeFlagsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mContext = this;
    setContentView(R.layout.activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mActionBar = getSupportActionBar();
    assert mActionBar != null;
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mDataList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        if (i == 0) {
            mDataList.add("我不能被拖拽,也不能滑动删除。");
        } else {
            mDataList.add("我是第" + i + "个。");
        }
    }
    SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    // 布局管理器。
    menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    // 添加分割线。
    menuRecyclerView.addItemDecoration(new ListViewDecoration());
    // 这个就不用添加菜单啦,因为滑动删除和菜单是冲突的。
    mMenuAdapter = new MenuAdapter(mDataList);
    mMenuAdapter.setOnItemClickListener(onItemClickListener);
    menuRecyclerView.setAdapter(mMenuAdapter);
    // 开启长安拖拽。
    menuRecyclerView.setLongPressDragEnabled(true);
    // 开启滑动删除。
    menuRecyclerView.setItemViewSwipeEnabled(true);
    // 监听拖拽,更新UI。
    menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
    menuRecyclerView.setOnItemMovementListener(onItemMovementListener);
    menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
Also used : ListViewDecoration(com.yanzhenjie.swiperecyclerview.view.ListViewDecoration) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) MenuAdapter(com.yanzhenjie.swiperecyclerview.adapter.MenuAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Toolbar(android.support.v7.widget.Toolbar)

Example 4 with SwipeMenuRecyclerView

use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.

the class DragGridMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mActionBar = getSupportActionBar();
    assert mActionBar != null;
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mContext = this;
    mDataList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        mDataList.add("我是第" + i + "个。");
    }
    SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    // 布局管理器。
    menuRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    // 添加分割线。
    menuRecyclerView.addItemDecoration(new ListViewDecoration());
    // 为SwipeRecyclerView的Item创建菜单就两句话,不错就是这么简单:
    // 设置菜单创建器。
    menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
    // 设置菜单Item点击监听。
    menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
    mMenuAdapter = new MenuAdapter(mDataList);
    mMenuAdapter.setOnItemClickListener(onItemClickListener);
    menuRecyclerView.setAdapter(mMenuAdapter);
    // 开启拖拽,就这么简单一句话。
    menuRecyclerView.setLongPressDragEnabled(true);
    // 监听拖拽,更新UI。
    menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
    // 拖拽和侧滑删除时,手指状态监听。
    menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
Also used : ListViewDecoration(com.yanzhenjie.swiperecyclerview.view.ListViewDecoration) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) GridLayoutManager(android.support.v7.widget.GridLayoutManager) MenuAdapter(com.yanzhenjie.swiperecyclerview.adapter.MenuAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 5 with SwipeMenuRecyclerView

use of com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView in project SwipeRecyclerView by yanzhenjie.

the class DragListMenuActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    mActionBar = getSupportActionBar();
    assert mActionBar != null;
    mActionBar.setDisplayHomeAsUpEnabled(true);
    mContext = this;
    mDataList = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        mDataList.add("我是第" + i + "个。");
    }
    SwipeMenuRecyclerView menuRecyclerView = (SwipeMenuRecyclerView) findViewById(R.id.recycler_view);
    // 布局管理器。
    menuRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    // 添加分割线。
    menuRecyclerView.addItemDecoration(new ListViewDecoration());
    // 为SwipeRecyclerView的Item创建菜单就两句话,不错就是这么简单:
    // 设置菜单创建器。
    menuRecyclerView.setSwipeMenuCreator(swipeMenuCreator);
    // 设置菜单Item点击监听。
    menuRecyclerView.setSwipeMenuItemClickListener(menuItemClickListener);
    mMenuAdapter = new MenuAdapter(mDataList);
    mMenuAdapter.setOnItemClickListener(onItemClickListener);
    menuRecyclerView.setAdapter(mMenuAdapter);
    // 开启拖拽,就这么简单一句话。
    menuRecyclerView.setLongPressDragEnabled(true);
    // 监听拖拽,更新UI。
    menuRecyclerView.setOnItemMoveListener(onItemMoveListener);
    menuRecyclerView.setOnItemStateChangedListener(mOnItemStateChangedListener);
}
Also used : ListViewDecoration(com.yanzhenjie.swiperecyclerview.view.ListViewDecoration) SwipeMenuRecyclerView(com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView) MenuAdapter(com.yanzhenjie.swiperecyclerview.adapter.MenuAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Toolbar (android.support.v7.widget.Toolbar)7 SwipeMenuRecyclerView (com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)6 ListViewDecoration (com.yanzhenjie.swiperecyclerview.view.ListViewDecoration)6 MenuAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuAdapter)4 ActionBar (android.support.v7.app.ActionBar)2 Rect (android.graphics.Rect)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 DragTouchAdapter (com.yanzhenjie.swiperecyclerview.adapter.DragTouchAdapter)1 MenuCardAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuCardAdapter)1 MenuViewTypeAdapter (com.yanzhenjie.swiperecyclerview.adapter.MenuViewTypeAdapter)1 ViewTypeBean (com.yanzhenjie.swiperecyclerview.entity.ViewTypeBean)1 ArrayList (java.util.ArrayList)1