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:net.potterpcs.recipebook.RecipeBookActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    boolean descending = false;
    switch (item.getItemId()) {
    case R.id.menunew:
        onNewItemSelected(item);//from w w w. jav a 2  s. c om
        return true;
    case R.id.menuhelp:
        onHelpItemSelected(item);
        return true;
    case R.id.menuprefs:
        onPreferences(item);
        return true;
    case R.id.menusearch:
        onSearchRequested();
        return true;
    case R.id.menusearchtag:
        onSearchByTag();
        return true;
    case R.id.menusearchtime:
        onSearchByTime();
        return true;
    case R.id.menushowall:
        onShowAllRecipes(item);
        return true;
    case R.id.menuexport:
        onExportRecipes(item);
    case R.id.menuimport:
        onImportFileList(item);

        // Sort direction items (only one active at a time)
    case R.id.menusortdescending:
        descending = true;
        // fall-through on purpose
    case R.id.menusortascending:
        item.setChecked(!item.isChecked());
        startSortActivity(sortKey, descending);
        return true;

    // Sort criteria items (only one active at a time)
    case R.id.menusortname:
    case R.id.menusortrating:
    case R.id.menusorttime:
    case R.id.menusortdate:
        item.setChecked(!item.isChecked());
        startSortActivity(item.getItemId(), sortDescending);
        return true;

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

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

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    FirebaseDatabase.getInstance().setPersistenceEnabled(true);
    myRef = FirebaseDatabase.getInstance().getReference("Shops");
    //ShopInterface shopInterface = new ShopInterface("asas","qaqa","wdwdwd","12","11","11");
    //myRef.child("Shops").child("1").setValue(shopInterface);
    //mAuth.signInAnonymously();
    myRef.keepSynced(true);//from  ww  w  . j av a 2 s.c o  m
    myRef.orderByValue().addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot snapshot, String previousChild) {
            Log.e("here", Integer.toString(shopInterfaces.size() - 1));
            shopInterfaces.add(snapshot.getValue(ShopInterface.class));
            Log.e("here", Integer.toString(shopInterfaces.size() - 1));
            main.setupMap();
            //System.out.println(shopInterfaces.get(1).getCoordX());
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
    //mAuth.signOut();
    main = this;
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle("OrgShop");
    DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    final Display display = getWindowManager().getDefaultDisplay();
    android.graphics.Point size = new android.graphics.Point();
    display.getSize(size);
    X = size.x;
    Y = size.y;
    //  Y = displaymetrics.heightPixels;
    //  X = displaymetrics.widthPixels;
    System.out.println(X + " " + Y);
    // Adding Toolbar to Main screen
    int ii = 0;
    places.clear();
    while (true) {
        String connectionsJSONString = getPreferences(MODE_PRIVATE).getString("places" + ii, null);
        Pair p = new Gson().fromJson(connectionsJSONString, Pair.class);
        if (p != null)
            places.add(p);
        else
            break;
        ii++;
    }
    placesIDX = ii;
    bottomNavigationView = (BottomNavigationView) findViewById(R.id.navigation);

    Manager.findFragmentById(R.id.fragment1);

    bottomNavigationView
            .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
                @Override
                public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                    //AsyncTask asyncTask = new NewAsyncTask();
                    switch (item.getItemId()) {
                    case R.id.Map:
                        //     Manager.beginTransaction()
                        //             .replace(R.id.fragment1, PrFr)
                        //             .commit();
                        Manager.beginTransaction().replace(R.id.fragment1, MapFr).addToBackStack("Map")
                                .commit();
                        //asyncTask.execute(R.id.Map);
                        break;
                    case R.id.Shops:
                        //     Manager.beginTransaction()
                        //            .replace(R.id.fragment1, PrFr)
                        //            .commit();

                        //  Listfr.flag = 0;
                        Manager.beginTransaction().replace(R.id.fragment1, CatFr).addToBackStack("Categories")
                                .commit();
                        //x = R.id.Shops;
                        //asyncTask.execute();
                        break;
                    case R.id.Third:
                        //    Manager.beginTransaction()
                        //           .replace(R.id.fragment1, PrFr)
                        //           .commit();
                        //     Manager.beginTransaction()
                        //             .replace(R.id.fragment1, PrFr)
                        //             .commit();
                        //      System.out.println(0);
                        int idx[] = new int[shopInterfaces.size()];
                        for (int i = 0; i < idx.length; i++) {
                            idx[i] = i;
                        }
                        try {
                            updateMyLoc();
                            idx = sortArraywithGeo(idx, myLoc);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        CardContentFragment.flag = 1;
                        CardContentFragment.idx = idx;
                        Manager.beginTransaction().replace(R.id.fragment1, Cardfr).addToBackStack(null)
                                .commit();
                        //new ImageLoad().execute();
                        //while (AsyncTest == 0){}
                        //System.out.println(1);
                        //Picturex();
                        //AsyncTest = -1;
                        /* Manager.beginTransaction()
                                  .replace(R.id.fragment1, Listfr)
                                  .commit();
                        */
                        // asyncTask.execute(R.id.Third);
                        break;
                    }
                    return false;
                }
            });

    // Setting ViewPager for each Tabs

    // Set Tabs inside Toolbar
    // Create Navigation drawer and inlfate layout

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    // Adding menu icon to Toolbar
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar != null) {
        VectorDrawableCompat indicator = VectorDrawableCompat.create(getResources(), R.drawable.ic_menu,
                getTheme());
        indicator.setTint(ResourcesCompat.getColor(getResources(), R.color.white, getTheme()));
        supportActionBar.setHomeAsUpIndicator(indicator);
        supportActionBar.setDisplayHomeAsUpEnabled(true);
    }
    //Set behavior of Navigation drawer
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setCheckedItem(R.id.mapButton);
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            // Set item in checked state
            menuItem.setChecked(true);
            if (menuItem.getItemId() == R.id.favorite_button) {
                sPref = getPreferences(MODE_PRIVATE);
                String savedText = sPref.getString("q", "");
                boolean w = true;
                for (int i = 0; i < 10; i++) {
                    if (savedText.contains(Integer.toString(i))) {
                        w = false;
                    }
                }
                if (w) {
                    Toast.makeText(main, " ?     ",
                            Toast.LENGTH_LONG).show();
                    SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                    editor.putString("q", "");
                    editor.commit();
                } else {
                    String[] q = savedText.split(" ");
                    int[] a = new int[q.length];
                    for (int i = 0; i < q.length; i++) {
                        a[i] = Integer.parseInt(q[i]);
                        System.out.println(a[i]);
                    }
                    try {
                        updateMyLoc();
                        a = sortArraywithGeo(a, myLoc);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    ListContentFragment l = new ListContentFragment();
                    l.flag = 1;
                    l.idx = a;
                    //  Manager.beginTransaction()
                    //          .replace(R.id.fragment1, PrFr)
                    //          .commit();
                    Manager.beginTransaction().replace(R.id.fragment1, l).addToBackStack("favorite").commit();
                }
            }
            if (menuItem.getItemId() == R.id.mapButton) {
                //  Manager.beginTransaction()
                //          .replace(R.id.fragment1, PrFr)
                //          .commit();
                Manager.beginTransaction().replace(R.id.fragment1, MapFr).addToBackStack("map").commit();
            }
            if (menuItem.getItemId() == R.id.clear_button) {
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("").setMessage(
                        "? ? ?? ? ? aka KiKoS,   aka paramomnod")
                        .setIcon(R.drawable.itkerk).setCancelable(false)
                        .setNegativeButton("    :)",
                                new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        dialog.cancel();
                                    }
                                });
                AlertDialog alert = builder.create();
                alert.show();

            }
            if (menuItem.getItemId() == R.id.login_button) {
                int ii = 0;
                places.clear();
                while (true) {
                    String connectionsJSONString = getPreferences(MODE_PRIVATE).getString("places" + ii, null);
                    Pair p = new Gson().fromJson(connectionsJSONString, Pair.class);
                    if (p != null)
                        places.add(p);
                    else
                        break;
                    ii++;
                }
                if (places.size() == 0) {
                    Toast.makeText(main, " ?   ?",
                            Toast.LENGTH_LONG).show();
                } else {
                    String q[] = new String[places.size()];
                    for (int i = 0; i < q.length; i++) {
                        q[i] = places.get(i).first;
                    }
                    new AlertDialog.Builder(main).setSingleChoiceItems(q, 0, null)
                            .setPositiveButton("", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.dismiss();
                                    int selectedPosition = ((AlertDialog) dialog).getListView()
                                            .getCheckedItemPosition();
                                    Pair p = places.get(selectedPosition);
                                    GeoPoint geo = p.second;
                                    int[] idx = new int[shopInterfaces.size()];
                                    for (int i = 0; i < idx.length; i++) {
                                        idx[i] = i;
                                    }
                                    idx = sortArraywithGeo(idx, geo);
                                    CardContentFragment c = new CardContentFragment();
                                    CardContentFragment.flag = 1;
                                    CardContentFragment.idx = idx;
                                    Manager.beginTransaction().replace(R.id.fragment1, c).addToBackStack("map")
                                            .commit();
                                }
                            }).setNegativeButton("", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    int selectedPosition = ((AlertDialog) dialog).getListView()
                                            .getCheckedItemPosition();
                                    places.remove(selectedPosition);
                                    placesIDX--;
                                    for (int i = 0; i < placesIDX; i++) {
                                        SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                                        String connectionsJSONString1 = new Gson().toJson(places.get(i));
                                        editor.putString("places" + i, connectionsJSONString1);
                                        editor.commit();
                                    }
                                    SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
                                    editor.putString("places" + placesIDX, null);
                                    editor.commit();
                                }
                            }).show();
                }
            }
            /*       if (menuItem.getItemId() == R.id.login_button) {
                    if (mAuth.getCurrentUser() == null) {
                        startActivity(new Intent(MainActivity.this, LoginActivity.class));
                    } else {
                        startActivity(new Intent(MainActivity.this, AccountActivity.class));
                    }
                    
                }
            */ // Closing drawer on item click
            mDrawerLayout.closeDrawers();
            return true;
        }
    });

    // Adding Floating Action Button to bottom right of main view
    /*FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Snackbar.make(v, "Hello Snackbar!",
                Snackbar.LENGTH_LONG).show();
    }
    });*/
    Manager.beginTransaction().replace(R.id.fragment1, MapFr).commit();
}

