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:org.peercast.core.PeerCastFragment.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    PeerCastServiceController controller = getActivity2().getPeerCastServiceController();

    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) item
            .getMenuInfo();/*www . j  a v a  2 s. co  m*/
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int gPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int cPos = ExpandableListView.getPackedPositionChild(info.packedPosition);

    Channel ch = (Channel) mListAdapter.getGroup(gPos);

    switch (item.getItemId()) {

    case R.id.menu_ch_disconnect:
        Log.i(TAG, "Disconnect channel: " + ch);
        controller.disconnectChannel(ch.getChannel_ID());
        return true;

    case R.id.menu_ch_keep:
        Log.i(TAG, "Keep channel: " + ch);
        controller.setChannelKeep(ch.getChannel_ID(), !item.isChecked());
        return true;

    case R.id.menu_ch_play:
        Uri u = getStreamUri(ch);
        Intent intent = new Intent(Intent.ACTION_VIEW, u);
        try {
            showToast(u.toString());
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            getActivity2().showAlertDialog(R.string.t_error, e.getLocalizedMessage(), false);
        }
        return true;

    case R.id.menu_ch_bump:
        Log.i(TAG, "Bump channel: " + ch);
        controller.bumpChannel(ch.getChannel_ID());
        return true;

    case R.id.menu_svt_disconnect:
        //
        Servent svt = (Servent) mListAdapter.getChild(gPos, cPos);
        Log.i(TAG, "Disconnect servent: " + svt);
        controller.disconnectServent(svt.getServent_ID());
        return true;

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

From source file:chaitanya.im.searchforreddit.LauncherActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_refresh:
        initializeSearch();//  w ww .j av a  2  s .  co m
        return true;

    case R.id.action_donate:
        dialog.setWhichDialog(0);
        dialog.setPurchaseDialog(-1);
        dialog.show(getSupportFragmentManager(), "tag");
        return true;

    case R.id.action_dark:
        if (donate == 1) {
            isChecked = !(item.isChecked());
            item.setChecked(isChecked);
            if (isChecked)
                UtilMethods.changeToTheme(this, 1, sharedPref);
            else
                UtilMethods.changeToTheme(this, 0, sharedPref);
            return true;
        } else {
            dialog.setWhichDialog(0);
            dialog.setPurchaseDialog(1);
            dialog.show(getSupportFragmentManager(), "tag");
            return true;
        }

    case R.id.action_licenses:
        dialog.setWhichDialog(1);
        dialog.show(getSupportFragmentManager(), "tag");
        return true;

    case R.id.action_about:
        dialog.setWhichDialog(2);
        dialog.show(getSupportFragmentManager(), "tag");
        return true;

    case R.id.action_whats_new:
        dialog.setWhichDialog(3);
        dialog.show(getSupportFragmentManager(), "tag");
        return true;

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

From source file:org.openbmap.activities.MapViewActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
    case R.id.menu_snaptoLocation:
        item.setChecked(!item.isChecked());
        snapToLocation = item.isChecked();
        return true;
    default://from w ww  . j ava 2  s  .  com
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.paramonod.kikos.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_settings));
    System.out.println(searchView);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//  ww  w .  j  a v  a  2  s .c o  m
        public boolean onQueryTextSubmit(String query) {
            Menu menu = bottomNavigationView.getMenu();
            Menu mm = navigationView.getMenu();
            FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            Fragment f = null;
            System.out.println(fragments);
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment != null && fragment.isVisible())
                        f = fragment;
                    System.out.println(f);
                }
            }
            if (f instanceof CardContentFragment) {
                main.searchListener(query, 2);

            }
            if (f instanceof CategoryContentFragment) {
                main.searchListener(query, 1);

            }
            if (f instanceof MapViewFragment) {
                main.searchListener(query, 0);

            }
            if (f instanceof ListContentFragment) {
                main.searchListener(query, 3);
            }
            if (mm.getItem(1).isChecked()) {
                main.searchListener(query, 3);
            } else
                for (int i = 0; i < bottomNavigationView.getMenu().size(); i++) {
                    MenuItem menuItem = menu.getItem(i);
                    if (menuItem.isChecked()) {
                        main.searchListener(query, i);
                    }
                }

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.menu_mute_button: {
        IUser self = getService().getSessionUser();

        boolean muted = !self.isSelfMuted();
        boolean deafened = self.isSelfDeafened();
        deafened &= muted; // Undeafen if mute is off
        getService().setSelfMuteDeafState(muted, deafened);

        getActivity().supportInvalidateOptionsMenu();
        return true;
    }//from ww w.  j  a v a 2 s .com
    case R.id.menu_deafen_button: {
        IUser self = getService().getSessionUser();

        boolean deafened = !self.isSelfDeafened();
        getService().setSelfMuteDeafState(deafened, deafened);

        getActivity().supportInvalidateOptionsMenu();
        return true;
    }
    case R.id.menu_search:
        return false;
    case R.id.menu_bluetooth:
        item.setChecked(!item.isChecked());
        if (item.isChecked()) {
            getService().enableBluetoothSco();
        } else {
            getService().disableBluetoothSco();
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:ar.com.tristeslostrestigres.diasporanativewebapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    progressBar = findViewById(R.id.progressBar);

    pm = new PrefManager(MainActivity.this);

    SharedPreferences config = getSharedPreferences("PodSettings", MODE_PRIVATE);
    podDomain = config.getString("podDomain", null);

    fab = findViewById(R.id.multiple_actions);
    fab.setVisibility(View.GONE);

    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*  w  ww .  jav  a  2s . c  o  m*/
    getSupportActionBar().setTitle(null);

    txtTitle = (TextView) findViewById(R.id.toolbar_title);
    txtTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Helpers.isOnline(MainActivity.this)) {
                txtTitle.setText(R.string.jb_stream);
                webView.loadUrl("https://" + podDomain + "/stream");
            } else {
                Snackbar.make(v, R.string.no_internet, Snackbar.LENGTH_SHORT).show();
            }
        }
    });

    webView = findViewById(R.id.webView);
    webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
    webView.addJavascriptInterface(new JavaScriptInterface(), "NotificationCounter");

    if (savedInstanceState != null) {
        webView.restoreState(savedInstanceState);
    }

    wSettings = webView.getSettings();
    wSettings.setJavaScriptEnabled(true);
    wSettings.setUseWideViewPort(true);
    wSettings.setLoadWithOverviewMode(true);
    wSettings.setDomStorageEnabled(true);
    wSettings.setMinimumFontSize(pm.getMinimumFontSize());
    wSettings.setLoadsImagesAutomatically(pm.getLoadImages());

    if (android.os.Build.VERSION.SDK_INT >= 21)
        wSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

    /*
     * WebViewClient
     */
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            if (!url.contains(podDomain)) {
                Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(i);
                return true;
            }
            return false;
        }

        public void onPageFinished(WebView view, String url) {
            if (url.contains("/new") || url.contains("/sign_in")) {
                fab.setVisibility(View.GONE);
            } else {
                fab.setVisibility(View.VISIBLE);
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            new AlertDialog.Builder(MainActivity.this).setIcon(android.R.drawable.ic_dialog_alert)
                    .setMessage(description).setPositiveButton("CLOSE", null).show();
        }
    });

    /*
     * WebChromeClient
     */
    webView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView wv, int progress) {
            progressBar.setProgress(progress);

            if (progress > 0 && progress <= 60) {
                Helpers.getNotificationCount(wv);
            }

            if (progress > 60) {
                Helpers.hideTopBar(wv);
                fab.setVisibility(View.VISIBLE);
            }

            if (progress == 100) {
                fab.collapse();
                progressBar.setVisibility(View.GONE);
            } else {
                progressBar.setVisibility(View.VISIBLE);
            }
        }

        @Override
        public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                FileChooserParams fileChooserParams) {
            if (mFilePathCallback != null)
                mFilePathCallback.onReceiveValue(null);

            mFilePathCallback = filePathCallback;

            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                // Create the File where the photo should go
                File photoFile = null;
                try {
                    photoFile = createImageFile();
                    takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
                } catch (IOException ex) {
                    // Error occurred while creating the File
                    Snackbar.make(getWindow().findViewById(R.id.drawer), "Unable to get image",
                            Snackbar.LENGTH_SHORT).show();
                }

                // Continue only if the File was successfully created
                if (photoFile != null) {
                    mCameraPhotoPath = "file:" + photoFile.getAbsolutePath();
                    takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
                } else {
                    takePictureIntent = null;
                }
            }

            Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
            contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
            contentSelectionIntent.setType("image/*");

            Intent[] intentArray;
            if (takePictureIntent != null) {
                intentArray = new Intent[] { takePictureIntent };
            } else {
                intentArray = new Intent[0];
            }

            Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
            chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
            chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
            chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);

            startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);

            return true;
        }

        public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            return super.onJsAlert(view, url, message, result);
        }
    });

    /*
     * NavigationView
     */
    NavigationView navigationView = findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
            if (menuItem.isChecked())
                menuItem.setChecked(false);
            else
                menuItem.setChecked(true);

            drawerLayout.closeDrawers();

            switch (menuItem.getItemId()) {
            default:
                Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                        Snackbar.LENGTH_SHORT).show();
                return true;

            case R.id.jb_stream:
                if (Helpers.isOnline(MainActivity.this)) {
                    txtTitle.setText(R.string.jb_stream);
                    webView.loadUrl("https://" + podDomain + "/stream");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_public:
                setTitle(R.string.jb_public);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/public");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_liked:
                txtTitle.setText(R.string.jb_liked);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/liked");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_commented:
                txtTitle.setText(R.string.jb_commented);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/commented");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_contacts:
                txtTitle.setText(R.string.jb_contacts);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/contacts");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_mentions:
                txtTitle.setText(R.string.jb_mentions);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/mentions");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_activities:
                txtTitle.setText(R.string.jb_activities);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/activity");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_followed_tags:
                txtTitle.setText(R.string.jb_followed_tags);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/followed_tags");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_manage_tags:

                txtTitle.setText(R.string.jb_manage_tags);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/tag_followings/manage");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_license:
                txtTitle.setText(R.string.jb_license);
                new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.license_title))
                        .setMessage(getString(R.string.license_text))
                        .setPositiveButton(getString(R.string.license_yes),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        Intent i = new Intent(Intent.ACTION_VIEW,
                                                Uri.parse("https://github.com/mdev88/Diaspora-Native-WebApp"));
                                        startActivity(i);
                                        dialog.cancel();
                                    }
                                })
                        .setNegativeButton(getString(R.string.license_no),
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                })
                        .show();

                return true;

            case R.id.jb_aspects:
                txtTitle.setText(R.string.jb_aspects);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/aspects");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }

            case R.id.jb_settings:
                txtTitle.setText(R.string.jb_settings);
                if (Helpers.isOnline(MainActivity.this)) {
                    webView.loadUrl("https://" + podDomain + "/user/edit");
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();

                    return false;
                }

            case R.id.jb_pod:
                txtTitle.setText(R.string.jb_pod);
                if (Helpers.isOnline(MainActivity.this)) {
                    new AlertDialog.Builder(MainActivity.this).setTitle(getString(R.string.confirmation))
                            .setMessage(getString(R.string.change_pod_warning))
                            .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() {
                                @TargetApi(11)
                                public void onClick(DialogInterface dialog, int id) {
                                    webView.clearCache(true);
                                    dialog.cancel();
                                    Intent i = new Intent(MainActivity.this, PodsActivity.class);
                                    startActivity(i);
                                    finish();
                                }
                            }).setNegativeButton(getString(R.string.no), new DialogInterface.OnClickListener() {
                                @TargetApi(11)
                                public void onClick(DialogInterface dialog, int id) {
                                    dialog.cancel();
                                }
                            }).show();
                    return true;
                } else {
                    Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet,
                            Snackbar.LENGTH_SHORT).show();
                    return false;
                }
            }
        }
    });

    /*
     * DrawerLayout
     */
    drawerLayout = findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
            R.string.openDrawer, R.string.closeDrawer);
    drawerLayout.setDrawerListener(actionBarDrawerToggle);
    //calling sync state is necessary or else your hamburger icon wont show up
    actionBarDrawerToggle.syncState();

    if (savedInstanceState == null) {
        if (Helpers.isOnline(MainActivity.this)) {
            webView.loadData("", "text/html", null);
            webView.loadUrl("https://" + podDomain);
        } else {
            Snackbar.make(getWindow().findViewById(R.id.drawer), R.string.no_internet, Snackbar.LENGTH_SHORT)
                    .show();
        }
    }

}

