Example usage for android.view MenuItem isCheckable

List of usage examples for android.view MenuItem isCheckable

Introduction

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

Prototype

public boolean isCheckable();

Source Link

Document

Return whether the item can currently display a check mark.

Usage

From source file:com.ruesga.rview.MainActivity.java

private boolean performSelectItem(int itemId, boolean force) {
    final Menu menu = mBinding.drawerNavigationView.getMenu();
    final MenuItem item = menu.findItem(itemId);
    if (item != null) {
        if (item.isCheckable()) {
            boolean changed = itemId != mModel.currentNavigationItemId;
            mBinding.drawerNavigationView.setCheckedItem(item.getItemId());
            mModel.currentNavigationItemId = itemId;
            return force || changed;
        } else {//from w  ww .j av a 2s . c om
            performNavigationAction(item);
        }
    }
    return false;
}

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 w  w w.  j a  va2  s  . com*/
    }

    //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.google.android.apps.forscience.whistlepunk.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    if (menuItem == null) {
        return false;
    }//from  ww  w.j  av a  2  s.c o m
    if (menuItem.getGroupId() == R.id.navigation_top) {
        FragmentManager fragmentManager = getFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        Fragment fragment;
        int itemId = menuItem.getItemId();

        final String tag = String.valueOf(itemId);
        fragment = getFragmentManager().findFragmentByTag(tag);
        if (fragment == null) {
            fragment = createNewFragment(itemId);
        }
        adjustActivityForSelectedItem(itemId);

        mTitleToRestore = getTitleToRestore(menuItem);
        transaction.replace(R.id.content_container, fragment, tag).commit();
        if (menuItem.isCheckable()) {
            menuItem.setChecked(true);
        }
        mDrawerLayout.closeDrawers();
        restoreActionBar();
        mSelectedItemId = itemId;
    } else if (menuItem.getGroupId() == R.id.navigation_bottom) {
        mDrawerLayout.closeDrawers();
        // Launch intents
        Intent intent = null;
        int itemId = menuItem.getItemId();

        if (itemId == R.id.navigation_item_website) {
            intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website_url)));
        } else if (itemId == R.id.navigation_item_settings) {
            intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(),
                    SettingsActivity.TYPE_SETTINGS);
        } else if (itemId == R.id.navigation_item_about) {
            intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(), SettingsActivity.TYPE_ABOUT);
        } else if (itemId == R.id.dev_testing_options) {
            intent = SettingsActivity.getLaunchIntent(this, menuItem.getTitle(),
                    SettingsActivity.TYPE_DEV_OPTIONS);
        } else if (itemId == R.id.navigation_item_feedback) {
            mFeedbackProvider.sendFeedback(new LoggingConsumer<Boolean>(TAG, "Send feedback") {
                @Override
                public void success(Boolean value) {
                    if (!value) {
                        showFeedbackError();
                    }
                }

                @Override
                public void fail(Exception e) {
                    super.fail(e);
                    showFeedbackError();
                }
            });
        }
        if (intent != null) {
            startActivity(intent);
        }
    }

    return false;
}

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

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

    if (mMenu == null) {
        return;
    }

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

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

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (DEBUG)// ww w  . ja va2 s  .c o  m
        Logger.LogDebug("OpenExplorer.onOptionsItemSelected(" + item + ")");
    if (item.getItemId() == R.id.menu_more && isGTV()) {
        showMenu(mOptsMenu, findViewById(item.getItemId()), false);
        return true;
    }

    if (item.getSubMenu() != null) {
        onPrepareOptionsMenu(item.getSubMenu());
        if (!USE_PRETTY_MENUS)
            return false;
        else {
            View anchor = findViewById(item.getItemId());
            if (anchor == null && !BEFORE_HONEYCOMB && item.getActionView() != null)
                anchor = item.getActionView();
            if (anchor == null && !BEFORE_HONEYCOMB) {
                anchor = getActionBar().getCustomView();
                if (anchor.findViewById(item.getItemId()) != null)
                    anchor = anchor.findViewById(item.getItemId());
            }
            if (anchor == null)
                anchor = mToolbarButtons;
            if (anchor == null)
                anchor = findViewById(android.R.id.home);
            if (anchor == null && !BEFORE_HONEYCOMB && USE_ACTION_BAR)
                anchor = getActionBar().getCustomView().findViewById(android.R.id.home);
            if (anchor == null)
                anchor = getCurrentFocus().getRootView();
            OpenFragment f = getSelectedFragment();
            if (f != null)
                if (f.onClick(item.getItemId(), anchor))
                    return true;
        }
    }

    if (item.isCheckable())
        item.setChecked(item.getGroupId() > 0 ? true : !item.isChecked());

    OpenFragment f = getSelectedFragment();
    if (f != null && f.onOptionsItemSelected(item))
        return true;

    if (DEBUG)
        Logger.LogDebug("OpenExplorer.onOptionsItemSelected(0x" + Integer.toHexString(item.getItemId()) + ")");

    return onClick(item.getItemId(), item, null);
}