Example usage for android.view MenuItem getTitle

List of usage examples for android.view MenuItem getTitle

Introduction

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

Prototype

public CharSequence getTitle();

Source Link

Document

Retrieve the current title of the item.

Usage

From source file:com.owncloud.android.ui.activity.DrawerActivity.java

/**
 * setup drawer content, basically setting the item selected listener.
 *
 * @param navigationView the drawers navigation view
 *///from w  ww  .  ja v  a  2s . c  om
protected void setupDrawerContent(NavigationView navigationView) {
    // Disable help or feedback on customization
    if (!getResources().getBoolean(R.bool.help_enabled)) {
        navigationView.getMenu().removeItem(R.id.drawer_menu_help);
    }

    if (!getResources().getBoolean(R.bool.feedback_enabled)) {
        navigationView.getMenu().removeItem(R.id.drawer_menu_feedback);
    }

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            mDrawerLayout.closeDrawers();

            switch (menuItem.getItemId()) {
            case R.id.nav_all_files:
                menuItem.setChecked(true);
                mCheckedMenuItem = menuItem.getItemId();

                allFilesOption();
                // TODO activate when On Device branch is merged
                // MainApp.showOnlyFilesOnDevice(false);
                // refreshDirectory();
                break;
            // TODO activate when On Device branch is merged
            // case R.id.nav_on_device:
            //     menuItem.setChecked(true);
            //     mCheckedMenuItem = menuItem.getItemId();
            //     MainApp.showOnlyFilesOnDevice(true);
            //     refreshDirectory();
            //     break;
            case R.id.nav_uploads:
                Intent uploadListIntent = new Intent(getApplicationContext(), UploadListActivity.class);
                uploadListIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(uploadListIntent);
                break;
            case R.id.nav_settings:
                Intent settingsIntent = new Intent(getApplicationContext(), Preferences.class);
                startActivity(settingsIntent);
                break;
            case R.id.drawer_menu_account_add:
                createAccount(false);
                break;
            case R.id.drawer_menu_account_manage:
                Intent manageAccountsIntent = new Intent(getApplicationContext(), ManageAccountsActivity.class);
                startActivityForResult(manageAccountsIntent, ACTION_MANAGE_ACCOUNTS);
                break;
            case R.id.drawer_menu_feedback:
                openFeedback();
                break;
            case R.id.drawer_menu_help:
                openHelp();
                break;
            case Menu.NONE:
                // account clicked
                accountClicked(menuItem.getTitle().toString());
            default:
                Log_OC.i(TAG, "Unknown drawer menu item clicked: " + menuItem.getTitle());
            }

            return true;
        }
    });

    // handle correct state
    if (mIsAccountChooserActive) {
        navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, true);

    } else {
        navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false);
    }
}

From source file:com.aimfire.gallery.GalleryActivity.java

