Example usage for android.view Menu add

List of usage examples for android.view Menu add

Introduction

In this page you can find the example usage for android.view Menu add.

Prototype

public MenuItem add(int groupId, int itemId, int order, @StringRes int titleRes);

Source Link

Document

Variation on #add(int,int,int,CharSequence) that takes a string resource identifier instead of the string itself.

Usage

From source file:com.actionbarsherlock.internal.view.MenuItemImpl.java

public void addTo(android.view.Menu menu) {
    if (this.mSubMenu != null) {
        android.view.SubMenu subMenu = menu.addSubMenu(this.mGroupId, this.mItemId, this.mOrder, this.mTitle);
        if (mIconRes != View.NO_ID) {
            subMenu.setIcon(mIconRes);/*  w w  w  . j  a va2s .c  om*/
        } else {
            subMenu.setIcon(mIcon);
        }

        for (MenuItemImpl item : this.mSubMenu.getItems()) {
            item.addTo(subMenu);
        }
    } else {
        android.view.MenuItem item = menu.add(this.mGroupId, this.mItemId, this.mOrder, this.mTitle)
                .setAlphabeticShortcut(this.mAlphabeticalShortcut).setNumericShortcut(this.mNumericalShortcut)
                .setVisible(this.isVisible()).setIntent(this.mIntent)
                .setOnMenuItemClickListener(this.mClickListener);

        if (this.isExclusiveCheckable()) {
            menu.setGroupCheckable(this.mGroupId, true, true);
        }

        //Create and initialize a native itemview wrapper
        NativeMenuItemView nativeWrapper = new NativeMenuItemView(item);
        nativeWrapper.initialize(this, MenuBuilder.TYPE_NATIVE);

        //Associate the itemview to this so changes will be reflected
        setItemView(MenuBuilder.TYPE_NATIVE, nativeWrapper);
    }
}

