Example usage for android.view MenuItem setChecked

List of usage examples for android.view MenuItem setChecked

Introduction

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

Prototype

public MenuItem setChecked(boolean checked);

Source Link

Document

Control whether this item is shown with a check mark.

Usage

From source file:com.adnanbal.fxdedektifi.forex.presentation.view.activity.SignalsActivity.java

public void selectDrawerItem(MenuItem menuItem) {
    // Create a new fragment and specify the fragment to show based on nav item clicked

    switch (menuItem.getItemId()) {
    case R.id.nav_item_signals_fragment:
        bottomNavigationView.setVisibility(View.VISIBLE);
        getSupportActionBar().setTitle(R.string.signals);
        addFragment(com.adnanbal.fxdedektifi.forex.presentation.R.id.fragmentContainer, new SignalsFragment());
        break;// w  ww  .  j  av a  2  s.  c o  m
    case R.id.nav_item_profit_fragment:
        //        bottomNavigationView.setVisibility(View.VISIBLE);
        getSupportActionBar().setTitle(R.string.profit);
        addFragment(com.adnanbal.fxdedektifi.forex.presentation.R.id.fragmentContainer, new ProfitFragment());
        break;

    case R.id.nav_item_my_account_fragment:
        bottomNavigationView.setVisibility(View.GONE);
        getSupportActionBar().setTitle(R.string.my_account);
        addFragment(com.adnanbal.fxdedektifi.forex.presentation.R.id.fragmentContainer,
                new AccountAndSubscriptionsFragment());
        break;

    default:
        getSupportActionBar().setTitle(R.string.signals);
        addFragment(com.adnanbal.fxdedektifi.forex.presentation.R.id.fragmentContainer, new SignalsFragment());
    }

    // Highlight the selected item has been done by NavigationView
    menuItem.setChecked(true);

    // Close the navigation drawer
    mDrawer.closeDrawers();
}

From source file:id.ridon.keude.AppDetailsData.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {

    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;

    case LAUNCH:/*w w  w  . ja v  a 2  s  . c  o m*/
        launchApk(app.id);
        return true;

    case SHARE:
        shareApp(app);
        return true;

    case INSTALL:
        // Note that this handles updating as well as installing.
        if (app.suggestedVercode > 0) {
            final Apk apkToInstall = ApkProvider.Helper.find(this, app.id, app.suggestedVercode);
            install(apkToInstall);
        }
        return true;

    case UNINSTALL:
        removeApk(app.id);
        return true;

    case IGNOREALL:
        app.ignoreAllUpdates ^= true;
        item.setChecked(app.ignoreAllUpdates);
        return true;

    case IGNORETHIS:
        if (app.ignoreThisUpdate >= app.suggestedVercode)
            app.ignoreThisUpdate = 0;
        else
            app.ignoreThisUpdate = app.suggestedVercode;
        item.setChecked(app.ignoreThisUpdate > 0);
        return true;

    case WEBSITE:
        tryOpenUri(app.webURL);
        return true;

    case ISSUES:
        tryOpenUri(app.trackerURL);
        return true;

    case SOURCE:
        tryOpenUri(app.sourceURL);
        return true;

    case BITCOIN:
        tryOpenUri("bitcoin:" + app.bitcoinAddr);
        return true;

    case LITECOIN:
        tryOpenUri("litecoin:" + app.litecoinAddr);
        return true;

    case DOGECOIN:
        tryOpenUri("dogecoin:" + app.dogecoinAddr);
        return true;

    case FLATTR:
        tryOpenUri("https://flattr.com/thing/" + app.flattrID);
        return true;

    case DONATE_URL:
        tryOpenUri(app.donateURL);
        return true;

    case SEND_VIA_BLUETOOTH:
        /*
         * If Bluetooth has not been enabled/turned on, then
         * enabling device discoverability will automatically enable Bluetooth
         */
        Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
        discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121);
        startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH);
        // if this is successful, the Bluetooth transfer is started
        return true;

    }
    return super.onOptionsItemSelected(item);
}

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 w  w .  ja v  a  2s  .  c om
        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.vmihalachi.turboeditor.fragment.EditorFragment.java

