Example usage for android.view MenuItem setTitle

List of usage examples for android.view MenuItem setTitle

Introduction

In this page you can find the example usage for android.view MenuItem setTitle.

Prototype


public MenuItem setTitle(@StringRes int title);

Source Link

Document

Change the title associated with this item.

Usage

From source file:com.filemanager.free.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem s = menu.findItem(R.id.view);
    MenuItem search = menu.findItem(R.id.search);
    MenuItem paste = menu.findItem(R.id.paste);
    String f = null;//from   w  ww .j a va 2 s  . c o m
    Fragment fragment;
    try {
        fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame);
        f = fragment.getClass().getName();
    } catch (Exception e1) {
        return true;
    }
    if (f.contains("TabFragment")) {
        setActionBarTitle("File Manager");
        if (aBoolean) {
            s.setTitle(getResources().getString(R.string.gridview));
        } else {
            s.setTitle(getResources().getString(R.string.listview));
        }
        try {
            TabFragment tabFragment = (TabFragment) fragment;
            Main ma = ((Main) tabFragment.getTab());
            if (ma.IS_LIST)
                s.setTitle(R.string.gridview);
            else
                s.setTitle(R.string.listview);
            updatePath(ma.CURRENT_PATH, ma.results, ma.openMode, ma.folder_count, ma.file_count);
        } catch (Exception ignored) {
        }

        initiatebbar();
        if (Build.VERSION.SDK_INT >= 21)
            toolbar.setElevation(0);
        invalidatePasteButton(paste);
        search.setVisible(true);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.VISIBLE);
        menu.findItem(R.id.search).setVisible(true);
        menu.findItem(R.id.home).setVisible(true);
        menu.findItem(R.id.history).setVisible(true);
        menu.findItem(R.id.sethome).setVisible(true);

        menu.findItem(R.id.item10).setVisible(true);
        if (showHidden)
            menu.findItem(R.id.hiddenitems).setVisible(true);
        menu.findItem(R.id.view).setVisible(true);
        menu.findItem(R.id.extract).setVisible(false);
        invalidatePasteButton(menu.findItem(R.id.paste));
        findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE);
    } else if (f.contains("AppsList") || f.contains("ProcessViewer")) {
        appBarLayout.setExpanded(true);
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        findViewById(R.id.buttonbarframe).setVisibility(View.GONE);
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.extract).setVisible(false);
        if (f.contains("ProcessViewer"))
            menu.findItem(R.id.item10).setVisible(false);
        else {
            menu.findItem(R.id.dsort).setVisible(false);
            menu.findItem(R.id.sortby).setVisible(false);
        }
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
    } else if (f.contains("ZipViewer")) {
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        TextView textView = (TextView) mainActivity.pathbar.findViewById(R.id.fullpath);
        pathbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.item10).setVisible(false);
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
        menu.findItem(R.id.extract).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.nononsenseapps.feeder.ui.FeedFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
    final long id = menuItem.getItemId();
    if (id == R.id.action_sync) {
        // Sync all feeds when menu button pressed
        RssContentProvider.RequestSync();
        return true;
    } else if (id == R.id.action_edit_feed && this.id > 0) {
        Intent i = new Intent(getActivity(), EditFeedActivity.class);
        // TODO do not animate the back movement here
        i.putExtra(EditFeedActivity.SHOULD_FINISH_BACK, true);
        i.putExtra(EditFeedActivity._ID, this.id);
        i.putExtra(EditFeedActivity.TITLE, customTitle);
        i.putExtra(EditFeedActivity.TAG, tag);
        i.setData(Uri.parse(url));// ww w .  j av  a 2  s  .  c  om
        startActivity(i);
        return true;
    } else if (id == R.id.action_add_templated && this.id > 0) {
        Intent i = new Intent(getActivity(), EditFeedActivity.class);
        // TODO do not animate the back movement here
        i.putExtra(EditFeedActivity.SHOULD_FINISH_BACK, true);
        i.putExtra(EditFeedActivity.TEMPLATE, true);
        //i.putExtra(EditFeedActivity.TITLE, title);
        i.putExtra(EditFeedActivity.TAG, tag);
        i.setData(Uri.parse(url));
        startActivity(i);
        return true;
    } else if (id == R.id.action_delete_feed && this.id > 0) {
        getActivity().getContentResolver().delete(FeedSQL.URI_FEEDS, Util.WHEREIDIS,
                Util.LongsToStringArray(this.id));
        RssContentProvider.notifyAllUris(getActivity());

        // Tell activity to open another fragment
        ((FeedActivity) getActivity()).loadFirstFeedInDB(true);
        return true;
    }
    //        else if (id == R.id.action_mark_as_read) {
    //            markAsRead();
    //            return true;
    //        }
    else if (id == R.id.action_only_unread) {
        final boolean onlyUnread = !menuItem.isChecked();
        PrefUtils.setPrefShowOnlyUnread(getActivity(), onlyUnread);
        menuItem.setChecked(onlyUnread);
        if (onlyUnread) {
            menuItem.setIcon(R.drawable.ic_action_visibility_off);
        } else {
            menuItem.setIcon(R.drawable.ic_action_visibility);
        }

        menuItem.setTitle(onlyUnread ? R.string.show_unread_items : R.string.show_all_items);
        //getActivity().invalidateOptionsMenu();
        // Restart loader
        getLoaderManager().restartLoader(FEEDITEMS_LOADER, new Bundle(), this);
        return true;
    } else {
        return super.onOptionsItemSelected(menuItem);
    }
}