From source file:aarddict.android.ArticleViewActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (showFindDialogMethod != null) {
        MenuItem miFindInPage = menu.add(0, MENU_FIND_IN_PAGE, 0, R.string.mnFindInPage)
                .setIcon(android.R.drawable.ic_menu_search);
        MenuItemCompat.setShowAsAction(miFindInPage, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    }/*from   w  w w .  j  a  v a2 s .  co  m*/
    miViewOnline = menu.add(0, MENU_VIEW_ONLINE, 0, R.string.mnViewOnline)
            .setIcon(android.R.drawable.ic_menu_view);
    menu.add(0, MENU_NEW_LOOKUP, 0, R.string.mnNewLookup).setIcon(android.R.drawable.ic_menu_search);
    menu.add(0, MENU_ZOOM_OUT, 0, R.string.mnZoomOut).setIcon(R.drawable.ic_menu_zoom_out);
    menu.add(0, MENU_ZOOM_IN, 0, R.string.mnZoomIn).setIcon(R.drawable.ic_menu_zoom_in);
    miNextArticle = menu.add(0, MENU_NEXT, 0, R.string.mnNext).setIcon(android.R.drawable.ic_media_next);
    MenuItemCompat.setShowAsAction(miNextArticle, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    return true;
}

From source file:io.mapsquare.osmcontributor.ui.activities.MapActivity.java

@Subscribe(threadMode = ThreadMode.MAIN)
public void onPleaseInitializeDrawer(PleaseInitializeDrawer event) {
    Timber.d("initializing drawer with poiType");

    if (filtersItemList == null) {
        filtersItemList = new ArrayList<>();
    }// w ww  .j  av a  2 s  .c o m
    List<PoiType> poiTypes = event.getPoiTypes();

    poiTypesHidden = event.getPoiTypeHidden();

    filters.clear();
    for (PoiType poiType : poiTypes) {
        Long id = poiType.getId();
        filters.add(new PoiTypeFilter(poiType.getName(), id, poiType.getIcon(), !poiTypesHidden.contains(id)));
    }
    Collections.sort(filters);

    Menu menu = filterView.getMenu();

    int order = 1;
    for (PoiTypeFilter poiTypeFilter : filters) {
        PoiTypeFilter nextPoiTypeFilter = null;
        if (order < filters.size()) {
            nextPoiTypeFilter = filters.get(order);
        }
        // Add only menu if not present
        if (menu.findItem(poiTypeFilter.getPoiTypeId().intValue()) == null) {
            filtersItemList.add(menu
                    .add(Menu.NONE, poiTypeFilter.getPoiTypeId().intValue(),
                            (nextPoiTypeFilter != null
                                    ? (poiTypeFilter.compareTo(nextPoiTypeFilter) > 0 ? order - 1 : order)
                                    : order),
                            poiTypeFilter.getPoiTypeName())
                    .setChecked(poiTypeFilter.isActive())
                    .setIcon(bitmapHandler.getDrawable(poiTypeFilter.getPoiTypeIconName())));
        }
        order++;
    }

    // Remove only filter removed by user
    if (filters.size() < filtersItemList.size()) {
        List<MenuItem> temp = new ArrayList<>(filters.size());
        for (MenuItem menuItem : filtersItemList) {
            PoiTypeFilter poiTypeFilter = new PoiTypeFilter("", (long) menuItem.getItemId(), "", true);
            if (!filters.contains(poiTypeFilter)) {
                menu.removeItem(poiTypeFilter.getPoiTypeId().intValue());
            } else {
                temp.add(menuItem);
            }
        }

        filtersItemList.clear();
        filtersItemList.addAll(temp);
        temp.clear();
    }

    selectAllMenuItem.setChecked(poiTypesHidden.isEmpty());
}

From source file:at.jclehner.rxdroid.DrugEditFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mIsEditing
            && !getActivity().getIntent().getBooleanExtra(DrugEditActivity2.EXTRA_DISALLOW_DELETE, false)) {
        MenuItem item = menu.add(0, MENU_DELETE, 0, R.string._title_delete)
                .setIcon(R.drawable.ic_action_delete_white);

        MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    }// w w w. ja v a  2  s. com

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.gmail.boiledorange73.ut.map.MapActivityBase.java

