Example usage for android.view MenuItem setChecked

List of usage examples for android.view MenuItem setChecked

Introduction

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

Prototype

public MenuItem setChecked(boolean checked);

Source Link

Document

Control whether this item is shown with a check mark.

Usage

From source file:com.money.manager.ex.fragment.PayeeListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_payee, menu);

    AppSettings settings = new AppSettings(mContext);
    int payeeSort = settings.getPayeeSort();

    //Check the default sort order
    final MenuItem item;
    // PreferenceManager.getDefaultSharedPreferences(getActivity()).getInt(getString(PreferenceConstants.PREF_SORT_PAYEE), 0)
    switch (payeeSort) {
    case 0:/*from  www . j a v  a  2s .  co  m*/
        item = menu.findItem(R.id.menu_sort_name);
        item.setChecked(true);
        break;
    case 1:
        item = menu.findItem(R.id.menu_sort_usage);
        item.setChecked(true);
        break;
    }
}

From source file:com.jiongbull.repository.ui.view.MainActivity.java

@Override
protected void initViews() {
    mNavigation.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//ww  w  .  j a  v a  2 s  . c  o m
        public boolean onNavigationItemSelected(MenuItem item) {
            FragmentManager fragmentManager = getSupportFragmentManager();
            switch (item.getItemId()) {
            case R.id.drawer_android_art:
                if (mAndroidArtFragment == null) {
                    mAndroidArtFragment = new AndroidArtFragment();
                }
                fragmentManager.beginTransaction().replace(R.id.flyt_content, mAndroidArtFragment).commit();
                break;
            case R.id.drawer_settings:

                break;
            default:
                break;
            }
            item.setChecked(true);
            mDrawer.closeDrawers();
            return true;
        }
    });
    if (mAndroidArtFragment == null) {
        mAndroidArtFragment = new AndroidArtFragment();
    }
    FragmentManager fragmentManager = getSupportFragmentManager();
    fragmentManager.beginTransaction().replace(R.id.flyt_content, mAndroidArtFragment).commit();
}

From source file:com.auth0.sample.ProfileActivity.java

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

    shares = getSharedPreferences("USER", 0);

    editor = shares.edit();//from w ww.  j  a v a2s.c o  m

    profile = getIntent().getParcelableExtra(Lock.AUTHENTICATION_ACTION_PROFILE_PARAMETER);

    access_token = getIntent().getParcelableExtra(Lock.AUTHENTICATION_ACTION_TOKEN_PARAMETER);
    Log.e("Access_Token", access_token.getAccessToken());
    editor.putString("ACCESS_TOKEN", access_token.getAccessToken());
    editor.commit();

    client = new AsyncHttpClient();
    app = (SampleApplication) getApplication();

    toolbar = (Toolbar) findViewById(R.id.toolbar);

    create = (TextView) toolbar.findViewById(R.id.create_tweet);
    create.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            createTweet(ProfileActivity.this);
        }
    });

    navigationView = (NavigationView) findViewById(R.id.navigation_view);

    header = navigationView.inflateHeaderView(R.layout.header);

    username = (TextView) header.findViewById(R.id.username);
    proPic = (ImageView) header.findViewById(R.id.profile_image);
    ((TextView) header.findViewById(R.id.email)).setText(profile.getEmail());

    /*
    client.get(((HashMap) profile.getExtraInfo().get("cover")).get("source").toString(), new FileAsyncHttpResponseHandler(ProfileActivity.this.getApplicationContext()) {
    @Override
    public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, Throwable throwable, File file) {
            
    }
            
    @Override
    public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, final File response) {
        ProfileActivity.this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                Bitmap image = BitmapFactory.decodeFile(response.getPath());
            
            }
        });
            
            
    }
    });
    */
    username.setText(profile.getName());

    if (profile.getPictureURL() != null) {
        ImageLoader.getInstance().displayImage(profile.getPictureURL(), proPic);
    }

    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {

        // This method will trigger on item Click of navigation menu
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {

            //Checking if the item is in checked state or not, if not make it in checked state

            nav = true;

            menuItem.setChecked(false);

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

            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            Fragment fragment;
            //Check to see which item was being clicked and perform appropriate action
            switch (menuItem.getItemId()) {
            case R.id.log_out:
                editor.remove("ENDPOINT_URL").remove("ACCESS_TOKEN").commit();
                Intent intent = getApplicationContext().getPackageManager()
                        .getLaunchIntentForPackage(getApplicationContext().getPackageName());
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);

            default:
                Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
                break;

            }
            return false;
        }
    });

    // Initializing Drawer Layout and ActionBarToggle
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer);
    ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
            (Toolbar) 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);
            drawerLayout.setSelected(false);
        }

        @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
    drawerLayout.setDrawerListener(actionBarDrawerToggle);

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

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    final LinearLayoutManager layoutManager = new LinearLayoutManager(ProfileActivity.this);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    recyclerView.setLayoutManager(layoutManager);

    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);

    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);

    // use a linear layout manager
    mRecyclerView.setLayoutManager(layoutManager);

    items = new ArrayList<Tweet>();

    try {
        items.add(new Tweet(new JSONObject("{\n" + "      \"id\": \"f808d40b-4c54-4824-b3e0-8217e0840067\",\n"
                + "      \"type\": \"tweets\",\n" + "      \"attributes\": {\n"
                + "        \"author\": \"Tang Rufus\",\n" + "        \"body\": \"Hi all\",\n"
                + "        \"created-at\": \"2015-02-17T01:28:32.402Z\"\n" + "      }\n" + "    }")));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    // specify an adapter (see also next example)
    mAdapter = new TweetAdapter(items);
    mRecyclerView.setAdapter(mAdapter);

    setEndpointURL(this);

    refresh_handler = new Handler();
    refresh_runnable = new Runnable() {
        @Override
        public void run() {
            if (!refresh) {
                ProfileActivity.this.get();
                refresh_handler.postDelayed(this, 50000);
                refresh = true;
            }
        }
    };

}

