@Override public boolean onPrepareOptionsMenu(Menu menu) { // Only show favourites and access tokens (DB-related) if the connected server has a DB // representation (non-public). MenuItem fullscreenItem = menu.findItem(R.id.menu_fullscreen); MenuItem favouritesViewItem = menu.findItem(R.id.menu_view_favorites_button); MenuItem accessTokensItem = menu.findItem(R.id.menu_access_tokens_button); userRegisterItem = menu.findItem(R.id.menu_user_register); userCommentItem = menu.findItem(R.id.menu_user_comment); userInformationItem = menu.findItem(R.id.menu_user_information); if (mService != null && mService.getConnectedServer() != null) { favouritesViewItem.setVisible(!mService.isConnectedServerPublic()); accessTokensItem.setVisible(!mService.isConnectedServerPublic()); } fullscreenItem.setVisible(mViewPager == null); // Only show fullscreen option if in tablet mode // Show whether or not SCO is enabled AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); bluetoothItem = menu.findItem(R.id.menu_bluetooth); bluetoothItem.setChecked(audioManager.isBluetoothScoOn()); return super.onPrepareOptionsMenu(menu); }
@Override public boolean onOptionsItemSelected(MenuItem item) { boolean connect = false; switch (item.getItemId()) { case OPTION_CONNECT: connect = true; break; case OPTION_LOCK_LANDSCAPE: setLockLandscape(!item.isChecked()); item.setChecked(isLockLandscape()); break; case OPTION_ENABLE_REMOTE_VIEW: controlFragment.setRemoteEnabled(!item.isChecked()); item.setChecked(controlFragment.isRemoteEnabled()); break; case OPTION_EXIT: finish(); break; case OPTION_HELP: showHelp(); break; case OPTION_EXAGGERATION: showVerticalExaggerationDialog(); break; case OPTION_FLY_HOME: communicator.sendMessage(new FlyHomeMessage()); break; case OPTION_SEND_LOCATION: setSendLocation(!item.isChecked()); item.setChecked(isSendLocation()); break; case android.R.id.home: getSupportActionBar().selectTab(getSupportActionBar().getTabAt(0)); connect = communicator.getState() != State.CONNECTED; break; } if (connect) { connect(); } return super.onOptionsItemSelected(item); }
private void changeSortOrFilter(String key, boolean state, MenuItem item) { // already start loading, do not need to wait on saving prefs getLoaderManager().restartLoader(ShowsFragment.LOADER_ID, null, this); // update menu item state, then save at last item.setChecked(state); PreferenceManager.getDefaultSharedPreferences(getActivity()) .edit() .putBoolean(key, state) .commit(); // refresh filter icon state getActivity().supportInvalidateOptionsMenu(); }
private void handleDistributionConversationEnabled(MenuItem item) { distributionType = ThreadDatabase.DistributionTypes.CONVERSATION; item.setChecked(true); if (threadId != -1) { new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { DatabaseFactory.getThreadDatabase(ConversationActivity.this) .setDistributionType(threadId, ThreadDatabase.DistributionTypes.CONVERSATION); return null; } }.execute(); } }
/* (non-Javadoc) * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem) */ @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_mute_button: if (!mService.isMuted()) { // Switching to muted updateMuteDeafenMenuItems(true, mService.isDeafened()); } else { // Switching to unmuted updateMuteDeafenMenuItems(false, false); } mService.setMuted(!mService.isMuted()); return true; case R.id.menu_deafen_button: updateMuteDeafenMenuItems(!mService.isDeafened(), !mService.isDeafened()); mService.setDeafened(!mService.isDeafened()); return true; case R.id.menu_fullscreen_chat: rightSplit.setVisibility( rightSplit.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); leftSplit.setVisibility(View.VISIBLE); fullscreenButton.setIcon(R.drawable.ic_action_unfullscreen); return true; case R.id.menu_fullscreen_channel: leftSplit.setVisibility( leftSplit.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); rightSplit.setVisibility(View.VISIBLE); fullscreenButton.setIcon(R.drawable.ic_action_unfullscreen); return true; case R.id.menu_fullscreen: if (leftSplit.getVisibility() == View.GONE || rightSplit.getVisibility() == View.GONE) { leftSplit.setVisibility(View.VISIBLE); rightSplit.setVisibility(View.VISIBLE); fullscreenButton.setIcon(R.drawable.ic_action_fullscreen); } return true; case R.id.menu_view_favorites_button: showFavouritesDialog(); return true; case R.id.menu_user_register: new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mService.registerSelf(); return null; } protected void onPostExecute(Void result) { Toast.makeText(ChannelActivity.this, R.string.registerSelfSuccess, Toast.LENGTH_SHORT) .show(); }; }.execute(); return true; case R.id.menu_user_comment: // TODO Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show(); return true; case R.id.menu_user_information: // TODO Toast.makeText(this, R.string.coming_soon, Toast.LENGTH_SHORT).show(); return true; case R.id.menu_clear_chat: mService.clearChat(); chatFragment.clear(); return true; case R.id.menu_search: return false; case R.id.menu_access_tokens_button: TokenDialogFragment dialogFragment = TokenDialogFragment.newInstance(); dialogFragment.setShowsDialog(mViewPager == null); dialogFragment.show(getSupportFragmentManager(), "tokens"); return true; case R.id.menu_bluetooth: item.setChecked(!item.isChecked()); if (item.isChecked()) mService.enableBluetooth(); else mService.disableBluetooth(); break; case R.id.menu_amplifier: AmplifierDialogFragment amplifierDialogFragment = AmplifierDialogFragment.newInstance(); amplifierDialogFragment.show(getSupportFragmentManager(), "amplifier"); return true; case R.id.menu_preferences: Intent intent = new Intent(this, Preferences.class); startActivity(intent); return true; case R.id.menu_disconnect_item: disconnect(); return true; } return super.onOptionsItemSelected(item); }