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:org.berlin_vegan.bvapp.activities.LocationsOverviewActivity.java

public void selectDrawerItem(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
    case R.id.nav_gastro:
        applyShownDataType(Locations.DATA_TYPE.GASTRO);
        menuItem.setChecked(true);
        break;/*from w ww  .  j  a v  a 2  s . com*/
    case R.id.nav_shopping:
        applyShownDataType(Locations.DATA_TYPE.SHOPPING);
        menuItem.setChecked(true);
        break;
    case R.id.nav_fav:
        applyShownDataType(Locations.DATA_TYPE.FAVORITE);
        menuItem.setChecked(true);
        break;
    case R.id.nav_rate:
        //set this to false in foss FDroid
        UiUtils.rateApp(this, true);
        break;
    case R.id.nav_pref:
        final Intent settings = new Intent(this, SettingsActivity.class);
        startActivity(settings);
        break;
    case R.id.nav_about:
        if (mContext != null) {
            UiUtils.showMaterialAboutDialog(mContext, getResources().getString(R.string.action_about));
        }
    default:
        break;
    }
    mDrawer.closeDrawers();
}

From source file:com.fimo_pitch.main.MainActivity.java

public void initNavMenu() {
    if (navigationView != null) {
        if (userModel.getUserType().equals(UserModel.TYPE_OWNER)) {
            navigationView/*from  w w w.j  ava 2  s  . c  o  m*/
                    .setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
                        // This method will trigger on item Click of navigation menu
                        @Override
                        public boolean onNavigationItemSelected(MenuItem menuItem) {
                            menuItem.setChecked(true);
                            navigationView.setCheckedItem(menuItem.getItemId());

                            switch (menuItem.getItemId()) {
                            case R.id.menu_home: {
                                frameLayout.setVisibility(View.GONE);
                                viewPager.setVisibility(View.VISIBLE);
                                tabs.setVisibility(View.VISIBLE);
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_notification: {
                                //                                        Utils.openDialog(MainActivity.this,"Chc nng hin ti khng kh dng");
                                mNotifcationFragment = NotifcationFragment.newInstance("1", "");
                                replaceFragment(mNotifcationFragment,
                                        mNotifcationFragment.getClass().getName());
                                break;
                            }
                            case R.id.menu_search: {
                                //                                    Log.d(TAG,);
                                mSearchFragment = SearchFragment.newInstance(listSystemData, "");
                                replaceFragment(mSearchFragment, mSearchFragment.getClass().getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_searchSysttem: {
                                //                                    Log.d(TAG,);
                                mSearchSytem = SearchSystemFragment.newInstance(listSystemData, "");
                                replaceFragment(mSearchSytem, mSearchSytem.getClass().getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_manage: {
                                replaceFragment(new OwnerFragment().newInstance("", ""),
                                        OwnerFragment.class.getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_settings: {
                                replaceFragment(new SettingsFragment().newInstance("", ""),
                                        NotifcationFragment.class.getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_logout: {
                                logoutDialog();
                                mDrawerLayout.closeDrawers();
                                break;
                            }

                            }
                            return true;
                        }
                    });
        } else {
            navigationView
                    .setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
                        // This method will trigger on item Click of navigation menu
                        @Override
                        public boolean onNavigationItemSelected(MenuItem menuItem) {
                            //                            ShowToast.showToastLong(MainActivity.this,mSystemPitchArrayList.size()+"");
                            menuItem.setChecked(true);
                            navigationView.setCheckedItem(menuItem.getItemId());

                            switch (menuItem.getItemId()) {
                            case R.id.menu_home: {
                                frameLayout.setVisibility(View.GONE);
                                viewPager.setVisibility(View.VISIBLE);
                                tabs.setVisibility(View.VISIBLE);
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_notification: {
                                Utils.openDialog(MainActivity.this,
                                        "Chc nng hin ti khng kh dng");
                                break;
                            }
                            case R.id.menu_search: {
                                //                                    Log.d(TAG,);
                                try {
                                    mSearchFragment = SearchFragment.newInstance(listSystemData, "");
                                    replaceFragment(mSearchFragment, mSearchFragment.getClass().getName());
                                    mDrawerLayout.closeDrawers();
                                    break;
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }
                            case R.id.menu_searchSysttem: {
                                //                                    Log.d(TAG,);
                                mSearchSytem = SearchSystemFragment.newInstance(listSystemData, "");
                                replaceFragment(mSearchSytem, mSearchSytem.getClass().getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_manage: {
                                replaceFragment(new UserOrderManagement(""), OwnerFragment.class.getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_settings: {
                                replaceFragment(new SettingsFragment().newInstance("", ""),
                                        NotifcationFragment.class.getName());
                                mDrawerLayout.closeDrawers();
                                break;
                            }
                            case R.id.menu_logout: {
                                logoutDialog();
                                mDrawerLayout.closeDrawers();
                                break;
                            }

                            }
                            return true;
                        }
                    });
        }
    }
    String fromNotification = getIntent().getStringExtra(CONSTANT.FROM_NOTIFICATION);

    if (fromNotification.contains("true")) {
        tabs.setVisibility(View.GONE);
        viewPager.setVisibility(View.GONE);
        frameLayout.setVisibility(View.VISIBLE);
        mNotifcationFragment = NotifcationFragment.newInstance("1", "1");
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.container, mNotifcationFragment, mNotifcationFragment.getClass().getName())
                .commit();
        mDrawerLayout.closeDrawers();
        //            Intent intent = new Intent(MainActivity.this,OrderManagementActivity.class);
        //            startActivity(intent);
    }
}

From source file:edu.Groove9.TunesMaster.statistics.StatisticsActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override/*w  w w.java2 s .  c om*/
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.list_navigation_menu_item:
                Intent intent = new Intent(StatisticsActivity.this, PlaylistActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                break;
            case R.id.statistics_navigation_menu_item:
                // Do nothing, we're already on that screen
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:com.emman.tame.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.

    int id = item.getItemId();
    if (id == R.id.settings) {
        startActivity(new Intent(this, Settings.class));
        return true;
    } else if (id == R.id.debug) {
        item.setChecked(!item.isChecked());
        if (item.isChecked())
            Utils.burntToast(this, getString(R.string.item_msg_tamelog, FILE_TAME_LOG));
        updateSharedPrefs(mPreferences, TAME_DEBUG, Utils.boolToString(item.isChecked()));
        return true;
    } else if (id == R.id.sob) {
        item.setChecked(!item.isChecked());
        TextView mSOBNote = (TextView) findViewById(R.id.sobnote);
        if (mSOBNote != null)
            mSOBNote.setEnabled(item.isChecked());
        updateSharedPrefs(mPreferences, SET_ON_BOOT, Utils.boolToString(item.isChecked()));
        return true;
    }// ww w. java  2  s  . c o m
    return super.onOptionsItemSelected(item);
}

From source file:com.example.sans.myapplication.AssignActivity.java

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

    final SharedPreferences shares = getSharedPreferences("SHARES", 0);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//  w ww.  j ava 2s .co  m

    //requestWindowFeature(Window.FEATURE_NO_TITLE);

    actionBarTitle = (TextView) toolbar.findViewById(R.id.action_bar_title);

    Intent i = getIntent();

    Bundle bundle = i.getExtras();

    try {
        j = new JSONObject(bundle.getString("data", "ERROR"));

    } catch (JSONException e) {
        Toast.makeText(AssignActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
    }

    new Thread(new Runnable() {
        @Override
        public void run() {

            for (int i = 30; i > 0; i--) {

                try {
                    Thread.sleep(1000);
                    final int finalI = i;
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            actionBarTitle.setText("" + finalI + "");
                        }
                    });
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

            }

            Handler mainHandler = new Handler(AssignActivity.this.getMainLooper());

            Runnable myRunnable = new Runnable() {

                @Override
                public void run() {
                    final Client client = new Client();

                    RequestParams params = new RequestParams();

                    client.addHeader("Authorization", shares.getString("ACCESS_TOKEN", "ERROR"));

                    client.post("OrderDistributor/rejectOrder", params, new JsonHttpResponseHandler());
                }
            };

            mainHandler.post(myRunnable);

            AssignActivity.this.finish();

        }
    }).start();

    setUpMapIfNeeded();

    //Initializing NavigationView

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

    header = navigationView.inflateHeaderView(R.layout.header);
    JSONObject driver_data = null;
    try {
        driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR"));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    TextView driver_name_header = (TextView) header.findViewById(R.id.username);
    TextView car_id_header = (TextView) header.findViewById(R.id.car_id);
    final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image);

    try {
        car_id_header.setText(driver_data.getString("license"));
        driver_name_header.setText(driver_data.getString("name"));
        Client client = new Client();
        client.get(driver_data.getString("image"),
                new FileAsyncHttpResponseHandler(AssignActivity.this.getApplicationContext()) {
                    @Override
                    public void onFailure(int i, Header[] headers, Throwable throwable, File file) {

                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final File response) {

                        AssignActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Bitmap image = BitmapFactory.decodeFile(response.getPath());

                                pp_header.setImageBitmap(image);

                            }
                        });

                    }

                });
    } catch (JSONException e) {
        e.printStackTrace();
    }

    header.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(AssignActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", 0);
            AssignActivity.this.startActivity(i);
            drawerLayout.closeDrawers();
        }
    });

    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.timetable:
            case R.id.service:
            case R.id.history:
            case R.id.mission:
            case R.id.points:
            case R.id.notice:
                Intent i = new Intent(AssignActivity.this, MenuItemActivity.class);
                i.putExtra("MENU_ITEM", menuItem.getItemId());
                AssignActivity.this.startActivity(i);
                break;
            case R.id.login:
                Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show();
                SharedPreferences.Editor editor = shares.edit();

                final Client client = new Client();
                RequestParams params = new RequestParams();
                params.put("id", shares.getInt("ID", 0));
                params.put("status", 999);
                client.post("driver/setStatus", params, new JsonHttpResponseHandler());

                editor.putBoolean("ONLINE", false);
                editor.putBoolean("LOGIN", false);
                editor.commit();
                Intent intent = getApplicationContext().getPackageManager()
                        .getLaunchIntentForPackage(getApplicationContext().getPackageName());
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            default:
                Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show();
                break;

            }
            return false;
        }
    });

    reject = (Button) findViewById(R.id.reject);

    reject.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Client client = new Client();

            RequestParams params = new RequestParams();

            client.addHeader("Authorization", shares.getString("ACCESS_TOKEN", "ERROR"));

            client.post("OrderDistributor/rejectOrder", params, new JsonHttpResponseHandler());

            AssignActivity.this.finish();
        }
    });

    accept = (Button) findViewById(R.id.accept);

    accept.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Client client = new Client();

            final RequestParams params = new RequestParams();

            try {
                params.put("orderId", j.getJSONObject("order_data").getDouble("id"));

                client.addHeader("Authorization", shares.getString("ACCESS_TOKEN", "ERROR"));

                client.post("OrderDistributor/takeOrder", params, new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject response) {

                    }

                    @Override
                    public void onFailure(int statusCode, Header[] headers, Throwable error,
                            JSONObject response) {
                        Log.i("Status Code", "" + statusCode);
                    }
                });

                AssignActivity.this.finish();
            } catch (JSONException e) {
                e.printStackTrace();
            }

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