From source file:com.androguide.honamicontrol.soundcontrol.SoundControlFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.link_seekbars:
        SharedPreferences soundPrefs = fa.getSharedPreferences("SOUND_CONTROL", 0);
        if (item.isChecked()) {
            item.setChecked(false);
            soundPrefs.edit().putBoolean("LINKED", false).commit();
        } else {//from   w ww  .j a  v a  2 s  .  co  m
            item.setChecked(true);
            soundPrefs.edit().putBoolean("LINKED", true).commit();
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.afollestad.polar.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    if (!Config.get().changelogEnabled())
        menu.findItem(R.id.changelog).setVisible(false);

    MenuItem darkTheme = menu.findItem(R.id.darkTheme);
    if (!Config.get().allowThemeSwitching())
        darkTheme.setVisible(false);//from   ww w  .j a  va  2  s. c  om
    else
        darkTheme.setChecked(darkTheme());

    MenuItem navDrawerMode = menu.findItem(R.id.navDrawerMode);
    if (Config.get().navDrawerModeAllowSwitch()) {
        navDrawerMode.setVisible(true);
        navDrawerMode.setChecked(Config.get().navDrawerModeEnabled());
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.alainesp.fan.sanderson.MainActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (!item.isChecked()) {
        if (id != R.id.nav_about) {
            this.setTitle(item.getTitle());
            item.setChecked(true);
        }//from   w ww .j  a  v  a2  s .co  m

        if (id == R.id.nav_main) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new SummaryFragment()).commit();
            app_state = APP_STATE_SUMMARY;
        } else if (id == R.id.nav_blog) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new BlogPostsFragment())
                    .commit();
            app_state = APP_STATE_BLOG;
        } else if (id == R.id.nav_events) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new EventsFragment()).commit();
            app_state = APP_STATE_EVENTS;
        } else if (id == R.id.nav_books) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new BooksFragment()).commit();
            app_state = APP_STATE_BOOKS;
        } else if (id == R.id.nav_twitter) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new TwitterFragment()).commit();
            app_state = APP_STATE_TWITTER;
        } else if (id == R.id.nav_tor0) {
            Uri webpage = Uri.parse("http://www.tor.com/features/series/the-way-of-kings-reread-on-torcom/");
            Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
            if (isIntentSafe(webIntent))
                startActivity(webIntent);

            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new TorWoKRereadFragment())
                    .commit();
            app_state = APP_STATE_WOK;
            this.setTitle("The Way of Kings Reread");
        } else if (id == R.id.nav_tor1) {
            //Uri webpage = Uri.parse("http://www.tor.com/series/words-of-radiance-reread-on-torcom/");
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new TorWoRRereadFragment())
                    .commit();
            app_state = APP_STATE_WOR;
            this.setTitle("Words of Radiance Reread");
        } else if (id == R.id.nav_17shard)// TODO: Handle posts and news in the app
        {
            Uri webpage = Uri.parse("http://www.17thshard.com/forum/");
            Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
            if (isIntentSafe(webIntent))
                startActivity(webIntent);

            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new Shard17thFragment())
                    .commit();
            app_state = APP_STATE_17SHARD;
        } else if (id == R.id.nav_settings) {
            getFragmentManager().beginTransaction().replace(R.id.main_fragment, new SettingsFragment())
                    .commit();
            app_state = APP_STATE_SETTINGS;
        } else if (id == R.id.nav_about) {
            try {
                new AlertDialog.Builder(this).setTitle("About")
                        .setMessage(Html.fromHtml("<em>Fan of Sanderson</em> "
                                + getPackageManager().getPackageInfo(getPackageName(), 0).versionName + " BETA"
                                + "<br/><br/>Application made by fans to fans.<br/><br/>"
                                + "Developer: Alain Espinosa &lt;alainesp@gmail.com&gt;"))
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create().show();
            } catch (PackageManager.NameNotFoundException ignored) {
            }
        }
    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}