/**
 * Override Activity lifecycle method./*from   www.  j  av a 2  s  .c  o  m*/
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;

    /* 
     * if user interacted with action bar, delay any scheduled hide()
     * operations to prevent the jarring behavior of controls going away
     * while interacting with the UI.
     */
    if (AUTO_HIDE) {
        delayedHide(AUTO_HIDE_DELAY_SHORT_MILLIS);
    }

    switch (item.getItemId()) {
    case android.R.id.home:
        intent = new Intent(GalleryActivity.this, MainActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra(MainConsts.EXTRA_MSG, mIsMyMedia);
        startActivity(intent);
        break;
    case R.id.action_share:
        createDriveLink();
        break;
    case R.id.action_thumb_view:
        switchThumbView();
        break;
    case R.id.action_delete:
        deleteFile();
        break;
    case R.id.action_anaglyph:
        if (!item.isChecked()) {
            mDisplayMode = DisplayMode.Anaglyph;
            if (item.getTitle().equals(getString(R.string.action_anaglyph_cyanred))) {
                mDisplaySwap = true;
            } else {
                mDisplaySwap = false;
            }

            item.setChecked(true);
            updateDisplayPrefs();
            invalidateOptionsMenu();
            switchDisplayMode();
        }
        break;
    case R.id.action_sbs:
        if (!item.isChecked()) {
            mDisplayMode = DisplayMode.SbsFull;
            if (item.getTitle().equals(getString(R.string.action_sbs_cross))) {
                mDisplaySwap = true;
            } else {
                mDisplaySwap = false;
            }

            item.setChecked(true);
            updateDisplayPrefs();
            invalidateOptionsMenu();
            switchDisplayMode();
        }
        break;
    case R.id.action_3dtv:
        if (!item.isChecked()) {
            mDisplayMode = DisplayMode.SbsHalf;
            item.setChecked(true);
            updateDisplayPrefs();
            invalidateOptionsMenu();
            switchDisplayMode();
        }
        break;
    case R.id.action_swap:
        if (item.isChecked()) {
            mDisplaySwap = false;
            item.setChecked(false);
        } else {
            mDisplaySwap = true;
            item.setChecked(true);
        }
        updateDisplayPrefs();
        invalidateOptionsMenu();
        switchDisplayMode();
        break;
    case R.id.action_grayscale:
        if (item.isChecked()) {
            mDisplayColor = true;
            item.setChecked(false);
        } else {
            mDisplayColor = false;
            item.setChecked(true);
        }
        updateDisplayPrefs();
        invalidateOptionsMenu();
        switchDisplayMode();
        break;
    default:
        return super.onOptionsItemSelected(item);
    }
    return true;
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int pos = -1;
    int id = item.getItemId();
    int show = m_show;
    switch (id) {
    case R.id.package_user:
        show = SHOW_USER;/*  w ww  .  ja va 2  s  . co m*/
        break;
    case R.id.package_system:
        show = SHOW_SYS;
        break;
    case R.id.package_pref:
        show = SHOW_PREF;
        break;
    case R.id.package_cache:
        show = SHOW_CACHE;
        break;
    case R.id.package_lib:
        show = SHOW_LIB;
        break;

    case R.id.package_uninstall:
        if (m_uninstallResId == R.string.package_del_cache)
            deleteCaches();
        else
            uninstallPackages();
        break;
    case R.id.package_uncheck_all:
        uncheckAll();
        break;

    case R.id.package_collapseAll:
        collapseAll();
        m_expand_collapse_toggle.setChecked(false);
        break;
    case R.id.package_expandAll:
        expandAll();
        m_expand_collapse_toggle.setChecked(true);
        break;
    case 0:
        break;
    default:
        item.setChecked(true);
        pos = Arrays.asList(getResources().getStringArray(R.array.pkg_sort_array)).indexOf(item.getTitle());
        m_sortSpinner.setSelection(pos);
        this.m_sortBy = id;
        Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST);
        m_handler.sendMessage(msgObj);
        break;
    }

    if (m_show != show) {
        m_show = show;
        item.setChecked(true);
        m_loadSpinner.setSelection(m_show);
        // updateList();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // This happens when the user begins to hold down the menu key, so
    // allow them to chord to get a shortcut.
    mCanChord = true;//w ww.ja va  2s  .c  om

    super.onPrepareOptionsMenu(menu);

    MenuItem src, dest;

    // Login/Logout
    if (mSettings.isLoggedIn()) {
        menu.findItem(R.id.login_menu_id).setVisible(false);

        if (!mSubreddit.equals(Constants.FRONTPAGE_STRING)) {
            ArrayList<String> mSubredditsList = CacheInfo.getCachedSubredditList(getApplicationContext());

            if (mSubredditsList != null && StringUtils.listContainsIgnoreCase(mSubredditsList, mSubreddit)) {
                menu.findItem(R.id.unsubscribe_menu_id).setVisible(true);
                menu.findItem(R.id.subscribe_menu_id).setVisible(false);
            } else {
                menu.findItem(R.id.subscribe_menu_id).setVisible(true);
                menu.findItem(R.id.unsubscribe_menu_id).setVisible(false);
            }
        }

        menu.findItem(R.id.inbox_menu_id).setVisible(true);
        menu.findItem(R.id.user_profile_menu_id).setVisible(true);
        menu.findItem(R.id.user_profile_menu_id).setTitle(
                String.format(getResources().getString(R.string.user_profile), mSettings.getUsername()));
        menu.findItem(R.id.logout_menu_id).setVisible(true);
        menu.findItem(R.id.logout_menu_id)
                .setTitle(String.format(getResources().getString(R.string.logout), mSettings.getUsername()));
    } else {
        menu.findItem(R.id.login_menu_id).setVisible(true);

        menu.findItem(R.id.unsubscribe_menu_id).setVisible(false);
        menu.findItem(R.id.subscribe_menu_id).setVisible(false);

        menu.findItem(R.id.inbox_menu_id).setVisible(false);
        menu.findItem(R.id.user_profile_menu_id).setVisible(false);
        menu.findItem(R.id.logout_menu_id).setVisible(false);
    }

    // Theme: Light/Dark
    src = Util.isLightTheme(mSettings.getTheme()) ? menu.findItem(R.id.dark_menu_id)
            : menu.findItem(R.id.light_menu_id);
    dest = menu.findItem(R.id.light_dark_menu_id);
    dest.setTitle(src.getTitle());

    // Sort
    if (Constants.ThreadsSort.SORT_BY_HOT_URL.equals(mSortByUrl))
        src = menu.findItem(R.id.sort_by_hot_menu_id);
    else if (Constants.ThreadsSort.SORT_BY_NEW_URL.equals(mSortByUrl))
        src = menu.findItem(R.id.sort_by_new_menu_id);
    else if (Constants.ThreadsSort.SORT_BY_CONTROVERSIAL_URL.equals(mSortByUrl))
        src = menu.findItem(R.id.sort_by_controversial_menu_id);
    else if (Constants.ThreadsSort.SORT_BY_TOP_URL.equals(mSortByUrl))
        src = menu.findItem(R.id.sort_by_top_menu_id);
    dest = menu.findItem(R.id.sort_by_menu_id);
    dest.setTitle(src.getTitle());

    return true;
}

