use of com.mikepenz.materialdrawer.DrawerBuilder in project MaterialDrawer by mikepenz.
the class ActionBarActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample_actionbar);
setTitle(R.string.drawer_item_action_bar_drawer);
// Handle Toolbar
result = new DrawerBuilder().withActivity(this).withSavedInstance(savedInstanceState).withDisplayBelowStatusBar(false).withTranslucentStatusBar(false).withDrawerLayout(R.layout.material_drawer_fits_not).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem instanceof Nameable) {
Toast.makeText(ActionBarActivity.this, ((Nameable) drawerItem).getName().getText(ActionBarActivity.this), Toast.LENGTH_SHORT).show();
}
return false;
}
}).build();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
use of com.mikepenz.materialdrawer.DrawerBuilder in project FastAdapter by mikepenz.
the class SampleActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//create the activity
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle("");
//Create the drawer
mResult = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withHasStableIds(true).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).addDrawerItems(new PrimaryDrawerItem().withName(R.string.sample_icon_grid).withDescription(R.string.sample_icon_grid_descr).withSelectable(false).withIdentifier(8).withIcon(MaterialDesignIconic.Icon.gmi_grid), new PrimaryDrawerItem().withName(R.string.sample_simple_item_list).withDescription(R.string.sample_simple_item_list_descr).withSelectable(false).withIdentifier(6).withIcon(MaterialDesignIconic.Icon.gmi_format_align_justify), new PrimaryDrawerItem().withName(R.string.sample_image_list).withDescription(R.string.sample_image_list_descr).withSelectable(false).withIdentifier(5).withIcon(MaterialDesignIconic.Icon.gmi_wallpaper), new PrimaryDrawerItem().withName(R.string.sample_multi_select).withDescription(R.string.sample_multi_select_descr).withSelectable(false).withIdentifier(1).withIcon(MaterialDesignIconic.Icon.gmi_select_all), new PrimaryDrawerItem().withName(R.string.sample_collapsible).withDescription(R.string.sample_collapsible_descr).withSelectable(false).withIdentifier(2).withIcon(MaterialDesignIconic.Icon.gmi_check_all), new PrimaryDrawerItem().withName(R.string.sample_sticky_header).withDescription(R.string.sample_sticky_header_descr).withSelectable(false).withIdentifier(3).withIcon(MaterialDesignIconic.Icon.gmi_format_align_left), new PrimaryDrawerItem().withName(R.string.sample_advanced).withDescription(R.string.sample_advanced_descr).withSelectable(false).withIdentifier(4).withIcon(MaterialDesignIconic.Icon.gmi_coffee), new PrimaryDrawerItem().withName(R.string.sample_generic_item).withDescription(R.string.sample_generic_item_descr).withSelectable(false).withIdentifier(7).withIcon(MaterialDesignIconic.Icon.gmi_font), new PrimaryDrawerItem().withName(R.string.sample_multi_generic_item).withDescription(R.string.sample_multi_generic_item_descr).withSelectable(false).withIdentifier(9).withIcon(MaterialDesignIconic.Icon.gmi_format_list_numbered), new PrimaryDrawerItem().withName(R.string.sample_checkbox_item).withDescription(R.string.sample_checkbox_item_descr).withSelectable(false).withIdentifier(10).withIcon(CommunityMaterial.Icon.cmd_checkbox_marked), new PrimaryDrawerItem().withName(R.string.sample_radiobutton_item).withDescription(R.string.sample_radiobutton_item_descr).withSelectable(false).withIdentifier(11).withIcon(CommunityMaterial.Icon.cmd_radiobox_marked), new PrimaryDrawerItem().withName(R.string.sample_swipe_list).withDescription(R.string.sample_swipe_list_descr).withSelectable(false).withIdentifier(12).withIcon(MaterialDesignIconic.Icon.gmi_format_align_left), new PrimaryDrawerItem().withName(R.string.sample_endless_scroll_list).withDescription(R.string.sample_endless_scroll_list_descr).withSelectable(false).withIdentifier(13).withIcon(MaterialDesignIconic.Icon.gmi_long_arrow_down), new PrimaryDrawerItem().withName(R.string.sample_sort).withDescription(R.string.sample_sort_descr).withSelectable(false).withIdentifier(14).withIcon(MaterialDesignIconic.Icon.gmi_sort_by_alpha), new PrimaryDrawerItem().withName(R.string.sample_mopub).withDescription(R.string.sample_mopub_descr).withSelectable(false).withIdentifier(15).withIcon(MaterialDesignIconic.Icon.gmi_accounts_list), new PrimaryDrawerItem().withName(R.string.sample_realm_list).withDescription(R.string.sample_realm_list_descr).withSelectable(false).withIdentifier(16).withIcon(MaterialDesignIconic.Icon.gmi_format_color_text), new PrimaryDrawerItem().withName(R.string.sample_collapsible_multi_select_delete).withDescription(R.string.sample_collapsible_multi_select_delete_descr).withSelectable(false).withIdentifier(17).withIcon(MaterialDesignIconic.Icon.gmi_check_all), new DividerDrawerItem(), new PrimaryDrawerItem().withName(R.string.open_source).withSelectable(false).withIdentifier(100).withIcon(MaterialDesignIconic.Icon.gmi_github)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
if (drawerItem != null) {
Intent intent = null;
if (drawerItem.getIdentifier() == 1) {
intent = new Intent(SampleActivity.this, MultiselectSampleActivity.class);
} else if (drawerItem.getIdentifier() == 2) {
intent = new Intent(SampleActivity.this, ExpandableSampleActivity.class);
} else if (drawerItem.getIdentifier() == 3) {
intent = new Intent(SampleActivity.this, StickyHeaderSampleActivity.class);
} else if (drawerItem.getIdentifier() == 4) {
intent = new Intent(SampleActivity.this, AdvancedSampleActivity.class);
} else if (drawerItem.getIdentifier() == 5) {
intent = new Intent(SampleActivity.this, ImageListActivity.class);
} else if (drawerItem.getIdentifier() == 6) {
intent = new Intent(SampleActivity.this, SimpleItemListActivity.class);
} else if (drawerItem.getIdentifier() == 7) {
intent = new Intent(SampleActivity.this, GenericItemActivity.class);
} else if (drawerItem.getIdentifier() == 8) {
intent = new Intent(SampleActivity.this, IconGridActivity.class);
} else if (drawerItem.getIdentifier() == 9) {
intent = new Intent(SampleActivity.this, MultiTypeGenericItemActivity.class);
} else if (drawerItem.getIdentifier() == 10) {
intent = new Intent(SampleActivity.this, CheckBoxSampleActivity.class);
} else if (drawerItem.getIdentifier() == 11) {
intent = new Intent(SampleActivity.this, RadioButtonSampleActivity.class);
} else if (drawerItem.getIdentifier() == 12) {
intent = new Intent(SampleActivity.this, SwipeListActivity.class);
} else if (drawerItem.getIdentifier() == 13) {
intent = new Intent(SampleActivity.this, EndlessScrollListActivity.class);
} else if (drawerItem.getIdentifier() == 14) {
intent = new Intent(SampleActivity.this, SortActivity.class);
} else if (drawerItem.getIdentifier() == 15) {
intent = new Intent(SampleActivity.this, MopubAdsActivity.class);
} else if (drawerItem.getIdentifier() == 16) {
intent = new Intent(SampleActivity.this, RealmActivity.class);
} else if (drawerItem.getIdentifier() == 17) {
intent = new Intent(SampleActivity.this, ExpandableMultiselectDeleteSampleActivity.class);
} else if (drawerItem.getIdentifier() == 100) {
intent = new LibsBuilder().withFields(R.string.class.getFields()).withActivityTitle(getString(R.string.open_source)).withActivityStyle(Libs.ActivityStyle.LIGHT).withAboutIconShown(true).withVersionShown(true).withAboutVersionShown(true).intent(SampleActivity.this);
}
if (intent != null) {
SampleActivity.this.startActivity(intent);
}
}
return false;
}
}).withSelectedItemByPosition(-1).build();
//create our FastAdapter which will manage everything
mFastAdapter = new FastAdapter<>();
mFastAdapter.withSelectable(true);
mFastAdapter.withMultiSelect(true);
mFastAdapter.withSelectOnLongClick(false);
//create our ItemAdapter which will host our items
mItemAdapter = new ItemAdapter<>();
//configure our fastAdapter
//get our recyclerView and do basic setup
mRecyclerView = (RecyclerView) findViewById(R.id.rv);
//mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mRecyclerView.setAdapter(mItemAdapter.wrap(mFastAdapter));
mRecyclerView.setItemAnimator(new SlideDownAlphaAnimator());
mRecyclerView.getItemAnimator().setAddDuration(500);
mRecyclerView.getItemAnimator().setRemoveDuration(500);
//if we do this. the first added items will be animated :D
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
//add some dummy data
mItemAdapter.add(ImageDummyData.getSimpleImageItems());
//restore selections (this has to be done after the items were added
mFastAdapter.withSavedInstanceState(savedInstanceState);
}
}, 50);
}
use of com.mikepenz.materialdrawer.DrawerBuilder in project Android-Iconics by mikepenz.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Handle Toolbar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
//order fonts by their name
mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
Collections.sort(mFonts, new Comparator<ITypeface>() {
@Override
public int compare(final ITypeface object1, final ITypeface object2) {
return object1.getFontName().compareTo(object2.getFontName());
}
});
//add all icons of all registered Fonts to the list
ArrayList<IDrawerItem> items = new ArrayList<>(Iconics.getRegisteredFonts(this).size());
int count = 0;
for (ITypeface font : mFonts) {
PrimaryDrawerItem pdi = new PrimaryDrawerItem().withName(font.getFontName()).withBadge("" + font.getIcons().size()).withDescription(TextUtils.isEmpty(font.getAuthor()) ? font.getVersion() : font.getVersion() + " - " + font.getAuthor()).withBadgeStyle(new BadgeStyle().withColorRes(R.color.md_grey_200)).withIcon(getRandomIcon(font)).withIdentifier(count);
if (font.getMappingPrefix().equals("gmd")) {
mIdentifierGmd = count;
}
items.add(pdi);
count++;
}
mDrawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withDrawerItems(items).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
loadIcons(mFonts.get(i).getFontName());
getSupportActionBar().setTitle(mFonts.get(i).getFontName());
return false;
}
}).withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
KeyboardUtil.hideKeyboard(MainActivity.this);
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}).withFireOnInitialOnClick(true).withSelectedItem(mIdentifierGmd).build();
}
use of com.mikepenz.materialdrawer.DrawerBuilder in project ChipsLayoutManager by BelooS.
the class MainActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
toolbar.setTitle(getString(R.string.app_name_and_version, BuildConfig.VERSION_NAME));
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, ItemsFragment.newInstance()).commit();
}
setSupportActionBar(toolbar);
assert getSupportActionBar() != null;
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
drawer = new DrawerBuilder(this).withToolbar(toolbar).addDrawerItems(new PrimaryDrawerItem().withName(R.string.main).withIdentifier(1)).addDrawerItems(new PrimaryDrawerItem().withName(R.string.bottom_sheet).withIdentifier(2)).withOnDrawerItemClickListener(this::onDrawerItemClickListener).build();
}
use of com.mikepenz.materialdrawer.DrawerBuilder in project Weather by Sparker0i.
the class WeatherActivity method initDrawer.
public void initDrawer() {
final Context context = this;
final IProfile profile = new ProfileDrawerItem().withName(getString(R.string.app_name)).withEmail(getString(R.string.drawer_version_header) + " : " + 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().withIdentifier(1).withName(R.string.drawer_item_home).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_day_sunny));
SecondaryDrawerItem item2 = new SecondaryDrawerItem().withIdentifier(2).withName(R.string.drawer_item_graph).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_trending_up));
SecondaryDrawerItem item3 = new SecondaryDrawerItem().withIdentifier(3).withName(R.string.drawer_item_map).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_map));
SecondaryDrawerItem item7 = new SecondaryDrawerItem().withIdentifier(7).withName(R.string.drawer_item_about).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info)).withSelectable(false);
SecondaryDrawerItem item6 = new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.drawer_item_custom_key)).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_create)).withSelectable(false);
SecondarySwitchDrawerItem item4 = new SecondarySwitchDrawerItem().withIdentifier(4).withName(getString(R.string.drawer_item_fahrenheit)).withChecked(preferences.getUnits().equals(Constants.IMPERIAL)).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_fahrenheit)).withSelectable(false);
SecondarySwitchDrawerItem item5 = new SecondarySwitchDrawerItem().withIdentifier(5).withName(getString(R.string.drawer_item_notifications)).withChecked(preferences.getNotifs()).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_notifications)).withSelectable(false);
item4.withOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
preferences.setUnits(Constants.IMPERIAL);
} else {
preferences.setUnits(Constants.METRIC);
}
Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (f instanceof WeatherFragment) {
wf = new WeatherFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
drawer.closeDrawer();
}
}
});
item5.withOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
preferences.setNotifs(true);
startService(new Intent(context, AlarmTriggerService.class));
} else {
preferences.setNotifs(false);
stopService(new Intent(context, AlarmTriggerService.class));
mManager.cancelAll();
}
}
});
drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withSelectedItem(1).withTranslucentStatusBar(true).withAccountHeader(headerResult).withActionBarDrawerToggleAnimated(true).addDrawerItems(item1, item2, item3, new DividerDrawerItem(), item4, item5, new DividerDrawerItem(), item6, item7).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
// do something with the clicked item :D
if (drawerItem != null) {
switch((int) drawerItem.getIdentifier()) {
case 1:
Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (!(f instanceof WeatherFragment)) {
wf = new WeatherFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
}
break;
case 2:
f = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (!(f instanceof GraphsFragment)) {
GraphsFragment graphsFragment = newGraphInstance(new ArrayList<>(wf.getDailyJson()));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, graphsFragment).commit();
}
break;
case 3:
f = getSupportFragmentManager().findFragmentById(R.id.fragment);
if (!(f instanceof MapsFragment)) {
MapsFragment mapsFragment = new MapsFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, mapsFragment).commit();
}
break;
case 6:
showApiKeyBox();
break;
case 7:
startActivity(new Intent(WeatherActivity.this, AboutActivity.class));
break;
}
}
return false;
}
}).build();
}
Aggregations