Java Code Examples for com.mikepenz.materialdrawer.DrawerBuilder#withOnDrawerItemClickListener()
The following examples show how to use
com.mikepenz.materialdrawer.DrawerBuilder#withOnDrawerItemClickListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From openapk with GNU General Public License v3.0 | 4 votes |
public static Drawer setNavigationDrawer(final Context context, final Toolbar toolbar, final RecyclerView recyclerView, boolean badge, final AppAdapter appInstalledAdapter, final AppAdapter appSystemAdapter, final AppAdapter appDisabledAdapter, final AppAdapter appHiddenAdapter, final AppAdapter appFavoriteAdapter) { AppPreferences appPreferences = App.getAppPreferences(); final Activity activity = (Activity) context; int header; // check for dark theme Integer badgeColor; BadgeStyle badgeStyle; if (appPreferences.getTheme().equals("0")) { badgeColor = ContextCompat.getColor(context, R.color.badge_light); badgeStyle = new BadgeStyle(badgeColor, badgeColor).withTextColor(context.getResources().getColor(R.color.text_light)); header = R.drawable.header_day; } else { badgeColor = ContextCompat.getColor(context, R.color.badge_dark); badgeStyle = new BadgeStyle(badgeColor, badgeColor).withTextColor(context.getResources().getColor(R.color.text_dark)); header = R.drawable.header_night; } AccountHeader headerResult = new AccountHeaderBuilder() .withActivity(activity) .withHeaderBackground(header) .build(); DrawerBuilder drawerBuilder = new DrawerBuilder(); drawerBuilder.withActivity(activity); drawerBuilder.withToolbar(toolbar); drawerBuilder.withAccountHeader(headerResult); drawerBuilder.withStatusBarColor(OtherUtils.dark(appPreferences.getPrimaryColor(), 0.8)); if (badge) { String installedApps = Integer.toString(appInstalledAdapter.getItemCount()); String systemApps = Integer.toString(appSystemAdapter.getItemCount()); String disabledApps = Integer.toString(appDisabledAdapter.getItemCount()); String hiddenApps = Integer.toString(appHiddenAdapter.getItemCount()); String favoriteApps = Integer.toString(appFavoriteAdapter.getItemCount()); drawerBuilder.addDrawerItems( new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_installed)).withIcon(GoogleMaterial.Icon.gmd_phone_android).withBadge(installedApps).withBadgeStyle(badgeStyle).withIdentifier(0), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_system)).withIcon(GoogleMaterial.Icon.gmd_android).withBadge(systemApps).withBadgeStyle(badgeStyle).withIdentifier(1), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_disabled)).withIcon(GoogleMaterial.Icon.gmd_remove_circle_outline).withBadge(disabledApps).withBadgeStyle(badgeStyle).withIdentifier(2), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_hidden)).withIcon(GoogleMaterial.Icon.gmd_visibility_off).withBadge(hiddenApps).withBadgeStyle(badgeStyle).withIdentifier(3), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_favorite)).withIcon(GoogleMaterial.Icon.gmd_star).withBadge(favoriteApps).withBadgeStyle(badgeStyle).withIdentifier(4), new DividerDrawerItem(), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.settings)).withIcon(GoogleMaterial.Icon.gmd_settings).withSelectable(false).withIdentifier(5), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.about)).withIcon(GoogleMaterial.Icon.gmd_info).withSelectable(false).withIdentifier(6)); } else { drawerBuilder.addDrawerItems( new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_installed)).withIcon(GoogleMaterial.Icon.gmd_phone_android).withIdentifier(0), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_system)).withIcon(GoogleMaterial.Icon.gmd_android).withIdentifier(1), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_disabled)).withIcon(GoogleMaterial.Icon.gmd_remove_circle_outline).withIdentifier(2), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_hidden)).withIcon(GoogleMaterial.Icon.gmd_visibility_off).withIdentifier(3), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.apps_favorite)).withIcon(GoogleMaterial.Icon.gmd_star).withIdentifier(4), new DividerDrawerItem(), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.settings)).withIcon(GoogleMaterial.Icon.gmd_settings).withSelectable(false).withIdentifier(5), new PrimaryDrawerItem().withName(context.getResources().getString(R.string.about)).withIcon(GoogleMaterial.Icon.gmd_info).withSelectable(false).withIdentifier(6)); } drawerBuilder.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override public boolean onItemClick(View view, int position, IDrawerItem drawerItem) { switch (drawerItem.getIdentifier()) { case 0: recyclerView.setAdapter(appInstalledAdapter); App.setCurrentAdapter(0); OtherUtils.setToolbarTitle(context, context.getResources().getString(R.string.apps_installed)); break; case 1: recyclerView.setAdapter(appSystemAdapter); App.setCurrentAdapter(1); OtherUtils.setToolbarTitle(context, context.getResources().getString(R.string.apps_system)); break; case 2: recyclerView.setAdapter(appDisabledAdapter); App.setCurrentAdapter(2); OtherUtils.setToolbarTitle(context, context.getResources().getString(R.string.apps_disabled)); break; case 3: recyclerView.setAdapter(appHiddenAdapter); App.setCurrentAdapter(3); OtherUtils.setToolbarTitle(context, context.getResources().getString(R.string.apps_hidden)); break; case 4: recyclerView.setAdapter(appFavoriteAdapter); App.setCurrentAdapter(4); OtherUtils.setToolbarTitle(context, context.getResources().getString(R.string.apps_favorite)); break; case 5: context.startActivity(new Intent(context, SettingsActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); break; case 6: context.startActivity(new Intent(context, AboutActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); break; default: break; } return false; } }); return drawerBuilder.build(); }
Example 2
Source File: MainActivity.java From ETSMobile-Android2 with Apache License 2.0 | 4 votes |
private void initDrawer() { boolean isUserLoggedIn = ApplicationManager.userCredentials != null; String studentName = ""; String codeUniversel = ""; ProfilManager profilManager = new ProfilManager(this); Etudiant etudiant = profilManager.getEtudiant(); if (etudiant != null) { String prenom = etudiant.prenom != null ? etudiant.prenom.trim() : ""; String nom = etudiant.nom != null ? etudiant.nom.trim() : ""; studentName = prenom + " " + nom; codeUniversel = etudiant.codePerm != null ? etudiant.codePerm : ""; } headerResult = new AccountHeaderBuilder() .withActivity(this) .withHeaderBackground(R.drawable.ets_background_grayscale) .withSelectionListEnabledForSingleProfile(false) .addProfiles( new ProfileDrawerItem() .withName(codeUniversel) .withEmail(studentName) .withSelectedTextColor(ContextCompat.getColor(this, R.color.red)) .withIcon(R.drawable.ic_user) .withSelectable(isUserLoggedIn) ).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() { @Override public boolean onProfileChanged(View view, IProfile profile, boolean current) { goToFragment(new ProfilFragment(), ProfilFragment.class.getName()); activityDrawer.deselect(); return false; } }).build(); DrawerBuilder drawerBuilder = new DrawerBuilder() .withActivity(this) .withToolbar(toolbar) .withAccountHeader(headerResult) .withSelectedItem(isUserLoggedIn ? TODAY_ITEM : ABOUT_ITEM) .withDisplayBelowStatusBar(true) .withShowDrawerOnFirstLaunch(true) .addDrawerItems( new ExpandableDrawerItem().withName(R.string.menu_section_1_moi).withSelectable(false).withSubItems( new SecondaryDrawerItem().withName(R.string.menu_section_1_profil).withIdentifier(PROFILE_ITEM).withIcon(R.drawable.ic_ico_profil).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_ajd).withIdentifier(TODAY_ITEM).withIcon(R.drawable.ic_ico_aujourdhui).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_horaire).withIdentifier(SCHEDULE_ITEM).withIcon(R.drawable.ic_ico_schedule).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_notes).withIdentifier(COURSE_ITEM).withIcon(R.drawable.ic_ico_notes).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_2_moodle).withIdentifier(MOODLE_ITEM).withIcon(R.drawable.ic_moodle_icon_small).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_monETS).withIdentifier(MONETS_ITEM).withSelectable(false).withIcon(R.drawable.ic_monets).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_bandwith).withIdentifier(BANDWIDTH_ITEM).withIcon(R.drawable.ic_ico_internet), new SecondaryDrawerItem().withName(R.string.menu_section_3_beta).withIdentifier(BETA_VERSION_ITEM).withIcon(R.drawable.ic_beta_24dp) ), new ExpandableDrawerItem().withName(R.string.menu_section_2_ets).withSelectable(false).withSubItems( new SecondaryDrawerItem().withName(R.string.menu_section_2_news).withIdentifier(NEWS_ITEM).withIcon(R.drawable.ic_ico_news), new SecondaryDrawerItem().withName(R.string.menu_section_2_bottin).withIdentifier(DIRECTORY_ITEM).withIcon(R.drawable.ic_ico_bottin), new SecondaryDrawerItem().withName(R.string.menu_section_2_biblio).withIdentifier(LIBRARY_ITEM).withSelectable(false).withIcon(R.drawable.ic_ico_library), new SecondaryDrawerItem().withName(R.string.menu_section_2_securite).withIdentifier(SECURITY_ITEM).withIcon(R.drawable.ic_ico_security) ), new ExpandableDrawerItem().withName(R.string.menu_section_3_applets).withSelectable(false).withSubItems( new SecondaryDrawerItem().withName(R.string.menu_section_3_apps).withIdentifier(ACHIEVEMENTS_ITEM).withIcon(R.drawable.ic_star_60x60), new SecondaryDrawerItem().withName(R.string.menu_section_3_about).withIdentifier(ABOUT_ITEM).withIcon(R.drawable.ic_logo_icon_final), new SecondaryDrawerItem().withName(R.string.menu_section_3_faq).withIdentifier(FAQ_ITEM).withIcon(R.drawable.ic_ico_faq) ) ); if (isUserLoggedIn) drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_logout).withIdentifier(LOGOUT).withTextColorRes(R.color.red)); else drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_login).withIdentifier(LOGIN)); drawerBuilder.withOnDrawerItemClickListener(drawerItemClickListener); activityDrawer = drawerBuilder.build(); activityDrawer.getExpandableExtension().expand(1); }