From source file:com.christophergs.mbientbasic.NavigationActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();
    Log.i(TAG, String.format("Fragment ID: %d", id));

    // update the main content by replacing fragments
    FragmentManager fragmentManager = getSupportFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();
    if (currentFragment != null) {
        transaction.detach(currentFragment);
    }// w  w  w . ja v  a  2 s  .  c o m

    if (currentFragment2 != null) {
        transaction.detach(currentFragment2);
    }

    //we keep tag 1 as the per the mbient code and make tag 2 the adjusted gyro,
    //knowing that the BothFragment is a copy of accelerometer with stream adjustments
    String fragmentTag = FRAGMENT_CLASSES.get(id).getCanonicalName();
    String fragmentTag2 = FRAGMENT_CLASSES.get(2131624130).getCanonicalName(); //Gyro New
    //2131165353

    Log.i(TAG, String.format("Fragment Tag: %s", fragmentTag));

    if (FRAGMENT_CLASSES.get(id).getCanonicalName().equals("com.christophergs.mbientbasic.BothFragment")) {
        Log.i(TAG, String.format("Both fragment selected2: %s", fragmentTag));
        currentFragment = fragmentManager.findFragmentByTag(fragmentTag);
        currentFragment2 = fragmentManager.findFragmentByTag("com.christophergs.mbientbasic.GyroFragmentNew");
    } else {
        currentFragment = fragmentManager.findFragmentByTag(fragmentTag);
        Log.i(TAG, String.format("Did not find tag: %s", fragmentTag));
    }

    if (currentFragment == null) {
        try {
            currentFragment = FRAGMENT_CLASSES.get(id).getConstructor().newInstance();
        } catch (Exception e) {
            throw new RuntimeException("Cannot instantiate fragment", e);
        }

        transaction.add(R.id.container, currentFragment, fragmentTag);
    }

    if (FRAGMENT_CLASSES.get(id).getCanonicalName().equals("com.christophergs.mbientbasic.BothFragment")) {

        if (currentFragment2 == null) {
            try {
                currentFragment2 = FRAGMENT_CLASSES.get(2131624130).getConstructor().newInstance();//new gyro
            } catch (Exception e) {
                throw new RuntimeException("Cannot instantiate fragment", e);
            }

            transaction.add(R.id.container2, currentFragment2, fragmentTag2);
        }
    }

    if (FRAGMENT_CLASSES.get(id).getCanonicalName().equals("com.christophergs.mbientbasic.BothFragment")) {
        transaction.attach(currentFragment);
        transaction.attach(currentFragment2);
        transaction.commit();
    } else {
        transaction.attach(currentFragment);
        transaction.commit();
    }

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setTitle(item.getTitle());
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);

    return true;
}

From source file:com.example.atsuto5.yahoo_rss_reader.MainActivity.java