/**
 * {@inheritDoc}//w  w  w  .j a va2 s .  co  m
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == R.id.im_save) {
        new SaveFile().execute();
    } else if (i == R.id.im_undo) {
        this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Z, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Z));
    } else if (i == R.id.im_redo) {
        this.mEditor.onKeyShortcut(KeyEvent.KEYCODE_Y, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_Y));
    } else if (i == R.id.im_editor_encoding) {
        EditDialogFragment dialogFrag = EditDialogFragment.newInstance(EditDialogFragment.Actions.Encoding,
                this.mCurrentEncoding);
        dialogFrag.setTargetFragment(this, 0);
        dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
    } else if (i == R.id.im_text_size) {
        int fontMax = 36;
        float scaledDensity = getResources().getDisplayMetrics().scaledDensity;
        int fontCurrent = (int) (mEditor.getTextSize() / scaledDensity);
        SeekbarDialogFragment dialogFrag = SeekbarDialogFragment
                .newInstance(SeekbarDialogFragment.Actions.FileSize, fontCurrent, fontMax);
        dialogFrag.setTargetFragment(this, 0);
        dialogFrag.show(getFragmentManager().beginTransaction(), "dialog");
    } else if (i == R.id.im_syntax_highlight) {
        item.setChecked(!item.isChecked());
        PreferenceHelper.setSyntaxHiglight(getActivity(), item.isChecked());
        updateTextEditor();
    } else if (i == R.id.im_line_numbers) {
        item.setChecked(!item.isChecked());
        PreferenceHelper.setLineNumbers(getActivity(), item.isChecked());
        updateTextEditor();
    } else if (i == R.id.im_use_monospace) {
        item.setChecked(!item.isChecked());
        PreferenceHelper.setUseMonospace(getActivity(), item.isChecked());
        updateTextEditor();
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.iiordanov.runsoft.bVNC.RemoteCanvasActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    canvas.getKeyboard().setAfterMenu(true);
    switch (item.getItemId()) {
    case R.id.itemInfo:
        canvas.showConnectionInfo();//from  w  ww.j a  v  a2 s .  com
        return true;
    case R.id.itemSpecialKeys:
        showDialog(R.layout.metakey);
        return true;
    //        case R.id.itemColorMode:
    //            selectColorModel();
    //            return true;
    // Following sets one of the scaling options
    case R.id.itemZoomable:
    case R.id.itemOneToOne:
    case R.id.itemFitToScreen:
        AbstractScaling.getById(item.getItemId()).setScaleTypeForActivity(this);
        item.setChecked(true);
        showPanningState(false);
        return true;
    case R.id.itemCenterMouse:
        canvas.getPointer().warpMouse(canvas.absoluteXPosition + canvas.getVisibleWidth() / 2,
                canvas.absoluteYPosition + canvas.getVisibleHeight() / 2);
        return true;
    case R.id.itemDisconnect:

        canvas.closeConnection();
        finish();
        return true;
    //        case R.id.itemEnterText:
    //            showDialog(R.layout.entertext);
    //            return true;
    case R.id.itemCtrlAltDel:
        canvas.getKeyboard().sendMetaKey(MetaKeyBean.keyCtrlAltDel);
        return true;
    /*        case R.id.itemFollowMouse:
    boolean newFollow = !connection.getFollowMouse();
    item.setChecked(newFollow);
    connection.setFollowMouse(newFollow);
    if (newFollow) {
        vncCanvas.panToMouse();
    }
    connection.save(database.getWritableDatabase());
    database.close();
    return true;
            case R.id.itemFollowPan:
    boolean newFollowPan = !connection.getFollowPan();
    item.setChecked(newFollowPan);
    connection.setFollowPan(newFollowPan);
    connection.save(database.getWritableDatabase());
    database.close();
    return true;
             
            case R.id.itemArrowLeft:
    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft);
    return true;
            case R.id.itemArrowUp:
    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowUp);
    return true;
            case R.id.itemArrowRight:
    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowRight);
    return true;
            case R.id.itemArrowDown:
    vncCanvas.sendMetaKey(MetaKeyBean.keyArrowDown);
    return true;
    */
    case R.id.itemSendKeyAgain:
        sendSpecialKeyAgain();
        return true;
    // Disabling Manual/Wiki Menu item as the original does not correspond to this project anymore.
    //case R.id.itemOpenDoc:
    //    Utils.showDocumentation(this);
    //    return true;
    case R.id.itemExtraKeys:
        if (connection.getExtraKeysToggleType() == Constants.EXTRA_KEYS_ON) {
            connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_OFF);
            item.setTitle(R.string.extra_keys_enable);
            setExtraKeysVisibility(View.GONE, false);
        } else {
            connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_ON);
            item.setTitle(R.string.extra_keys_disable);
            setExtraKeysVisibility(View.VISIBLE, false);
            extraKeysHidden = false;
        }
        setKeyStowDrawableAndVisibility();
        connection.save(database.getWritableDatabase());
        database.close();
        return true;
    case R.id.itemHelpInputMode:
        showDialog(R.id.itemHelpInputMode);
        return true;
    default:
        AbstractInputHandler input = getInputHandlerById(item.getItemId());
        if (input != null) {
            inputHandler = input;
            connection.setInputMode(input.getName());
            if (input.getName().equals(SimulatedTouchpadInputHandler.TOUCHPAD_MODE)) {
                connection.setFollowMouse(true);
                connection.setFollowPan(true);
            } else {
                connection.setFollowMouse(false);
                connection.setFollowPan(false);
            }

            item.setChecked(true);
            showPanningState(true);
            connection.save(database.getWritableDatabase());
            database.close();
            return true;
        }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.irccloud.android.activity.PastebinViewerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();// w  w w . j  a v a2s  .com
        if (getWindowManager().getDefaultDisplay().getWidth() < TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 800, getResources().getDisplayMetrics())
                || isMultiWindow())
            overridePendingTransition(R.anim.fade_in, R.anim.slide_out_right);
        return true;
    } else if (item.getItemId() == R.id.delete) {
        if (Uri.parse(url).getQueryParameter("own_paste").equals("1")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(PastebinViewerActivity.this);
            builder.setTitle("Delete Snippet");
            builder.setMessage("Are you sure you want to delete this snippet?");
            builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    NetworkConnection.getInstance().delete_paste(Uri.parse(url).getQueryParameter("id"));
                    finish();
                    Toast.makeText(PastebinViewerActivity.this, "Snippet deleted", Toast.LENGTH_SHORT).show();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(PastebinViewerActivity.this);
            d.show();
        }
    } else if (item.getItemId() == R.id.action_linenumbers) {
        item.setChecked(!item.isChecked());
        mWebView.loadUrl("javascript:window.PASTEVIEW.doToggleLines()");
    } else if (item.getItemId() == R.id.action_browser) {
        if (!PreferenceManager
                .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
                .getBoolean("browser", false)
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            builder.setToolbarColor(ColorScheme.getInstance().navBarColor);
            builder.addDefaultShareMenuItem();
            builder.addMenuItem("Copy URL",
                    PendingIntent.getBroadcast(this, 0, new Intent(this, ChromeCopyLinkBroadcastReceiver.class),
                            PendingIntent.FLAG_UPDATE_CURRENT));

            CustomTabsIntent intent = builder.build();
            intent.intent.setData(Uri.parse(url.contains("?") ? url.substring(0, url.indexOf("?")) : url));
            if (Build.VERSION.SDK_INT >= 22)
                intent.intent.putExtra(Intent.EXTRA_REFERRER,
                        Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getPackageName()));
            if (Build.VERSION.SDK_INT >= 16 && intent.startAnimationBundle != null) {
                startActivity(intent.intent, intent.startAnimationBundle);
            } else {
                startActivity(intent.intent);
            }
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url.contains("?") ? url.substring(0, url.indexOf("?")) : url));
            startActivity(intent);
        }
        finish();
        return true;
    } else if (item.getItemId() == R.id.action_copy) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            if (url.contains("?"))
                clipboard.setText(url.substring(0, url.indexOf("?")));
            else
                clipboard.setText(url);
        } else {
            @SuppressLint("ServiceCast")
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            android.content.ClipData clip;
            if (url.contains("?"))
                clip = android.content.ClipData.newRawUri("IRCCloud Snippet URL",
                        Uri.parse(url.substring(0, url.indexOf("?"))));
            else
                clip = android.content.ClipData.newRawUri("IRCCloud Snippet URL", Uri.parse(url));
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(PastebinViewerActivity.this, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
    } else if (item.getItemId() == R.id.action_share) {
        if (getIntent() != null && getIntent().getDataString() != null) {
            Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(url));
            intent.setType("text/plain");
            if (url.contains("?"))
                intent.putExtra(Intent.EXTRA_TEXT, url.substring(0, url.indexOf("?")));
            else
                intent.putExtra(Intent.EXTRA_TEXT, url);
            intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
            intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                    getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(Intent.createChooser(intent, "Share Snippet"));
            Answers.getInstance().logShare(new ShareEvent().putContentType("Pastebin"));
        }
    } else if (item.getItemId() == R.id.action_edit) {
        mSpinner.setVisibility(View.VISIBLE);
        Intent i = new Intent(this, PastebinEditorActivity.class);
        i.putExtra("paste_id", Uri.parse(url).getQueryParameter("id"));
        startActivityForResult(i, 1);
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.stoutner.privacybrowser.MainWebViewActivity.java

@Override
// Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.
@SuppressLint("SetJavaScriptEnabled")
// removeAllCookies is deprecated, but it is required for API < 21.
@SuppressWarnings("deprecation")
public boolean onOptionsItemSelected(MenuItem menuItem) {
    int menuItemId = menuItem.getItemId();

    // Set the commands that relate to the menu entries.
    switch (menuItemId) {
    case R.id.toggleJavaScript:
        // Switch the status of javaScriptEnabled.
        javaScriptEnabled = !javaScriptEnabled;

        // Apply the new JavaScript status.
        mainWebView.getSettings().setJavaScriptEnabled(javaScriptEnabled);

        // Update the privacy icon.
        updatePrivacyIcon();//ww w.  j a v a2 s  .  c om

        // Display a Snackbar.
        if (javaScriptEnabled) {
            Snackbar.make(findViewById(R.id.mainWebView), R.string.javascript_enabled, Snackbar.LENGTH_SHORT)
                    .show();
        } else {
            if (domStorageEnabled || firstPartyCookiesEnabled) {
                Snackbar.make(findViewById(R.id.mainWebView), R.string.javascript_disabled,
                        Snackbar.LENGTH_SHORT).show();
            } else {
                Snackbar.make(findViewById(R.id.mainWebView), R.string.privacy_mode, Snackbar.LENGTH_SHORT)
                        .show();
            }
        }

        // Reload the WebView.
        mainWebView.reload();
        return true;

    case R.id.toggleFirstPartyCookies:
        // Switch the status of firstPartyCookiesEnabled.
        firstPartyCookiesEnabled = !firstPartyCookiesEnabled;

        // Update the menu checkbox.
        menuItem.setChecked(firstPartyCookiesEnabled);

        // Apply the new cookie status.
        cookieManager.setAcceptCookie(firstPartyCookiesEnabled);

        // Update the privacy icon.
        updatePrivacyIcon();

        // Reload the WebView.
        mainWebView.reload();
        return true;

    case R.id.toggleThirdPartyCookies:
        if (Build.VERSION.SDK_INT >= 21) {
            // Switch the status of thirdPartyCookiesEnabled.
            thirdPartyCookiesEnabled = !thirdPartyCookiesEnabled;

            // Update the menu checkbox.
            menuItem.setChecked(thirdPartyCookiesEnabled);

            // Apply the new cookie status.
            cookieManager.setAcceptThirdPartyCookies(mainWebView, thirdPartyCookiesEnabled);

            // Reload the WebView.
            mainWebView.reload();
        } // Else do nothing because SDK < 21.
        return true;

    case R.id.toggleDomStorage:
        // Switch the status of domStorageEnabled.
        domStorageEnabled = !domStorageEnabled;

        // Update the menu checkbox.
        menuItem.setChecked(domStorageEnabled);

        // Apply the new DOM Storage status.
        mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled);

        // Update the privacy icon.
        updatePrivacyIcon();

        // Reload the WebView.
        mainWebView.reload();
        return true;

    case R.id.clearCookies:
        if (Build.VERSION.SDK_INT < 21) {
            cookieManager.removeAllCookie();
        } else {
            cookieManager.removeAllCookies(null);
        }
        Snackbar.make(findViewById(R.id.mainWebView), R.string.cookies_deleted, Snackbar.LENGTH_SHORT).show();
        return true;

    case R.id.clearDomStorage:
        WebStorage webStorage = WebStorage.getInstance();
        webStorage.deleteAllData();
        Snackbar.make(findViewById(R.id.mainWebView), R.string.dom_storage_deleted, Snackbar.LENGTH_SHORT)
                .show();
        return true;

    case R.id.share:
        Intent shareIntent = new Intent();
        shareIntent.setAction(Intent.ACTION_SEND);
        shareIntent.putExtra(Intent.EXTRA_TEXT, urlTextBox.getText().toString());
        shareIntent.setType("text/plain");
        startActivity(Intent.createChooser(shareIntent, "Share URL"));
        return true;

    case R.id.addToHomescreen:
        // Show the CreateHomeScreenShortcut AlertDialog and name this instance createShortcut.
        AppCompatDialogFragment shortcutDialog = new CreateHomeScreenShortcut();
        shortcutDialog.show(getSupportFragmentManager(), "createShortcut");

        //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below.
        return true;

    case R.id.refresh:
        mainWebView.reload();
        return true;

    default:
        // Don't consume the event.
        return super.onOptionsItemSelected(menuItem);
    }
}

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

