com.mikepenz.materialdrawer.model.SecondaryDrawerItem Java Examples

The following examples show how to use com.mikepenz.materialdrawer.model.SecondaryDrawerItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerItemClick(IDrawerItem drawerItem) {
        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case SHOW_ALL:
                    clickAndUpdateMainFragmentData(new ArrayList<String>(), "全部文章",drawerItem.getIdentifier());
                    break;
                case SHOW_STAR:
                    StarActivity.activityStart(MainActivity.this);
                    break;
                case SHOW_DISCOVER:
                    FeedCategoryActivity.activityStart(MainActivity.this);
                    break;
                case DRAWER_FOLDER_ITEM:
//                    ALog.d("名称为" + ((SecondaryDrawerItem) drawerItem).getName() + "id为" + drawerItem.getIdentifier());
                    ArrayList<String> list = new ArrayList<>();
                    list.add(String.valueOf(drawerItem.getIdentifier()));
                    clickAndUpdateMainFragmentData(list, ((SecondaryDrawerItem) drawerItem).getName().toString(),drawerItem.getIdentifier());
                    break;

                case DRAWER_FOLDER:
                    break;

            }
        }

    }
 
Example #2
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerLongClick(IDrawerItem drawerItem) {

        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case DRAWER_FOLDER:
                    //获取到这个文件夹的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedFolderOperationPopupView(MainActivity.this, drawerItem.getIdentifier() - FEED_FOLDER_IDENTIFY_PLUS, ((ExpandableBadgeDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
                case DRAWER_FOLDER_ITEM:
                    //获取到这个feed的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedOperationPopupView(MainActivity.this, drawerItem.getIdentifier(), ((SecondaryDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
            }
        }
    }
 
Example #3
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerItemClick(IDrawerItem drawerItem) {
        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case SHOW_ALL:
                    clickAndUpdateMainFragmentData(new ArrayList<String>(), "全部文章",drawerItem.getIdentifier());
                    break;
                case SHOW_STAR:
                    StarActivity.activityStart(MainActivity.this);
                    break;
                case SHOW_DISCOVER:
                    FeedCategoryActivity.activityStart(MainActivity.this);
                    break;
                case DRAWER_FOLDER_ITEM:
//                    ALog.d("名称为" + ((SecondaryDrawerItem) drawerItem).getName() + "id为" + drawerItem.getIdentifier());
                    ArrayList<String> list = new ArrayList<>();
                    list.add(String.valueOf(drawerItem.getIdentifier()));
                    clickAndUpdateMainFragmentData(list, ((SecondaryDrawerItem) drawerItem).getName().toString(),drawerItem.getIdentifier());
                    break;

                case DRAWER_FOLDER:
                    break;

            }
        }

    }
 
Example #4
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
private void drawerLongClick(IDrawerItem drawerItem) {

        if (drawerItem.getTag() != null) {
            switch ((int) drawerItem.getTag()) {
                case DRAWER_FOLDER:
                    //获取到这个文件夹的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedFolderOperationPopupView(MainActivity.this, drawerItem.getIdentifier() - FEED_FOLDER_IDENTIFY_PLUS, ((ExpandableBadgeDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
                case DRAWER_FOLDER_ITEM:
                    //获取到这个feed的数据
                    new XPopup.Builder(MainActivity.this)
                            .asCustom(new FeedOperationPopupView(MainActivity.this, drawerItem.getIdentifier(), ((SecondaryDrawerItem) drawerItem).getName().toString(), "", new Help(false)))
                            .show();
                    break;
            }
        }
    }
 
