List of usage examples for android.view MenuItem setChecked
public MenuItem setChecked(boolean checked);
From source file:de.badaix.snapcast.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(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { ServerDialogFragment serverDialogFragment = new ServerDialogFragment(); serverDialogFragment.setHost(Settings.getInstance(this).getHost(), Settings.getInstance(this).getStreamPort(), Settings.getInstance(this).getControlPort()); serverDialogFragment.setAutoStart(Settings.getInstance(this).isAutostart()); serverDialogFragment.setListener(new ServerDialogFragment.ServerDialogListener() { @Override//from w w w . j av a2 s. c o m public void onHostChanged(String host, int streamPort, int controlPort) { setHost(host, streamPort, controlPort); startRemoteControl(); } @Override public void onAutoStartChanged(boolean autoStart) { Settings.getInstance(MainActivity.this).setAutostart(autoStart); } }); serverDialogFragment.show(getSupportFragmentManager(), "serverDialogFragment"); // NsdHelper.getInstance(this).startListening("_snapcast._tcp.", SERVICE_NAME, this); return true; } else if (id == R.id.action_play_stop) { if (bound && snapclientService.isRunning()) { stopSnapclient(); } else { item.setEnabled(false); startSnapclient(); } return true; } else if (id == R.id.action_hide_offline) { item.setChecked(!item.isChecked()); Settings.getInstance(this).put("hide_offline", item.isChecked()); sectionsPagerAdapter.setHideOffline(item.isChecked()); return true; } else if (id == R.id.action_refresh) { startRemoteControl(); remoteControl.getServerStatus(); } else if (id == R.id.action_about) { Intent intent = new Intent(this, AboutActivity.class); startActivity(intent); } return super.onOptionsItemSelected(item); }
From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { try {// www .j a v a 2 s. c o m if (mDrawerToggle.onOptionsItemSelected(item)) { return true; } } catch (Exception e) { } switch (item.getItemId()) { case R.id.menu_compose_with_search: Intent compose = new Intent(context, ComposeActivity.class); compose.putExtra("user", searchQuery.replaceAll("\"", "") + " "); startActivity(compose); return super.onOptionsItemSelected(item); case R.id.menu_save_search: Toast.makeText(context, getString(R.string.saving_search), Toast.LENGTH_SHORT).show(); new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context)); twitter.createSavedSearch(searchQuery.replaceAll("\"", "")); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(context, getString(R.string.success), Toast.LENGTH_SHORT).show(); } }); } catch (TwitterException e) { // something went wrong } } }).start(); return super.onOptionsItemSelected(item); case R.id.menu_settings: Intent settings = new Intent(context, SettingsActivity.class); startActivityForResult(settings, SETTINGS_RESULT); return true; case R.id.menu_pic_filter: listView.setVisibility(View.GONE); if (!item.isChecked()) { searchQuery += " filter:links twitter.com"; item.setChecked(true); } else { searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", ""); item.setChecked(false); } doSearch(searchQuery); return super.onOptionsItemSelected(item); case R.id.menu_remove_rt: listView.setVisibility(View.GONE); if (!item.isChecked()) { searchQuery += " -RT"; item.setChecked(true); } else { searchQuery = searchQuery.replace(" -RT", ""); item.setChecked(false); } doSearch(searchQuery); return super.onOptionsItemSelected(item); case R.id.menu_show_top_tweets: if (!item.isChecked()) { searchQuery += " TOP"; item.setChecked(true); } else { searchQuery = searchQuery.replace(" TOP", ""); item.setChecked(false); } doSearch(searchQuery); return super.onOptionsItemSelected(item); default: return super.onOptionsItemSelected(item); } }
From source file:com.klinker.android.twitter.activities.search.SearchPager.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: sharedPrefs.edit().putBoolean("should_refresh", false).commit(); onBackPressed();//from w ww . j a v a 2 s . c o m return true; case R.id.menu_settings: Intent settings = new Intent(context, SettingsActivity.class); startActivityForResult(settings, SETTINGS_RESULT); return true; case R.id.menu_save_search: Toast.makeText(context, getString(R.string.saving_search), Toast.LENGTH_SHORT).show(); new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, AppSettings.getInstance(context)); twitter.createSavedSearch(searchQuery.replace(" -RT", "").replace(" TOP", "")); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(context, getString(R.string.success), Toast.LENGTH_SHORT).show(); } }); } catch (TwitterException e) { // something went wrong } } }).start(); return super.onOptionsItemSelected(item); case R.id.menu_compose_with_search: Intent compose = new Intent(context, ComposeActivity.class); compose.putExtra("user", searchQuery); startActivity(compose); return super.onOptionsItemSelected(item); case R.id.menu_search: //overridePendingTransition(0,0); //finish(); //overridePendingTransition(0,0); //return super.onOptionsItemSelected(item); case R.id.menu_pic_filter: if (!item.isChecked()) { searchQuery += " filter:links twitter.com"; item.setChecked(true); } else { searchQuery = searchQuery.replace("filter:links", "").replace("twitter.com", ""); item.setChecked(false); } Intent broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH"); broadcast.putExtra("query", searchQuery); context.sendBroadcast(broadcast); return super.onOptionsItemSelected(item); case R.id.menu_remove_rt: if (!item.isChecked()) { searchQuery += " -RT"; item.setChecked(true); } else { searchQuery = searchQuery.replace(" -RT", ""); item.setChecked(false); } broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH"); broadcast.putExtra("query", searchQuery); context.sendBroadcast(broadcast); return super.onOptionsItemSelected(item); case R.id.menu_show_top_tweets: if (!item.isChecked()) { searchQuery += " TOP"; item.setChecked(true); } else { searchQuery = searchQuery.replace(" TOP", ""); item.setChecked(false); } broadcast = new Intent("com.klinker.android.twitter.NEW_SEARCH"); broadcast.putExtra("query", searchQuery); context.sendBroadcast(broadcast); return super.onOptionsItemSelected(item); default: return super.onOptionsItemSelected(item); } }
From source file:com.ubergeek42.WeechatAndroid.WeechatActivity.java
@MainThread @Override/*from w ww . j ava2s. c o m*/ @Cat("Menu") public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (slidy && drawerEnabled) { if (drawerShowing) hideDrawer(); else showDrawer(); } break; case R.id.menu_connection_state: if (state.contains(STARTED)) disconnect(); else connect(); break; case R.id.menu_preferences: Intent intent = new Intent(this, PreferencesActivity.class); startActivity(intent); break; case R.id.menu_close: BufferFragment current = adapter.getCurrentBufferFragment(); if (current != null) current.onBufferClosed(); break; case R.id.menu_hotlist: break; case R.id.menu_nicklist: final Buffer buffer = BufferList.findByFullName(adapter.getCurrentBufferFullName()); if (buffer == null) break; final NickListAdapter nicklistAdapter = new NickListAdapter(WeechatActivity.this, buffer); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setAdapter(nicklistAdapter, (dialogInterface, position) -> { Nick nick = nicklistAdapter.getItem(position); SendMessageEvent.fire("input 0x%x /query %s", buffer.pointer, nick.name); }); AlertDialog dialog = builder.create(); dialog.setTitle("squirrels are awesome"); dialog.setOnShowListener(nicklistAdapter); dialog.setOnDismissListener(nicklistAdapter); dialog.show(); break; case R.id.menu_filter_lines: final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(this); final boolean filter = !P.filterLines; item.setChecked(filter); p.edit().putBoolean(PREF_FILTER_LINES, filter).apply(); break; } return super.onOptionsItemSelected(item); }
From source file:org.fdroid.fdroid.AppDetails.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (getIntent().hasExtra(EXTRA_HINT_SEARCHING)) { finish();/* w w w . j a v a 2 s .c o m*/ } else { navigateUp(); } return true; case LAUNCH: launchApk(app.packageName); return true; case SHARE: shareApp(app); return true; case INSTALL: // Note that this handles updating as well as installing. if (app.suggestedVersionCode > 0) { final Apk apkToInstall = ApkProvider.Helper.find(this, app.packageName, app.suggestedVersionCode); install(apkToInstall); } return true; case UNINSTALL: removeApk(app.packageName); return true; case IGNOREALL: app.ignoreAllUpdates ^= true; item.setChecked(app.ignoreAllUpdates); return true; case IGNORETHIS: if (app.ignoreThisUpdate >= app.suggestedVersionCode) { app.ignoreThisUpdate = 0; } else { app.ignoreThisUpdate = app.suggestedVersionCode; } item.setChecked(app.ignoreThisUpdate > 0); return true; case SEND_VIA_BLUETOOTH: /* * If Bluetooth has not been enabled/turned on, then * enabling device discoverability will automatically enable Bluetooth */ Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121); startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH); // if this is successful, the Bluetooth transfer is started return true; } return super.onOptionsItemSelected(item); }
From source file:com.jtechme.apphub.AppDetailsData.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (getIntent().hasExtra(EXTRA_HINT_SEARCHING)) { finish();//from w w w . j a va2s .co m } else { navigateUp(); } return true; case LAUNCH: launchApk(app.packageName); return true; case SHARE: shareApp(app); return true; case INSTALL: // Note that this handles updating as well as installing. if (app.suggestedVercode > 0) { final Apk apkToInstall = ApkProvider.Helper.find(this, app.packageName, app.suggestedVercode); install(apkToInstall); } return true; case UNINSTALL: removeApk(app.packageName); return true; case IGNOREALL: app.ignoreAllUpdates ^= true; item.setChecked(app.ignoreAllUpdates); return true; case IGNORETHIS: if (app.ignoreThisUpdate >= app.suggestedVercode) app.ignoreThisUpdate = 0; else app.ignoreThisUpdate = app.suggestedVercode; item.setChecked(app.ignoreThisUpdate > 0); return true; case SEND_VIA_BLUETOOTH: /* * If Bluetooth has not been enabled/turned on, then * enabling device discoverability will automatically enable Bluetooth */ Intent discoverBt = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE); discoverBt.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 121); startActivityForResult(discoverBt, REQUEST_ENABLE_BLUETOOTH); // if this is successful, the Bluetooth transfer is started return true; } return super.onOptionsItemSelected(item); }
From source file:com.undatech.opaque.RemoteCanvasActivity.java
@Override public boolean onOptionsItemSelected(MenuItem menuItem) { int itemID = menuItem.getItemId(); switch (itemID) { case R.id.menuExtraKeys: if (connection.getExtraKeysToggleType() == Constants.EXTRA_KEYS_ON) { connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_OFF); menuItem.setTitle(R.string.extra_keys_enable); setExtraKeysVisibility(View.GONE, false); } else {/*w ww . j a va 2 s . co m*/ connection.setExtraKeysToggleType(Constants.EXTRA_KEYS_ON); menuItem.setTitle(R.string.extra_keys_disable); setExtraKeysVisibility(View.VISIBLE, false); extraKeysHidden = false; } setKeyStowDrawableAndVisibility(); connection.saveToSharedPreferences(getApplicationContext()); return true; case R.id.menuDisconnect: canvas.disconnectAndCleanUp(); finish(); return true; case R.id.menuSendCAD: canvas.getKeyboard().keyEvent(112, new KeyEvent(KeyEvent.ACTION_DOWN, 112), RemoteKeyboard.CTRL_ON_MASK | RemoteKeyboard.ALT_ON_MASK); canvas.getKeyboard().keyEvent(112, new KeyEvent(KeyEvent.ACTION_UP, 112)); return true; case R.id.menuHelpInputMethod: showDialog(R.id.menuHelpInputMethod); return true; default: InputHandler newInputHandler = inputHandlerIdMap.get(menuItem.getItemId()); if (newInputHandler != null) { inputHandler = newInputHandler; connection.setInputMethod(newInputHandler.getId()); menuItem.setChecked(true); displayInputModeInfo(true); connection.saveToSharedPreferences(getApplicationContext()); return true; } } return super.onOptionsItemSelected(menuItem); }
From source file:androidVNC.VncCanvasActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { vncCanvas.afterMenu = true;/*from w w w. ja v a 2s .c om*/ switch (item.getItemId()) { case fi.aalto.openoranges.project1.mcc.R.id.itemInfo: vncCanvas.showConnectionInfo(); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemSpecialKeys: showDialog(fi.aalto.openoranges.project1.mcc.R.layout.metakey); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemColorMode: selectColorModel(); return true; // Following sets one of the scaling options case fi.aalto.openoranges.project1.mcc.R.id.itemZoomable: case fi.aalto.openoranges.project1.mcc.R.id.itemOneToOne: case fi.aalto.openoranges.project1.mcc.R.id.itemFitToScreen: AbstractScaling.getById(item.getItemId()).setScaleTypeForActivity(this); item.setChecked(true); showPanningState(); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemCenterMouse: vncCanvas.warpMouse(vncCanvas.absoluteXPosition + vncCanvas.getVisibleWidth() / 2, vncCanvas.absoluteYPosition + vncCanvas.getVisibleHeight() / 2); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemDisconnect: vncCanvas.closeConnection(); finish(); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemEnterText: showDialog(fi.aalto.openoranges.project1.mcc.R.layout.entertext); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemCtrlAltDel: vncCanvas.sendMetaKey(MetaKeyBean.keyCtrlAltDel); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemFollowMouse: boolean newFollow = !connection.getFollowMouse(); item.setChecked(newFollow); connection.setFollowMouse(newFollow); if (newFollow) { vncCanvas.panToMouse(); } connection.save(database.getWritableDatabase()); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemFollowPan: boolean newFollowPan = !connection.getFollowPan(); item.setChecked(newFollowPan); connection.setFollowPan(newFollowPan); connection.save(database.getWritableDatabase()); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemArrowLeft: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowLeft); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemArrowUp: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowUp); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemArrowRight: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowRight); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemArrowDown: vncCanvas.sendMetaKey(MetaKeyBean.keyArrowDown); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemSendKeyAgain: sendSpecialKeyAgain(); return true; case fi.aalto.openoranges.project1.mcc.R.id.itemOpenDoc: Utils.showDocumentation(this); return true; default: AbstractInputHandler input = getInputHandlerById(item.getItemId()); if (input != null) { inputHandler = input; connection.setInputMode(input.getName()); if (input.getName().equals(TOUCHPAD_MODE)) connection.setFollowMouse(true); item.setChecked(true); showPanningState(); connection.save(database.getWritableDatabase()); return true; } } return super.onOptionsItemSelected(item); }
From source file:org.catnut.fragment.TweetFragment.java
@Override public boolean onMenuItemClick(MenuItem item) { // first check emotions if (item.getItemId() == R.id.action_emotions) { GridView emotions = (GridView) LayoutInflater.from(getActivity()).inflate(R.layout.emotions, null); emotions.setAdapter(new EmotionsAdapter(getActivity())); emotions.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// ww w . ja v a 2 s. c om public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int cursor = mSendText.getSelectionStart(); mSendText.getText().insert(cursor, CatnutUtils.text2Emotion(getActivity(), TweetImageSpan.EMOTION_KEYS[position], getResources().getInteger(R.integer.icon_bound_px))); mSendText.requestFocus(); } }); AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setView(emotions).create(); alertDialog.show(); alertDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, getResources().getDimensionPixelSize(R.dimen.emotion_window_height)); return true; } switch (item.getItemId()) { case R.id.action_reply_none: mRetweetOption = 0; break; case R.id.action_reply_current: mRetweetOption = 1; break; case R.id.action_reply_original: mRetweetOption = 2; break; case R.id.action_reply_both: mRetweetOption = 3; break; default: break; } if (!item.isChecked()) { item.setChecked(true); } return true; }
From source file:de.azapps.mirakel.main_activity.MainActivity.java
@Override public boolean onOptionsItemSelected(final MenuItem item) { if (this.mDrawerToggle.onOptionsItemSelected(item)) { return true; }/*w w w . ja v a2s . co m*/ switch (item.getItemId()) { case R.id.menu_delete: handleDestroyTask(this.currentTask); updateShare(); return true; case R.id.menu_move: handleMoveTask(this.currentTask); return true; case R.id.list_delete: handleDestroyList(this.currentList); return true; case R.id.task_sorting: this.currentList = ListDialogHelpers.handleSortBy(this, this.currentList, new Helpers.ExecInterface() { @Override public void exec() { setCurrentList(MainActivity.this.currentList); } }, null); return true; case R.id.menu_new_list: getListFragment().editList(null); return true; case R.id.menu_sort_lists: final boolean t = !item.isChecked(); getListFragment().enableDrop(t); item.setChecked(t); return true; case R.id.menu_settings: final Intent intent = new Intent(MainActivity.this, SettingsActivity.class); startActivityForResult(intent, MainActivity.RESULT_SETTINGS); break; case R.id.menu_contact: Helpers.contact(this); break; case R.id.menu_new_ui: MirakelCommonPreferences.setUseNewUI(true); Helpers.restartApp(this); break; case R.id.menu_sync_now: final Bundle bundle = new Bundle(); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true); bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true); new Thread(new Runnable() { @SuppressLint("InlinedApi") @Override public void run() { final List<AccountMirakel> accounts = AccountMirakel.getEnabled(true); for (final AccountMirakel a : accounts) { // davdroid accounts should be there only from // API>=14... ContentResolver.requestSync(a.getAndroidAccount(), DefinitionsHelper.AUTHORITY_TYP, bundle); } } }).start(); break; case R.id.share_task: SharingHelper.share(this, getCurrentTask()); break; case R.id.share_list: SharingHelper.share(this, getCurrentList()); break; case R.id.search: onSearchRequested(); break; case R.id.menu_undo: UndoHistory.undoLast(this); updateCurrentListAndTask(); if (this.currentPosition == getTaskFragmentPosition()) { setCurrentTask(this.currentTask); } else if ((getListFragment() != null) && (getTasksFragment() != null) && (getListFragment().getAdapter() != null) && (getTasksFragment().getAdapter() != null)) { getListFragment().getAdapter().changeData(ListMirakel.all()); getListFragment().getAdapter().notifyDataSetChanged(); getTasksFragment().getAdapter().notifyDataSetChanged(); if (!MirakelCommonPreferences.isTablet() && (this.currentPosition == MainActivity.getTasksFragmentPosition())) { setCurrentList(getCurrentList()); } } break; case R.id.mark_as_subtask: TaskDialogHelpers.handleSubtask(this, this.currentTask, null, true); break; case R.id.menu_task_clone: try { final Task newTask = this.currentTask.create(); setCurrentTask(newTask, true); getListFragment().update(); updatesForTask(newTask); } catch (final NoSuchListException e) { Log.wtf(MainActivity.TAG, "List vanished on task cloning"); } break; default: return super.onOptionsItemSelected(item); } return true; }