@SuppressWarnings("StatementWithEmptyBody")
@Override/*from  w  w  w. java  2 s  . c  o m*/
public boolean onNavigationItemSelected(MenuItem item) {

    int id = item.getItemId();

    android.app.FragmentManager fragmentManager = getFragmentManager();
    android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

    if (id == R.id.maintopics_logo) {
        fragmentTransaction.replace(R.id.fragment_container, MainTopicsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(140, 0, 0, 0);

    } else if (id == R.id.international_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InternationalFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.entertainment) {
        fragmentTransaction.replace(R.id.fragment_container, EntertainmentFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(260, 0, 0, 0);

    } else if (id == R.id.it_logo) {
        fragmentTransaction.replace(R.id.fragment_container, ItFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("IT");
        mToolbar.setTitleMargin(340, 0, 0, 0);

    } else if (id == R.id.local_logo) {
        fragmentTransaction.replace(R.id.fragment_container, LocalFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.domestic_logo) {
        fragmentTransaction.replace(R.id.fragment_container, DomesticFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.economy_logo) {
        fragmentTransaction.replace(R.id.fragment_container, EconomyFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.sports_logo) {
        fragmentTransaction.replace(R.id.fragment_container, SportsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?");
        mToolbar.setTitleMargin(260, 0, 0, 0);

    } else if (id == R.id.science_logo) {
        fragmentTransaction.replace(R.id.fragment_container, ScienceFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(320, 0, 0, 0);

    } else if (id == R.id.interestgraph_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InterestChartFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?????");
        mToolbar.setTitleMargin(200, 0, 0, 0);

    } else if (id == R.id.your_like_logo) {
        fragmentTransaction.replace(R.id.fragment_container, InterestChartFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("?????");
        mToolbar.setTitleMargin(200, 0, 0, 0);

    } else if ("License".equals(item.getTitle())) {
        fragmentTransaction.replace(R.id.fragment_container, LicenseFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("License");
        mToolbar.setTitleMargin(280, 0, 0, 0);

    } else if ("?".equals(item.getTitle())) {
        fragmentTransaction.replace(R.id.fragment_container, MainTopicsFragment.newInstance());
        fragmentTransaction.commit();
        mToolbar.setTitle("");
        mToolbar.setTitleMargin(140, 0, 0, 0);

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:org.mozilla.gecko.BrowserApp.java

private void updateAddonMenuItem(int id, JSONObject options) {
    // Set attribute for the menu item in cache, if available
    if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
        for (MenuItemInfo item : mAddonMenuItemsCache) {
            if (item.id == id) {
                item.label = options.optString("name", item.label);
                item.checkable = options.optBoolean("checkable", item.checkable);
                item.checked = options.optBoolean("checked", item.checked);
                item.enabled = options.optBoolean("enabled", item.enabled);
                item.visible = options.optBoolean("visible", item.visible);
                item.added = (mMenu != null);
                break;
            }//from w  w  w . jav a 2s.co m
        }
    }

    if (mMenu == null) {
        return;
    }

    final MenuItem menuItem = mMenu.findItem(id);
    if (menuItem != null) {
        menuItem.setTitle(options.optString("name", menuItem.getTitle().toString()));
        menuItem.setCheckable(options.optBoolean("checkable", menuItem.isCheckable()));
        menuItem.setChecked(options.optBoolean("checked", menuItem.isChecked()));
        menuItem.setEnabled(options.optBoolean("enabled", menuItem.isEnabled()));
        menuItem.setVisible(options.optBoolean("visible", menuItem.isVisible()));
    }
}

From source file:com.vuze.android.remote.fragment.TorrentListFragment.java

private void setupActionModeCallback() {
    mActionModeCallbackV7 = new Callback() {

        // Called when the action mode is created; startActionMode() was called
        @Override/*from   w ww  .  j av  a2s.c o  m*/
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onCreateActionMode");
            }

            if (mode == null && torrentListAdapter.getCheckedItemCount() == 0
                    && torrentListAdapter.getSelectedPosition() < 0) {
                return false;
            }

            Menu origMenu = menu;
            if (tb != null) {
                menu = tb.getMenu();
            }
            if (mode != null) {
                mActionMode = (mode instanceof ActionModeWrapperV7) ? mode
                        : new ActionModeWrapperV7(mode, tb, getActivity());

                mActionMode.setTitle(R.string.context_torrent_title);
            }
            ActionBarToolbarSplitter.buildActionBar(getActivity(), this, R.menu.menu_context_torrent_details,
                    menu, tb);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onCreateActionMode(mode, menu);
            }

            if (sideListArea == null) {
                SubMenu subMenu = origMenu.addSubMenu(R.string.menu_global_actions);
                subMenu.setIcon(R.drawable.ic_menu_white_24dp);
                MenuItemCompat.setShowAsAction(subMenu.getItem(), MenuItemCompat.SHOW_AS_ACTION_NEVER);

                try {
                    // Place "Global" actions on top bar in collapsed menu
                    MenuInflater mi = mode == null ? getActivity().getMenuInflater() : mode.getMenuInflater();
                    mi.inflate(R.menu.menu_torrent_list, subMenu);
                    onPrepareOptionsMenu(subMenu);
                } catch (UnsupportedOperationException e) {
                    Log.e(TAG, e.getMessage());
                    menu.removeItem(subMenu.getItem().getItemId());
                }
            }

            if (AndroidUtils.usesNavigationControl()) {
                MenuItem add = origMenu.add(R.string.select_multiple_items);
                add.setCheckable(true);
                add.setChecked(torrentListAdapter.isMultiCheckMode());
                add.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick(MenuItem item) {
                        boolean turnOn = !torrentListAdapter.isMultiCheckModeAllowed();

                        torrentListAdapter.setMultiCheckModeAllowed(turnOn);
                        if (turnOn) {
                            torrentListAdapter.setMultiCheckMode(turnOn);
                            torrentListAdapter.setItemChecked(torrentListAdapter.getSelectedPosition(), true);
                        }
                        return true;
                    }
                });
            }

            return true;
        }

        // Called each time the action mode is shown. Always called after
        // onCreateActionMode, but
        // may be called multiple times if the mode is invalidated.
        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "MULTI:onPrepareActionMode " + mode);
            }
            if (tb != null) {
                menu = tb.getMenu();
            }

            // Must be called first, because our drawer sets all menu items
            // visible.. :(
            getActivity().onPrepareOptionsMenu(menu);

            prepareContextMenu(menu);

            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                frag.onPrepareActionMode(mode, menu);
            }

            AndroidUtils.fixupMenuAlpha(menu);

            return true;
        }

        // Called when the user selects a contextual menu item
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onActionItemClicked " + item.getTitle());
            }

            if (TorrentListFragment.this.handleFragmentMenuItems(item.getItemId())) {
                return true;
            }
            if (getActivity().onOptionsItemSelected(item)) {
                return true;
            }
            TorrentDetailsFragment frag = (TorrentDetailsFragment) getActivity().getSupportFragmentManager()
                    .findFragmentById(R.id.frag_torrent_details);
            if (frag != null) {
                if (frag.onActionItemClicked(mode, item)) {
                    return true;
                }
            }
            return false;
        }

        // Called when the user exits the action mode
        @Override
        public void onDestroyActionMode(ActionMode mode) {
            if (AndroidUtils.DEBUG_MENU) {
                Log.d(TAG, "onDestroyActionMode. BeingReplaced?" + actionModeBeingReplaced);
            }

            mActionMode = null;

            if (!actionModeBeingReplaced) {
                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        torrentListAdapter.setMultiCheckMode(false);
                        torrentListAdapter.clearChecked();
                        updateCheckedIDs();
                    }
                });

                listview.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mCallback != null) {
                            mCallback.actionModeBeingReplacedDone();
                        }
                    }
                });

                listview.setLongClickable(true);
                listview.requestLayout();
                AndroidUtils.invalidateOptionsMenuHC(getActivity(), mActionMode);
            }
        }
    };
}