Example #5
Source File: MainActivity.java    From ShoppingList with Apache License 2.0 5 votes vote down vote up
private void buildDrawer() {
    result = new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withHeader(R.layout.drawer_header)
            .withTranslucentStatusBar(false)
            .withActionBarDrawerToggle(true)
            .withActionBarDrawerToggleAnimated(false)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(R.string.nav_item_home).withTag(CONSTS.TAG_LIST).withIcon(R.drawable.ic_toc_black_),
                    new PrimaryDrawerItem().withName(R.string.nav_item_cached).withTag(CONSTS.TAG_CACHED).withIcon(R.drawable.ic_toc_black_),
                    new PrimaryDrawerItem().withName(R.string.nav_item_favorites).withTag(CONSTS.TAG_FAVORITES).withIcon(R.drawable.ic_star_rate_black)
            )
            .addStickyDrawerItems(
                    new SecondaryDrawerItem().withName(R.string.nav_item_about).withTag(CONSTS.TAG_ABOUT).withIcon(R.drawable.ic_action_about),
                    new SecondaryDrawerItem().withName(R.string.nav_item_settings).withTag(CONSTS.TAG_SETTINGS).withIcon(R.drawable.ic_action_settings)
            )
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    fragmentSelector(Integer.parseInt(drawerItem.getTag().toString()));
                    return false;
                }
            })
            .withSelectedItem(0)
            .build();
}
 
Example #6
Source File: MainActivity.java    From minx with MIT License 5 votes vote down vote up
private void setUpDrawer() {

        AccountHeader accountHeader = new AccountHeaderBuilder()
                .withActivity(MainActivity.this)
                .withHeaderBackground(R.drawable.minx_small)
                .withHeaderBackgroundScaleType(ImageView.ScaleType.FIT_CENTER)
                .withHeightDp(200)
                .build();

        result = new DrawerBuilder()
                .withHeaderDivider(true)
                .withActivity(this)
                .withAccountHeader(accountHeader)
                .withToolbar(toolbar)
                .addDrawerItems(
                        new PrimaryDrawerItem().withName(R.string.drawer_item_home),
                        new DividerDrawerItem(),
                        new SecondaryDrawerItem().withName(R.string.drawer_item_saved),
                        new SecondaryDrawerItem().withName(R.string.drawer_item_share),
                        new SecondaryDrawerItem().withName(R.string.drawer_item_settings),
                        new SecondaryDrawerItem().withName(R.string.drawer_item_about)
                )
                .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                    @Override
                    public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) {
                        // do something with the clicked item :D
                        Toast.makeText(MainActivity.this, "You clicked on item : " + position, Toast.LENGTH_SHORT).show();
                        loadFragment(position);
                        return false;
                    }
                })
                .build();
        getSupportActionBar().setDisplayHomeAsUpEnabled(false);
        result.getActionBarDrawerToggle().setDrawerIndicatorEnabled(true);

    }
 
Example #7
Source File: DrawerUtils.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * helper method to fill the sticky footer with it's elements
 *
 * @param drawer
 * @param container
 * @param onClickListener
 */
public static void fillStickyDrawerItemFooter(DrawerBuilder drawer, ViewGroup container, View.OnClickListener onClickListener) {
    //add all drawer items
    for (IDrawerItem drawerItem : drawer.mStickyDrawerItems) {
        //get the selected_color
        int selected_color = UIUtils.getThemeColorFromAttrOrRes(container.getContext(), R.attr.material_drawer_selected, R.color.material_drawer_selected);
        if (drawerItem instanceof PrimaryDrawerItem) {
            selected_color = ColorHolder.color(((PrimaryDrawerItem) drawerItem).getSelectedColor(), container.getContext(), R.attr.material_drawer_selected, R.color.material_drawer_selected);
        } else if (drawerItem instanceof SecondaryDrawerItem) {
            selected_color = ColorHolder.color(((SecondaryDrawerItem) drawerItem).getSelectedColor(), container.getContext(), R.attr.material_drawer_selected, R.color.material_drawer_selected);
        }

        View view = drawerItem.generateView(container.getContext(), container);
        view.setTag(drawerItem);

        if (drawerItem.isEnabled()) {
            UIUtils.setBackground(view, DrawerUIUtils.getSelectableBackground(container.getContext(), selected_color));
            view.setOnClickListener(onClickListener);
        }

        container.addView(view);

        //for android API 17 --> Padding not applied via xml
        DrawerUIUtils.setDrawerVerticalPadding(view);
    }
    //and really. don't ask about this. it won't set the padding if i don't set the padding for the container
    container.setPadding(0, 0, 0, 0);
}
 
Example #8
Source File: MiniDrawer.java    From MaterialDrawer-Xamarin with Apache License 2.0 5 votes vote down vote up
/**
 * generates a MiniDrawerItem from a IDrawerItem
 *
 * @param drawerItem
 * @return
 */
