use of com.mikepenz.materialdrawer.model.ProfileDrawerItem in project MaterialDrawer by mikepenz.
the class PersistentDrawerActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_persistent_drawer);
//Remove line to test RTL support
// getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
//example how to implement a persistentDrawer as shown in the google material design guidelines
//https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0Bx4BSt6jniD7YVdKQlF3TEo2S3M/patterns_navdrawer_behavior_persistent2.png
//https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-behavior
// Handle Toolbar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.drawer_item_persistent_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).withTranslucentStatusBar(true).withHeaderBackground(new ColorDrawable(Color.parseColor("#FDFDFD"))).withHeightPx(UIUtils.getActionBarHeight(this)).withAccountHeader(R.layout.material_drawer_compact_persistent_header).withTextColor(Color.BLACK).addProfiles(profile, profile2, profile3, profile4, profile5).withSavedInstance(savedInstanceState).build();
//Create the drawer
result = new DrawerBuilder().withActivity(this).withTranslucentStatusBar(true).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), 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)).withGenerateMiniDrawer(true).withSavedInstance(savedInstanceState).buildView();
// create the MiniDrawer and define the drawer and header to be used (it will automatically use the items from them)
miniResult = result.getMiniDrawer().withIncludeSecondaryDrawerItems(true);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
//get the widths in px for the first and second panel
int firstWidth = (int) com.mikepenz.crossfader.util.UIUtils.convertDpToPixel(300, this);
int secondWidth = (int) com.mikepenz.crossfader.util.UIUtils.convertDpToPixel(72, this);
//create and build our crossfader (see the MiniDrawer is also builded in here, as the build method returns the view to be used in the crossfader)
crossFader = new Crossfader().withContent(findViewById(R.id.crossfade_content)).withFirst(result.getSlider(), firstWidth).withSecond(miniResult.build(this), secondWidth).withSavedInstance(savedInstanceState).build();
//define the crossfader to be used with the miniDrawer. This is required to be able to automatically toggle open / close
miniResult.withCrossFader(new CrossfadeWrapper(crossFader));
//define and create the arrow ;)
ImageView toggle = (ImageView) headerResult.getView().findViewById(R.id.material_drawer_account_header_toggle);
//for RTL you would have to define the other arrow
toggle.setImageDrawable(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_chevron_left).sizeDp(16).color(Color.BLACK));
toggle.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
crossFader.crossFade();
}
});
}
use of com.mikepenz.materialdrawer.model.ProfileDrawerItem in project Tusky by Vavassor.
the class MainActivity method onFetchUserInfoSuccess.
private void onFetchUserInfoSuccess(Account me, String domain) {
// Add the header image and avatar from the account, into the navigation drawer header.
headerResult.clear();
ImageView background = headerResult.getHeaderBackgroundView();
int backgroundWidth = background.getWidth();
int backgroundHeight = background.getHeight();
if (backgroundWidth == 0 || backgroundHeight == 0) {
/* The header ImageView may not be layed out when the verify credentials call returns so
* measure the dimensions and use those. */
background.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
backgroundWidth = background.getMeasuredWidth();
backgroundHeight = background.getMeasuredHeight();
}
background.setBackgroundColor(ContextCompat.getColor(this, R.color.window_background_dark));
Picasso.with(MainActivity.this).load(me.header).placeholder(R.drawable.account_header_default).resize(backgroundWidth, backgroundHeight).centerCrop().into(background);
headerResult.addProfiles(new ProfileDrawerItem().withName(me.getDisplayName()).withEmail(String.format("%s@%s", me.username, domain)).withIcon(me.avatar));
// Show follow requests in the menu, if this is a locked account.
if (me.locked) {
PrimaryDrawerItem followRequestsItem = new PrimaryDrawerItem().withIdentifier(6).withName(R.string.action_view_follow_requests).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person_add);
drawer.addItemAtPosition(followRequestsItem, 3);
}
// Update the current login information.
loggedInAccountId = me.id;
loggedInAccountUsername = me.username;
getPrivatePreferences().edit().putString("loggedInAccountId", loggedInAccountId).putString("loggedInAccountUsername", loggedInAccountUsername).putBoolean("loggedInAccountLocked", me.locked).apply();
}
use of com.mikepenz.materialdrawer.model.ProfileDrawerItem in project Tusky by tuskyapp.
the class MainActivity method updateProfiles.
private void updateProfiles() {
List<AccountEntity> allAccounts = accountManager.getAllAccountsOrderedByActive();
// remove profiles before adding them again to avoid duplicates
List<IProfile> profiles = new ArrayList<>(headerResult.getProfiles());
for (IProfile profile : profiles) {
if (profile.getIdentifier() != DRAWER_ITEM_ADD_ACCOUNT) {
headerResult.removeProfile(profile);
}
}
for (AccountEntity acc : allAccounts) {
headerResult.addProfiles(new ProfileDrawerItem().withName(acc.getDisplayName()).withIcon(acc.getProfilePictureUrl()).withNameShown(true).withIdentifier(acc.getId()).withEmail(acc.getFullName()));
}
}
use of com.mikepenz.materialdrawer.model.ProfileDrawerItem in project Weather by Sparker0i.
the class WeatherActivity method initDrawer.
public void initDrawer() {
final IProfile profile = new ProfileDrawerItem().withName(getString(R.string.app_name)).withEmail("Version : " + BuildConfig.VERSION_NAME).withIcon(R.mipmap.ic_launcher_x);
AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).withTextColor(ContextCompat.getColor(this, R.color.md_amber_400)).addProfiles(profile).withSelectionListEnabled(false).withProfileImagesClickable(false).build();
SecondaryDrawerItem item1 = new SecondaryDrawerItem().withName(R.string.drawer_item_home).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_day_sunny)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
wf = new WeatherFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
return true;
}
});
SecondaryDrawerItem item2 = new SecondaryDrawerItem().withName(R.string.drawer_item_graph).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_trending_up)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (!(f instanceof GraphsFragment)) {
GraphsFragment graphsFragment = newGraphInstance(new ArrayList<>(wf.getDailyJson()));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, graphsFragment).commit();
}
return true;
}
});
SecondaryDrawerItem item3 = new SecondaryDrawerItem().withName(R.string.drawer_item_map).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_map)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (!(f instanceof MapsFragment)) {
MapsFragment mapsFragment = new MapsFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, mapsFragment).commit();
}
return true;
}
});
SecondaryDrawerItem item4 = new SecondaryDrawerItem().withName(R.string.drawer_item_add_city).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_add_location)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
showCityDialog();
return true;
}
}).withSelectable(false);
SecondaryDrawerItem item8 = new SecondaryDrawerItem().withName(R.string.drawer_item_about).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info)).withSelectable(false).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
startActivity(new Intent(WeatherActivity.this, AboutActivity.class));
return true;
}
});
SecondaryDrawerItem item9 = new SecondaryDrawerItem().withName(R.string.settings).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_settings)).withSelectable(false).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
startActivity(new Intent(WeatherActivity.this, SettingsActivity.class));
return true;
}
});
DrawerBuilder drawerBuilder = new DrawerBuilder();
drawerBuilder.withActivity(this).withToolbar(toolbar).withTranslucentStatusBar(true).withAccountHeader(headerResult).withActionBarDrawerToggleAnimated(true).addDrawerItems(item1, item2, item3, new DividerDrawerItem(), item4).addStickyDrawerItems(item8, item9);
List<String> cities = dbHelper.getCities();
final ListIterator<String> listIterator = cities.listIterator(cities.size());
while (listIterator.hasPrevious()) {
final String city = listIterator.previous();
drawerBuilder.addDrawerItems(new SecondaryDrawerItem().withName(city).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_place)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
wf = new WeatherFragment().setCity(city);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
return true;
}
}));
}
drawer = drawerBuilder.build();
}
Aggregations