From source file:com.master.metehan.filtereagle.ActivityMain.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.i(TAG, "Menu=" + item.getTitle());

    // Handle item selection
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    switch (item.getItemId()) {
    case R.id.menu_app_user:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_user", item.isChecked()).apply();
        return true;

    case R.id.menu_app_system:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_system", item.isChecked()).apply();
        return true;

    case R.id.menu_app_nointernet:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_nointernet", item.isChecked()).apply();
        return true;

    case R.id.menu_app_disabled:
        item.setChecked(!item.isChecked());
        prefs.edit().putBoolean("show_disabled", item.isChecked()).apply();
        return true;

    case R.id.menu_sort_name:
        item.setChecked(true);/* www. jav  a2s  . c  o m*/
        prefs.edit().putString("sort", "name").apply();
        return true;

    case R.id.menu_sort_uid:
        item.setChecked(true);
        prefs.edit().putString("sort", "uid").apply();
        return true;

    case R.id.menu_sort_data:
        item.setChecked(true);
        prefs.edit().putString("sort", "data").apply();
        return true;

    case R.id.menu_log:
        if (IAB.isPurchased(ActivityPro.SKU_LOG, this))
            startActivity(new Intent(this, ActivityLog.class));
        else
            startActivity(new Intent(this, ActivityPro.class));
        return true;

    case R.id.menu_settings:
        startActivity(new Intent(this, ActivitySettings.class));
        return true;

    case R.id.menu_pro:
        startActivity(new Intent(ActivityMain.this, ActivityPro.class));
        return true;

    case R.id.menu_invite:
        startActivityForResult(getIntentInvite(this), REQUEST_INVITE);
        return true;

    case R.id.menu_legend:
        menu_legend();
        return true;

    case R.id.menu_support:
        startActivity(getIntentSupport());
        return true;

    case R.id.menu_about:
        menu_about();
        return true;

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

From source file:ru.orangesoftware.financisto.activity.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    //Checking if the item is in checked state or not, if not make it in checked state
    if (menuItem.isCheckable()) {
        menuItem.setChecked(true);/*from   www . j  a  v  a 2s .  c  om*/
    }

    //Closing drawer on item click
    mDrawerLayout.closeDrawers();

    if (menuItem.isChecked()) {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setTitle(menuItem.getTitle());
        actionBar.setIcon(menuItem.getIcon());
    }

    FragmentManager fm = getSupportFragmentManager();

    navMenuItemId = menuItem.getItemId();
    //Check to see which item was being clicked and perform appropriate action
    switch (navMenuItemId) {

    //Replacing the main content with ContentFragment Which is our Inbox View;
    case R.id.accounts:
        selectedAccountId = -1;
        android.support.v4.app.FragmentTransaction fragmentTransaction = fm.beginTransaction();
        fragmentTransaction.replace(R.id.main_content_frame, AccountListFragment.newInstance(), "accounts");
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();

        fab.show();
        break;
    case R.id.blotter:
        android.support.v4.app.FragmentTransaction blotterFragmentTransaction = fm.beginTransaction();
        blotterFragmentTransaction.replace(R.id.main_content_frame,
                BlotterFragment.newInstance(true, selectedAccountId), "blotter");
        blotterFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        blotterFragmentTransaction.addToBackStack(null);
        blotterFragmentTransaction.commit();

        fab.show();
        break;
    case R.id.scheduled_transactions:
        startActivity(new Intent(this, ScheduledListActivity.class));
        break;
    case R.id.budgets:
        android.support.v4.app.FragmentTransaction budgetFragmentTransaction = fm.beginTransaction();
        budgetFragmentTransaction.replace(R.id.main_content_frame, new BudgetListFragment());
        budgetFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        budgetFragmentTransaction.addToBackStack(null);
        budgetFragmentTransaction.commit();

        fab.show();
        break;
    case R.id.reports:
        android.support.v4.app.FragmentTransaction reportsFragmentTransaction = fm.beginTransaction();
        reportsFragmentTransaction.replace(R.id.main_content_frame, new ReportListFragment());
        reportsFragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
        reportsFragmentTransaction.addToBackStack(null);
        reportsFragmentTransaction.commit();

        fab.hide();
        break;
    case R.id.planner:
        startActivity(new Intent(this, PlannerActivity.class));
        break;
    case R.id.entities:
        final MenuEntities[] entities = MenuEntities.values();
        ListAdapter adapter = EnumUtils.createEntityEnumAdapter(this, entities);
        final AlertDialog d = new AlertDialog.Builder(this)
                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        MenuEntities e = entities[which];
                        startActivity(new Intent(MainActivity.this, e.getActivityClass()));
                    }
                }).create();
        d.setTitle(R.string.entities);
        d.show();
        break;
    case R.id.menu_sync_online:
        doOnlineSync();
        break;
    //            case R.id.menu_sync_flowzr:
    //                doFlowzrSync();
    //                break;
    case R.id.menu_mass_operations:
        startActivity(new Intent(this, MassOpActivity.class));
        break;
    case R.id.menu_restore_database:
        doImport();
        break;
    case R.id.menu_backup_database:
        doBackup();
        break;
    case R.id.menu_backup_database_to:
        doBackupTo();
        break;
    case R.id.menu_backup_restore_database_online:
        showPickOneDialog(this, R.string.backup_restore_database_online, BackupRestoreEntities.values(), this);
        break;
    case R.id.menu_import_export:
        showPickOneDialog(this, R.string.import_export, ImportExportEntities.values(), this);
        break;
    case R.id.menu_settings:
        startActivityForResult(new Intent(this, PreferencesActivity.class), CHANGE_PREFERENCES_RESULT);
        break;
    case R.id.menu_integrity_fix:
        doIntegrityFix();
        break;
    case R.id.menu_donate:
        openBrowser("market://search?q=pname:ru.orangesoftware.financisto.support");
        break;
    case R.id.menu_about:
        startActivity(new Intent(this, AboutActivity.class));
        break;
    default:
        Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
        fab.hide();
        break;
    }

    fm.executePendingTransactions();
    return true;
}