public IDrawerItem generateMiniDrawerItem(IDrawerItem drawerItem) {
    if (drawerItem instanceof PrimaryDrawerItem) {
        return new MiniDrawerItem((PrimaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground);
    } else if (drawerItem instanceof SecondaryDrawerItem && mIncludeSecondaryDrawerItems) {
        return new MiniDrawerItem((SecondaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground);
    } else if (drawerItem instanceof ProfileDrawerItem) {
        MiniProfileDrawerItem mpdi = new MiniProfileDrawerItem((ProfileDrawerItem) drawerItem);
        mpdi.withEnabled(mEnableProfileClick);
        return mpdi;
    }
    return null;
}
 
Example #9
Source File: DrawerHelper.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
public static IDrawerItem getSecondaryMenuItem(DrawerItem drawerItem) {
    SecondaryDrawerItem secondaryDrawerItem = new SecondaryDrawerItem()
            .withName(drawerItem.name)
            .withIdentifier(drawerItem.id)
            .withIcon(drawerItem.icon);

    if (drawerItem.withBadge) {
        secondaryDrawerItem
                .withBadgeStyle(new BadgeStyle()
                        .withTextColor(Color.WHITE)
                        .withColorRes(R.color.grey));
    }
    return secondaryDrawerItem;
}
 
Example #10
Source File: MainViewModel.java    From hacker-news-android with Apache License 2.0 5 votes vote down vote up
List<IDrawerItem> getDrawerItems() {
    if (mDrawerItems != null && !mDrawerItems.isEmpty()) {
        return mDrawerItems;
    }

    List<PrimaryDrawerItem> primaryDrawerItems = new ArrayList<>();
    List<SecondaryDrawerItem> secondaryDrawerItems = new ArrayList<>();
    mDrawerItems = new ArrayList<>();

    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_TOP).withName(R.string.title_section_top).withIcon(R.drawable.ic_action_whatshot));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_BEST).withName(R.string.title_section_best).withIcon(R.drawable.ic_action_grade));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_NEWEST).withName(R.string.title_section_newest).withIcon(R.drawable.ic_action_note_add));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_SHOW_HN).withName(R.string.title_section_show).withIcon(R.drawable.ic_action_visibility));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_SHOW_HN_NEW).withName(R.string.title_section_show_new).withIcon(R.drawable.ic_action_visibility));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_ASK).withName(R.string.title_section_ask).withIcon(R.drawable.ic_action_live_help));
    primaryDrawerItems.add(new PrimaryDrawerItem().withIdentifier(SECTION_SAVED).withName(R.string.title_section_saved).withIcon(R.drawable.ic_action_archive));
    mDrawerItems.addAll(primaryDrawerItems);

    mDrawerItems.add(new DividerDrawerItem());

    secondaryDrawerItems.add(new SecondaryDrawerItem().withIdentifier(SECTION_SETTINGS).withName(R.string.title_section_settings).withCheckable(false));
    secondaryDrawerItems.add(new SecondaryDrawerItem().withIdentifier(SECTION_ABOUT).withName(R.string.title_section_about).withCheckable(false));

    mDrawerItems.addAll(secondaryDrawerItems);

    return mDrawerItems;
}
 
