List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:com.almarsoft.GroundhogReader.MessageListActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.messagelist_menu_newpost: String name = mPrefs.getString("name", null); String email = mPrefs.getString("email", null); if (name == null || name.trim().length() == 0 || email == null || email.trim().length() == 0) { new AlertDialog.Builder(this).setTitle(getString(R.string.user_info_unset)) .setMessage(getString(R.string.must_fill_name_email_goto_settings)) .setPositiveButton(getString(R.string.yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dlg, int sumthin) { startActivity(new Intent(MessageListActivity.this, OptionsActivity.class)); }/*from w w w . ja v a 2 s .c om*/ }).setNegativeButton(getString(R.string.no), null).show(); } else { Intent intent_Compose = new Intent(MessageListActivity.this, ComposeActivity.class); intent_Compose.putExtra("isNew", true); intent_Compose.putExtra("group", mGroup); startActivityForResult(intent_Compose, UsenetConstants.COMPOSEMESSAGEINTENT); } return true; case R.id.messagelist_menu_getnew: getNewMessagesFromServer(false); return true; case R.id.messagelist_menu_get_latest: getNewMessagesFromServer(true); return true; case R.id.messagelist_menu_refresh: threadMessagesFromDB(); return true; case R.id.messagelist_menu_markread: markAllRead(); return true; case R.id.messagelist_menu_charset: startActivity(new Intent(MessageListActivity.this, ReadCharsetActivity.class)); return true; case R.id.messagelist_menu_settings: startActivity(new Intent(MessageListActivity.this, OptionsActivity.class)); return true; case R.id.messagelist_menu_showread: Editor editor = mPrefs.edit(); item.setChecked(!item.isChecked()); editor.putBoolean("showRead", item.isChecked()); editor.commit(); threadMessagesFromDB(); return true; case R.id.messagelist_menu_managebanneds: Intent intent_bannedthreads = new Intent(MessageListActivity.this, BannedActivity.class); intent_bannedthreads.putExtra("typeban", UsenetConstants.BANNEDTHREADS); intent_bannedthreads.putExtra("group", mGroup); startActivityForResult(intent_bannedthreads, UsenetConstants.BANNEDACTIVITYINTENT); return true; case R.id.messagelist_menu_managebannedusers: Intent intent_bannedusers = new Intent(MessageListActivity.this, BannedActivity.class); intent_bannedusers.putExtra("typeban", UsenetConstants.BANNEDTROLLS); intent_bannedusers.putExtra("group", mGroup); startActivityForResult(intent_bannedusers, UsenetConstants.BANNEDACTIVITYINTENT); return true; case R.id.messagelist_menu_catchup: catchupGroup(); return true; } return false; }
From source file:org.de.jmg.learn.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. try {//from www . jav a 2 s . co m getMenuInflater().inflate(R.menu.main, menu); //findViewById(R.menu.main).setBackgroundColor(Color.BLACK); //.setBackgroundColor(Color.BLACK); //resize(); OptionsMenu = menu; if (OptionsMenu != null) { mnuAddNew = menu.findItem(R.id.mnuAddWord); mnuUploadToQuizlet = menu.findItem(R.id.mnuUploadToQuizlet); Resources resources = context.getResources(); DisplayMetrics metrics = resources.getDisplayMetrics(); int height = metrics.heightPixels; int viewTop = this.findViewById(Window.ID_ANDROID_CONTENT).getTop(); height = height - viewTop; double scale = (double) height / (double) 950; if (scale < .5f) { isSmallDevice = true; } if (Build.VERSION.SDK_INT < 11) { menu.findItem(R.id.mnuOpenQuizlet).setVisible(false); menu.findItem(R.id.mnuUploadToQuizlet).setVisible(false); } /* if (isSmallDevice) { MenuItemCompat.setShowAsAction(menu.findItem(R.id.mnuSaveAs), MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); } */ MenuItem mnuQuizlet = menu.findItem(R.id.mnuLoginQuizlet); mnuQuizlet.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { //throw new RuntimeException("Test"); return false; } }); if (BuildConfig.DEBUG) { mnuQuizlet.setVisible(true); } else { mnuQuizlet.setVisible(false); } MenuItem mnuAskReverse = OptionsMenu.findItem(R.id.mnuAskReverse); mnuAskReverse.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { item.setChecked(!item.isChecked()); vok.reverse = item.isChecked(); setMnuReverse(); return true; } }); setMnuReverse(); /* if (isSmallDevice) { MenuItem m = menu.findItem(R.id.mnuHome); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); m = menu.findItem(R.id.mnuFileOpen); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); m = menu.findItem(R.id.mnuSaveAs); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); m = menu.findItem(R.id.mnuAddWord); MenuItemCompat.setShowAsAction(m,MenuItemCompat.SHOW_AS_ACTION_IF_ROOM); //lib.ShowToast(this,"Menus set to IF_ROOM!"); } */ mainView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Ensure you call it only once : lib.removeLayoutListener(mainView.getViewTreeObserver(), this); //MainActivity.this.SetShowAsAction(mnuUploadToQuizlet); } }); return true; } throw new RuntimeException("menu is null!"); } catch (Exception ex) { lib.ShowException(this, ex); } return false; }
From source file:com.aimfire.gallery.GalleryActivity.java
/** * Override Activity lifecycle method.//from w w w . j a v a 2 s . c om */ @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent; /* * if user interacted with action bar, delay any scheduled hide() * operations to prevent the jarring behavior of controls going away * while interacting with the UI. */ if (AUTO_HIDE) { delayedHide(AUTO_HIDE_DELAY_SHORT_MILLIS); } switch (item.getItemId()) { case android.R.id.home: intent = new Intent(GalleryActivity.this, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(MainConsts.EXTRA_MSG, mIsMyMedia); startActivity(intent); break; case R.id.action_share: createDriveLink(); break; case R.id.action_thumb_view: switchThumbView(); break; case R.id.action_delete: deleteFile(); break; case R.id.action_anaglyph: if (!item.isChecked()) { mDisplayMode = DisplayMode.Anaglyph; if (item.getTitle().equals(getString(R.string.action_anaglyph_cyanred))) { mDisplaySwap = true; } else { mDisplaySwap = false; } item.setChecked(true); updateDisplayPrefs(); invalidateOptionsMenu(); switchDisplayMode(); } break; case R.id.action_sbs: if (!item.isChecked()) { mDisplayMode = DisplayMode.SbsFull; if (item.getTitle().equals(getString(R.string.action_sbs_cross))) { mDisplaySwap = true; } else { mDisplaySwap = false; } item.setChecked(true); updateDisplayPrefs(); invalidateOptionsMenu(); switchDisplayMode(); } break; case R.id.action_3dtv: if (!item.isChecked()) { mDisplayMode = DisplayMode.SbsHalf; item.setChecked(true); updateDisplayPrefs(); invalidateOptionsMenu(); switchDisplayMode(); } break; case R.id.action_swap: if (item.isChecked()) { mDisplaySwap = false; item.setChecked(false); } else { mDisplaySwap = true; item.setChecked(true); } updateDisplayPrefs(); invalidateOptionsMenu(); switchDisplayMode(); break; case R.id.action_grayscale: if (item.isChecked()) { mDisplayColor = true; item.setChecked(false); } else { mDisplayColor = false; item.setChecked(true); } updateDisplayPrefs(); invalidateOptionsMenu(); switchDisplayMode(); break; default: return super.onOptionsItemSelected(item); } return true; }
From source file:org.gdgsp.fragment.PeopleFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_random: // Se o tamanho da lista for maior que 0 significa que j carregou if (selectedList.size() > 0) { // Aqui vai gerar um nmero aleatrio entre 0 e o tamanho da lista - 1 Random random = new Random(); int number = random.nextInt(selectedList.size()); // Aps isso o aplicativo vai dar scroll e exibir a pessoa na posio do nmero aleatrio ((LinearLayoutManager) list.getLayoutManager()).scrollToPositionWithOffset(number, 0); if (person != null && selectedList.get(number).getId() == person.getId()) { count = 0;/*ww w . ja v a2s . c o m*/ // Verifica o tanto de tempo que a pessoa ficou com o alerta aberto, se demorar muito vai ter coisa errada, como mudar a hora do sistema e aguardar o sorteio final Timer timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { count++; } }, 1000, 1000); SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy"); String localDate = sdf.format(new Date()); SimpleDateFormat dbDateSDF = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); final String dbDate = dbDateSDF.format(new Date()); AlertDialog alertDialog = new AlertDialog.Builder(activity) .setTitle(getString(R.string.raffle_person)) .setMessage("Voc!\n\nSorteado s " + localDate) .setPositiveButton(getString(R.string.send), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface p1, int p2) { timer.cancel(); sendRaffle(dbDate); } }).setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface p1, int p2) { timer.cancel(); } }) .create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } else { AlertDialog alertDialog = new AlertDialog.Builder(activity) .setTitle(getString(R.string.raffle_person)) .setMessage(selectedList.get(number).getName()).setPositiveButton("OK", null).create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } } return true; case R.id.menu_hasapp: // Exibir apenas pessoas que usam o aplicativo, essa informao vem de um banco de dados no back-end item.setChecked(!item.isChecked()); selectedList.clear(); selectedList.addAll(item.isChecked() ? hasAppPeople : listPeople); adapter.notifyDataSetChanged(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:com.musiqueplayer.playlistequalizerandroidwear.activities.MainActivity.java
private void updatePosition(final MenuItem menuItem) { runnable = null;/*w w w .ja va2 s. c o m*/ switch (menuItem.getItemId()) { case R.id.nav_library: runnable = navigateLibrary; break; case R.id.nav_playlists: runnable = navigatePlaylist; break; case R.id.nav_folders: runnable = navigateFolder; break; case R.id.nav_nowplaying: NavigationUtils.navigateToNowplaying(MainActivity.this, false); break; case R.id.nav_queue: runnable = navigateQueue; break; case R.id.nav_timer: runnable = navigateTimer; break; case R.id.nav_settings: NavigationUtils.navigateToSettings(MainActivity.this); break; case R.id.nav_about: mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { final String APP_PNAME = "com.musiqueplayer.playlistequalizerandroidwear"; final Context mContext = getApplicationContext(); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( new ContextThemeWrapper(MainActivity.this, R.style.myDialog)); final SpannableString s = new SpannableString( Html.fromHtml("Thanks for downloading Music Player.<br>" + "Thanks for being an awesome user! If you enjoy using <b>Music Player</b> app, please take a moment to rate it with <b>5 stars</b>. " + "")); Linkify.addLinks(s, Linkify.ALL); alertDialogBuilder.setTitle("About"); alertDialogBuilder.setMessage(s); alertDialogBuilder.setPositiveButton("Rate Now", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { mContext.startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + APP_PNAME))); } }); alertDialogBuilder.setNegativeButton("Remind Later", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); SharedPreferences prefs = mContext.getSharedPreferences("apprater", 0); SharedPreferences.Editor editor = prefs.edit(); editor.putLong("launch_count", 0); editor.commit(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } }, 350); break; } if (runnable != null) { menuItem.setChecked(true); mDrawerLayout.closeDrawers(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { runnable.run(); } }, 350); } }
From source file:com.landenlabs.all_devtool.GpsFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int pos = -1; int id = item.getItemId(); switch (id) { case R.id.clock_12: s_hourFormat = s_hour12Format; addMsgToDetailRow(s_colorMsg, "12h Clock"); break;//w w w.ja v a2s . co m case R.id.clock_24: s_hourFormat = s_hour24Format; addMsgToDetailRow(s_colorMsg, "24h Clock"); break; case R.id.gps_clear_list: clearList(); break; case R.id.gps_fast_accurate: if (m_locationRequest != null) { m_locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); m_locationRequest.setSmallestDisplacement(0); addMsgToDetailRow(s_colorMsg, "1sec 0 miles HighPwr"); startLocationUpdates(); } break; case R.id.gps_fast_accurate_one_mile: if (m_locationRequest != null) { m_locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); m_locationRequest.setSmallestDisplacement(1609.0f); // 1 mile = 1609 km addMsgToDetailRow(s_colorMsg, "1sec 1 mile HighPwr"); startLocationUpdates(); } break; case R.id.gps_fast_balanced: if (m_locationRequest != null) { m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); m_locationRequest.setSmallestDisplacement(0); addMsgToDetailRow(s_colorMsg, "1sec 0 miles Balanced"); startLocationUpdates(); } break; case R.id.gps_fast_balanced_one_mile: if (m_locationRequest != null) { m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); m_locationRequest.setFastestInterval(GPS_FASTEST_INTERVAL); m_locationRequest.setSmallestDisplacement(1609.0f); // 1 mile = 1609 km addMsgToDetailRow(s_colorMsg, "1sec 1 miles Balanced"); startLocationUpdates(); } break; case R.id.gps_slow_balanced_one_mile: if (m_locationRequest != null) { m_locationRequest.setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY); m_locationRequest.setFastestInterval(GPS_SLOW_INTERVAL); m_locationRequest.setSmallestDisplacement(1609.0f); // 1 mile = 1609 km addMsgToDetailRow(s_colorMsg, "5min 1 miles Balanced"); startLocationUpdates(); } break; default: break; } item.setChecked(true); return super.onOptionsItemSelected(item); }
From source file:com.example.yuen.e_carei.ShowAppointmentList.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_list); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setTitle("E-care"); setSupportActionBar(toolbar);/*from ww w. j a v a 2s . co m*/ db = new SQLiteHandler(getApplicationContext()); session = new SessionManager(getApplicationContext()); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); NavigationView view = (NavigationView) findViewById(R.id.navigation_view); view.getMenu().getItem(1).setChecked(true); view.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(MenuItem menuItem) { Toast.makeText(ShowAppointmentList.this, menuItem.getItemId() + " pressed", Toast.LENGTH_LONG) .show(); Intent intent = new Intent(); Log.d(R.id.nav_1 + "", menuItem.getItemId() + " "); switch (menuItem.getItemId()) { case R.id.nav_1: intent.setClass(ShowAppointmentList.this, Case_history_review.class); startActivity(intent); break; case R.id.nav_2: intent.setClass(ShowAppointmentList.this, ShowAppointmentList.class); //intent .putExtra("name", "Hello B Activity"); startActivity(intent); break; case R.id.nav_3: intent.setClass(ShowAppointmentList.this, Appointmentcreate.class); //intent .putExtra("name", "Hello B Activity"); startActivity(intent); break; case R.id.nav_4: intent.setClass(ShowAppointmentList.this, AlarmActivity.class); //intent .putExtra("name", "Hello B Activity"); startActivity(intent); break; case R.id.nav_5: intent.setClass(ShowAppointmentList.this, PatientReport.class); //intent .putExtra("name", "Hello B Activity"); startActivity(intent); break; case R.id.nav_6: //logout AlertDialog.Builder builder = new AlertDialog.Builder(ShowAppointmentList.this); //Uncomment the below code to Set the message and title from the strings.xml file //builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title); //Setting message manually and performing action on button click builder.setMessage("Do you want to close this application ?").setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { session.setLogin(false); db.deleteUsers(); final Intent intent_logout = new Intent(ShowAppointmentList.this, LoginActivity.class); startActivity(intent_logout); finish(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually alert.setTitle("AlertDialogExample"); alert.show(); break; } menuItem.setChecked(true); drawerLayout.closeDrawers(); return true; } }); ActionBarDrawerToggle actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); } }; db = new SQLiteHandler(getApplicationContext()); dbuser = db.getUserDetails(); View header = view.getHeaderView(0); TextView headerName = (TextView) header.findViewById(R.id.drawer_name); username = dbuser.get("name"); uid = dbuser.get("uid"); headerName.setText(username); ImageLoader imageLoader = AppController.getInstance().getImageLoader(); com.example.yuen.e_carei_doctor.customlistviewvolley.CirculaireNetworkImageView headerphoto = (com.example.yuen.e_carei_doctor.customlistviewvolley.CirculaireNetworkImageView) header .findViewById(R.id.drawer_thumbnail); headerphoto.setImageUrl("http://10.89.133.147/test/" + dbuser.get("image"), imageLoader); drawerLayout.setDrawerListener(actionBarDrawerToggle); actionBarDrawerToggle.syncState(); mListView = (SwipeMenuListView) findViewById(R.id.listView); swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout); swipeRefreshLayout.setOnRefreshListener(this); /** * Showing Swipe Refresh animation on activity create * As animation won't start on onCreate, post runnable is used */ swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); fetchPatients(); } }); PD = new ProgressDialog(this); //Showing progress dialog before making http request PD.setMessage("Loading..."); PD.show(); mAdapter = new AppointmentListAdapter(this, appointmentList); mListView.setAdapter(mAdapter); //fetchPatients(); // step 1. create a MenuCreator SwipeMenuCreator creator = new SwipeMenuCreator() { @Override public void create(SwipeMenu menu) { // create "delete" item SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext()); // set item background deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9, 0x3F, 0x25))); // set item width deleteItem.setWidth(dp2px(90)); // set a icon deleteItem.setIcon(R.drawable.ic_delete); // add to menu menu.addMenuItem(deleteItem); } }; // set creator mListView.setMenuCreator(creator); // step 2. listener item click event mListView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(int position, SwipeMenu menu, int index) { AppointmentList item = appointmentList.get(position); switch (index) { case 0: // delete //delete(item); final String row_aid = aidlist.get(position).toString(); AlertDialog.Builder builder = new AlertDialog.Builder(ShowAppointmentList.this); //Setting message manually and performing action on button click builder.setMessage("Do you want to delete this row ?").setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { delete(uid, row_aid); fetchPatients(); } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // Action for 'NO' Button dialog.cancel(); } }); //Creating dialog box AlertDialog alert = builder.create(); //Setting the title manually alert.setTitle("AlertDialogExample"); alert.show(); break; } return false; } }); // set SwipeListener mListView.setOnSwipeListener(new SwipeMenuListView.OnSwipeListener() { @Override public void onSwipeStart(int position) { // swipe start } @Override public void onSwipeEnd(int position) { // swipe end } }); // set MenuStateChangeListener mListView.setOnMenuStateChangeListener(new SwipeMenuListView.OnMenuStateChangeListener() { @Override public void onMenuOpen(int position) { } @Override public void onMenuClose(int position) { } }); // other setting // listView.setCloseInterpolator(new BounceInterpolator()); // test item long click mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), position + " long click", Toast.LENGTH_SHORT).show(); return false; } }); }
From source file:hu.zelena.guide.MainActivity.java
public void selectDrawerItem(MenuItem menuItem) { Fragment fragment = null;//from w w w.j av a 2 s . c o m Bundle bundle = new Bundle(); switch (menuItem.getItemId()) { case R.id.alcatel_frag: fragment = new PhonesFragment(); brand = "Alcatel"; analyticINFO = brand; break; case R.id.apple_frag: fragment = new PhonesFragment(); brand = "Apple"; analyticINFO = brand; break; case R.id.balckberry_frag: fragment = new PhonesFragment(); brand = "BlackBerry"; analyticINFO = brand; break; case R.id.cat_frag: fragment = new PhonesFragment(); brand = "CAT"; analyticINFO = brand; break; case R.id.honor_frag: fragment = new PhonesFragment(); brand = "Honor"; analyticINFO = brand; break; case R.id.HTC_frag: fragment = new PhonesFragment(); brand = "HTC"; analyticINFO = brand; break; case R.id.huawei_frag: fragment = new PhonesFragment(); brand = "Huawei"; analyticINFO = brand; break; case R.id.lenovo_frag: fragment = new PhonesFragment(); brand = "Lenovo"; analyticINFO = brand; break; case R.id.lg_frag: fragment = new PhonesFragment(); brand = "LG"; analyticINFO = brand; break; case R.id.samsung_frag: fragment = new PhonesFragment(); brand = "Samsung"; analyticINFO = brand; break; case R.id.sony_frag: fragment = new PhonesFragment(); brand = "Sony"; analyticINFO = brand; break; case R.id.watch_frag: fragment = new WatchFragment(); analyticINFO = "Watch"; break; case R.id.tablet_frag: fragment = new TabletFragment(); analyticINFO = "Tablet"; break; case R.id.postpaid_frag: fragment = new PostPaidFragment(); analyticINFO = "PostPaid"; break; case R.id.prepaid_frag: fragment = new PrePaidFragment(); analyticINFO = "PrePaid"; break; case R.id.net_frag: fragment = new InternetFragment(); analyticINFO = "Net"; break; case R.id.magicbook_frag: fragment = new MagicbookFragment(); analyticINFO = "MagicBook"; break; case R.id.others_frag: fragment = new OthersFragment(); analyticINFO = "Others"; break; default: break; } if (fragment != null) { mTracker.send(new HitBuilders.EventBuilder().setCategory("Action") .setAction(analyticINFO + " drawer select").build()); firstFrag = false; bundle.putString("brand", brand); fragment.setArguments(bundle); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); } else { Intent i = new Intent(this, ErrorActivity.class); i.putExtra("error", "Nem sikerlt a FRAGMENT betltse. [Null object]"); startActivity(i); Log.e("MainActivity", "Error in creating fragment"); } // Kivlasztott kijellse menuItem.setChecked(true); // Cm bellts setTitle(menuItem.getTitle()); // Drawer bezrsa mDrawer.closeDrawers(); }
From source file:de.tap.easy_xkcd.Activities.MainActivity.java
public void selectDrawerItem(final MenuItem menuItem, final boolean showOverview) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (menuItem.getItemId() == R.id.nav_whatif) toolbar.setElevation(0);/*from w w w. ja v a2 s .c o m*/ else { Resources r = getResources(); float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4, r.getDisplayMetrics()); toolbar.setElevation(px); } } switch (menuItem.getItemId()) { case R.id.nav_browser: if (!prefHelper.isOnline(this) && !fullOffline) { showDrawerErrorToast(R.string.no_connection); return; } //showComicBrowserFragment animateToolbar(-300); showFragment("pref_random_comics", menuItem.getItemId(), "Comics", BROWSER_TAG, FAV_TAG, WHATIF_TAG, showOverview); break; case R.id.nav_favorites: //Check if there are any Favorites if (Favorites.getFavoriteList(this).length == 0) { showDrawerErrorToast(R.string.no_favorites); return; } //showFavoritesFragment animateToolbar(300); showFragment("pref_random_favorites", menuItem.getItemId(), getResources().getString(R.string.nv_favorites), FAV_TAG, BROWSER_TAG, WHATIF_TAG, showOverview); break; case R.id.nav_whatif: if (!prefHelper.isOnline(this) && !fullOfflineWhatIf) { showDrawerErrorToast(R.string.no_connection); return; } animateToolbar(300); if (getSupportFragmentManager().findFragmentByTag(WHATIF_TAG) == null) { mDrawer.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { showFragment("", menuItem.getItemId(), "What if?", WHATIF_TAG, FAV_TAG, BROWSER_TAG, showOverview); } }, 150); } else { showFragment("", menuItem.getItemId(), "What if?", WHATIF_TAG, FAV_TAG, BROWSER_TAG, showOverview); } break; case R.id.nav_settings: mDrawer.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(MainActivity.this, SettingsActivity.class); startActivity(i); } }, 200); return; case R.id.nav_feedback: mDrawer.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", "easyxkcd@gmail.com", null)); startActivity(Intent.createChooser(i, getResources().getString(R.string.nav_feedback_send))); } }, 200); return; case R.id.nav_about: mDrawer.closeDrawers(); new Handler().postDelayed(new Runnable() { @Override public void run() { Intent i = new Intent(MainActivity.this, AboutActivity.class); startActivity(i); } }, 250); return; } menuItem.setChecked(true); mDrawer.closeDrawers(); mCurrentFragment = menuItem.getItemId(); invalidateOptionsMenu(); }