/** Called whe the menu is created. */
@Override/*from w w w.j a  va 2  s .c  o m*/
public boolean onCreateOptionsMenu(Menu menu) {
    // zoom (invisible)
    menu.add(Menu.NONE, ID_ZOOM, Menu.NONE, Messages.getString("W_ZOOM"))
            .setIcon(android.R.drawable.ic_menu_zoom).setVisible(false);
    // mylocation (invisible)
    menu.add(Menu.NONE, ID_MYLOCATION, Menu.NONE, Messages.getString("W_MYLOCATION"))
            .setIcon(android.R.drawable.ic_menu_mylocation).setVisible(false);
    // maptypes (invisible)
    menu.add(Menu.NONE, ID_MAPTYPE, Menu.NONE, Messages.getString("W_CHANGE_MAP"))
            .setIcon(android.R.drawable.ic_menu_mapmode).setVisible(false);
    // geocoder (invisible)
    if (this.getGeocoderActivityClass() != null) {
        menu.add(Menu.NONE, ID_GEOCODER, Menu.NONE, Messages.getString("W_GEOCODER"))
                .setIcon(android.R.drawable.ic_menu_search).setVisible(false);
    }
    // more
    SubMenu smMore = menu.addSubMenu(Messages.getString("W_MORE")).setIcon(android.R.drawable.ic_menu_more);
    if (this.getPreferenceActivityClass() != null) {
        smMore.add(Menu.NONE, ID_MORE_PREFERENCES, Menu.NONE, Messages.getString("W_PREFERENCES"));
    }
    // more/externalmap (invisible)
    smMore.add(Menu.NONE, ID_MORE_EXTERNALMAP, Menu.NONE, Messages.getString("W_EXTERNALMAP"))
            .setVisible(false);
    // more/removedownloadedfiles (shown if needed)
    if (this.hasDownloadedFiles()) {
        smMore.add(Menu.NONE, ID_MORE_REMOVEDOWNLOADEDFILES, Menu.NONE,
                Messages.getString("W_REMOVEDOWNLOADEDFILES")).setIcon(android.R.drawable.ic_menu_delete);
    }
    // more/clearcache (2013/08/07)
    smMore.add(Menu.NONE, ID_MORE_CLEARCACHE, Menu.NONE, Messages.getString("W_CLEARCACHE"));

    // more/about
    smMore.add(Menu.NONE, ID_MORE_ABOUT, Menu.NONE, Messages.getString("W_ABOUT"));
    // more/exit
    smMore.add(Menu.NONE, ID_MORE_EXIT, Menu.NONE, Messages.getString("W_EXIT"));
    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.testtab.fragment.TwitEyesPageFragment.java

public boolean onCreateOptionsMenu(Menu menu) {
    //       boolean result = super.onCreateOptionsMenu(menu);

    // OPTION/*from  w  ww  .  ja v  a  2  s.  c  o  m*/
    MenuItem item0 = menu.add(0, MENU0_ID, Menu.NONE, R.string.menu0);
    item0.setIcon(R.drawable.home);

    // REFRESH
    MenuItem item1 = menu.add(0, MENU1_ID, Menu.NONE, R.string.menu1);
    item1.setIcon(R.drawable.cancel);
    //       return result;
    return false;
}

From source file:com.nttec.everychan.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (!MainApplication.getInstance().settings.showSidePanel() && Build.VERSION.SDK_INT < 11) {
        menu.add(Menu.NONE, R.id.menu_open_close_drawer, Menu.FIRST, R.string.menu_open_drawer)
                .setIcon(R.drawable.ic_menu_windows);
    }//ww w .  j  a v a2 s.com
    if (tabsAdapter != null && tabsAdapter.getSelectedItem() >= 0) {
        TabModel tab = tabsAdapter.getItem(tabsAdapter.getSelectedItem());
        if (canFavorite(tab)) {
            menu.add(Menu.NONE, R.id.menu_favorites, 201, R.string.menu_add_favorites)
                    .setIcon(R.drawable.ic_menu_add_bookmark);
        }
        if (tab.webUrl != null) {
            menu.add(Menu.NONE, R.id.menu_open_browser, 202, R.string.menu_open_browser)
                    .setIcon(R.drawable.ic_menu_browser);
        }
    }
    menu.add(Menu.NONE, R.id.menu_settings, 203, R.string.menu_preferences)
            .setIcon(android.R.drawable.ic_menu_preferences);
    Menu subMenu = menu.addSubMenu(Menu.NONE, R.id.menu_sub_settings, 203, R.string.menu_preferences)
            .setIcon(android.R.drawable.ic_menu_preferences);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_suspend, 1, R.string.menu_sub_preferences_suspend);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_autoupdate, 2, R.string.menu_sub_preferences_autoupdate)
            .setCheckable(true);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_maskpictures, 3, R.string.menu_sub_preferences_maskpictures)
            .setCheckable(true);
    subMenu.add(Menu.NONE, R.id.menu_sub_settings_all, 4, R.string.menu_sub_preferences_all);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.shurik.droidzebra.DroidZebra.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, MENU_NEW_GAME, 0, R.string.menu_item_new_game).setIcon(R.drawable.ic_menu_play);
    menu.add(0, MENU_HINT, 0, R.string.menu_item_hint).setIcon(android.R.drawable.ic_menu_compass);
    menu.add(0, MENU_TAKE_BACK, 0, R.string.menu_item_undo).setIcon(android.R.drawable.ic_menu_revert);
    menu.add(0, MENU_TAKE_REDO, 0, R.string.menu_item_redo).setIcon(android.R.drawable.ic_menu_rotate);
    menu.add(0, MENU_SETTINGS, 0, R.string.menu_item_settings).setIcon(android.R.drawable.ic_menu_preferences);
    menu.add(0, MENU_SWITCH_SIDES, 0, R.string.menu_item_switch_sides).setIcon(R.drawable.ic_menu_switch_sides);
    menu.add(0, MENU_DONATE, 0, R.string.menu_item_donate).setIcon(android.R.drawable.ic_menu_send);
    menu.add(0, MENU_MAIL, 0, R.string.menu_item_mail).setIcon(android.R.drawable.ic_menu_send);
    menu.add(0, MENU_QUIT, 0, R.string.menu_item_quit).setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    return true;//  w w  w . j  av  a  2  s  . co m
}