From source file:com.white.bihudaily.module.dailys.DailyActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/* w  ww  . j av  a 2 s  . c o m*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            int themeId = menuItem.getOrder();
            switch (menuItem.getItemId()) {
            case R.id.menu_main_page:
                // 
                mDailyFragment = (DailyFragment) getSupportFragmentManager()
                        .findFragmentByTag(Constant.TAG_MAIN);
                if (mDailyFragment == null) {
                    mDailyFragment = new DailyFragment();
                }
                switchFragment(mDailyFragment, Constant.TAG_MAIN, getResources().getString(R.string.index));
                break;
            default:
                // ?
                ThemesFragment themesFragment = (ThemesFragment) getSupportFragmentManager()
                        .findFragmentByTag(themeId + "");
                if (themesFragment == null) {
                    themesFragment = ThemesFragment.newInstance(themeId);
                }
                switchFragment(themesFragment, themeId + "", menuItem.getTitle().toString());
                break;

            }
            // ??
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:de.dreier.mytargets.features.training.input.InputActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    final MenuItem eye = menu.findItem(R.id.action_show);
    final MenuItem keyboard = menu.findItem(R.id.action_keyboard);
    final MenuItem grouping = menu.findItem(R.id.action_grouping);
    final MenuItem timer = menu.findItem(R.id.action_timer);
    final MenuItem newRound = menu.findItem(R.id.action_new_round);
    if (targetView == null || data.getEnds().size() == 0) {
        eye.setVisible(false);/*from  w  w  w  . j a  va 2s. c o  m*/
        keyboard.setVisible(false);
        grouping.setVisible(false);
        timer.setVisible(false);
        newRound.setVisible(false);
    } else {
        final boolean plotting = targetView.getInputMode() == EInputMethod.PLOTTING;
        eye.setVisible(plotting);
        grouping.setVisible(plotting);
        keyboard.setIcon(plotting ? R.drawable.ic_keyboard_white_24dp : R.drawable.ic_keyboard_white_off_24dp);
        keyboard.setChecked(!plotting);
        keyboard.setVisible(data.getCurrentEnd().getId() == null);
        timer.setIcon(SettingsManager.getTimerEnabled() ? R.drawable.ic_timer_off_white_24dp
                : R.drawable.ic_timer_white_24dp);
        timer.setVisible(true);
        timer.setChecked(SettingsManager.getTimerEnabled());
        newRound.setVisible(data.training.standardRoundId == null);
    }

    switch (SettingsManager.getShowMode()) {
    case END:
        menu.findItem(R.id.action_show_end).setChecked(true);
        break;
    case ROUND:
        menu.findItem(R.id.action_show_round).setChecked(true);
        break;
    case TRAINING:
        menu.findItem(R.id.action_show_training).setChecked(true);
        break;
    default:
        // Never called: All enum values are checked
        break;
    }
    switch (SettingsManager.getAggregationStrategy()) {
    case NONE:
        menu.findItem(R.id.action_grouping_none).setChecked(true);
        break;
    case AVERAGE:
        menu.findItem(R.id.action_grouping_average).setChecked(true);
        break;
    case CLUSTER:
        menu.findItem(R.id.action_grouping_cluster).setChecked(true);
        break;
    default:
        // Never called: All enum values are checked
        break;
    }
    return true;
}

