use of com.mikepenz.materialdrawer.model.interfaces.Badgeable in project MaterialDrawer by mikepenz.
the class MultiDrawerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_multi_drawer);
//first create the main drawer (this one will be used to add the second drawer on the other side)
result = new DrawerBuilder().withActivity(this).withHeader(R.layout.header).withSavedInstance(savedInstanceState).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withBadge("99").withIdentifier(1), new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad), new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye).withBadge("6").withIdentifier(2), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog), new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github).withBadge("12").withIdentifier(3), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)).withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
Toast.makeText(MultiDrawerActivity.this, "onDrawerOpened", Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerClosed(View drawerView) {
Toast.makeText(MultiDrawerActivity.this, "onDrawerClosed", Toast.LENGTH_SHORT).show();
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem != null) {
if (drawerItem instanceof Nameable) {
Toast.makeText(MultiDrawerActivity.this, ((Nameable) drawerItem).getName().getText(MultiDrawerActivity.this), Toast.LENGTH_SHORT).show();
}
if (drawerItem instanceof Badgeable) {
Badgeable badgeable = (Badgeable) drawerItem;
if (badgeable.getBadge() != null) {
//note don't do this if your badge contains a "+"
//only use toString() if you set the test as String
int badge = Integer.valueOf(badgeable.getBadge().toString());
if (badge > 0) {
badgeable.withBadge(String.valueOf(badge - 1));
result.updateItem(drawerItem);
}
}
}
}
return false;
}
}).withOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {
@Override
public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem instanceof SecondaryDrawerItem) {
Toast.makeText(MultiDrawerActivity.this, ((SecondaryDrawerItem) drawerItem).getName().getText(MultiDrawerActivity.this), Toast.LENGTH_SHORT).show();
}
return false;
}
}).withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
if (drawerView == result.getSlider()) {
Log.e("sample", "left opened");
} else if (drawerView == resultAppended.getSlider()) {
Log.e("sample", "right opened");
}
}
@Override
public void onDrawerClosed(View drawerView) {
if (drawerView == result.getSlider()) {
Log.e("sample", "left closed");
} else if (drawerView == resultAppended.getSlider()) {
Log.e("sample", "right closed");
}
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}).build();
//now we add the second drawer on the other site.
//use the .append method to add this drawer to the first one
resultAppended = new DrawerBuilder().withActivity(this).withFooter(R.layout.footer).withDisplayBelowStatusBar(true).withSavedInstance(savedInstanceState).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye), new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home), new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog), new DividerDrawerItem(), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github), new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem instanceof Nameable) {
Toast.makeText(MultiDrawerActivity.this, ((Nameable) drawerItem).getName().getText(MultiDrawerActivity.this), Toast.LENGTH_SHORT).show();
}
return false;
}
}).withDrawerGravity(Gravity.END).append(result);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
use of com.mikepenz.materialdrawer.model.interfaces.Badgeable in project MaterialDrawer by mikepenz.
the class Drawer method updateBadge.
/**
* update the badge for a specific drawerItem
* identified by its id
*
* @param identifier
* @param badge
*/
public void updateBadge(long identifier, StringHolder badge) {
IDrawerItem drawerItem = getDrawerItem(identifier);
if (drawerItem instanceof Badgeable) {
Badgeable badgeable = (Badgeable) drawerItem;
badgeable.withBadge(badge);
updateItem((IDrawerItem) badgeable);
}
}
Aggregations