From source file:com.igniva.filemanager.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem s = menu.findItem(R.id.view);
    MenuItem search = menu.findItem(R.id.search);
    MenuItem paste = menu.findItem(R.id.paste);
    String f = null;//from  w w w.java  2 s .c  o  m
    Fragment fragment;
    try {
        fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame);
        f = fragment.getClass().getName();
    } catch (Exception e1) {
        return true;
    }
    if (f.contains("TabFragment")) {
        setActionBarTitle("Filemanager");
        if (aBoolean) {
            s.setTitle(getResources().getString(R.string.gridview));
        } else {
            s.setTitle(getResources().getString(R.string.listview));
        }
        try {
            TabFragment tabFragment = (TabFragment) fragment;
            Main ma = ((Main) tabFragment.getTab());
            if (ma.IS_LIST)
                s.setTitle(R.string.gridview);
            else
                s.setTitle(R.string.listview);
            updatePath(ma.CURRENT_PATH, ma.results, ma.openMode, ma.folder_count, ma.file_count);
        } catch (Exception e) {
        }

        initiatebbar();
        if (Build.VERSION.SDK_INT >= 21)
            toolbar.setElevation(0);
        invalidatePasteButton(paste);
        search.setVisible(true);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.VISIBLE);
        menu.findItem(R.id.search).setVisible(true);
        menu.findItem(R.id.home).setVisible(true);
        menu.findItem(R.id.history).setVisible(true);
        menu.findItem(R.id.sethome).setVisible(true);

        menu.findItem(R.id.item10).setVisible(true);
        if (showHidden)
            menu.findItem(R.id.hiddenitems).setVisible(true);
        menu.findItem(R.id.view).setVisible(true);
        menu.findItem(R.id.extract).setVisible(false);
        invalidatePasteButton(menu.findItem(R.id.paste));
        findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE);
    } else if (f.contains("AppsList") || f.contains("ProcessViewer")
            || f.contains(FTPServerFragment.class.getName())) {
        appBarLayout.setExpanded(true);
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        findViewById(R.id.buttonbarframe).setVisibility(View.GONE);
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.extract).setVisible(false);
        if (f.contains("ProcessViewer"))
            menu.findItem(R.id.item10).setVisible(false);
        else {
            menu.findItem(R.id.dsort).setVisible(false);
            menu.findItem(R.id.sortby).setVisible(false);
        }
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
    } else if (f.contains("ZipViewer")) {
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        TextView textView = (TextView) mainActivity.pathbar.findViewById(R.id.fullpath);
        pathbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.item10).setVisible(false);
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
        menu.findItem(R.id.extract).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.amaze.filemanager.activities.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem s = menu.findItem(R.id.view);
    MenuItem search = menu.findItem(R.id.search);
    MenuItem paste = menu.findItem(R.id.paste);
    String f = null;//w  w w .jav a2s .c om
    Fragment fragment;
    try {
        fragment = getSupportFragmentManager().findFragmentById(R.id.content_frame);
        f = fragment.getClass().getName();
    } catch (Exception e1) {
        return true;
    }
    if (f.contains("TabFragment")) {
        setActionBarTitle("Amaze");
        if (aBoolean) {
            s.setTitle(getResources().getString(R.string.gridview));
        } else {
            s.setTitle(getResources().getString(R.string.listview));
        }
        try {
            TabFragment tabFragment = (TabFragment) fragment;
            Main ma = ((Main) tabFragment.getTab());
            if (ma.IS_LIST)
                s.setTitle(R.string.gridview);
            else
                s.setTitle(R.string.listview);
            updatePath(ma.CURRENT_PATH, ma.results, ma.openMode, ma.folder_count, ma.file_count);
        } catch (Exception e) {
        }

        initiatebbar();
        if (Build.VERSION.SDK_INT >= 21)
            toolbar.setElevation(0);
        invalidatePasteButton(paste);
        search.setVisible(true);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.VISIBLE);
        menu.findItem(R.id.search).setVisible(true);
        menu.findItem(R.id.home).setVisible(true);
        menu.findItem(R.id.history).setVisible(true);
        menu.findItem(R.id.sethome).setVisible(true);

        menu.findItem(R.id.item10).setVisible(true);
        if (showHidden)
            menu.findItem(R.id.hiddenitems).setVisible(true);
        menu.findItem(R.id.view).setVisible(true);
        menu.findItem(R.id.extract).setVisible(false);
        invalidatePasteButton(menu.findItem(R.id.paste));
        findViewById(R.id.buttonbarframe).setVisibility(View.VISIBLE);
    } else if (f.contains("AppsList") || f.contains("ProcessViewer")) {
        appBarLayout.setExpanded(true);
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        findViewById(R.id.buttonbarframe).setVisibility(View.GONE);
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.extract).setVisible(false);
        if (f.contains("ProcessViewer"))
            menu.findItem(R.id.item10).setVisible(false);
        else {
            menu.findItem(R.id.dsort).setVisible(false);
            menu.findItem(R.id.sortby).setVisible(false);
        }
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
    } else if (f.contains("ZipViewer")) {
        menu.findItem(R.id.sethome).setVisible(false);
        if (indicator_layout != null)
            indicator_layout.setVisibility(View.GONE);
        TextView textView = (TextView) mainActivity.pathbar.findViewById(R.id.fullpath);
        pathbar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
            }
        });
        menu.findItem(R.id.search).setVisible(false);
        menu.findItem(R.id.home).setVisible(false);
        menu.findItem(R.id.history).setVisible(false);
        menu.findItem(R.id.item10).setVisible(false);
        menu.findItem(R.id.hiddenitems).setVisible(false);
        menu.findItem(R.id.view).setVisible(false);
        menu.findItem(R.id.paste).setVisible(false);
        menu.findItem(R.id.extract).setVisible(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.ichi2.anki2.Reviewer.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Resources res = getResources();
    MenuItem item = menu.findItem(MENU_MARK);
    if (mCurrentCard != null && mCurrentCard.note().hasTag("marked")) {
        item.setTitle(R.string.menu_unmark_card);
        item.setIcon(R.drawable.ic_menu_marked);
    } else {/* w  w  w  . jav a2 s.c  om*/
        item.setTitle(R.string.menu_mark_card);
        item.setIcon(R.drawable.ic_menu_mark);
    }
    item = menu.findItem(MENU_UNDO);
    if (AnkiDroidApp.colIsOpen() && AnkiDroidApp.getCol().undoAvailable()) {
        item.setEnabled(true);
        item.setIcon(R.drawable.ic_menu_revert);
    } else {
        item.setEnabled(false);
        item.setIcon(R.drawable.ic_menu_revert_disabled);
    }
    item = menu.findItem(MENU_SEARCH);
    if (item != null) {
        item.setTitle(clipboardHasText() ? Lookup.getSearchStringTitle() : res.getString(R.string.menu_select));
    }
    return true;
}