From source file:com.andrewshu.android.reddit.comments.CommentsListActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // This happens when the user begins to hold down the menu key, so
    // allow them to chord to get a shortcut.
    mCanChord = true;/*from   w  w w .j a va 2s .c  om*/

    super.onPrepareOptionsMenu(menu);

    MenuItem src, dest;

    menu.findItem(R.id.find_next_menu_id)
            .setVisible(last_search_string != null && last_search_string.length() > 0);

    // Login/Logout
    if (mSettings.isLoggedIn()) {
        menu.findItem(R.id.login_menu_id).setVisible(false);
        menu.findItem(R.id.inbox_menu_id).setVisible(true);
        menu.findItem(R.id.user_profile_menu_id).setVisible(true);
        menu.findItem(R.id.user_profile_menu_id).setTitle(
                String.format(getResources().getString(R.string.user_profile), mSettings.getUsername()));
        menu.findItem(R.id.logout_menu_id).setVisible(true);
        menu.findItem(R.id.logout_menu_id)
                .setTitle(String.format(getResources().getString(R.string.logout), mSettings.getUsername()));
    } else {
        menu.findItem(R.id.login_menu_id).setVisible(true);
        menu.findItem(R.id.inbox_menu_id).setVisible(false);
        menu.findItem(R.id.user_profile_menu_id).setVisible(false);
        menu.findItem(R.id.logout_menu_id).setVisible(false);
    }

    // Edit and delete
    if (getOpThingInfo() != null) {
        if (mSettings.getUsername() != null
                && mSettings.getUsername().equalsIgnoreCase(getOpThingInfo().getAuthor())) {
            if (getOpThingInfo().isIs_self())
                menu.findItem(R.id.op_edit_menu_id).setVisible(true);
            else
                menu.findItem(R.id.op_edit_menu_id).setVisible(false);
            menu.findItem(R.id.op_delete_menu_id).setVisible(true);
        } else {
            menu.findItem(R.id.op_edit_menu_id).setVisible(false);
            menu.findItem(R.id.op_delete_menu_id).setVisible(false);
        }
    }

    // Theme: Light/Dark
    src = Util.isLightTheme(mSettings.getTheme()) ? menu.findItem(R.id.dark_menu_id)
            : menu.findItem(R.id.light_menu_id);
    dest = menu.findItem(R.id.light_dark_menu_id);
    dest.setTitle(src.getTitle());

    // Sort
    if (Constants.CommentsSort.SORT_BY_BEST_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_best_menu_id);
    else if (Constants.CommentsSort.SORT_BY_HOT_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_hot_menu_id);
    else if (Constants.CommentsSort.SORT_BY_NEW_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_new_menu_id);
    else if (Constants.CommentsSort.SORT_BY_CONTROVERSIAL_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_controversial_menu_id);
    else if (Constants.CommentsSort.SORT_BY_TOP_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_top_menu_id);
    else if (Constants.CommentsSort.SORT_BY_OLD_URL.equals(mSettings.getCommentsSortByUrl()))
        src = menu.findItem(R.id.sort_by_old_menu_id);
    dest = menu.findItem(R.id.sort_by_menu_id);
    dest.setTitle(src.getTitle());

    return true;
}