Example #11
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
/**
     * 获取用户的订阅数据,显示在左侧边栏的drawer中
     */
    public synchronized void refreshLeftDrawerFeedList(boolean isUpdate) {

        subItems.clear();

        AllDrawerItem = new SecondaryDrawerItem().withName("全部").withIcon(GoogleMaterial.Icon.gmd_home).withSelectable(true).withTag(SHOW_ALL);
        subItems.add(AllDrawerItem);
        subItems.add(new SecondaryDrawerItem().withName("收藏").withIcon(GoogleMaterial.Icon.gmd_star).withSelectable(false).withTag(SHOW_STAR));
        subItems.add(new SecondaryDrawerItem().withName("发现").withIcon(GoogleMaterial.Icon.gmd_explore).withSelectable(false).withTag(SHOW_DISCOVER));
        subItems.add(new SectionDrawerItem().withName("订阅源").withDivider(false));




        List<FeedFolder> feedFolderList = LitePal.order("ordervalue").find(FeedFolder.class);
        for (int i = 0; i < feedFolderList.size(); i++) {

            int notReadNum = 0;

            List<IDrawerItem> feedItems = new ArrayList<>();
            List<Feed> feedList = LitePal.where("feedfolderid = ?", String.valueOf(feedFolderList.get(i).getId())).order("ordervalue").find(Feed.class);

            boolean haveErrorFeedInCurrentFolder = false;
            for (int j = 0; j < feedList.size(); j++) {
                final Feed temp = feedList.get(j);
                int current_notReadNum = LitePal.where("read = ? and feedid = ?", "0", String.valueOf(temp.getId())).count(FeedItem.class);

                final SecondaryDrawerItem secondaryDrawerItem = new SecondaryDrawerItem().withName(temp.getName()).withSelectable(true).withTag(DRAWER_FOLDER_ITEM).withIdentifier(feedList.get(j).getId());
                if (feedList.get(j).isOffline()){
                    secondaryDrawerItem.withIcon(GoogleMaterial.Icon.gmd_cloud_off);
                }else if (feedList.get(j).isErrorGet()) {
                    haveErrorFeedInCurrentFolder = true;
                    secondaryDrawerItem.withIcon(GoogleMaterial.Icon.gmd_sync_problem);
                } else {
                    //TODO: 加载订阅的图标
                    secondaryDrawerItem.withIcon(GoogleMaterial.Icon.gmd_rss_feed);



                }

                if (current_notReadNum != 0) {
                    secondaryDrawerItem.withBadge(current_notReadNum + "");
                }
                //不需要这样了,因为都是直接setitems来更新的
                /*if (isUpdate) {
                    drawer.updateItem(secondaryDrawerItem);
                }*/
                feedItems.add(secondaryDrawerItem);

                notReadNum += current_notReadNum;
            }
            ExpandableBadgeDrawerItem one = new ExpandableBadgeDrawerItem().withName(feedFolderList.get(i).getName()).withSelectable(true).withIdentifier(feedFolderList.get(i).getId()+FEED_FOLDER_IDENTIFY_PLUS).withTag(DRAWER_FOLDER).withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withSubItems(
                    feedItems
            );

            ALog.d("文件夹的identity" + (feedFolderList.get(i).getId()+FEED_FOLDER_IDENTIFY_PLUS));
            //恢复折叠状态

            //
//            one.getViewHolder(R.)

            if (haveErrorFeedInCurrentFolder) {
                one.withTextColorRes(R.color.md_red_700);
            }
            if (notReadNum != 0) {
                one.withBadge(notReadNum + "");
            }
            //添加文件夹
            subItems.add(one);
        }

        //要记得把这个list置空
        errorFeedIdList.clear();

    }
 