From source file:com.android.calendar.AllInOneActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Time t = null;// www.  j av  a2s  .  com
    int viewType = ViewType.CURRENT;
    long extras = CalendarController.EXTRA_GOTO_TIME;
    final int itemId = item.getItemId();
    if (itemId == R.id.action_refresh) {
        mController.refreshCalendars();
        return true;
    } else if (itemId == R.id.action_today) {
        viewType = ViewType.CURRENT;
        t = new Time(mTimeZone);
        t.setToNow();
        extras |= CalendarController.EXTRA_GOTO_TODAY;
    } else if (itemId == R.id.action_goto) {
        Time todayTime;
        t = new Time(mTimeZone);
        t.set(mController.getTime());
        todayTime = new Time(mTimeZone);
        todayTime.setToNow();
        if (todayTime.month == t.month) {
            t = todayTime;
        }

        DatePickerDialog datePickerDialog = DatePickerDialog
                .newInstance(new DatePickerDialog.OnDateSetListener() {
                    @Override
                    public void onDateSet(DatePickerDialog dialog, int year, int monthOfYear, int dayOfMonth) {
                        Time selectedTime = new Time(mTimeZone);
                        selectedTime.year = year;
                        selectedTime.month = monthOfYear;
                        selectedTime.monthDay = dayOfMonth;
                        long extras = CalendarController.EXTRA_GOTO_TIME | CalendarController.EXTRA_GOTO_DATE;
                        mController.sendEvent(this, EventType.GO_TO, selectedTime, null, selectedTime, -1,
                                ViewType.CURRENT, extras, null, null);
                    }
                }, t.year, t.month, t.monthDay);
        datePickerDialog.show(getFragmentManager(), "datePickerDialog");

    } else if (itemId == R.id.action_hide_controls) {
        mHideControls = !mHideControls;
        Utils.setSharedPreference(this, GeneralPreferences.KEY_SHOW_CONTROLS, !mHideControls);
        item.setTitle(mHideControls ? mShowString : mHideString);
        if (!mHideControls) {
            mMiniMonth.setVisibility(View.VISIBLE);
            mCalendarsList.setVisibility(View.VISIBLE);
            mMiniMonthContainer.setVisibility(View.VISIBLE);
        }
        final ObjectAnimator slideAnimation = ObjectAnimator.ofInt(this, "controlsOffset",
                mHideControls ? 0 : mControlsAnimateWidth, mHideControls ? mControlsAnimateWidth : 0);
        slideAnimation.setDuration(mCalendarControlsAnimationTime);
        ObjectAnimator.setFrameDelay(0);
        slideAnimation.start();
        return true;
    } else if (itemId == R.id.action_search) {
        return false;
    } else if (itemId == R.id.action_import) {
        ImportActivity.pickImportFile(this);
    } else {
        return mExtensions.handleItemSelected(item, this);
    }
    mController.sendEvent(this, EventType.GO_TO, t, null, t, -1, viewType, extras, null, null);
    return true;
}

