packagecom.spaceapps.garden.activities; | |
importandroid.os.Bundle; | |
importandroid.support.v7.app.AppCompatActivity; | |
importandroid.support.v7.widget.Toolbar; | |
importandroid.view.View; | |
importcom.mikepenz.community_material_typeface_library.CommunityMaterial; | |
importcom.mikepenz.google_material_typeface_library.GoogleMaterial; | |
importcom.mikepenz.materialdrawer.AccountHeader; | |
importcom.mikepenz.materialdrawer.AccountHeaderBuilder; | |
importcom.mikepenz.materialdrawer.Drawer; | |
importcom.mikepenz.materialdrawer.DrawerBuilder; | |
importcom.mikepenz.materialdrawer.model.PrimaryDrawerItem; | |
importcom.mikepenz.materialdrawer.model.interfaces.IDrawerItem; | |
importcom.spaceapps.garden.R; | |
importcom.spaceapps.garden.fragments.GardensFragment; | |
importcom.spaceapps.garden.fragments.PlantsFragment; | |
importjava.util.ArrayList; | |
publicclassMainActivityextendsAppCompatActivity { | |
privateToolbar toolbar; | |
privateString garden; | |
privateString plants; | |
privateString calendar; | |
privateArrayList<IDrawerItem> drawerItems =newArrayList<>(); | |
@Override | |
protectedvoidonCreate(BundlesavedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
garden = getString(R.string.garden); | |
plants = getString(R.string.plants); | |
calendar = getString(R.string.calendar); | |
setupNavigationDrawer();//this method already calls setupDrawerItems() | |
getSupportFragmentManager().beginTransaction() | |
.replace(R.id.root_layout, newGardensFragment()) | |
.commit(); | |
} | |
privatevoidsetupNavigationDrawer() { | |
DrawerBuilder drawerBuilder =newDrawerBuilder(); | |
int header =R.drawable.drawer_image; | |
AccountHeader accountHeader =newAccountHeaderBuilder() | |
.withActivity(this) | |
.withHeaderBackground(header) | |
//.addProfiles(profile) | |
//.withHeaderBackgroundScaleType(ImageView.ScaleType.CENTER_CROP) | |
.withSelectionListEnabledForSingleProfile(false) | |
.withProfileImagesClickable(false) | |
.build(); | |
drawerBuilder.withActivity(this); | |
drawerBuilder.withToolbar(toolbar); | |
drawerBuilder.withAccountHeader(accountHeader); | |
//drawerBuilder.withShowDrawerOnFirstLaunch(true); | |
drawerBuilder.withActionBarDrawerToggleAnimated(true); | |
drawerBuilder.withStickyFooterShadow(false); | |
drawerBuilder.withStickyFooterDivider(true); | |
drawerBuilder.withSelectedItem(-1); | |
setupDrawerItems(); | |
drawerBuilder.withDrawerItems(drawerItems); | |
/* drawerBuilder.addStickyDrawerItems( | |
new SecondaryDrawerItem().withName(tutoriel).withIcon(GoogleMaterial.Icon | |
.gmd_help_outline).withIdentifier(7).withIconColor(getResources() | |
.getColor(R.color.md_grey_700)).withSelectable(false), | |
new SecondaryDrawerItem().withName(aboutApp).withIcon(GoogleMaterial.Icon | |
.gmd_more_horiz).withIdentifier(80).withIconColor(getResources() | |
.getColor(R.color.md_grey_700)).withSelectable(false)) | |
new SecondaryDrawerItem().withName(settings).withIcon(GoogleMaterial | |
.Icon.gmd_settings).withIdentifier(8).withIconColor(getResources() | |
.getColor(R.color.md_grey_700)).withSelectable(false))*/ | |
; | |
drawerBuilder.withOnDrawerItemClickListener(newDrawer.OnDrawerItemClickListener() { | |
@Override | |
publicbooleanonItemClick(Viewview, intposition, IDrawerItemdrawerItem) { | |
long id = drawerItem.getIdentifier(); | |
if (id ==1) { | |
getSupportFragmentManager().beginTransaction() | |
.replace(R.id.root_layout, newGardensFragment()) | |
.commit(); | |
} elseif (id ==2) { | |
getSupportFragmentManager().beginTransaction() | |
.replace(R.id.root_layout, newPlantsFragment()) | |
.commit(); | |
} elseif (id ==3) { | |
} elseif (id ==5) { | |
// startActivity(new Intent(MainActivity.this, AboutActivity.class)); | |
} | |
returnfalse; | |
} | |
}); | |
drawerBuilder.build(); | |
} | |
privatevoidsetupDrawerItems() { | |
drawerItems.add(newPrimaryDrawerItem().withIdentifier(1).withName(garden) | |
.withIcon(GoogleMaterial.Icon.gmd_grid_on) | |
.withSelectedTextColorRes(R.color.colorAccent) | |
.withIconColor(getResources().getColor(R.color.md_blue_grey_500)) | |
.withSelectedIconColorRes(R.color.md_blue_grey_500)); | |
drawerItems.add(newPrimaryDrawerItem().withIdentifier(2).withName(plants) | |
.withIcon(CommunityMaterial.Icon.cmd_nature) | |
.withSelectedTextColorRes(R.color.colorAccent) | |
.withIconColor(getResources().getColor(R.color.md_blue_grey_500)) | |
.withSelectedIconColorRes(R.color.md_blue_grey_500)); | |
drawerItems.add(newPrimaryDrawerItem().withIdentifier(3).withName(calendar) | |
.withIcon(CommunityMaterial.Icon.cmd_calendar_multiple) | |
.withSelectedTextColorRes(R.color.colorAccent) | |
.withIconColor(getResources().getColor(R.color.md_blue_grey_500)) | |
.withSelectedIconColorRes(R.color.md_blue_grey_500)); | |
} | |
} |
SpaceApps is a NASA incubator innovation program.