From source file:info.papdt.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable() && item.isEnabled()) {
        item.setChecked(!item.isChecked());
    }/*from   www. ja v  a 2s.  c om*/

    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

From source file:de.badaix.snapcast.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_snapcast, menu);
    miStartStop = menu.findItem(R.id.action_play_stop);
    miSettings = menu.findItem(R.id.action_settings);
    //        miRefresh = menu.findItem(R.id.action_refresh);
    updateStartStopMenuItem();//from  ww w .j  a v  a2  s  .c o  m
    boolean isChecked = Settings.getInstance(this).getBoolean("hide_offline", false);
    MenuItem menuItem = menu.findItem(R.id.action_hide_offline);
    menuItem.setChecked(isChecked);
    sectionsPagerAdapter.setHideOffline(isChecked);
    //        setHost(host, port, controlPort);
    if (remoteControl != null) {
        updateMenuItems(remoteControl.isConnected());
    }
    return true;
}

From source file:pl.bcichecki.rms.client.android.fragments.EventsListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getActivity().getMenuInflater().inflate(R.menu.fragment_events_list, menu);

    MenuItem showArchivedMenuItem = menu.findItem(R.id.fragment_events_list_menu_show_archived);
    showArchivedMenuItem.setChecked(showArchivedEvents);
    showArchivedMenuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

        @Override//from ww  w  .j av a2  s .co m
        public boolean onMenuItemClick(MenuItem item) {
            item.setChecked(!item.isChecked());
            showArchivedEvents = item.isChecked();

            downloadData();
            downloadArchivedData();

            return false;
        }
    });
}

From source file:hu.zelena.guide.MainActivity.java

@Override
public void onBackPressed() {
    if (mDrawer.isDrawerOpen(GravityCompat.START)) {
        mDrawer.closeDrawers();/*from   www.  ja v  a2s. c  o m*/
    } else {

        if (doubleBackToExitPressedOnce) {
            super.onBackPressed();
            return;
        }

        Fragment fragment = new AboutFragment();
        if (fragment != null) {
            firstFrag = true;
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
            setTitle("MOBILTUDS GUIDE");

            final Menu menu = nvDrawer.getMenu();
            for (int i = 0; i < menu.size(); i++) {
                MenuItem item = menu.getItem(i);
                if (item.hasSubMenu()) {
                    SubMenu subMenu = item.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        subMenuItem.setChecked(false);
                    }
                } else {
                    item.setChecked(false);
                }
            }
        } else {
            Intent i = new Intent(this, ErrorActivity.class);
            i.putExtra("error", "Nem sikerlt a HOME-FRAGMENT betltse. [Null object]");
            startActivity(i);

            Log.e("MainActivity", "Error in creating fragment");
        }
        this.doubleBackToExitPressedOnce = true;
        Toast.makeText(this, "Nyomja meg mgegyszer a kilpshez", Toast.LENGTH_SHORT).show();

        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                doubleBackToExitPressedOnce = false;
            }
        }, 2000);
    }
}