From source file:com.example.sans.myapplication.Utility.MainActivity.java

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

    shares = getSharedPreferences("SHARES", 0);

    Client client = new Client();

    loc_array = "";

    RequestParams params = new RequestParams();
    params.put("id", shares.getInt("ID", -1));
    params.put("loc_array", loc_array);

    client.addHeader("Authorization", shares.getString("ACCESS_TOKEN", ""));

    client.post("driver/updateLocation", params, new JsonHttpResponseHandler());

    Fragment newFragment = new OrderListFragment();
    FragmentTransaction transaction = getFragmentManager().beginTransaction();
    transaction.replace(R.id.frame, newFragment);
    transaction.addToBackStack(null);/*from   w ww . j a va  2 s.com*/
    transaction.commit();

    LocationRequest lr = LocationRequest.create();
    lr.setInterval(1000);
    lr.setFastestInterval(500);
    lr.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
    stored_locations = new ArrayList<Location>();

    controller = (AppController) getApplication();

    controller.startGetStatus();
    controller.startAquireOrder();

    // Initializing Toolbar and setting it as the actionbar
    toolbar = (Toolbar) findViewById(R.id.toolbar);

    order_num = (TextView) toolbar.findViewById(R.id.order_num);

    order_num.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nav = true;
            Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", R.id.timetable);
            MainActivity.this.startActivity(i);
        }
    });

    toolbar.findViewById(R.id.toolbar_calendar).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nav = true;
            Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", R.id.timetable);
            MainActivity.this.startActivity(i);
        }
    });
    setSupportActionBar(toolbar);

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

    //Location
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    ll = new myLocationListener();

    startLocationUpdates();

    //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu

    header = navigationView.inflateHeaderView(R.layout.header);
    JSONObject driver_data = null;
    try {
        driver_data = new JSONObject(shares.getString("DRIVER_DATA", "ERROR"));
    } catch (JSONException e) {
        e.printStackTrace();
    }

    TextView driver_name_header = (TextView) header.findViewById(R.id.username);
    TextView car_id_header = (TextView) header.findViewById(R.id.car_id);
    final ImageView pp_header = (ImageView) header.findViewById(R.id.profile_image);

    try {
        car_id_header.setText(driver_data.getString("license"));
        driver_name_header.setText(driver_data.getString("name"));
        client = new Client();
        client.get(driver_data.getString("image"),
                new FileAsyncHttpResponseHandler(MainActivity.this.getApplicationContext()) {
                    @Override
                    public void onFailure(int i, Header[] headers, Throwable throwable, File file) {

                    }

                    @Override
                    public void onSuccess(int statusCode, Header[] headers, final File response) {

                        MainActivity.this.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Bitmap image = BitmapFactory.decodeFile(response.getPath());

                                pp_header.setImageBitmap(image);

                            }
                        });

                    }

                });
    } catch (JSONException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {
        SharedPreferences.Editor editor = shares.edit();

        final Client client1 = new Client();
        RequestParams params1 = new RequestParams();

        editor.putBoolean("ONLINE", false);
        editor.putBoolean("LOGIN", false);
        editor.commit();
        Intent intent = getApplicationContext().getPackageManager()
                .getLaunchIntentForPackage(getApplicationContext().getPackageName());
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(intent);
    }

    header.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
            i.putExtra("MENU_ITEM", 0);
            MainActivity.this.startActivity(i);
            drawerLayout.closeDrawers();
        }
    });

    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.timetable:
            case R.id.service:
            case R.id.history:
            case R.id.mission:
            case R.id.points:
            case R.id.notice:
                Intent i = new Intent(MainActivity.this, MenuItemActivity.class);
                i.putExtra("MENU_ITEM", menuItem.getItemId());
                MainActivity.this.startActivity(i);
                break;
            case R.id.login:
                Toast.makeText(getApplicationContext(), "Logout Selected", Toast.LENGTH_SHORT).show();
                SharedPreferences.Editor editor = shares.edit();

                final Client client = new Client();
                RequestParams params = new RequestParams();
                params.put("id", shares.getInt("ID", 0));
                params.put("status", 999);
                client.post("driver/setStatus", params, new JsonHttpResponseHandler());

                editor.putBoolean("ONLINE", false);
                editor.putBoolean("LOGIN", false);
                editor.commit();
                Intent intent = getApplicationContext().getPackageManager()
                        .getLaunchIntentForPackage(getApplicationContext().getPackageName());
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intent);
                break;
            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,
            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();

}