From source file:org.brandroid.openmanager.activities.OpenExplorer.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (DEBUG)// www.  jav  a2 s  .  co  m
        Logger.LogDebug("OpenExplorer.onKeyUp(" + keyCode + "," + event + ")");
    if (event.getAction() != KeyEvent.ACTION_UP)
        return super.onKeyUp(keyCode, event);
    if (MenuUtils.getMenuShortcut(event) != null) {
        if (getCurrentFocus() != null) {
            View cf = getCurrentFocus();
            if (cf instanceof TextView)
                return false;
        }
        MenuItem item = MenuUtils.getMenuShortcut(event);
        if (item != null)
            if (onOptionsItemSelected(item)) {
                showToast(item.getTitle(), Toast.LENGTH_SHORT);
                return true;
            }
    }
    if (keyCode == KeyEvent.KEYCODE_MENU && USE_PRETTY_MENUS) {
        View more = findViewById(R.id.menu_more);
        if (more != null && more.isShown() && more.isClickable() && more.performClick()) {
            Logger.LogDebug("!SHOULD BE HERE!");
            return true;
        } else {
            Logger.LogWarning("Couldn't find \"More Menu\"!");
            MenuBuilder menu = new MenuBuilder(this);
            getSelectedFragment().onCreateOptionsMenu(menu, getMenuInflater());
            getMenuInflater().inflate(R.menu.global, menu);
            onPrepareOptionsMenu(menu);
            showMenu(menu, getCurrentFocus(), true);
        }
    } else if (keyCode == KeyEvent.KEYCODE_BOOKMARK) {
        OpenPath path = getDirContentFragment(false).getPath();
        if (mBookmarks.hasBookmark(path))
            addBookmark(path);
        else
            removeBookmark(path);
    } else if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) {
        int pos = keyCode - KeyEvent.KEYCODE_1;
        if (mToolbarButtons != null) {
            if (pos < mToolbarButtons.getChildCount() && mToolbarButtons.getChildAt(pos).performClick())
                return true;
            return false;
        }
        if (mOptsMenu != null && pos < mOptsMenu.size())
            return onOptionsItemSelected(mOptsMenu.getItem(pos));
        if (mMainMenu != null && pos < mMainMenu.size())
            return onOptionsItemSelected(mMainMenu.getItem(pos));
    }
    /*
    if (keyCode == KeyEvent.KEYCODE_BACK) {
       if (mBackQuit) {
    return super.onKeyUp(keyCode, event);
       } else {
    Toast.makeText(this, "Press back again to quit", Toast.LENGTH_SHORT).show();
    mBackQuit = true;
    return true;
       }      
    }*/
    return super.onKeyUp(keyCode, event);
}