Search in sources :

Example 31 with IconicsDrawable

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();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment) Fragment(android.support.v4.app.Fragment) MapsFragment(com.a5corp.weather.fragment.MapsFragment) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) MapsFragment(com.a5corp.weather.fragment.MapsFragment) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Context(android.content.Context) OnCheckedChangeListener(com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) BindView(butterknife.BindView) View(android.view.View) SecondarySwitchDrawerItem(com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) CompoundButton(android.widget.CompoundButton) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment)

Aggregations

IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)31 View (android.view.View)14 MenuInflater (android.view.MenuInflater)9 Toolbar (android.support.v7.widget.Toolbar)7 SearchView (android.support.v7.widget.SearchView)6 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)6 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)6 Intent (android.content.Intent)5 RecyclerView (android.support.v7.widget.RecyclerView)5 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)5 Context (android.content.Context)4 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)4 Drawer (com.mikepenz.materialdrawer.Drawer)4 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)4 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)4 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)4 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)4 Drawable (android.graphics.drawable.Drawable)3