Example #12
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 4 votes vote down vote up
/**
     * 获取用户的订阅数据,显示在左侧边栏的drawer中
     */
    public synchronized void refreshLeftDrawerFeedList(boolean isUpdate) {

        subItems.clear();

        AllDrawerItem = new SecondaryDrawerItem().withName("全部").withIcon(GoogleMaterial.Icon.gmd_home).withSelectable(true).withTag(SHOW_ALL);
        subItems.add(AllDrawerItem);
        subItems.add(new SecondaryDrawerItem().withName("收藏").withIcon(GoogleMaterial.Icon.gmd_star).withSelectable(false).withTag(SHOW_STAR));
        subItems.add(new SecondaryDrawerItem().withName("发现").withIcon(GoogleMaterial.Icon.gmd_explore).withSelectable(false).withTag(SHOW_DISCOVER));
        subItems.add(new SectionDrawerItem().withName("订阅源").withDivider(false));




        List<FeedFolder> feedFolderList = LitePal.order("ordervalue").find(FeedFolder.class);
        for (int i = 0; i < feedFolderList.size(); i++) {

            int notReadNum = 0;

            List<IDrawerItem> feedItems = new ArrayList<>();
            List<Feed> feedList = LitePal.where("feedfolderid = ?", String.valueOf(feedFolderList.get(i).getId())).order("ordervalue").find(Feed.class);

            boolean haveErrorFeedInCurrentFolder = false;
            for (int j = 0; j < feedList.size(); j++) {
                final Feed temp = feedList.get(j);
                int current_notReadNum = LitePal.where("read = ? and feedid = ?", "0", String.valueOf(temp.getId())).count(FeedItem.class);

                final SecondaryDrawerItem secondaryDrawerItem = new SecondaryDrawerItem().withName(temp.getName()).withSelectable(true).withTag(DRAWER_FOLDER_ITEM).withIdentifier(feedList.get(j).getId());
                if (feedList.get(j).isOffline()){
                    secondaryDrawerItem.withIcon(GoogleMaterial.Icon.gmd_cloud_off);
                }else if (feedList.get(j).isErrorGet()) {
                    haveErrorFeedInCurrentFolder = true;
                    secondaryDrawerItem.withIcon(GoogleMaterial.Icon.gmd_sync_problem);
                } else {
                    //TODO: 加载订阅的图标
                    secondaryDrawerItem.withIcon(GoogleMaterial.Icon.gmd_rss_feed);



                }

                if (current_notReadNum != 0) {
                    secondaryDrawerItem.withBadge(current_notReadNum + "");
                }
                //不需要这样了,因为都是直接setitems来更新的
                /*if (isUpdate) {
                    drawer.updateItem(secondaryDrawerItem);
                }*/
                feedItems.add(secondaryDrawerItem);

                notReadNum += current_notReadNum;
            }
            ExpandableBadgeDrawerItem one = new ExpandableBadgeDrawerItem().withName(feedFolderList.get(i).getName()).withSelectable(true).withIdentifier(feedFolderList.get(i).getId()+FEED_FOLDER_IDENTIFY_PLUS).withTag(DRAWER_FOLDER).withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withSubItems(
                    feedItems
            );

            ALog.d("文件夹的identity" + (feedFolderList.get(i).getId()+FEED_FOLDER_IDENTIFY_PLUS));
            //恢复折叠状态

            //
//            one.getViewHolder(R.)

            if (haveErrorFeedInCurrentFolder) {
                one.withTextColorRes(R.color.md_red_700);
            }
            if (notReadNum != 0) {
                one.withBadge(notReadNum + "");
            }
            //添加文件夹
            subItems.add(one);
        }

        //要记得把这个list置空
        errorFeedIdList.clear();

    }
 
Example #13
Source File: SheetMusicActivity.java    From MidiSheetMusic-Android with GNU General Public License v3.0 4 votes vote down vote up
void createViews() {
    layout = findViewById(R.id.sheet_content);

    SwitchDrawerItem scrollVertically = new SwitchDrawerItem()
            .withName(R.string.scroll_vertically)
            .withChecked(options.scrollVert)
            .withOnCheckedChangeListener((iDrawerItem, compoundButton, isChecked) -> {
                options.scrollVert = isChecked;
                createSheetMusic(options);
            });

    SwitchDrawerItem useColors = new SwitchDrawerItem()
            .withName(R.string.use_note_colors)
            .withChecked(options.useColors)
            .withOnCheckedChangeListener((iDrawerItem, compoundButton, isChecked) -> {
                options.useColors = isChecked;
                createSheetMusic(options);
            });

    SecondarySwitchDrawerItem showMeasures = new SecondarySwitchDrawerItem()
            .withName(R.string.show_measures)
            .withLevel(2)
            .withChecked(options.showMeasures)
            .withOnCheckedChangeListener((iDrawerItem, compoundButton, isChecked) -> {
                options.showMeasures = isChecked;
                createSheetMusic(options);
            });

    SecondaryDrawerItem loopStart = new SecondaryDrawerItem()
            .withIdentifier(ID_LOOP_START)
            .withBadge(Integer.toString(options.playMeasuresInLoopStart + 1))
            .withName(R.string.play_measures_in_loop_start)
            .withLevel(2);

    SecondaryDrawerItem loopEnd = new SecondaryDrawerItem()
            .withIdentifier(ID_LOOP_END)
            .withBadge(Integer.toString(options.playMeasuresInLoopEnd + 1))
            .withName(R.string.play_measures_in_loop_end)
            .withLevel(2);

    ExpandableSwitchDrawerItem loopSettings = new ExpandableSwitchDrawerItem()
            .withIdentifier(ID_LOOP_ENABLE)
            .withName(R.string.loop_on_measures)
            .withChecked(options.playMeasuresInLoop)
            .withOnCheckedChangeListener((iDrawerItem, compoundButton, isChecked) -> {
                options.playMeasuresInLoop = isChecked;
            })
            .withSubItems(showMeasures, loopStart, loopEnd);

    // Drawer
    drawer = new DrawerBuilder()
            .withActivity(this)
            .withInnerShadow(true)
            .addDrawerItems(
                    scrollVertically,
                    useColors,
                    loopSettings,
                    new DividerDrawerItem()
            )
            .inflateMenu(R.menu.sheet_menu)
            .withOnDrawerItemClickListener((view, i, item) -> drawerItemClickListener(item))
            .withDrawerGravity(Gravity.RIGHT)
            .build();

    // Make sure that the view extends over the navigation buttons area
    drawer.getDrawerLayout().setFitsSystemWindows(false);
    // Lock the drawer so swiping doesn't open it
    drawer.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

    player = new MidiPlayer(this);
    player.setDrawer(drawer);
    layout.addView(player);

    piano = new Piano(this);
    layout.addView(piano);
    player.SetPiano(piano);
    layout.requestLayout();

    player.setSheetUpdateRequestListener(() -> createSheetMusic(options));
    createSheetMusic(options);
}
 