From source file:de.vanita5.twittnuker.util.Utils.java

public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) {
    if (context == null || menu == null || status == null)
        return;//  w ww .  java  2 s.c  o m
    final int activatedColor = ThemeUtils.getUserThemeColor(context);
    final boolean isMyRetweet = isMyRetweet(status);
    final MenuItem delete = menu.findItem(MENU_DELETE);
    if (delete != null) {
        delete.setVisible(status.account_id == status.user_id && !isMyRetweet);
    }
    final MenuItem retweet = menu.findItem(MENU_RETWEET);
    if (retweet != null) {
        final Drawable icon = retweet.getIcon().mutate();
        retweet.setVisible(!status.user_is_protected || isMyRetweet);
        if (isMyRetweet) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
            retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            retweet.setTitle(R.string.retweet);
        }
    }
    final MenuItem itemRetweetSubmenu = menu.findItem(R.id.retweet_submenu);
    if (itemRetweetSubmenu != null) {
        final Drawable icon = itemRetweetSubmenu.getIcon().mutate();
        if (isMyRetweet) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            icon.clearColorFilter();
        }
    }
    final MenuItem favorite = menu.findItem(MENU_FAVORITE);
    if (favorite != null) {
        final Drawable icon = favorite.getIcon().mutate();
        if (status.is_favorite) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
            favorite.setTitle(R.string.unfavorite);
        } else {
            icon.clearColorFilter();
            favorite.setTitle(R.string.favorite);
        }
    }
    final MenuItem love = menu.findItem(MENU_LOVE);
    if (love != null) {
        final Drawable icon = love.getIcon().mutate();
        love.setVisible(!status.user_is_protected || isMyRetweet);
        if (isMyRetweet && status.is_favorite) {
            icon.setColorFilter(activatedColor, Mode.SRC_ATOP);
        } else {
            icon.clearColorFilter();
        }
    }
    final MenuItem translate = menu.findItem(MENU_TRANSLATE);
    if (translate != null) {
        final AccountWithCredentials account = Account.getAccountWithCredentials(context, status.account_id);
        final boolean isOfficialKey = AccountWithCredentials.isOfficialCredentials(context, account);
        setMenuItemAvailability(menu, MENU_TRANSLATE, isOfficialKey);
    }
    final MenuItem shareItem = menu.findItem(R.id.share_submenu);
    final Menu shareSubmenu = shareItem != null && shareItem.hasSubMenu() ? shareItem.getSubMenu() : null;
    if (shareSubmenu != null) {
        final Intent shareIntent = createStatusShareIntent(context, status);
        shareSubmenu.removeGroup(MENU_GROUP_STATUS_SHARE);
        addIntentToMenu(context, shareSubmenu, shareIntent, MENU_GROUP_STATUS_SHARE);
    }
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

