Search in sources :

Example 26 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem in project MaterialDrawer by mikepenz.

the class DrawerItemViewHelper method build.

public View build() {
    //create the container view
    LinearLayout linearLayout = new LinearLayout(mContext);
    linearLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    //create the divider
    if (mDivider) {
        LinearLayout divider = new LinearLayout(mContext);
        divider.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        divider.setMinimumHeight((int) UIUtils.convertDpToPixel(1, mContext));
        divider.setOrientation(LinearLayout.VERTICAL);
        divider.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(mContext, R.attr.material_drawer_divider, R.color.material_drawer_divider));
        linearLayout.addView(divider);
    }
    //add all drawer items
    for (IDrawerItem drawerItem : mDrawerItems) {
        View view = drawerItem.generateView(mContext);
        view.setTag(drawerItem);
        if (drawerItem.isEnabled()) {
            view.setBackgroundResource(UIUtils.getSelectableBackgroundRes(mContext));
            view.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (mOnDrawerItemClickListener != null) {
                        mOnDrawerItemClickListener.onItemClick(v, (IDrawerItem) v.getTag());
                    }
                }
            });
        }
        linearLayout.addView(view);
    }
    return linearLayout;
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 27 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem 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);
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) Toolbar(android.support.v7.widget.Toolbar) Handler(android.os.Handler) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Example 28 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem 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();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) ArrayList(java.util.ArrayList) Drawer(com.mikepenz.materialdrawer.Drawer) SearchView(android.support.v7.widget.SearchView) View(android.view.View) ITypeface(com.mikepenz.iconics.typeface.ITypeface) BadgeStyle(com.mikepenz.materialdrawer.holder.BadgeStyle) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Toolbar(android.support.v7.widget.Toolbar)

Example 29 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem 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

IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)29 View (android.view.View)20 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)16 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)14 Toolbar (android.support.v7.widget.Toolbar)13 Drawer (com.mikepenz.materialdrawer.Drawer)12 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)12 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)10 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)9 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)8 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)7 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)7 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)6 Intent (android.content.Intent)5 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)5 RecyclerView (android.support.v7.widget.RecyclerView)4 LinearLayout (android.widget.LinearLayout)4 LibsBuilder (com.mikepenz.aboutlibraries.LibsBuilder)4 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)4 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)4