From source file:ca.six.unittestapp.todo.tasks.TasksActivity.java

private void setupDrawerContent(NavigationView navigationView) {
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override//ww w  .j av  a  2s .co  m
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
            case R.id.list_navigation_menu_item:
                // Do nothing, we're already on that screen
                break;
            case R.id.statistics_navigation_menu_item:
                Intent intent = new Intent(TasksActivity.this, StatisticsActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                break;
            default:
                break;
            }
            // Close the navigation drawer when an item is selected.
            menuItem.setChecked(true);
            mDrawerLayout.closeDrawers();
            return true;
        }
    });
}

From source file:net.sourceforge.fidocadj.FidoMain.java

/** Create the menus to be shown and ensure that the checkable items
   do reflect the current state of the application.
*///  w  w  w.  j  a  va  2 s  .c  o  m
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);

    // Set the correct checking state.
    MenuItem showGrid = menu.findItem(R.id.showgrid);
    showGrid.setChecked(drawingPanel.getShowGrid());
    MenuItem snapToGrid = menu.findItem(R.id.snaptogrid);
    snapToGrid.setChecked(drawingPanel.getMapCoordinates().getSnap());
    MenuItem useSensors = menu.findItem(R.id.use_sensors_rotate_mirror);
    useSensors.setChecked(activateSensors);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.inovex.zabbixmobile.activities.BaseActivity.java