From source file:de.gebatzens.sia.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(SIAApp.SIA_APP.school.getTheme());
    super.onCreate(savedInstanceState);
    Log.w("ggvp", "CREATE NEW MAINACTIVITY");
    //Debug.startMethodTracing("sia3");
    SIAApp.SIA_APP.activity = this;
    savedState = savedInstanceState;/*from   ww w .  java2s .  c om*/

    final FragmentData.FragmentList fragments = SIAApp.SIA_APP.school.fragments;

    Intent intent = getIntent();
    if (intent != null && intent.getStringExtra("fragment") != null) {
        FragmentData frag = fragments
                .getByType(FragmentData.FragmentType.valueOf(intent.getStringExtra("fragment"))).get(0);
        SIAApp.SIA_APP.setFragmentIndex(fragments.indexOf(frag));
    }

    if (intent != null && intent.getBooleanExtra("reload", false)) {
        SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex()));
        intent.removeExtra("reload");
    }

    setContentView(R.layout.activity_main);

    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    mContent = getFragment();
    transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment");
    transaction.commit();

    Log.d("ggvp", "DATA: " + fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData());
    if (fragments.get(SIAApp.SIA_APP.getFragmentIndex()).getData() == null)
        SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex()));

    if ("Summer".equals(SIAApp.SIA_APP.getCurrentThemeName())) {
        ImageView summerNavigationPalm = (ImageView) findViewById(R.id.summer_navigation_palm);
        summerNavigationPalm.setImageResource(R.drawable.summer_palm);
        ImageView summerBackgroundImage = (ImageView) findViewById(R.id.summer_background_image);
        summerBackgroundImage.setImageResource(R.drawable.summer_background);
    }

    mToolBar = (Toolbar) findViewById(R.id.toolbar);
    mToolBar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {

            switch (menuItem.getItemId()) {
            case R.id.action_refresh:
                ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh)).setRefreshing(true);
                SIAApp.SIA_APP.refreshAsync(new Runnable() {
                    @Override
                    public void run() {
                        ((SwipeRefreshLayout) mContent.getView().findViewById(R.id.refresh))
                                .setRefreshing(false);
                    }
                }, true, fragments.get(SIAApp.SIA_APP.getFragmentIndex()));
                return true;
            case R.id.action_settings:
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(i, 1);
                return true;
            case R.id.action_addToCalendar:
                showExamDialog();
                return true;
            case R.id.action_help:
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle(getApplication().getString(R.string.help));
                builder.setMessage(getApplication().getString(R.string.exam_explain));
                builder.setPositiveButton(getApplication().getString(R.string.close),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                builder.create().show();
                return true;
            }

            return false;
        }
    });

    updateToolbar(SIAApp.SIA_APP.school.name, fragments.get(SIAApp.SIA_APP.getFragmentIndex()).name);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SIAApp.SIA_APP.setStatusBarColorTransparent(getWindow()); // because of the navigation drawer
    }

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolBar, R.string.drawer_open,
            R.string.drawer_close) {

        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.addDrawerListener(mDrawerToggle);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    mNavigationHeader = navigationView.getHeaderView(0);
    mNavigationSchoolpictureText = (TextView) mNavigationHeader.findViewById(R.id.drawer_image_text);
    mNavigationSchoolpictureText.setText(SIAApp.SIA_APP.school.name);
    mNavigationSchoolpicture = (ImageView) mNavigationHeader.findViewById(R.id.navigation_schoolpicture);
    mNavigationSchoolpicture.setImageBitmap(SIAApp.SIA_APP.school.loadImage());
    mNavigationSchoolpictureLink = mNavigationHeader.findViewById(R.id.navigation_schoolpicture_link);
    mNavigationSchoolpictureLink.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View viewIn) {
            mDrawerLayout.closeDrawers();
            Intent linkIntent = new Intent(Intent.ACTION_VIEW);
            linkIntent.setData(Uri.parse(SIAApp.SIA_APP.school.website));
            startActivity(linkIntent);
        }
    });

    final Menu menu = navigationView.getMenu();
    menu.clear();
    for (int i = 0; i < fragments.size(); i++) {
        MenuItem item = menu.add(R.id.fragments, Menu.NONE, i, fragments.get(i).name);
        item.setIcon(fragments.get(i).getIconRes());
    }

    menu.add(R.id.settings, R.id.settings_item, fragments.size(), R.string.settings);
    menu.setGroupCheckable(R.id.fragments, true, true);
    menu.setGroupCheckable(R.id.settings, false, false);

    final Menu navMenu = navigationView.getMenu();
    selectedItem = SIAApp.SIA_APP.getFragmentIndex();
    if (selectedItem != -1)
        navMenu.getItem(selectedItem).setChecked(true);

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.settings_item) {
                mDrawerLayout.closeDrawers();
                Intent i = new Intent(MainActivity.this, SettingsActivity.class);
                startActivityForResult(i, 1);
            } else {
                final int index = menuItem.getOrder();
                if (SIAApp.SIA_APP.getFragmentIndex() != index) {
                    SIAApp.SIA_APP.setFragmentIndex(index);
                    menuItem.setChecked(true);
                    updateToolbar(SIAApp.SIA_APP.school.name, menuItem.getTitle().toString());
                    mContent = getFragment();
                    Animation fadeOut = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.fade_out);
                    fadeOut.setAnimationListener(new Animation.AnimationListener() {

                        @Override
                        public void onAnimationStart(Animation animation) {

                        }

                        @Override
                        public void onAnimationEnd(Animation animation) {
                            FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment);
                            contentFrame.setVisibility(View.INVISIBLE);
                            if (fragments.get(index).getData() == null)
                                SIAApp.SIA_APP.refreshAsync(null, true, fragments.get(index));

                            //removeAllFragments();

                            FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                            transaction.replace(R.id.content_fragment, mContent, "gg_content_fragment");
                            transaction.commit();

                            snowView.updateSnow();
                        }

                        @Override
                        public void onAnimationRepeat(Animation animation) {

                        }
                    });
                    FrameLayout contentFrame = (FrameLayout) findViewById(R.id.content_fragment);
                    contentFrame.startAnimation(fadeOut);
                    mDrawerLayout.closeDrawers();
                } else {
                    mDrawerLayout.closeDrawers();
                }
            }
            return true;
        }
    });

    if (Build.VERSION.SDK_INT >= 25) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
        shortcutManager.removeAllDynamicShortcuts();

        for (int i = 0; i < fragments.size(); i++) {
            Drawable drawable = getDrawable(fragments.get(i).getIconRes());
            Bitmap icon;
            if (drawable instanceof VectorDrawable) {
                icon = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                        Bitmap.Config.ARGB_8888);
                Canvas canvas = new Canvas(icon);
                drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
                drawable.draw(canvas);
            } else {
                icon = BitmapFactory.decodeResource(getResources(), fragments.get(i).getIconRes());
            }

            Bitmap connectedIcon = Bitmap.createBitmap(icon.getWidth(), icon.getHeight(),
                    Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(connectedIcon);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(Color.parseColor("#f5f5f5"));
            canvas.drawCircle(icon.getWidth() / 2, icon.getHeight() / 2, icon.getWidth() / 2, paint);
            paint.setColorFilter(
                    new PorterDuffColorFilter(SIAApp.SIA_APP.school.getColor(), PorterDuff.Mode.SRC_ATOP));
            canvas.drawBitmap(icon, null, new RectF(icon.getHeight() / 4.0f, icon.getHeight() / 4.0f,
                    icon.getHeight() - icon.getHeight() / 4.0f, icon.getHeight() - icon.getHeight() / 4.0f),
                    paint);

            Intent newTaskIntent = new Intent(this, MainActivity.class);
            newTaskIntent.setAction(Intent.ACTION_MAIN);
            newTaskIntent.putExtra("fragment", fragments.get(i).type.toString());

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, fragments.get(i).name)
                    .setShortLabel(fragments.get(i).name).setLongLabel(fragments.get(i).name)
                    .setIcon(Icon.createWithBitmap(connectedIcon)).setIntent(newTaskIntent).build();

            shortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
        }
    }

    if (SIAApp.SIA_APP.preferences.getBoolean("app_130_upgrade", true)) {
        if (!SIAApp.SIA_APP.preferences.getBoolean("first_use_filter", true)) {
            TextDialog.newInstance(R.string.upgrade1_3title, R.string.upgrade1_3)
                    .show(getSupportFragmentManager(), "upgrade_dialog");
        }

        SIAApp.SIA_APP.preferences.edit().putBoolean("app_130_upgrade", false).apply();
    }

    snowView = (SnowView) findViewById(R.id.snow_view);

    shareToolbar = (Toolbar) findViewById(R.id.share_toolbar);
    shareToolbar.getMenu().clear();
    shareToolbar.inflateMenu(R.menu.share_toolbar_menu);
    shareToolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            toggleShareToolbar(false);
            for (Shareable s : MainActivity.this.shared) {
                s.setMarked(false);
            }
            MainActivity.this.shared.clear();

            mContent.updateFragment();
        }
    });

    shareToolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            toggleShareToolbar(false);

            HashMap<Date, ArrayList<Shareable>> dates = new HashMap<Date, ArrayList<Shareable>>();

            for (Shareable s : MainActivity.this.shared) {
                ArrayList<Shareable> list = dates.get(s.getDate());
                if (list == null) {
                    list = new ArrayList<Shareable>();
                    dates.put(s.getDate(), list);
                }

                list.add(s);

                s.setMarked(false);
            }
            MainActivity.this.shared.clear();

            List<Date> dateList = new ArrayList<Date>(dates.keySet());
            Collections.sort(dateList);
            String content = "";

            for (Date key : dateList) {
                content += SubstListAdapter.translateDay(key) + "\n\n";

                Collections.sort(dates.get(key));
                for (Shareable s : dates.get(key)) {
                    content += s.getShareContent() + "\n";
                }

                content += "\n";
            }

            content = content.substring(0, content.length() - 1);

            mContent.updateFragment();

            if (item.getItemId() == R.id.action_copy) {
                ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

                ClipData clip = ClipData.newPlainText(getString(R.string.entries), content);
                clipboard.setPrimaryClip(clip);
            } else if (item.getItemId() == R.id.action_share) {
                Intent sendIntent = new Intent();
                sendIntent.setAction(Intent.ACTION_SEND);
                sendIntent.putExtra(Intent.EXTRA_TEXT, content);
                sendIntent.setType("text/plain");
                startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)));
            }

            return true;
        }
    });

    if (shared.size() > 0) {
        shareToolbar.setVisibility(View.VISIBLE);
        updateShareToolbarText();
    }

    // if a fragment is opened via a notification or a shortcut reset the shared entries
    // delete extra fragment because the same intent is used when the device gets rotated and the user could have opened a new fragment
    if (intent != null && intent.hasExtra("fragment")) {
        resetShareToolbar();
        intent.removeExtra("fragment");
    }

}