From source file:net.momodalo.app.vimtouch.VimTouch.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (getSlidingMenu().isMenuShowing() && mMenu.onOptionsItemSelected(item))
        return super.onOptionsItemSelected(item);

    if (id == R.id.menu_preferences) {
        doPreferences();// w ww .j  a  v a 2 s .  c  o  m
    } else if (id == R.id.menu_fullscreen) {
        item.setChecked(doToggleFullscreen());
    } else if (id == R.id.menu_vimrc) {
        Exec.doCommand("tabnew ~/.vimrc");
        Exec.updateScreen();
    } else if (id == R.id.menu_quickbar) {
        Exec.doCommand("tabnew " + getQuickbarFile());
        Exec.updateScreen();
    } else if (id == R.id.menu_toggle_soft_keyboard) {
        doToggleSoftKeyboard();
    } else if (id == R.id.menu_ESC) {
        mSession.write(27);
        Exec.updateScreen();
        mEmulatorView.lateCheckInserted();
    } else if (id == R.id.menu_quit) {
        Exec.doCommand("q!");
        Exec.updateScreen();
    } else if (id == R.id.menu_ime_composing) {
        item.setChecked(mEmulatorView.toggleIMEComposing());
    } else if (id == R.id.menu_extra_downloads) {
        Intent search = new Intent(Intent.ACTION_VIEW);
        search.setData(Uri.parse("market://search?q=VimTouch"));
        search.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(search);
        /*
        } else if (id == R.id.menu_full_vim_runtime)  {
            downloadFullRuntime();
        */
    } else if (id == R.id.menu_new) {
        item.setChecked(true);
        mOpenCommand = "new";
        showMenu();
    } else if (id == R.id.menu_vnew) {
        item.setChecked(true);
        mOpenCommand = "vnew";
        showMenu();
    } else if (id == R.id.menu_tabnew) {
        item.setChecked(true);
        mOpenCommand = "tabnew";
        showMenu();
    } else if (id == R.id.menu_diff) {
        item.setChecked(true);
        mOpenCommand = "vert diffsplit";
        showMenu();
    } else if (id == R.id.menu_save) {
        Exec.doCommand("w");
    } else if (id == R.id.menu_backup) {
        Intent intent = new Intent(getApplicationContext(), InstallProgress.class);
        intent.setData(Uri
                .parse("backup://" + Environment.getExternalStorageDirectory() + "/" + "VimTouchBackup.vrz"));
        startActivityForResult(intent, REQUEST_BACKUP);
    } else if (id == R.id.menu_keys) {
        if (mButtonBarLayout.isShown()) {
            mSettings.setQuickbarShow(false);
            item.setChecked(false);
            mButtonBar.setVisibility(View.GONE);
        } else {
            mSettings.setQuickbarShow(true);
            item.setChecked(true);
            mButtonBar.setVisibility(View.VISIBLE);
        }
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.jefftharris.passwdsafe.PasswdSafeOpenFileFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if ((itsListener != null) && itsListener.isNavDrawerClosed()) {
        inflater.inflate(R.menu.fragment_passwdsafe_open_file, menu);

        switch (itsYubiState) {
        case ENABLED:
        case DISABLED: {
            break;
        }//from w w  w.  ja va 2  s  .c  o m
        case UNAVAILABLE: {
            menu.setGroupVisible(R.id.menu_group_slots, false);
            break;
        }
        }

        MenuItem item;
        switch (itsYubiSlot) {
        case 2:
        default: {
            item = menu.findItem(R.id.menu_slot_2);
            itsYubiSlot = 2;
            break;
        }
        case 1: {
            item = menu.findItem(R.id.menu_slot_1);
            break;
        }
        }
        item.setChecked(true);
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.money.manager.ex.account.AccountTransactionListFragment.java

private boolean datePeriodItemSelected(MenuItem item) {
    int stringId;
    int itemId = item.getItemId();

    DefinedDateRanges dateRanges = new DefinedDateRanges(getActivity());
    DefinedDateRange range = dateRanges.getByMenuId(itemId);
    if (range == null)
        return false;
    stringId = range.nameResourceId;/*from  w w  w  .j  a v  a2 s  .  c o  m*/

    LookAndFeelSettings settings = new AppSettings(getActivity()).getLookAndFeelSettings();
    settings.setShowTransactions(range.key);

    // Save the selected period.
    mFilter.dateRange = new MmxDateTimeUtils().getDateRangeForPeriod(getActivity(), stringId);

    item.setChecked(true);

    loadTransactions();

    return true;
}

From source file:com.tingtingapps.securesms.ConversationActivity.java

private void handleDistributionBroadcastEnabled(MenuItem item) {
    distributionType = ThreadDatabase.DistributionTypes.BROADCAST;
    item.setChecked(true);

    if (threadId != -1) {
        new AsyncTask<Void, Void, Void>() {
            @Override/*from w w w . j  av  a 2s  .  c  o m*/
            protected Void doInBackground(Void... params) {
                DatabaseFactory.getThreadDatabase(ConversationActivity.this).setDistributionType(threadId,
                        ThreadDatabase.DistributionTypes.BROADCAST);
                return null;
            }
        }.execute();
    }
}

From source file:com.android.purenexussettings.TinkerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // toggle nav drawer on selecting action bar app icon/title
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        return true;
    }//from  ww  w.  ja  va2  s  .c  o m

    // Handle action bar actions click
    switch (item.getItemId()) {
    case R.id.action_about:
        if (mItemPosition != 0) {
            myHandler.removeCallbacksAndMessages(null);
            mMenu = true;
            removeCurrent();
            // below replicates the visual delay seen when launching frags from navdrawer
            myHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    displayView(0);
                }
            }, 400);
        }
        return true;
    case R.id.action_launchhide:
        boolean checked = item.isChecked();
        item.setChecked(!checked);
        setLauncherIconEnabled(checked);
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.tingtingapps.securesms.ConversationActivity.java

private void handleDistributionConversationEnabled(MenuItem item) {
    distributionType = ThreadDatabase.DistributionTypes.CONVERSATION;
    item.setChecked(true);

    if (threadId != -1) {
        new AsyncTask<Void, Void, Void>() {
            @Override//w  w w . j  a  va 2s. co  m
            protected Void doInBackground(Void... params) {
                DatabaseFactory.getThreadDatabase(ConversationActivity.this).setDistributionType(threadId,
                        ThreadDatabase.DistributionTypes.CONVERSATION);
                return null;
            }
        }.execute();
    }
}