/**
 * Override Activity lifecycle method.// www.  ja  va 2 s  .c o m
 */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem sbs = menu.findItem(R.id.action_sbs);
    MenuItem tv = menu.findItem(R.id.action_3dtv);
    MenuItem ag = menu.findItem(R.id.action_anaglyph);
    MenuItem sw = menu.findItem(R.id.action_swap);
    MenuItem gs = menu.findItem(R.id.action_grayscale);

    switch (mDisplayMode) {
    case SbsFull:
        sbs.setChecked(true);
        sw.setEnabled(true);
        if (mDisplaySwap) {
            sbs.setIcon(R.drawable.ic_crossed_eye);
            sbs.setTitle(R.string.action_sbs_cross);
        } else {
            sbs.setIcon(R.drawable.ic_parallel_eye_white);
            sbs.setTitle(R.string.action_sbs_parallel);
        }
        break;
    case SbsHalf:
        tv.setChecked(true);
        sw.setEnabled(false);
        break;
    case Anaglyph:
        ag.setChecked(true);
        sw.setEnabled(true);
        if (mDisplaySwap) {
            ag.setIcon(R.drawable.ic_cyan_red);
            ag.setTitle(R.string.action_anaglyph_cyanred);
        } else {
            ag.setIcon(R.drawable.ic_red_cyan);
            ag.setTitle(R.string.action_anaglyph_redcyan);
        }
        break;
    default:
        break;
    }

    if (mDisplaySwap) {
        sw.setChecked(true);
    } else {
        sw.setChecked(false);
    }

    if (mDisplayColor) {
        gs.setChecked(false);
    } else {
        gs.setChecked(true);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.klinker.android.twitter.ui.search.SearchPager.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case android.R.id.home:
        sharedPrefs.edit().putBoolean("should_refresh", false).commit();
        onBackPressed();/* w ww .  j  av  a  2 s  .c o  m*/
        return true;

    case R.id.menu_settings:
        Intent settings = new Intent(context, SettingsActivity.class);
        startActivityForResult(settings, SETTINGS_RESULT);
        return true;

    case R.id.menu_save_search:
        Toast.makeText(context, getString(R.string.saving_search), Toast.LENGTH_SHORT).show();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context));
                    twitter.createSavedSearch(searchQuery);

                    ((Activity) context).runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Toast.makeText(context, getString(R.string.success), Toast.LENGTH_SHORT).show();
                        }
                    });
                } catch (TwitterException e) {
                    // something went wrong
                }
            }
        }).start();
        return super.onOptionsItemSelected(item);

    case R.id.menu_compose_with_search:
        Intent compose = new Intent(context, ComposeActivity.class);
        compose.putExtra("user", searchQuery);
        startActivity(compose);
        return super.onOptionsItemSelected(item);

    case R.id.menu_search:
        //overridePendingTransition(0,0);
        //finish();
        //overridePendingTransition(0,0);
        //return super.onOptionsItemSelected(item);

    case R.id.menu_pic_filter:
        if (!item.isChecked()) {
            searchQuery += " filter:links twitter.com";
            item.setChecked(true);
        } else {
            searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", "");
            item.setChecked(false);
        }

        Intent broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
        broadcast.putExtra("query", searchQuery);
        context.sendBroadcast(broadcast);

        return super.onOptionsItemSelected(item);

    case R.id.menu_remove_rt:
        if (!item.isChecked()) {
            searchQuery += " -RT";
            item.setChecked(true);
        } else {
            searchQuery = searchQuery.replace(" -RT", "");
            item.setChecked(false);
        }

        broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
        broadcast.putExtra("query", searchQuery);
        context.sendBroadcast(broadcast);

        return super.onOptionsItemSelected(item);

    case R.id.menu_show_top_tweets:
        if (!item.isChecked()) {
            searchQuery += " TOP";
            item.setChecked(true);
        } else {
            searchQuery = searchQuery.replace(" TOP", "");
            item.setChecked(false);
        }

        broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH");
        broadcast.putExtra("query", searchQuery);
        context.sendBroadcast(broadcast);

        return super.onOptionsItemSelected(item);

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:io.apptik.multiview.AnimatorsFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (recyclerView == null)
        return false;
    switch (item.getItemId()) {
    case R.id.action_text_only:
        recyclerView.setAdapter(recyclerAdapter);
        break;/*from  w w w.jav  a2 s  .  c  om*/
    case R.id.action_image_only:
        break;
    case R.id.action_Image_text:
        recyclerView.setAdapter(recyclerMixedAdapter);
        break;

    case R.id.action_layout_linear:
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        break;
    case R.id.action_layout_grid:
        recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
        break;
    case R.id.action_layout_staggered:
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        break;

    case R.id.action_rv_add:
        resetItemAnimator();
        recyclerAdapter.jarr.put(1, MockData.getRandomEntry(1, 500));
        recyclerView.getAdapter().notifyItemInserted(1);
        break;
    case R.id.action_rv_remove:
        resetItemAnimator();
        recyclerAdapter.jarr.remove(1);
        recyclerView.getAdapter().notifyItemRemoved(1);
        break;
    case R.id.action_rv_move:
        resetItemAnimator();
        recyclerAdapter.jarr.put(2, recyclerAdapter.jarr.get(1));
        recyclerAdapter.jarr.put(1, MockData.getRandomEntry(1, 500));
        recyclerView.getAdapter().notifyItemMoved(1, 2);
        break;
    case R.id.action_rv_change:
        resetItemAnimator();
        recyclerAdapter.jarr.put(1, MockData.getRandomEntry(1, 500));
        recyclerView.getAdapter().notifyItemChanged(1);
        break;

    case R.id.action_add_animation_default:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.defaultAddAnimProvider();
        }
        break;
    case R.id.action_add_animation_garagedoor:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.garageDoorAddProvider();
        }
        break;

    case R.id.action_remove_animation_default:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.defaultRemoveAnimProvider();
        }
        break;
    case R.id.action_remove_animation_garagedoor:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.garageDoorRemoveProvider();
        }
        break;
    case R.id.action_add_animation_slide_to_left:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.slideInRightProvider();
        }
        break;
    case R.id.action_remove_animation_slide_to_left:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.slideOutLeftProvider();
        }
        break;
    case R.id.action_add_animation_slide_to_right:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.slideInLeftProvider();
        }
        break;
    case R.id.action_remove_animation_slide_to_right:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.slideOutRightProvider();
        }
        break;

    case R.id.action_add_animation_slide_to_top:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.slideInBottomProvider();
        }
        break;
    case R.id.action_remove_animation_slide_to_top:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.slideOutTopProvider();
        }
        break;
    case R.id.action_add_animation_slide_to_bottom:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.slideInTopProvider();
        }
        break;
    case R.id.action_remove_animation_slide_to_bottom:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.slideOutBottomProvider();
        }
        break;
    case R.id.action_add_animation_zoom_to_left:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.zoomInEnterRightProvider();
        }
        break;
    case R.id.action_remove_animation_zoom_to_left:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.zoomInExitLeftProvider();
        }
        break;
    case R.id.action_add_animation_zoom_to_right:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.zoomInEnterLeftProvider();
        }
        break;
    case R.id.action_remove_animation_zoom_to_right:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.zoomOutExitRightProvider();
        }
        break;

    case R.id.action_add_animation_zoom_to_top:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.zoomInEnterBottomProvider();
        }
        break;
    case R.id.action_remove_animation_zoom_to_top:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.zoomOutExitTopProvider();
        }
        break;
    case R.id.action_add_animation_zoom_to_bottom:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.zoomInEnterTopProvider();
        }
        break;
    case R.id.action_remove_animation_zoom_to_bottom:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.zoomOutExitBottomProvider();
        }
        break;

    case R.id.action_add_animation_flip_to_left:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.flipEnterRightProvider();
        }
        break;
    case R.id.action_remove_animation_flip_to_left:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.flipExitLeftProvider();
        }
        break;
    case R.id.action_add_animation_flip_to_right:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.flipEnterLeftProvider();
        }
        break;
    case R.id.action_remove_animation_flip_to_right:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.flipExitRightProvider();
        }
        break;

    case R.id.action_add_animation_flip_to_top:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.flipEnterBottomProvider();
        }
        break;
    case R.id.action_remove_animation_flip_to_top:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.flipExitTopProvider();
        }
        break;
    case R.id.action_add_animation_flip_to_bottom:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            addProvider = Providers.flipEnterTopProvider();
        }
        break;
    case R.id.action_remove_animation_flip_to_bottom:
        if (item.isChecked()) {
            item.setChecked(false);
        } else {
            item.setChecked(true);
            removeProvider = Providers.flipExitBottomProvider();
        }
        break;

    }
    return true;
}