Java源码示例:com.mcxtzhang.swipemenulib.SwipeMenuLayout

示例1
private void update(View swipeView, int position,MusicInfo musicInfo,boolean isDelete){
    if (isDelete){
        final int curId = musicInfo.getId();
        final int musicId = MyMusicUtil.getIntShared(Constant.KEY_ID);
        //从列表移除
        dbManager.removeMusic(musicInfo.getId(),Constant.ACTIVITY_LOCAL);
        if (curId == musicId) {
            //移除的是当前播放的音乐
            Intent intent = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
            intent.putExtra(Constant.COMMAND, Constant.COMMAND_STOP);
            context.sendBroadcast(intent);
        }
        recyclerViewAdapter.notifyItemRemoved(position);//推荐用这个
        updateView();
    }else {

    }
    //如果删除时,不使用mAdapter.notifyItemRemoved(pos),则删除没有动画效果,
    //且如果想让侧滑菜单同时关闭,需要同时调用 ((CstSwipeDelMenu) holder.itemView).quickClose();
    ((SwipeMenuLayout) swipeView).quickClose();
}
 
示例2
private void update(View swipeView, int position,MusicInfo musicInfo,boolean isDelete){
    if (isDelete){
        final int curId = musicInfo.getId();
        final int musicId = MyMusicUtil.getIntShared(Constant.KEY_ID);
        //从列表移除
        if (label.equals(Constant.LABEL_LAST)){
            dbManager.removeMusic(musicInfo.getId(),Constant.ACTIVITY_RECENTPLAY);
        }else if (label.equals(Constant.ACTIVITY_MYLOVE)){
            dbManager.removeMusic(musicInfo.getId(),Constant.LIST_LASTPLAY);
        }
        if (curId == musicId) {
            //移除的是当前播放的音乐
            Intent intent = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
            intent.putExtra(Constant.COMMAND, Constant.COMMAND_STOP);
            sendBroadcast(intent);
        }
        recyclerViewAdapter.notifyItemRemoved(position);//推荐用这个
        updateView();
    }else {

    }
    //如果删除时,不使用mAdapter.notifyItemRemoved(pos),则删除没有动画效果,
    //且如果想让侧滑菜单同时关闭,需要同时调用 ((CstSwipeDelMenu) holder.itemView).quickClose();
    ((SwipeMenuLayout) swipeView).quickClose();
}
 
示例3
private void update(View swipeView, int position,MusicInfo musicInfo,boolean isDelete){
    if (isDelete){
        final int curId = musicInfo.getId();
        final int musicId = MyMusicUtil.getIntShared(Constant.KEY_ID);
        //从列表移除
        dbManager.removeMusic(musicInfo.getId(),Constant.ACTIVITY_LOCAL);
        if (curId == musicId) {
            //移除的是当前播放的音乐
            Intent intent = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
            intent.putExtra(Constant.COMMAND, Constant.COMMAND_STOP);
            context.sendBroadcast(intent);
        }
        recyclerViewAdapter.notifyItemRemoved(position);//推荐用这个
        updateView();
    }else {

    }
    //如果删除时,不使用mAdapter.notifyItemRemoved(pos),则删除没有动画效果,
    //且如果想让侧滑菜单同时关闭,需要同时调用 ((CstSwipeDelMenu) holder.itemView).quickClose();
    ((SwipeMenuLayout) swipeView).quickClose();
}
 
示例4
private void update(View swipeView, int position,MusicInfo musicInfo,boolean isDelete){
    if (isDelete){
        final int curId = musicInfo.getId();
        final int musicId = MyMusicUtil.getIntShared(Constant.KEY_ID);
        //从列表移除
        if (label.equals(Constant.LABEL_LAST)){
            dbManager.removeMusic(musicInfo.getId(),Constant.ACTIVITY_RECENTPLAY);
        }else if (label.equals(Constant.ACTIVITY_MYLOVE)){
            dbManager.removeMusic(musicInfo.getId(),Constant.LIST_LASTPLAY);
        }
        if (curId == musicId) {
            //移除的是当前播放的音乐
            Intent intent = new Intent(MusicPlayerService.PLAYER_MANAGER_ACTION);
            intent.putExtra(Constant.COMMAND, Constant.COMMAND_STOP);
            sendBroadcast(intent);
        }
        recyclerViewAdapter.notifyItemRemoved(position);//推荐用这个
        updateView();
    }else {

    }
    //如果删除时,不使用mAdapter.notifyItemRemoved(pos),则删除没有动画效果,
    //且如果想让侧滑菜单同时关闭,需要同时调用 ((CstSwipeDelMenu) holder.itemView).quickClose();
    ((SwipeMenuLayout) swipeView).quickClose();
}
 
示例5
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_swipe_menu);
    mFlowViewGroup = (FlowViewGroup) findViewById(R.id.flowLayout);
    mAdapter = new SingleAdapter<FlowBean>(this, mDatas = iniDatas(), R.layout.item_flow) {
        @Override
        public void onBindViewHolder(ViewGroup parent, final ViewHolder holder, final FlowBean data, int pos) {
            TextView tv = holder.getView(R.id.tv);
            tv.setText(data.getTag());
            //点击事件只能在这里设置 因为ItemView是侧滑控件
            tv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(FlowSwipeActivity.this, "点击了:" + data.getTag(), Toast.LENGTH_SHORT).show();
                }
            });
            //侧滑菜单的事件设置
            holder.setOnClickListener(R.id.btnDel, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mDatas.remove(data);
                    ((SwipeMenuLayout) holder.itemView).quickClose();
                    mVGUtil.bind();
                }
            });
        }


    };
    mVGUtil = new VGUtil(mFlowViewGroup, mAdapter)
            .bind();

}
 
