com.mikepenz.materialdrawer.AccountHeader Java Examples

The following examples show how to use com.mikepenz.materialdrawer.AccountHeader. 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: DrawerManager.java    From FragmentNavigationPatternDemo with Apache License 2.0 5 votes vote down vote up
private AccountHeader getAccountHeader(Activity activity) {
    //@formatter:off
    return new AccountHeaderBuilder()
                    .withActivity(activity)
                    .withHeaderBackground(R.color.primary_dark)
                    .addProfiles(
                        new ProfileDrawerItem()
                                        .withName(activity.getString(R.string.app_name))
                    )
                    .build();
    //@formatter:on
}
 
Example #2
Source File: LeftDrawerManager.java    From timecat with Apache License 2.0 4 votes vote down vote up
public AccountHeader header() {
    return headerResult;
}
 
Example #3
Source File: CurrencyListTabsActivity.java    From CryptoBuddy with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_currency_list_tabs);
    context = this;
    mToolbar = findViewById(R.id.toolbar_currency_list);
    setSupportActionBar(mToolbar);
    TabLayout tabLayout = findViewById(R.id.currency_list_tabs);
    mViewPager = findViewById(R.id.currency_list_tabs_container);
    libsBuilder = new LibsBuilder()
            //provide a style (optional) (LIGHT, DARK, LIGHT_DARK_TOOLBAR)
            .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
            .withAboutIconShown(true)
            .withLicenseShown(true)
            .withVersionShown(true)
            .withAboutVersionShownName(true)
            .withAboutVersionShownCode(true)
            .withAboutVersionString("Version: " + BuildConfig.VERSION_NAME)
            .withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
            .withActivityTitle("CryptoBuddy")
            .withLibraries("easyrest", "materialabout", "androiddevicenames", "customtabs", "togglebuttongroup", "materialfavoritebutton");

    TextDrawable t = new TextDrawable(this);
    t.setText("ART");
    t.setTextAlign(Layout.Alignment.ALIGN_CENTER);
    t.setTextColor(Color.BLACK);
    t.setTextSize(10);
    AccountHeader headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(t).build();
    drawer = new DrawerBuilder()
            .withActivity(this)
            .withToolbar(mToolbar)
            .withSelectedItem(1)
            .withAccountHeader(headerResult)
            .addDrawerItems(
                new PrimaryDrawerItem().withIdentifier(1).withName(R.string.Home).withIcon(FontAwesome.Icon.faw_home),
                new PrimaryDrawerItem().withIdentifier(2).withName(R.string.News).withIcon(FontAwesome.Icon.faw_newspaper),
                new PrimaryDrawerItem().withIdentifier(3).withName("About").withIcon(FontAwesome.Icon.faw_question_circle),
                new PrimaryDrawerItem().withIdentifier(4).withName("Open Source").withIcon(FontAwesome.Icon.faw_github_square),
                new PrimaryDrawerItem().withIdentifier(5).withName("Rate on Google Play").withIcon(FontAwesome.Icon.faw_thumbs_up)
            )
            .withTranslucentStatusBar(false)
            .build();
    drawer.setOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            switch (position) {
                case 1:
                    drawer.closeDrawer();
                    return true;
                case 2:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, NewsListActivity.class));
                    return true;
                case 3:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    startActivity(new Intent(context, AboutTheDevActivity.class));
                    return true;
                case 4:
                    drawer.closeDrawer();
                    drawer.setSelection(1);
                    libsBuilder.start(context);
                default:
                    return true;
            }
        }
    });

    mSectionsPagerAdapter = new SectionsPagerAdapterCurrencyList(getSupportFragmentManager());
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOffscreenPageLimit(2);
    mViewPager.addOnPageChangeListener(this);
    tabLayout.setupWithViewPager(mViewPager);
    tabLayout.setSelectedTabIndicatorColor(Color.WHITE);
}
 