/**
 * Called after an item is selected in the navigation drawer.
 *
 * @param menuItem ID of the selected item.
 *///from  w  w w.j a v  a2 s. c  o  m
private void selectDrawerItem(MenuItem menuItem) {

    switch (menuItem.getItemId()) {

    //            case R.id.debug_view_item:
    //
    //                // Create the debug view - if it is not already created:
    //                if (mDebugViewFragment == null) {
    //                    mDebugViewFragment = new DebugViewFragment();
    //                }
    //
    //                // Show the debug view:
    //                if (getSupportFragmentManager().findFragmentByTag(DEBUG_VIEW_FRAGMENT) == null) {
    //                    mIsDebugViewEnabled = true;
    //                    menuItem.setTitle(R.string.hide_debug_view_text);
    //                    getSupportFragmentManager().beginTransaction().add(R.id.container_layout, mDebugViewFragment, DEBUG_VIEW_FRAGMENT).commit();
    //                }
    //                // Hide the debug view:
    //                else {
    //                    mIsDebugViewEnabled = false;
    //                    menuItem.setTitle(R.string.show_debug_view_text);
    //                    getSupportFragmentManager().beginTransaction().remove(mDebugViewFragment).commit();
    //                }
    //
    //                break;

    // Focus measurement:
    case R.id.show_fm_values_item:

        if (mPaintView.isFocusTextVisible()) {
            menuItem.setTitle(R.string.show_fm_values_text);
            mPaintView.drawFocusText(false);
        } else {
            menuItem.setTitle(R.string.hide_fm_values_text);
            mPaintView.drawFocusText(true);
        }

        break;

    // Guide lines:
    case R.id.show_guide_item:

        if (mPaintView.areGuideLinesDrawn()) {
            mPaintView.drawGuideLines(false);
            menuItem.setTitle(R.string.show_guide_text);
        } else {
            mPaintView.drawGuideLines(true);
            menuItem.setTitle(R.string.hide_guide_text);
        }

        break;

    //            // Switch between the two page segmentation methods:
    //            case R.id.action_precise_page_seg:
    //
    //                if (NativeWrapper.useLab()) {
    //                    NativeWrapper.setUseLab(false);
    //                    menuItem.setTitle(R.string.precise_page_seg_text);
    //                }
    //                else {
    //                    NativeWrapper.setUseLab(true);
    //                    menuItem.setTitle(R.string.fast_page_seg_text);
    //                }

    }

    mDrawerLayout.closeDrawers();

}