示例6
@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder;
            if (convertView == null) {
                holder = new Holder();
                convertView = LayoutInflater.from(activity).inflate(R.layout.play_list_view_item, null, false);
                holder.swipView =  (SwipeMenuLayout)convertView.findViewById(R.id.play_list_content_swip_view);
                holder.contentLl = (LinearLayout) convertView.findViewById(R.id.play_list_content_ll);
                holder.coverIv = (ImageView) convertView.findViewById(R.id.play_list_cover_iv);
                holder.listName = (TextView) convertView.findViewById(R.id.play_list_name_tv);
                holder.listCount = (TextView) convertView.findViewById(R.id.play_list_music_count_tv);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            holder.swipView.setSwipeEnable(false);

//        if (dataList.size() == 0){
//            //展现默认的新建歌单列表
//            holder.listName.setText("aaa");
//            holder.listCount.setText("0首");
//        }else {
            //展现已有的歌单列表
            final PlayListInfo playListInfo = dataList.get(position);
            holder.listName.setText(playListInfo.getName());
            holder.listCount.setText(playListInfo.getCount() + "首");
//        }

            holder.contentLl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(dbManager.isExistPlaylist(playListInfo.getId(),musicInfo.getId())){
                        Toast.makeText(activity,"该歌单已存在该歌曲",Toast.LENGTH_SHORT).show();
                    }else {
                        dbManager.addToPlaylist(playListInfo.getId(),musicInfo.getId());
                        Toast.makeText(activity,"添加到歌单成功",Toast.LENGTH_SHORT).show();
                    }
                    dismiss();
//                if (dataList.size() == 0){
//                    //添加歌单
//                    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
//                    View view = LayoutInflater.from(context).inflate(R.layout.dialog_create_playlist,null);
//                    final EditText playlistEt = (EditText)view.findViewById(R.id.dialog_playlist_name_et);
//                    builder.setView(view);
//                    builder.setTitle("新建歌单");
//                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            String name = playlistEt.getText().toString();
//                            dbManager.createPlaylist(name);
//                            dialog.dismiss();
//                            updateDataList();
//                        }
//                    });
//
//                    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                        }
//                    });
//
//                    builder.show();//配置好后再builder show
//                }else {
                    //进入歌单
//                }
                }
            });


            return convertView;
        }
 
示例7
@Override
        public View getView(int position, View convertView, ViewGroup parent) {
            Holder holder;
            if (convertView == null) {
                holder = new Holder();
                convertView = LayoutInflater.from(activity).inflate(R.layout.play_list_view_item, null, false);
                holder.swipView =  (SwipeMenuLayout)convertView.findViewById(R.id.play_list_content_swip_view);
                holder.contentLl = (LinearLayout) convertView.findViewById(R.id.play_list_content_ll);
                holder.coverIv = (ImageView) convertView.findViewById(R.id.play_list_cover_iv);
                holder.listName = (TextView) convertView.findViewById(R.id.play_list_name_tv);
                holder.listCount = (TextView) convertView.findViewById(R.id.play_list_music_count_tv);
                convertView.setTag(holder);
            } else {
                holder = (Holder) convertView.getTag();
            }
            holder.swipView.setSwipeEnable(false);

//        if (dataList.size() == 0){
//            //展现默认的新建歌单列表
//            holder.listName.setText("aaa");
//            holder.listCount.setText("0首");
//        }else {
            //展现已有的歌单列表
            final PlayListInfo playListInfo = dataList.get(position);
            holder.listName.setText(playListInfo.getName());
            holder.listCount.setText(playListInfo.getCount() + "首");
//        }

            holder.contentLl.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(dbManager.isExistPlaylist(playListInfo.getId(),musicInfo.getId())){
                        Toast.makeText(activity,"该歌单已存在该歌曲",Toast.LENGTH_SHORT).show();
                    }else {
                        dbManager.addToPlaylist(playListInfo.getId(),musicInfo.getId());
                        Toast.makeText(activity,"添加到歌单成功",Toast.LENGTH_SHORT).show();
                    }
                    dismiss();
//                if (dataList.size() == 0){
//                    //添加歌单
//                    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
//                    View view = LayoutInflater.from(context).inflate(R.layout.dialog_create_playlist,null);
//                    final EditText playlistEt = (EditText)view.findViewById(R.id.dialog_playlist_name_et);
//                    builder.setView(view);
//                    builder.setTitle("新建歌单");
//                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            String name = playlistEt.getText().toString();
//                            dbManager.createPlaylist(name);
//                            dialog.dismiss();
//                            updateDataList();
//                        }
//                    });
//
//                    builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
//                        @Override
//                        public void onClick(DialogInterface dialog, int which) {
//                            dialog.dismiss();
//                        }
//                    });
//
//                    builder.show();//配置好后再builder show
//                }else {
                    //进入歌单
//                }
                }
            });


            return convertView;
        }
 
示例8
public void onDelClick(FlowBean flowBean, View view) {
    mDatas.remove(flowBean);
    ((SwipeMenuLayout) view.getParent()).quickClose();
    //ViewGroupUtils.refreshUI(mBinding.flowLayout, mAdapter);
    mAdapter.notifyDatasetChanged();
}