Example #4
Source File: MainActivity.java    From openapk with GNU General Public License v3.0 4 votes vote down vote up
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 #5
Source File: DrawerActivity.java    From outlay with Apache License 2.0 4 votes vote down vote up
public void setupDrawer(User currentUser) {
    String email = TextUtils.isEmpty(currentUser.getEmail()) ? "Guest" : currentUser.getEmail();

    AccountHeader headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withTextColor(getOutlayTheme().secondaryTextColor)
            .withAlternativeProfileHeaderSwitching(false)
            .withSelectionListEnabledForSingleProfile(false)
            .withProfileImagesClickable(false)
            .withCloseDrawerOnProfileListClick(false)
            .addProfiles(
                    new ProfileDrawerItem()
                            .withEmail(email)
            )
            .build();

    List<IDrawerItem> items = new ArrayList<>();
    if (currentUser.isAnonymous()) {
        items.add(new PrimaryDrawerItem().withName(app.outlay.R.string.menu_item_create_user).withIcon(MaterialDesignIconic.Icon.gmi_account_add).withIdentifier(ITEM_CREATE_USER));
    }

    items.add(new PrimaryDrawerItem().withName(app.outlay.R.string.menu_item_analysis).withIcon(MaterialDesignIconic.Icon.gmi_trending_up).withIdentifier(ITEM_ANALYSIS));
    items.add(new PrimaryDrawerItem().withName(app.outlay.R.string.menu_item_categories).withIcon(MaterialDesignIconic.Icon.gmi_apps).withIdentifier(ITEM_CATEGORIES));
    items.add(new PrimaryDrawerItem().withName(app.outlay.R.string.menu_item_feedback).withIcon(MaterialDesignIconic.Icon.gmi_email).withIdentifier(ITEM_FEEDBACK));
    items.add(new PrimaryDrawerItem().withName(R.string.menu_item_settings).withIcon(MaterialDesignIconic.Icon.gmi_settings).withIdentifier(ITEM_SETTINGS));
    items.add(new PrimaryDrawerItem().withName(app.outlay.R.string.menu_item_signout).withIcon(MaterialDesignIconic.Icon.gmi_sign_in).withIdentifier(ITEM_SING_OUT));


    mainDrawer = new DrawerBuilder()
            .withFullscreen(true)
            .withActivity(this)
            .withAccountHeader(headerResult)
            .withSelectedItem(-1)
            .addDrawerItems(items.toArray(new IDrawerItem[items.size()]))
            .withOnDrawerItemClickListener((view, i, iDrawerItem) -> {
                if (iDrawerItem != null) {
                    int id = (int) iDrawerItem.getIdentifier();
                    switch (id) {
                        case ITEM_CATEGORIES:
                            analytics().trackViewCategoriesList();
                            SingleFragmentActivity.start(this, CategoriesFragment.class);
                            break;
                        case ITEM_ANALYSIS:
                            analytics().trackAnalysisView();
                            SingleFragmentActivity.start(this, AnalysisFragment.class);
                            break;
                        case ITEM_SETTINGS:
                            SingleFragmentActivity.start(this, SettingsFragment.class);
                            break;
                        case ITEM_FEEDBACK:
                            analytics().trackFeedbackClick();
                            Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                                    "mailto", Constants.CONTACT_EMAIL, null));
                            emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{Constants.CONTACT_EMAIL});
                            emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Outlay Feedback");
                            try {
                                startActivity(Intent.createChooser(emailIntent, getString(app.outlay.R.string.label_send_email)));
                            } catch (android.content.ActivityNotFoundException ex) {
                                Alert.error(getRootView(), getString(app.outlay.R.string.error_no_email_clients));
                            }
                            break;
                        case ITEM_ABOUT:
                            SingleFragmentActivity.start(this, AboutFragment.class);
                            break;
                        case ITEM_SING_OUT:
                            analytics().trackSingOut();
                            signOut();
                            break;
                        case ITEM_CREATE_USER:
                            createUser();
                            break;
                    }

                    mainDrawer.setSelection(-1);
                    mainDrawer.closeDrawer();
                }
                return false;
            })
            .build();
}
 
Example #6
Source File: MainActivity.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
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);

}