@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
    Intent intent;/*from  ww w  . ja v a  2  s .c  o  m*/
    if (menuItem.isChecked())
        menuItem.setChecked(false);
    else
        menuItem.setChecked(true);

    if (mServerSelectMode) {
        selectServerItem(menuItem.getItemId());
        toggleServerSelectionMode();
        return true;
    }

    //Closing drawer on item click
    switch (menuItem.getItemId()) {
    case R.id.navigation_item_problems:
        intent = new Intent(this, ProblemsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        mDrawerLayout.closeDrawers();
        break;
    case R.id.navigation_item_events:
        intent = new Intent(this, EventsActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        mDrawerLayout.closeDrawers();
        break;
    case R.id.navigation_item_checks:
        intent = new Intent(this, ChecksActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        mDrawerLayout.closeDrawers();
        break;
    case R.id.navigation_item_screens:
        intent = new Intent(this, ScreensActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        mDrawerLayout.closeDrawers();
        break;
    case R.id.navigation_settings:
        intent = new Intent(this, ZaxPreferenceActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        startActivityForResult(intent, REQUEST_CODE_PREFERENCES);
        overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
        return true;
    case R.id.navigation_manage_servers:
        intent = new Intent(this, ServersActivity.class);
        break;
    case R.id.navigation_info:
        intent = new Intent(this, InfoActivity.class);
        break;
    default:
        return true;
    }
    startActivity(intent);
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // update selected item and title, then close the drawer
    //mDrawerFragment.selectMenuItem(position);
    return true;
}

From source file:com.granita.tasks.TaskListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.task_list_activity_menu, menu);

    // restore menu state
    MenuItem item = menu.findItem(R.id.menu_alarms);
    if (item != null) {
        item.setChecked(AlarmBroadcastReceiver.getAlarmPreference(this));
    }//from   w w  w  .j a v  a 2 s . c o  m

    // search
    setupSearch(menu);

    //customs start
    SharedPreferences sharedPref = getSharedPreferences("localPreferences", Context.MODE_PRIVATE);
    if (sharedPref.getBoolean(getString(R.string.HIDE_AD_BOOLEAN), false)) {
        //remove all ads
        MenuItem removeAdItem = menu.findItem(R.id.removeads);
        removeAdItem.setVisible(false);
    } else {
        MenuItem removeAdItem = menu.findItem(R.id.removeads);
        removeAdItem.setVisible(true);
    }
    //custom end

    return true;
}