Example #14
Source File: SheetMusicActivity.java    From MidiSheetMusic-Android with GNU General Public License v3.0 4 votes vote down vote up
/** Handle clicks on the drawer menu */
public boolean drawerItemClickListener(IDrawerItem item) {
    switch ((int)item.getIdentifier()) {
        case R.id.song_settings:
            changeSettings();
            drawer.closeDrawer();
            break;
        case R.id.save_images:
            showSaveImagesDialog();
            drawer.closeDrawer();
            break;
        case ID_LOOP_START:
            // Note that we display the measure numbers starting at 1,
            // but the actual playMeasuresInLoopStart field starts at 0.
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.play_measures_in_loop_start);
            String[] items = makeStringList(1, options.lastMeasure + 1);
            builder.setItems(items, (dialog, i) -> {
                options.playMeasuresInLoopStart = Integer.parseInt(items[i]) - 1;
                // Make sure End is not smaller than Start
                if (options.playMeasuresInLoopStart > options.playMeasuresInLoopEnd) {
                    options.playMeasuresInLoopEnd = options.playMeasuresInLoopStart;
                    drawer.updateBadge(ID_LOOP_END, new StringHolder(items[i]));
                }
                ((SecondaryDrawerItem) item).withBadge(items[i]);
                drawer.updateItem(item);
            });
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
            alertDialog.getListView().setSelection(options.playMeasuresInLoopStart);
            break;
        case ID_LOOP_END:
            // Note that we display the measure numbers starting at 1,
            // but the actual playMeasuresInLoopEnd field starts at 0.
            builder = new AlertDialog.Builder(this);
            builder.setTitle(R.string.play_measures_in_loop_end);
            items = makeStringList(1, options.lastMeasure + 1);
            builder.setItems(items, (dialog, i) -> {
                options.playMeasuresInLoopEnd = Integer.parseInt(items[i]) - 1;
                // Make sure End is not smaller than Start
                if (options.playMeasuresInLoopStart > options.playMeasuresInLoopEnd) {
                    options.playMeasuresInLoopStart = options.playMeasuresInLoopEnd;
                    drawer.updateBadge(ID_LOOP_START, new StringHolder(items[i]));
                }
                ((SecondaryDrawerItem) item).withBadge(items[i]);
                drawer.updateItem(item);
            });
            alertDialog = builder.create();
            alertDialog.show();
            alertDialog.getListView().setSelection(options.playMeasuresInLoopEnd);
            break;
    }
    return true;
}
 
