Example usage for android.view MenuItem isChecked

List of usage examples for android.view MenuItem isChecked

Introduction

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

Prototype

public boolean isChecked();

Source Link

Document

Return whether the item is currently displaying a check mark.

Usage

From source file:ngoc.com.pedometer.ui.Fragment_Overview.java

private void setUpNavigationView() {
    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override/*w  w  w  .j av  a2s.c  o  m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {
            //Replacing the main content with ContentFragment Which is our Inbox View;
            case R.id.action_settings:
                drawer.closeDrawers();

                ActivityOptionsCompat options = ActivityOptionsCompat.makeCustomAnimation(getActivity(),
                        R.anim.push_in_to_right, R.anim.push_in_to_left);
                Intent intent = new Intent(getActivity(), SettingActivity.class);

                ((Activity) getActivity()).startActivity(intent, options.toBundle());

                break;
            case R.id.action_split_count:
                drawer.closeDrawers();
                Dialog_Split.getDialog(getActivity(), total_start + Math.max(todayOffset + since_boot, 0))
                        .show();
                break;
            case R.id.action_faq:
                drawer.closeDrawers();
                FAQDialog.getInstance().show(getActivity());

                break;

            case R.id.action_about:
                drawer.closeDrawers();
                showAboutDialog();

                break;

            default:
            }

            //Checking if the item is in checked state or not, if not make it in checked state
            if (menuItem.isChecked()) {
                menuItem.setChecked(false);
            } else {
                menuItem.setChecked(true);
            }
            menuItem.setChecked(true);

            return true;
        }
    });

    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(getActivity(), drawer, toolbar,
            R.string.openDrawer, R.string.closeDrawer) {

        @Override
        public void onDrawerClosed(View drawerView) {
            // Code here will be triggered once the drawer closes as we dont want anything to happen so we leave this blank
            super.onDrawerClosed(drawerView);
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            // Code here will be triggered once the drawer open as we dont want anything to happen so we leave this blank
            super.onDrawerOpened(drawerView);
        }
    };

    //Setting the actionbarToggle to drawer layout
    drawer.addDrawerListener(actionBarDrawerToggle);

    //calling sync state is necessary or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();

}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    ((OsmTemplateApplication) getApplication()).init(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_map);

    ((OsmTemplateApplication) getApplication()).getOsmTemplateComponent().inject(this);
    ButterKnife.bind(this);

    PreferenceManager.setDefaultValues(this, R.xml.pref_accessibility, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_connection, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_data_sync, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_general, false);
    PreferenceManager.setDefaultValues(this, R.xml.pref_notification, false);
    setSupportActionBar(toolbar);/*  w  w w  . ja  v a 2  s . c  o  m*/

    eventBus.post(new UpdateFirstConnectionEvent());
    checkFirstStart();

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getGroupId()) {
            case R.id.drawer_options_group:
                onOptionsClick(menuItem);
                break;
            case R.id.sync:
                onOptionsSyncClick(menuItem);
                break;
            }
            return true;
        }
    });
    filterView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            if (menuItem.getItemId() == R.id.select_all_item) {
                selectAllMenuItem.setChecked(!selectAllMenuItem.isChecked());
                onSelectAllClick();
            } else if (menuItem.getItemId() != R.id.display_open_notes_item
                    && menuItem.getItemId() != R.id.display_closed_notes_item
                    && menuItem.getItemId() != R.id.display_yes_accessibility
                    && menuItem.getItemId() != R.id.display_limited_accessibility
                    && menuItem.getItemId() != R.id.display_no_accessibility
                    && menuItem.getItemId() != R.id.display_unknown_accessibility) {
                menuItem.setChecked(!menuItem.isChecked());
                onFilterItemClick(menuItem);
            } else {
                menuItem.setChecked(!menuItem.isChecked());
                onOtherItemClick(menuItem);
            }
            return true;
        }
    });

    selectAllMenuItem = filterView.getMenu().findItem(R.id.select_all_item);

    if (configManager.hasPoiAddition()) {
        navigationView.getMenu().findItem(R.id.replay_tuto_menu).setVisible(true);
    }

    navigationView.getMenu().findItem(R.id.save_changes).setEnabled(false);

    drawerLayout.setDrawerListener(new DrawerLayout.DrawerListener() {
        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {

        }

        @Override
        public void onDrawerOpened(View drawerView) {
            eventBus.post(new PleaseTellIfDbChanges());
        }

        @Override
        public void onDrawerClosed(View drawerView) {

        }

        @Override
        public void onDrawerStateChanged(int newState) {

        }
    });

    if (FlavorUtils.isBus()) {
        eventBus.post(new PleaseApplyNoteFilterEvent(false, false));
        List<Poi.AccessibilityType> accessibilityTypesToHide = new ArrayList<>();
        eventBus.post(new PleaseApplyAccessibilityFilter(accessibilityTypesToHide));
    }
    navigationView.getMenu().findItem(R.id.manage_poi_types)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    startPoiTypeEditionActivity();
                    return true;
                }
            });

    // Get the arpi fragment.
    arpiGlFragment = (ArpiGlFragment) getFragmentManager().findFragmentById(R.id.engine_fragment);
    getFragmentManager().beginTransaction().hide(arpiGlFragment).commit();

    if (sharedPreferences.getBoolean(getString(R.string.easter_egg), false)) {
        navigationView.getMenu().findItem(R.id.arpi_view).setVisible(true);
    }
}