From source file:com.cerema.cloud2.ui.activity.FileDisplayActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean retval = true;
    switch (item.getItemId()) {
    case R.id.action_sync_account: {
        startSynchronization();/* w  ww . j  a v  a  2s. c o  m*/
        break;
    }
    case android.R.id.home: {
        FileFragment second = getSecondFragment();
        OCFile currentDir = getCurrentDir();
        if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
            mDrawerLayout.closeDrawer(GravityCompat.START);
        } else if ((currentDir != null && currentDir.getParentId() != 0)
                || (second != null && second.getFile() != null)) {
            onBackPressed();

        } else {
            mDrawerLayout.openDrawer(GravityCompat.START);
        }
        break;
    }
    case R.id.action_sort: {
        SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(this);

        // Read sorting order, default to sort by name ascending
        Integer sortOrder = appPreferences.getInt("sortOrder", FileStorageUtils.SORT_NAME);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.actionbar_sort_title).setSingleChoiceItems(R.array.actionbar_sortby,
                sortOrder, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        switch (which) {
                        case 0:
                            sortByName(true);
                            break;
                        case 1:
                            sortByDate(false);
                            break;
                        }

                        dialog.dismiss();
                    }
                });
        builder.create().show();
        break;
    }
    case R.id.action_switch_view: {
        if (isGridView()) {
            item.setTitle(getString(R.string.action_switch_grid_view));
            item.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_view_module));
            getListOfFilesFragment().setListAsPreferred();
        } else {
            item.setTitle(getApplicationContext().getString(R.string.action_switch_list_view));
            item.setIcon(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_view_list));
            getListOfFilesFragment().setGridAsPreferred();
        }
        return true;
    }
    default:
        retval = super.onOptionsItemSelected(item);
    }
    return retval;
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);

    boolean drawerOpen = mDrawerLayout != null && mDrawerLayout.isDrawerOpen(mDrawerListsView);
    boolean holoSearch = PreferenceActivity.getUsingHoloSearchFromPrefs(this);
    // TODO: supposed to hide content-related actions when the drawer is open.

    // TODO: Add item-specific menu items (see NotesList.java example)
    // like edit, strike-through, delete.

    // Add menu option for auto adding items from string array in intent
    // extra if they exist
    if (mExtraItems == null) {
        menu.removeItem(MENU_INSERT_FROM_EXTRAS);
    }//w  w  w.  ja v a2  s  . c o m

    // Selected list:
    long listId = getSelectedListId();

    // set menu title for change mode
    MenuItem menuItem = menu.findItem(MENU_PICK_ITEMS);

    if (mItemsView.mMode == MODE_ADD_ITEMS) {
        menuItem.setTitle(R.string.menu_start_shopping);
        menuItem.setIcon(android.R.drawable.ic_menu_myplaces);
    } else {
        menu.findItem(MENU_PICK_ITEMS).setTitle(R.string.menu_pick_items);
        menuItem.setIcon(android.R.drawable.ic_menu_add);
    }

    menuItem = menu.findItem(MENU_SEARCH_ADD);
    if (menuItem != null) {
        menuItem.setVisible(holoSearch && !drawerOpen);
        if (!holoSearch) {
            mAddPanel.setVisibility(View.VISIBLE);
        }

        View searchView = menuItem.getActionView();
        int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
        View imageView = searchView.findViewById(searchImgId);
        if (imageView instanceof ImageView) {
            ((ImageView) imageView).setImageResource(android.R.drawable.ic_menu_add);
        }

    }

    menuItem = menu.findItem(MENU_SYNC_WEAR);
    if (menuItem != null) {
        menuItem.setVisible(mItemsView.isWearSupportAvailable());
    }

    menuItem = menu.findItem(MENU_MARK_ALL_ITEMS).setVisible(mItemsView.mNumUnchecked > 0);
    menuItem = menu.findItem(MENU_UNMARK_ALL_ITEMS).setVisible(mItemsView.mNumChecked > 0);

    menuItem = menu.findItem(MENU_CLEAN_UP_LIST).setEnabled(mItemsView.mNumChecked > 0).setVisible(!drawerOpen);

    // Delete list is possible, if we have more than one list:
    // AND
    // the current list is not the default list (listId == 0) - issue #105
    // TODO: Later, the default list should be user-selectable,
    // and not deletable.

    // TODO ???
    /*
     * menu.setItemShown(MENU_DELETE_LIST, mCursorListFilter.count() > 1 &&
     * listId != 1); // 1 is hardcoded number of default first list.
     */

    // The following code is put from onCreateOptionsMenu to
    // onPrepareOptionsMenu,
    // because the URI of the shopping list can change if the user switches
    // to another list.
    // Generate any additional actions that can be performed on the
    // overall list. This allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    // menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
    // new ComponentName(this, NoteEditor.class), null, intent, 0, null);

    // Workaround to add icons:
    MenuIntentOptionsWithIcons menu2 = new MenuIntentOptionsWithIcons(this, menu);
    menu2.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(this, org.openintents.shopping.ShoppingActivity.class), null, intent, 0, null);

    return true;
}