use of com.mikepenz.iconics.IconicsDrawable 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