Example #15
Source File: MainActivity.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
private void initDrawer() {
    boolean isUserLoggedIn = ApplicationManager.userCredentials != null;
    String studentName = "";
    String codeUniversel = "";
    ProfilManager profilManager = new ProfilManager(this);
    Etudiant etudiant = profilManager.getEtudiant();
    if (etudiant != null) {
        String prenom = etudiant.prenom != null ? etudiant.prenom.trim() : "";
        String nom = etudiant.nom != null ? etudiant.nom.trim() : "";
        studentName = prenom + " " + nom;
        codeUniversel = etudiant.codePerm != null ? etudiant.codePerm : "";
    }
    headerResult = new AccountHeaderBuilder()
            .withActivity(this)
            .withHeaderBackground(R.drawable.ets_background_grayscale)
            .withSelectionListEnabledForSingleProfile(false)
            .addProfiles(
                    new ProfileDrawerItem()
                            .withName(codeUniversel)
                            .withEmail(studentName)
                            .withSelectedTextColor(ContextCompat.getColor(this, R.color.red))
                            .withIcon(R.drawable.ic_user)
                            .withSelectable(isUserLoggedIn)
            ).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean current) {
                    goToFragment(new ProfilFragment(), ProfilFragment.class.getName());
                    activityDrawer.deselect();
                    return false;
                }
            }).build();

    DrawerBuilder drawerBuilder = new DrawerBuilder()
            .withActivity(this)
            .withToolbar(toolbar)
            .withAccountHeader(headerResult)
            .withSelectedItem(isUserLoggedIn ? TODAY_ITEM : ABOUT_ITEM)
            .withDisplayBelowStatusBar(true)
            .withShowDrawerOnFirstLaunch(true)
            .addDrawerItems(
                    new ExpandableDrawerItem().withName(R.string.menu_section_1_moi).withSelectable(false).withSubItems(
                            new SecondaryDrawerItem().withName(R.string.menu_section_1_profil).withIdentifier(PROFILE_ITEM).withIcon(R.drawable.ic_ico_profil).withEnabled(isUserLoggedIn),
                            new SecondaryDrawerItem().withName(R.string.menu_section_1_ajd).withIdentifier(TODAY_ITEM).withIcon(R.drawable.ic_ico_aujourdhui).withEnabled(isUserLoggedIn),
                            new SecondaryDrawerItem().withName(R.string.menu_section_1_horaire).withIdentifier(SCHEDULE_ITEM).withIcon(R.drawable.ic_ico_schedule).withEnabled(isUserLoggedIn),
                            new SecondaryDrawerItem().withName(R.string.menu_section_1_notes).withIdentifier(COURSE_ITEM).withIcon(R.drawable.ic_ico_notes).withEnabled(isUserLoggedIn),
                            new SecondaryDrawerItem().withName(R.string.menu_section_2_moodle).withIdentifier(MOODLE_ITEM).withIcon(R.drawable.ic_moodle_icon_small).withEnabled(isUserLoggedIn),
                            new SecondaryDrawerItem().withName(R.string.menu_section_1_monETS).withIdentifier(MONETS_ITEM).withSelectable(false).withIcon(R.drawable.ic_monets).withEnabled(isUserLoggedIn),
                            new SecondaryDrawerItem().withName(R.string.menu_section_1_bandwith).withIdentifier(BANDWIDTH_ITEM).withIcon(R.drawable.ic_ico_internet),
                            new SecondaryDrawerItem().withName(R.string.menu_section_3_beta).withIdentifier(BETA_VERSION_ITEM).withIcon(R.drawable.ic_beta_24dp)
                    ),
                    new ExpandableDrawerItem().withName(R.string.menu_section_2_ets).withSelectable(false).withSubItems(
                            new SecondaryDrawerItem().withName(R.string.menu_section_2_news).withIdentifier(NEWS_ITEM).withIcon(R.drawable.ic_ico_news),
                            new SecondaryDrawerItem().withName(R.string.menu_section_2_bottin).withIdentifier(DIRECTORY_ITEM).withIcon(R.drawable.ic_ico_bottin),
                            new SecondaryDrawerItem().withName(R.string.menu_section_2_biblio).withIdentifier(LIBRARY_ITEM).withSelectable(false).withIcon(R.drawable.ic_ico_library),
                            new SecondaryDrawerItem().withName(R.string.menu_section_2_securite).withIdentifier(SECURITY_ITEM).withIcon(R.drawable.ic_ico_security)
                    ),
                    new ExpandableDrawerItem().withName(R.string.menu_section_3_applets).withSelectable(false).withSubItems(
                            new SecondaryDrawerItem().withName(R.string.menu_section_3_apps).withIdentifier(ACHIEVEMENTS_ITEM).withIcon(R.drawable.ic_star_60x60),
                            new SecondaryDrawerItem().withName(R.string.menu_section_3_about).withIdentifier(ABOUT_ITEM).withIcon(R.drawable.ic_logo_icon_final),
                            new SecondaryDrawerItem().withName(R.string.menu_section_3_faq).withIdentifier(FAQ_ITEM).withIcon(R.drawable.ic_ico_faq)
                    )
            );
    if (isUserLoggedIn)
        drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_logout).withIdentifier(LOGOUT).withTextColorRes(R.color.red));
    else
        drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_login).withIdentifier(LOGIN));

    drawerBuilder.withOnDrawerItemClickListener(drawerItemClickListener);

    activityDrawer = drawerBuilder.build();
    activityDrawer.getExpandableExtension().expand(1);

}
 
