List of usage examples for android.view MenuItem isChecked
public boolean isChecked();
From source file:com.owncloud.android.ui.fragment.FileDetailSharingFragment.java
private boolean optionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_hide_file_listing: { item.setChecked(!item.isChecked()); if (capabilities.getFilesFileDrop().isTrue()) { setHideFileListingPermissionsToShare(publicShare, item.isChecked()); } else {/*from w ww .j ava 2 s .co m*/ // not supported in ownCloud showNotSupportedByOcMessage(); } return true; } case R.id.action_password: { requestPasswordForShareViaLink(false); return true; } case R.id.action_share_expiration_date: { ExpirationDatePickerDialogFragment dialog = ExpirationDatePickerDialogFragment.newInstance(file, -1); dialog.show(getActivity().getSupportFragmentManager(), ExpirationDatePickerDialogFragment.DATE_PICKER_DIALOG); return true; } case R.id.action_share_send_link: { if (shareByLink.isChecked() && file.isSharedViaLink() && !TextUtils.isEmpty(file.getPublicLink())) { ((FileDisplayActivity) getActivity()).showShareLinkDialog(file.getPublicLink()); } else { showSendLinkTo(); } return true; } default: return super.onOptionsItemSelected(item); } }
From source file:org.comixwall.pffw.MainActivity.java
/** * Select the fragment to display./*from w ww . ja v a2s .com*/ * We modify the backstack ourselves so that no fragment is pushed to the backstack twice. * So if a fragment which is already in the backstack is selected, we roll back the backstack * to its position. * <p> * We never push the Dashboard fragment to the backstack because it is always * the first fragment displayed (if we push it to the backstack too, pressing the back button * while Dashboard fragment is displayed causes a blank activity screen). * * @param item The menu item selected. * @return See {@link NavigationView.OnNavigationItemSelectedListener} */ @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { // Handle navigation view item clicks here. int id = item.getItemId(); // Ignore requests for the same fragment already displayed if (!mMenuItems2Fragments.get(id).isInstance(fragment)) { FragmentManager fm = getSupportFragmentManager(); boolean add = true; if (id == R.id.menuDashboard) { // Dashboard is the main fragment, should never be removed, // so remove all backstack entries first to reach the first Dashboard. popAllBackStack(); // Never add Dashboard to the backstack add = false; fragment = new Dashboard(); // ATTENTION: menuDashboard does not check initially, so we need to manage it ourselves item.setChecked(true); } else { // TODO: Check why android:checkableBehavior="single" does not uncheck menuDashboard MenuItem itemDashboard = navigationView.getMenu().findItem(R.id.menuDashboard); if (itemDashboard.isChecked()) { itemDashboard.setChecked(false); } try { fragment = (Fragment) mMenuItems2Fragments.get(id).getConstructor().newInstance(); } catch (Exception e) { e.printStackTrace(); logger.severe("EXCEPTION: " + e.toString()); return false; } } String fragmentName = fragment.getClass().getSimpleName(); // Rolls back the backstack if the fragment is already in if (!fm.popBackStackImmediate(fragmentName, 0)) { android.support.v4.app.FragmentTransaction transaction = fm.beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); if (add) { transaction.addToBackStack(fragmentName); } // TODO: Check if we need to pass any args //fragment.setArguments(getIntent().getExtras()); transaction.replace(R.id.fragmentContainer, fragment); transaction.commit(); } } else { logger.finest("onNavigationItemSelected will not show the same fragment"); } drawer.closeDrawer(GravityCompat.START); createOptionsMenu(); return true; }
From source file:com.example.ronald.tracle.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new DownloadTask().execute("https://flifo-qa.api.aero/flifo/v3/flight/sin/sq/998/d"); /*//from w w w . j a v a 2s.com Parsing of data from previous activity */ String username = getIntent().getStringExtra("name"); String password = getIntent().getStringExtra("password"); String alias = getIntent().getStringExtra("alias"); myUser = username; pw = password; /* Declare your layout here */ Button sendBtn = (Button) findViewById(R.id.buttonSendAll); TextView nametv = (TextView) findViewById(R.id.username); TextView emailtv = (TextView) findViewById(R.id.email); emailtv.setText(username); nametv.setText(alias); // Initializing Toolbar and setting it as the actionbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); //Initializing NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view); //Setting Navigation View Item Selected Listener to handle the item click of the navigation menu 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 if (menuItem.isChecked()) menuItem.setChecked(false); else menuItem.setChecked(true); //Closing drawer on item click drawerLayout.closeDrawers(); //Check to see which item was being clicked and perform appropriate action switch (menuItem.getItemId()) { //Replacing the main content with ContentFragment Which is our Inbox View; case R.id.home: Intent intent = new Intent(MainActivity.this, MainActivity.class); startActivity(intent); return true; case R.id.explore: Intent intente = new Intent(MainActivity.this, SlideTab.class); startActivity(intente); return true; case R.id.network: Intent intentk = new Intent(MainActivity.this, SlideTab.class); startActivity(intentk); return true; case R.id.announcement: Intent intenti = new Intent(MainActivity.this, AnnounceActivity.class); startActivity(intenti); return true; case R.id.setting: String username = ""; String pw = ""; String PREFS_LOGIN_USERNAME_KEY = ""; String PREFS_LOGIN_PASSWORD_KEY = ""; PrefUtils.saveToPrefs(getApplication(), PREFS_LOGIN_USERNAME_KEY, username); PrefUtils.saveToPrefs(getApplication(), PREFS_LOGIN_PASSWORD_KEY, pw); System.exit(0); return true; // For rest of the options we just show a toast on click default: Toast.makeText(getApplicationContext(), "Somethings Wrong", Toast.LENGTH_SHORT).show(); return true; } } }); // 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); } @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); //Toast.makeText(this, "username: "+username+" pw: "+password, Toast.LENGTH_SHORT).show(); //calling sync state is necessay or else your hamburger icon wont show up actionBarDrawerToggle.syncState(); /* This is the initial step in getting back the token from GCM */ //mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar); mRegistrationBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { //mRegistrationProgressBar.setVisibility(ProgressBar.GONE); SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false); if (sentToken) { // mInformationTextView.setText(getString(R.string.gcm_send_message)); } else { // mInformationTextView.setText(getString(R.string.token_error_message)); } } }; //mInformationTextView = (TextView) findViewById(R.id.informationTextView); /* Check play services, if not GCM won't work. */ if (checkPlayServices()) { // Start IntentService to register this application with GCM. Intent intent = new Intent(this, RegistrationIntentService.class); Bundle localBundle = new Bundle(); localBundle.putString("name", username); localBundle.putString("password", password); intent.putExtras(localBundle); startService(intent); } }
From source file:org.xbmc.kore.ui.sections.video.TVShowListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); switch (item.getItemId()) { case R.id.action_hide_watched: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOWS_FILTER_HIDE_WATCHED, item.isChecked()).apply(); refreshList();/* www . ja v a2 s .c o m*/ break; case R.id.action_show_watched_status: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOWS_SHOW_WATCHED_STATUS, item.isChecked()).apply(); showWatchedStatus = item.isChecked(); refreshList(); break; case R.id.action_ignore_prefixes: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOWS_IGNORE_PREFIXES, item.isChecked()).apply(); refreshList(); break; case R.id.action_sort_by_name: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_NAME).apply(); refreshList(); break; case R.id.action_sort_by_year: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_YEAR).apply(); refreshList(); break; case R.id.action_sort_by_rating: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_RATING).apply(); refreshList(); break; case R.id.action_sort_by_date_added: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_DATE_ADDED).apply(); refreshList(); break; case R.id.action_sort_by_last_played: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_LAST_PLAYED).apply(); refreshList(); break; default: break; } return super.onOptionsItemSelected(item); }
From source file:org.xbmc.kore.ui.sections.video.MovieListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); switch (item.getItemId()) { case R.id.action_hide_watched: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_MOVIES_FILTER_HIDE_WATCHED, item.isChecked()).apply(); refreshList();//from ww w.java 2 s. co m break; case R.id.action_show_watched_status: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_MOVIES_SHOW_WATCHED_STATUS, item.isChecked()).apply(); showWatchedStatus = item.isChecked(); refreshList(); break; case R.id.action_ignore_prefixes: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_MOVIES_IGNORE_PREFIXES, item.isChecked()).apply(); refreshList(); break; case R.id.action_sort_by_name: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_NAME).apply(); refreshList(); break; case R.id.action_sort_by_year: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_YEAR).apply(); refreshList(); break; case R.id.action_sort_by_rating: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_RATING).apply(); refreshList(); break; case R.id.action_sort_by_date_added: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_DATE_ADDED).apply(); refreshList(); break; case R.id.action_sort_by_last_played: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_LAST_PLAYED).apply(); refreshList(); break; case R.id.action_sort_by_length: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_LENGTH).apply(); refreshList(); break; default: break; } return super.onOptionsItemSelected(item); }
From source file:io.mapsquare.osmcontributor.ui.activities.MapActivity.java
private void onNoteItemClick(MenuItem menuItem) { boolean checked = menuItem.isChecked(); switch (menuItem.getItemId()) { case R.id.display_open_notes_item: displayOpenNotes = checked;//from w w w. jav a2 s .c om break; case R.id.display_closed_notes_item: displayClosedNotes = checked; break; } eventBus.post(new PleaseApplyNoteFilterEvent(displayOpenNotes, displayClosedNotes)); }
From source file:com.syncedsynapse.kore2.ui.TVShowListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); switch (item.getItemId()) { case R.id.action_hide_watched: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOWS_FILTER_HIDE_WATCHED, item.isChecked()).apply(); getLoaderManager().restartLoader(LOADER_TVSHOWS, null, this); break;/*from w ww . java2 s. c om*/ case R.id.action_ignore_prefixes: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOWS_IGNORE_PREFIXES, item.isChecked()).apply(); getLoaderManager().restartLoader(LOADER_TVSHOWS, null, this); break; case R.id.action_sort_by_name: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_NAME).apply(); getLoaderManager().restartLoader(LOADER_TVSHOWS, null, this); break; case R.id.action_sort_by_date_added: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_TVSHOWS_SORT_ORDER, Settings.SORT_BY_DATE_ADDED).apply(); getLoaderManager().restartLoader(LOADER_TVSHOWS, null, this); break; default: break; } return super.onOptionsItemSelected(item); }
From source file:com.syncedsynapse.kore2.ui.TVShowEpisodeListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_hide_watched: item.setChecked(!item.isChecked()); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); preferences.edit().putBoolean(Settings.KEY_PREF_TVSHOW_EPISODES_FILTER_HIDE_WATCHED, item.isChecked()) .apply();/*ww w . j av a 2 s .c o m*/ getLoaderManager().restartLoader(LOADER_SEASONS, null, this); break; default: break; } return super.onOptionsItemSelected(item); }
From source file:org.mariotaku.twidere.fragment.RetweetQuoteDialogFragment.java
@NonNull @Override/*from w w w.ja v a2 s. co m*/ public Dialog onCreateDialog(final Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); final Context context = builder.getContext(); final ParcelableStatus status = getStatus(); assert status != null; final ParcelableCredentials credentials = ParcelableCredentialsUtils.getCredentials(getContext(), status.account_key); assert credentials != null; builder.setView(R.layout.dialog_status_quote_retweet); builder.setTitle(R.string.retweet_quote_confirm_title); builder.setPositiveButton(R.string.retweet, null); builder.setNegativeButton(android.R.string.cancel, null); builder.setNeutralButton(R.string.quote, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Intent intent = new Intent(INTENT_ACTION_QUOTE); final Menu menu = mPopupMenu.getMenu(); final MenuItem quoteOriginalStatus = menu.findItem(R.id.quote_original_status); intent.putExtra(EXTRA_STATUS, status); intent.putExtra(EXTRA_QUOTE_ORIGINAL_STATUS, quoteOriginalStatus.isChecked()); startActivity(intent); } }); final Dialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final AlertDialog dialog = (AlertDialog) dialogInterface; final View itemContent = dialog.findViewById(R.id.item_content); final StatusTextCountView textCountView = (StatusTextCountView) dialog .findViewById(R.id.comment_text_count); final View itemMenu = dialog.findViewById(R.id.item_menu); final View actionButtons = dialog.findViewById(R.id.action_buttons); final View commentContainer = dialog.findViewById(R.id.comment_container); final ComposeEditText editComment = (ComposeEditText) dialog.findViewById(R.id.edit_comment); final View commentMenu = dialog.findViewById(R.id.comment_menu); assert itemContent != null && textCountView != null && itemMenu != null && actionButtons != null && commentContainer != null && editComment != null && commentMenu != null; final DummyItemAdapter adapter = new DummyItemAdapter(context); adapter.setShouldShowAccountsColor(true); final IStatusViewHolder holder = new StatusViewHolder(adapter, itemContent); holder.displayStatus(status, false, true); textCountView.setMaxLength(TwidereValidator.getTextLimit(credentials)); itemMenu.setVisibility(View.GONE); actionButtons.setVisibility(View.GONE); itemContent.setFocusable(false); final boolean useQuote = useQuote(!status.user_is_protected, credentials); commentContainer.setVisibility(useQuote ? View.VISIBLE : View.GONE); editComment.setAccountKey(status.account_key); final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND); final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach(editComment, new EditTextEnterHandler.EnterListener() { @Override public boolean shouldCallListener() { return true; } @Override public boolean onHitEnter() { final ParcelableStatus status = getStatus(); if (status == null) return false; if (retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM)) { dismiss(); return true; } return false; } }, sendByEnter); enterHandler.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateTextCount(getDialog(), s, status, credentials); } @Override public void afterTextChanged(Editable s) { } }); mPopupMenu = new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0); commentMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mPopupMenu.show(); } }); commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener()); mPopupMenu.inflate(R.menu.menu_dialog_comment); final Menu menu = mPopupMenu.getMenu(); MenuUtils.setMenuItemAvailability(menu, R.id.quote_original_status, status.retweet_id != null || status.quoted_id != null); mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.isCheckable()) { item.setChecked(!item.isChecked()); return true; } return false; } }); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { boolean dismissDialog = false; if (editComment.length() > 0) { dismissDialog = retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM); } else if (isMyRetweet(status)) { mTwitterWrapper.cancelRetweetAsync(status.account_key, status.id, status.my_retweet_id); dismissDialog = true; } else if (useQuote(!status.user_is_protected, credentials)) { dismissDialog = retweetOrQuote(credentials, status, SHOW_PROTECTED_CONFIRM); } else { TwidereBugReporter.logException(new IllegalStateException(status.toString())); } if (dismissDialog) { dismiss(); } } }); updateTextCount(dialog, editComment.getText(), status, credentials); } }); return dialog; }
From source file:com.syncedsynapse.kore2.ui.MovieListFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); switch (item.getItemId()) { case R.id.action_hide_watched: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_MOVIES_FILTER_HIDE_WATCHED, item.isChecked()).apply(); getLoaderManager().restartLoader(LOADER_MOVIES, null, this); break;// w w w .jav a2s. com case R.id.action_ignore_prefixes: item.setChecked(!item.isChecked()); preferences.edit().putBoolean(Settings.KEY_PREF_MOVIES_IGNORE_PREFIXES, item.isChecked()).apply(); getLoaderManager().restartLoader(LOADER_MOVIES, null, this); break; case R.id.action_sort_by_name: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_NAME).apply(); getLoaderManager().restartLoader(LOADER_MOVIES, null, this); break; case R.id.action_sort_by_date_added: item.setChecked(true); preferences.edit().putInt(Settings.KEY_PREF_MOVIES_SORT_ORDER, Settings.SORT_BY_DATE_ADDED).apply(); getLoaderManager().restartLoader(LOADER_MOVIES, null, this); break; default: break; } return super.onOptionsItemSelected(item); }