use of com.mikepenz.materialdrawer.model.PrimaryDrawerItem 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.PrimaryDrawerItem in project MaterialDrawer by mikepenz.
the class NonTranslucentDrawerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_nontranslucent);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_non_translucent_status_drawer);
// Create a few sample profile
result = new DrawerBuilder().withActivity(this).withTranslucentStatusBar(false).addDrawerItems(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 PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye), 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), 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(NonTranslucentDrawerActivity.this, ((Nameable) drawerItem).getName().getText(NonTranslucentDrawerActivity.this), Toast.LENGTH_SHORT).show();
}
return false;
}
}).withSelectedItemByPosition(2).withSavedInstance(savedInstanceState).build();
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
use of com.mikepenz.materialdrawer.model.PrimaryDrawerItem in project MaterialDrawer by mikepenz.
the class AdvancedActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
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_advanced_drawer);
// Create a few sample profile
profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile));
profile2 = new ProfileDrawerItem().withName("Max Muster").withEmail("max.mustermann@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile2)).withIdentifier(2);
profile3 = new ProfileDrawerItem().withName("Felix House").withEmail("felix.house@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile3));
profile4 = new ProfileDrawerItem().withName("Mr. X").withEmail("mister.x.super@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile4)).withIdentifier(4);
profile5 = new ProfileDrawerItem().withName("Batman").withEmail("batman@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile5));
// Create the AccountHeader
buildHeader(false, savedInstanceState);
//Create the drawer
result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(//set the AccountHeader we created earlier for the header
headerResult).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home), //this custom DrawerItem extends the PrimaryDrawerItem so it just overwrites some methods
new OverflowMenuDrawerItem().withName(R.string.drawer_item_menu_drawer_item).withDescription(R.string.drawer_item_menu_drawer_item_desc).withMenu(R.menu.fragment_menu).withOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
Toast.makeText(AdvancedActivity.this, item.getTitle(), Toast.LENGTH_SHORT).show();
return false;
}
}).withIcon(GoogleMaterial.Icon.gmd_filter_center_focus), new CustomPrimaryDrawerItem().withBackgroundRes(R.color.accent).withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad), new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withDescription("This is a description").withIcon(FontAwesome.Icon.faw_eye), new CustomUrlPrimaryDrawerItem().withName(R.string.drawer_item_fragment_drawer).withDescription(R.string.drawer_item_fragment_drawer_desc).withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460"), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cart_plus), new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_database).withEnabled(false), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withSelectedIconColor(Color.RED).withIconTintingEnabled(true).withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus).actionBar().paddingDp(5).colorRes(R.color.material_drawer_dark_primary_text)).withTag("Bullhorn"), new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false)).withOnDrawerNavigationListener(new Drawer.OnDrawerNavigationListener() {
@Override
public boolean onNavigationClickListener(View clickedView) {
//this method is only called if the Arrow icon is shown. The hamburger is automatically managed by the MaterialDrawer
//if the back arrow is shown. close the activity
AdvancedActivity.this.finish();
//return true if we have consumed the event
return true;
}
}).addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog).withIdentifier(10), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github)).withSavedInstance(savedInstanceState).build();
}
use of com.mikepenz.materialdrawer.model.PrimaryDrawerItem in project MaterialDrawer by mikepenz.
the class CollapsingToolbarActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_collapsing_toolbar);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
collapsingToolbarLayout.setTitle(getString(R.string.drawer_item_collapsing_toolbar_drawer));
headerResult = new AccountHeaderBuilder().withActivity(this).withCompactStyle(false).withHeaderBackground(R.drawable.header).withSavedInstance(savedInstanceState).build();
result = new DrawerBuilder().withActivity(this).withAccountHeader(headerResult).withToolbar(toolbar).withFullscreen(true).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).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), 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), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)).withSavedInstance(savedInstanceState).build();
fillFab();
loadBackdrop();
}
use of com.mikepenz.materialdrawer.model.PrimaryDrawerItem in project MaterialDrawer by mikepenz.
the class CompactHeaderDrawerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_compact_header);
// Create a few sample profile
final IProfile profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon(R.drawable.profile);
final IProfile profile2 = new ProfileDrawerItem().withName("Max Muster").withEmail("max.mustermann@gmail.com").withIcon(R.drawable.profile2);
final IProfile profile3 = new ProfileDrawerItem().withName("Felix House").withEmail("felix.house@gmail.com").withIcon(R.drawable.profile3);
final IProfile profile4 = new ProfileDrawerItem().withName("Mr. X").withEmail("mister.x.super@gmail.com").withIcon(R.drawable.profile4);
final IProfile profile5 = new ProfileDrawerItem().withName("Batman").withEmail("batman@gmail.com").withIcon(R.drawable.profile5);
// Create the AccountHeader
headerResult = new AccountHeaderBuilder().withActivity(this).withCompactStyle(true).withHeaderBackground(R.drawable.header).addProfiles(profile, profile2, profile3, profile4, profile5, //don't ask but google uses 14dp for the add account icon in gmail but 20dp for the normal icons (like manage account)
new ProfileSettingDrawerItem().withName("Add Account").withDescription("Add new GitHub Account").withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus).actionBar().paddingDp(5).colorRes(R.color.material_drawer_dark_primary_text)).withIdentifier(PROFILE_SETTING), new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings)).withSavedInstance(savedInstanceState).build();
//Create the drawer
result = new DrawerBuilder().withActivity(this).withAccountHeader(//set the AccountHeader we created earlier for the header
headerResult).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).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).withIdentifier(5), 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), 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 != null && drawerItem.getIdentifier() == 1) {
startSupportActionMode(new ActionBarCallBack());
findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(CompactHeaderDrawerActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
}
if (drawerItem instanceof Nameable) {
toolbar.setTitle(((Nameable) drawerItem).getName().getText(CompactHeaderDrawerActivity.this));
}
return false;
}
}).withSavedInstance(savedInstanceState).build();
// set the selection to the item with the identifier 5
if (savedInstanceState == null) {
result.setSelection(5, false);
}
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
Aggregations