Example #16
Source File: UtilsUI.java    From Moticons with GNU General Public License v3.0 4 votes vote down vote up
public static Drawer showNavigationDrawer(final Context context, Toolbar toolbar, final MoticonAdapter moticonAdapter, final MoticonAdapter moticonPositiveAdapter, final MoticonAdapter moticonNegativeAdapter, final MoticonAdapter moticonFunnyAdapter, final MoticonAdapter moticonAnimalsAdapter, final MoticonAdapter moticonSpecialAdapter, final RecyclerView recyclerView) {
    Activity activity = (Activity) context;

    AccountHeader headerResult = new AccountHeaderBuilder()
            .withActivity(activity)
            .withHeaderBackground(R.drawable.header)
            .build();
    return new DrawerBuilder()
            .withActivity(activity)
            .withToolbar(toolbar)
            .withAccountHeader(headerResult)
            .withStatusBarColor(context.getResources().getColor(R.color.primary_dark))
            .addDrawerItems(
                    new PrimaryDrawerItem().withName(context.getResources().getString(R.string.app_name)).withIcon(R.mipmap.ic_launcher),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_positive)).withIcon(FontAwesome.Icon.faw_thumbs_up).withBadge("(/^▽^)/"),
                    new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_negative)).withIcon(FontAwesome.Icon.faw_thumbs_down).withBadge("(>_<)"),
                    new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_funny)).withIcon(FontAwesome.Icon.faw_child).withBadge("¯\\_(ツ)_/¯"),
                    new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_animal)).withIcon(FontAwesome.Icon.faw_paw).withBadge("∪・ω・∪"),
                    new PrimaryDrawerItem().withName(context.getResources().getString(R.string.action_special)).withIcon(FontAwesome.Icon.faw_star).withBadge("ʕ•̬͡•ʕ•̫͡•♥"),
                    new DividerDrawerItem(),
                    new SecondaryDrawerItem().withName(context.getResources().getString(R.string.action_about)).withCheckable(false)
            )
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(AdapterView<?> adapterView, View view, int position, long id, IDrawerItem iDrawerItem) {
                    switch (position) {
                        case 0:
                            recyclerView.setAdapter(moticonAdapter);
                            break;
                        case 2:
                            recyclerView.setAdapter(moticonPositiveAdapter);
                            break;
                        case 3:
                            recyclerView.setAdapter(moticonNegativeAdapter);
                            break;
                        case 4:
                            recyclerView.setAdapter(moticonFunnyAdapter);
                            break;
                        case 5:
                            recyclerView.setAdapter(moticonAnimalsAdapter);
                            break;
                        case 6:
                            recyclerView.setAdapter(moticonSpecialAdapter);
                            break;
                        case 8:
                            context.startActivity(new Intent(context, AboutActivity.class));
                            break;
                        default:
                            break;
                    }

                    return false;
                }
            }).build();
}