From source file:com.free.searcher.MainFragment.java

public boolean regex(MenuItem item) {
    item.setChecked(!item.isChecked());
    MainActivity.checkRE = item.isChecked();
    Log.d("checkRE", "" + MainActivity.checkRE);
    ((MainActivity) activity).mSearchView.requestFocus();
    return true;//from   w w w. j a va2  s.  c  o  m
}

From source file:com.vmihalachi.turboeditor.fragment.EditorFragment.java

/**
 * {@inheritDoc}/*from  w  w w.  jav  a 2 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.maxwen.wallpaper.board.activities.WallpaperBoardActivity.java

public void initMainActivity(@Nullable Bundle savedInstanceState, boolean isLicenseCheckerEnabled,
        @NonNull byte[] salt, @NonNull String licenseKey, @NonNull String[] donationProductsId) {
    super.setTheme(Preferences.getPreferences(this).isDarkTheme() ? R.style.AppThemeDark : R.style.AppTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wallpaper_board);
    ButterKnife.bind(this);

    ViewHelper.resetNavigationBarTranslucent(this, getResources().getConfiguration().orientation);

    ColorHelper.setStatusBarIconColor(this);
    registerBroadcastReceiver();//w w w  .  j  a  va  2s .c  o  m

    SoftKeyboardHelper softKeyboardHelper = new SoftKeyboardHelper(this, findViewById(R.id.container));
    softKeyboardHelper.enable();

    mFragManager = getSupportFragmentManager();
    mLicenseKey = licenseKey;
    mDonationProductsId = donationProductsId;

    Toolbar toolbar = ButterKnife.findById(this, R.id.toolbar);
    toolbar.setTitle("");

    ViewHelper.setupToolbar(toolbar, true);
    setSupportActionBar(toolbar);

    mBottomNavigationView.setOnNavigationItemSelectedListener(
            new BottomNavigationViewNew.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    int id = item.getItemId();
                    int newPosition = -1;
                    if (id == R.id.navigation_view_wallpapers) {
                        newPosition = 0;
                    }
                    if (id == R.id.navigation_view_favorites) {
                        newPosition = 2;
                    }
                    if (id == R.id.navigation_view_categories) {
                        newPosition = 1;
                    }
                    if (id == R.id.navigation_view_new) {
                        newPosition = 4;
                    }
                    if (newPosition != -1 && newPosition != mPosition) {
                        setMenuChecked(false);
                        mPosition = newPosition;
                        setFragment(getFragment(mPosition));
                        item.setChecked(true);
                        mToolbarTitle.setText(getToolbarTitle());
                        return true;
                    }
                    if (id == R.id.menu_filter) {
                        final PopupMenu popup = new PopupMenu(WallpaperBoardActivity.this,
                                ((ViewGroup) mBottomNavigationView.getChildAt(0)).getChildAt(2));
                        fileCategoryMenu(popup.getMenu());
                        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                            public boolean onMenuItemClick(MenuItem item) {
                                item.setChecked(!item.isChecked());
                                new Database(WallpaperBoardActivity.this).selectCategory(
                                        item.getItemId() - MENU_CATEGORY_START, item.isChecked());
                                filterWallpapers();
                                return true;
                            }
                        });
                        popup.show();
                        return false;
                    }
                    return false;
                }
            });

    initInAppBilling();

    mPosition = 0;
    if (savedInstanceState != null) {
        mPosition = savedInstanceState.getInt(Extras.EXTRA_POSITION, 0);
    }
    setMenuChecked(false);
    setFragment(getFragment(mPosition));
    MenuItem item = mBottomNavigationView.getMenu().findItem(mapPositionToMenuId());
    if (item != null) {
        item.setChecked(true);
    }
    mToolbarTitle.setText(getToolbarTitle());

    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.coordinator),
            new OnApplyWindowInsetsListener() { // setContentView() must be fired already
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    mNavBarHeight = insets.getSystemWindowInsetBottom();
                    ViewHelper.resetViewBottomPadding(mBottomNavigationView, mNavBarHeight, true);
                    // need to call here since first fragment is created before this
                    WallpapersFragment fragment = (WallpapersFragment) mFragManager
                            .findFragmentByTag(Extras.TAG_WALLPAPERS);
                    if (fragment != null) {
                        fragment.resetViewBottomPadding();
                    }
                    return insets;
                }
            });
    if (Preferences.getPreferences(this).isFirstRun() && isLicenseCheckerEnabled) {
        LicenseHelper.getLicenseChecker(this).checkLicense(mLicenseKey, salt);
        return;
    }

    checkWallpapers();

    if (isLicenseCheckerEnabled && !Preferences.getPreferences(this).isLicensed()) {
        finish();
    }
}

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();/*from w  w w . j a v  a  2  s. co  m*/
        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.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();/*from w ww.  j  a v a 2 s . com*/
        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:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    try {/*  w  w w. ja va 2  s . c  om*/
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
    } catch (Exception e) {

    }

    switch (item.getItemId()) {

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

    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.replaceAll("\"", ""));

                    ((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_settings:
        Intent settings = new Intent(context, SettingsActivity.class);
        startActivityForResult(settings, SETTINGS_RESULT);
        return true;

    case R.id.menu_pic_filter:
        listView.setVisibility(View.GONE);
        if (!item.isChecked()) {
            searchQuery += " filter:links twitter.com";
            item.setChecked(true);
        } else {
            searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", "");
            item.setChecked(false);
        }
        doSearch(searchQuery);
        return super.onOptionsItemSelected(item);

    case R.id.menu_remove_rt:
        listView.setVisibility(View.GONE);
        if (!item.isChecked()) {
            searchQuery += " -RT";
            item.setChecked(true);
        } else {
            searchQuery = searchQuery.replace(" -RT", "");
            item.setChecked(false);
        }
        doSearch(searchQuery);
        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);
        }

        doSearch(searchQuery);

        return super.onOptionsItemSelected(item);

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

From source file:com.klinker.android.twitter.activities.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();/*from   www .j  a va2 s  . c  om*/
        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.replace(" -RT", "").replace(" TOP", ""));

                    ((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;//www .  ja  va 2s.  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;
}