use of com.baoyz.swipemenulistview.SwipeMenu in project SwipeMenuListView by baoyongzhang.
the class SimpleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
mAppList = getPackageManager().getInstalledApplications(0);
mListView = (SwipeMenuListView) findViewById(R.id.listView);
mAdapter = new AppAdapter();
mListView.setAdapter(mAdapter);
// step 1. create a MenuCreator
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "open" item
SwipeMenuItem openItem = new SwipeMenuItem(getApplicationContext());
// set item background
openItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
// set item width
openItem.setWidth(dp2px(90));
// set item title
openItem.setTitle("Open");
// set item title fontsize
openItem.setTitleSize(18);
// set item title font color
openItem.setTitleColor(Color.WHITE);
// add to menu
menu.addMenuItem(openItem);
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
// set item width
deleteItem.setWidth(dp2px(90));
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};
// set creator
mListView.setMenuCreator(creator);
// step 2. listener item click event
mListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
ApplicationInfo item = mAppList.get(position);
switch(index) {
case 0:
// open
open(item);
break;
case 1:
// delete
// delete(item);
mAppList.remove(position);
mAdapter.notifyDataSetChanged();
break;
}
return false;
}
});
// set SwipeListener
mListView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() {
@Override
public void onSwipeStart(int position) {
// swipe start
}
@Override
public void onSwipeEnd(int position) {
// swipe end
}
});
// set MenuStateChangeListener
mListView.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() {
@Override
public void onMenuOpen(int position) {
}
@Override
public void onMenuClose(int position) {
}
});
// other setting
// listView.setCloseInterpolator(new BounceInterpolator());
// test item long click
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getApplicationContext(), position + " long click", Toast.LENGTH_SHORT).show();
return false;
}
});
}
use of com.baoyz.swipemenulistview.SwipeMenu in project JustAndroid by chinaltz.
the class MvvmGreenDaoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note);
ButterKnife.bind(this);
noteDao = MyApplication.getInstance().getDaoSession().getNoteDao();
navBack.setVisibility(View.VISIBLE);
navTitle.setText("简单笔记本");
navRight.setVisibility(View.VISIBLE);
navRightText.setText("添加");
noteList = new ArrayList<>();
adapter = new MvvmNoteAdapter(mContext, noteList);
navBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
navRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View view = LayoutInflater.from(mContext).inflate(R.layout.view_add_note, null);
final EditText titleText = (EditText) view.findViewById(R.id.titleText);
final EditText contentText = (EditText) view.findViewById(R.id.contentText);
Button commitButton = (Button) view.findViewById(R.id.commitButton);
AbDialogUtil.showDialog(view, Gravity.CENTER);
commitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String title = titleText.getText().toString();
String content = contentText.getText().toString();
if (AbStrUtil.isEmpty(title)) {
AbDialogUtil.removeDialog(mContext);
return;
}
if (AbStrUtil.isEmpty(content)) {
AbDialogUtil.removeDialog(mContext);
return;
}
Note note = new Note();
note.setCreatDate(new Date());
note.setNoteTitle(title);
note.setFavFlag(0);
note.setNoteContent(content);
noteDao.insert(note);
AbDialogUtil.removeDialog(mContext);
refreshNoteList();
}
});
}
});
listView.setAdapter(adapter);
refreshNoteList();
//1.创建侧滑按钮菜单
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "open" item
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
// set item width
deleteItem.setWidth(150);
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};
// 设置 MenuCreator
listView.setMenuCreator(creator);
// 2. 设置侧滑按钮 监听事件
listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
switch(index) {
case 0:
// delete
noteDao.delete(noteList.get(position));
refreshNoteList();
break;
}
return false;
}
});
}
use of com.baoyz.swipemenulistview.SwipeMenu in project JustAndroid by chinaltz.
the class MvpGreenDaoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note);
ButterKnife.bind(this);
navBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
presenter = new NotePresenter(this);
noteDao = MyApplication.getInstance().getDaoSession().getNoteDao();
navBack.setVisibility(View.VISIBLE);
navTitle.setText("简单笔记本");
navRight.setVisibility(View.VISIBLE);
navRightText.setText("添加");
noteList = new ArrayList<>();
adapter = new NoteAdapter(mContext, noteList);
navRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showAddNoteDialog();
}
});
refreshList();
listView.setAdapter(adapter);
//1.创建侧滑按钮菜单
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "open" item
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
// set item width
deleteItem.setWidth(150);
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};
// 设置 MenuCreator
listView.setMenuCreator(creator);
// 2. 设置侧滑按钮 监听事件
listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
switch(index) {
case 0:
// delete
presenter.deleteNote(noteList.get(position));
break;
}
return false;
}
});
}
use of com.baoyz.swipemenulistview.SwipeMenu in project JustAndroid by chinaltz.
the class GreenDaoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_note);
ButterKnife.bind(this);
noteDao = MyApplication.getInstance().getDaoSession().getNoteDao();
navBack.setVisibility(View.VISIBLE);
navTitle.setText("简单笔记本");
navRight.setVisibility(View.VISIBLE);
navRightText.setText("添加");
noteList = new ArrayList<>();
adapter = new NoteAdapter(mContext, noteList);
navRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
View view = LayoutInflater.from(mContext).inflate(R.layout.view_add_note, null);
final EditText titleText = (EditText) view.findViewById(R.id.titleText);
final EditText contentText = (EditText) view.findViewById(R.id.contentText);
Button commitButton = (Button) view.findViewById(R.id.commitButton);
AbDialogUtil.showDialog(view, Gravity.CENTER);
commitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String title = titleText.getText().toString();
String content = contentText.getText().toString();
if (AbStrUtil.isEmpty(title)) {
AbDialogUtil.removeDialog(mContext);
return;
}
if (AbStrUtil.isEmpty(content)) {
AbDialogUtil.removeDialog(mContext);
return;
}
Note note = new Note();
note.setCreatDate(new Date());
note.setNoteTitle(title);
note.setFavFlag(0);
note.setNoteContent(content);
noteDao.insert(note);
AbDialogUtil.removeDialog(mContext);
refreshNoteList();
}
});
}
});
listView.setAdapter(adapter);
refreshNoteList();
//1.创建侧滑按钮菜单
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// create "open" item
// create "delete" item
SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext());
// set item background
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
// set item width
deleteItem.setWidth(150);
// set a icon
deleteItem.setIcon(R.drawable.ic_delete);
// add to menu
menu.addMenuItem(deleteItem);
}
};
// 设置 MenuCreator
listView.setMenuCreator(creator);
// 2. 设置侧滑按钮 监听事件
listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
switch(index) {
case 0:
// delete
noteDao.insert(noteList.get(position));
refreshNoteList();
break;
}
return false;
}
});
}
use of com.baoyz.swipemenulistview.SwipeMenu in project SwipeMenuListView by baoyongzhang.
the class DifferentMenuActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
mAppList = getPackageManager().getInstalledApplications(0);
SwipeMenuListView listView = (SwipeMenuListView) findViewById(R.id.listView);
mAdapter = new AppAdapter();
listView.setAdapter(mAdapter);
// step 1. create a MenuCreator
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// Create different menus depending on the view type
switch(menu.getViewType()) {
case 0:
createMenu1(menu);
break;
case 1:
createMenu2(menu);
break;
case 2:
createMenu3(menu);
break;
}
}
private void createMenu1(SwipeMenu menu) {
SwipeMenuItem item1 = new SwipeMenuItem(getApplicationContext());
item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0x18, 0x5E)));
item1.setWidth(dp2px(90));
item1.setIcon(R.drawable.ic_action_favorite);
menu.addMenuItem(item1);
SwipeMenuItem item2 = new SwipeMenuItem(getApplicationContext());
item2.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
item2.setWidth(dp2px(90));
item2.setIcon(R.drawable.ic_action_good);
menu.addMenuItem(item2);
}
private void createMenu2(SwipeMenu menu) {
SwipeMenuItem item1 = new SwipeMenuItem(getApplicationContext());
item1.setBackground(new ColorDrawable(Color.rgb(0xE5, 0xE0, 0x3F)));
item1.setWidth(dp2px(90));
item1.setIcon(R.drawable.ic_action_important);
menu.addMenuItem(item1);
SwipeMenuItem item2 = new SwipeMenuItem(getApplicationContext());
item2.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25)));
item2.setWidth(dp2px(90));
item2.setIcon(R.drawable.ic_action_discard);
menu.addMenuItem(item2);
}
private void createMenu3(SwipeMenu menu) {
SwipeMenuItem item1 = new SwipeMenuItem(getApplicationContext());
item1.setBackground(new ColorDrawable(Color.rgb(0x30, 0xB1, 0xF5)));
item1.setWidth(dp2px(90));
item1.setIcon(R.drawable.ic_action_about);
menu.addMenuItem(item1);
SwipeMenuItem item2 = new SwipeMenuItem(getApplicationContext());
item2.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9, 0xCE)));
item2.setWidth(dp2px(90));
item2.setIcon(R.drawable.ic_action_share);
menu.addMenuItem(item2);
}
};
// set creator
listView.setMenuCreator(creator);
// step 2. listener item click event
listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
ApplicationInfo item = mAppList.get(position);
switch(index) {
case 0:
// open
break;
case 1:
// delete
// delete(item);
mAppList.remove(position);
mAdapter.notifyDataSetChanged();
break;
}
return false;
}
});
}
Aggregations