From source file:com.grarak.kerneladiutor.fragments.tools.customcontrols.CustomControlsFragment.java

private CardView getCard(final Controls.ControlItem controlItem) {
    CardView cardView = new CardView(getActivity());
    cardView.setOnMenuListener(new CardView.OnMenuListener() {

        @Override/*from ww w  . j a  v a  2  s  .  c  o  m*/
        public void onMenuReady(CardView cardView, PopupMenu popupMenu) {
            Menu menu = popupMenu.getMenu();
            menu.add(Menu.NONE, 0, Menu.NONE, getString(R.string.edit));
            final MenuItem onBoot = menu.add(Menu.NONE, 1, Menu.NONE, getString(R.string.on_boot))
                    .setCheckable(true);
            onBoot.setChecked(controlItem.isOnBootEnabled());
            menu.add(Menu.NONE, 2, Menu.NONE, getString(R.string.export));
            menu.add(Menu.NONE, 3, Menu.NONE, getString(R.string.delete));

            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case 0:
                        edit(controlItem);
                        break;
                    case 1:
                        onBoot.setChecked(!onBoot.isChecked());
                        controlItem.enableOnBoot(onBoot.isChecked());
                        mControlsProvider.commit();
                        break;
                    case 2:
                        mExportItem = controlItem;
                        requestPermission(0, Manifest.permission.WRITE_EXTERNAL_STORAGE);
                        break;
                    case 3:
                        mDeleteDialog = ViewUtils.dialogBuilder(getString(R.string.sure_question),
                                new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                    }
                                }, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        delete(controlItem.getUniqueId());
                                    }
                                }, new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialog) {
                                        mDeleteDialog = null;
                                    }
                                }, getActivity()).setTitle(getString(R.string.delete));
                        mDeleteDialog.show();
                        break;
                    }
                    return false;
                }
            });
        }
    });
    return cardView;
}

From source file:org.totschnig.myexpenses.fragment.CategoryList.java

private boolean handleGrouping(MenuItem item) {
    Grouping newGrouping = Utils.getGroupingFromMenuItemId(item.getItemId());
    if (newGrouping != null) {
        if (!item.isChecked()) {
            setGrouping(newGrouping);//from w  ww  . j  ava  2  s  .  co m
        }
        return true;
    }
    return false;
}