List of usage examples for android.view MenuItem setEnabled
public MenuItem setEnabled(boolean enabled);
From source file:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java
public AdminNVRAMTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) {/*from w w w. ja v a 2 s . co m*/ super(parentFragment, arguments, router, R.layout.tile_admin_nvram, R.id.tile_admin_nvram_togglebutton); sortIds.put(R.id.tile_admin_nvram_sort_default, 11); sortIds.put(R.id.tile_admin_nvram_sort_asc, 12); sortIds.put(R.id.tile_admin_nvram_sort_desc, 13); this.mNvramInfoDefaultSorting = new NVRAMInfo(); mRecyclerView = (RecyclerView) layout.findViewById(R.id.tile_admin_nvram_ListView); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView // allows for optimizations if all items are of the same size: mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(mParentFragmentActivity); mLayoutManager.scrollToPosition(0); mRecyclerView.setLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new NVRAMDataRecyclerViewAdapter(mParentFragmentActivity, router, mNvramInfoDefaultSorting); mRecyclerView.setAdapter(mAdapter); //Create Options Menu final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_admin_nvram_menu); if (!isThemeLight(mParentFragmentActivity, mRouter.getUuid())) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); } tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(AdminNVRAMTile.this); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_admin_nvram_options, menu); //Disable menu item from preference Integer currentSort = null; if (mParentFragmentPreferences != null) { currentSort = sortIds.inverse().get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), sortIds.get(R.id.tile_admin_nvram_sort_default))); } if (currentSort == null) { currentSort = R.id.tile_admin_nvram_sort_default; } final MenuItem currentSortMenuItem = menu.findItem(currentSort); if (currentSortMenuItem != null) { currentSortMenuItem.setEnabled(false); } // Locate MenuItem with ShareActionProvider final MenuItem shareMenuItem = menu.findItem(R.id.tile_admin_nvram_share); // Fetch and store ShareActionProvider mShareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider(); popup.show(); } }); //Handle for Search EditText final EditText filterEditText = (EditText) this.layout.findViewById(R.id.tile_admin_nvram_filter); //Initialize with existing search data filterEditText.setText(mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING) : EMPTY_STRING); filterEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (filterEditText.getRight() - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { //'Clear' button - clear data, and reset everything out //Reset everything filterEditText.setText(EMPTY_STRING); final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); //Update adapter in the preferences if (mParentFragmentPreferences != null) { final Integer currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); if (currentSort == null || currentSort <= 0) { mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); } else { switch (currentSort) { case R.id.tile_admin_nvram_sort_asc: //asc mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_desc: //desc mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_default: default: mNvramInfoToDisplay = new HashMap<>(); break; } mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData); } } else { mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); } ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplay); mAdapter.notifyDataSetChanged(); if (mParentFragmentPreferences != null) { final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING); editor.apply(); } return true; } } return false; } }); filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { final String textToFind = filterEditText.getText().toString(); if (isNullOrEmpty(textToFind)) { //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present return true; } final String existingSearch = mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null) : null; if (mParentFragmentPreferences != null) { if (textToFind.equalsIgnoreCase(existingSearch)) { //No need to go further as this is already the string we are looking for return true; } final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind); editor.apply(); } //Filter out (and sort by user-preference) final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); //Update adapter in the preferences final Map<Object, Object> mNvramInfoToDisplayCopy; if (mParentFragmentPreferences != null) { final Integer currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); if (currentSort == null || currentSort <= 0) { mNvramInfoToDisplayCopy = new HashMap<>(mNvramInfoDefaultSortingData); } else { switch (currentSort) { case R.id.tile_admin_nvram_sort_asc: //asc mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_desc: //desc mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_default: default: mNvramInfoToDisplayCopy = new HashMap<>(); break; } //noinspection ConstantConditions for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); if (key == null) { continue; } if (containsIgnoreCase(key.toString(), textToFind) || containsIgnoreCase(value.toString(), textToFind)) { mNvramInfoToDisplayCopy.put(key, value); } } } } else { mNvramInfoToDisplayCopy = new HashMap<>(); //noinspection ConstantConditions for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); if (key == null) { continue; } if (containsIgnoreCase(key.toString(), textToFind) || containsIgnoreCase(value.toString(), textToFind)) { mNvramInfoToDisplayCopy.put(key, value); } } } ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplayCopy); mAdapter.notifyDataSetChanged(); return true; } return false; } }); }
From source file:com.almarsoft.GroundhogReader.MessageActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { int textSize = mPrefs.getInt("webViewTextSize", UsenetConstants.TEXTSIZE_NORMAL); MenuItem bigtext = menu.findItem(R.id.message_menu_bigtext); MenuItem smalltext = menu.findItem(R.id.message_menu_smalltext); if (textSize == UsenetConstants.TEXTSIZE_LARGEST) bigtext.setEnabled(false); else//w w w .j a v a 2s . c om bigtext.setEnabled(true); if (textSize == UsenetConstants.TEXTSIZE_SMALLEST) smalltext.setEnabled(false); else smalltext.setEnabled(true); return (super.onPrepareOptionsMenu(menu)); }
From source file:org.cobaltians.cobalt.activities.CobaltActivity.java
public void setActionItemEnabled(String actionName, boolean enabled) { MenuItem menuItem = mMenuItemByNameMap.get(actionName); if (menuItem != null) { menuItem.setEnabled(enabled); }/*from ww w .jav a2s . c om*/ if (mMenuItemsHashMap.containsKey(actionName)) { ActionViewMenuItem actionViewMenuItem = mMenuItemsHashMap.get(actionName); actionViewMenuItem.setEnabled(enabled); } }
From source file:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java
@Override public boolean onMenuItemClick(MenuItem item) { final int itemId = item.getItemId(); //Store current value in preferences switch (itemId) { case R.id.tile_admin_nvram_sort_default: case R.id.tile_admin_nvram_sort_asc: case R.id.tile_admin_nvram_sort_desc: item.setEnabled(false); //Store in preferences if any final Integer currentSort; if (mParentFragmentPreferences != null) { currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); } else {/*from ww w.j a v a 2 s . c o m*/ currentSort = null; } if (mParentFragmentPreferences != null && (currentSort == null || currentSort != itemId)) { //No pref on file or different pref on file => store in preferences final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putInt(getFormattedPrefKey(SORT), sortIds.get(itemId)); editor.apply(); } break; default: break; } if (itemId != R.id.tile_admin_nvram_share) { Map<Object, Object> mNvramInfoToDisplayCopy = null; boolean notifyDatasetChanged = false; //Filter out by search and sort preferences final String textToFind = mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null) : null; if (isNullOrEmpty(textToFind)) { //Filter on while dataset final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); switch (itemId) { case R.id.tile_admin_nvram_sort_default: mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); notifyDatasetChanged = true; break; case R.id.tile_admin_nvram_sort_asc: mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData); notifyDatasetChanged = true; break; case R.id.tile_admin_nvram_sort_desc: mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData); notifyDatasetChanged = true; break; default: break; } mNvramInfoToDisplayCopy = mNvramInfoToDisplay; } else { //Already filtered data final Map<Object, Object> adapterNvramInfo = ((NVRAMDataRecyclerViewAdapter) mAdapter) .getNvramInfo(); switch (itemId) { case R.id.tile_admin_nvram_sort_default: mNvramInfoToDisplayCopy = new HashMap<>(adapterNvramInfo); notifyDatasetChanged = true; break; case R.id.tile_admin_nvram_sort_asc: mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); mNvramInfoToDisplayCopy.putAll(adapterNvramInfo); notifyDatasetChanged = true; break; case R.id.tile_admin_nvram_sort_desc: mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); mNvramInfoToDisplayCopy.putAll(adapterNvramInfo); notifyDatasetChanged = true; break; default: break; } } if (mNvramInfoToDisplayCopy != null && notifyDatasetChanged) { ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplayCopy); mAdapter.notifyDataSetChanged(); } } else { //Share action final Map<Object, Object> nvramInfo = ((NVRAMDataRecyclerViewAdapter) mAdapter).getNvramInfo(); if (nvramInfo == null || nvramInfo.isEmpty()) { Crouton.makeText(mParentFragmentActivity, "Nothing to share!", Style.ALERT).show(); return true; } Exception exception = null; File file = new File(mParentFragmentActivity.getCacheDir(), String.format("nvram_data_%s_%s_%s.txt", mRouter.getUuid(), mRouter.getName(), mRouter.getRemoteIpAddress())); OutputStream outputStream = null; try { outputStream = new BufferedOutputStream(new FileOutputStream(file, false)); outputStream.write(PROPERTIES_JOINER_TO_FILE.join(nvramInfo).getBytes()); } catch (IOException e) { exception = e; e.printStackTrace(); } finally { try { if (outputStream != null) { outputStream.close(); } } catch (IOException e) { e.printStackTrace(); } } if (exception != null) { Crouton.makeText(mParentFragmentActivity, "Error while trying to share file - please try again later", Style.ALERT).show(); return true; } setShareFile(file); return true; } return false; }
From source file:com.piusvelte.webcaster.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); MenuItem mediaRouteItem = menu.findItem(R.id.action_mediaroute); if (mediaRouteSelector != null) { mediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView(); mediaRouteButton.setRouteSelector(mediaRouteSelector); mediaRouteButton.setDialogFactory(new MediaRouteDialogFactory()); mediaRouteItem.setVisible(true); mediaRouteItem.setEnabled(true); } else {// w w w . ja v a 2s . co m mediaRouteItem.setVisible(false); mediaRouteItem.setEnabled(false); } return true; }
From source file:com.mobicage.rogerthat.plugins.messaging.MessagingActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); switch (item.getItemId()) { case R.id.select_all: case R.id.deselect_all: item.setVisible(mEditing);//from w w w. ja va 2s. c o m break; case R.id.delete_messages: item.setEnabled(((CursorAdapter) getListAdapter()).getCursor().getCount() > 0); //$FALL-THROUGH$ default: item.setVisible(!mEditing); break; } } return super.onPrepareOptionsMenu(menu); }
From source file:com.taw.gotothere.GoToThereActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); MenuItem refresh = menu.findItem(R.id.refresh); if (!navigating) { // Disable the refresh menu item initially; it's re-enabled when the // user's navigating refresh.setEnabled(false); } else {/*from w w w.ja v a 2s . c o m*/ refresh.setEnabled(true); } return true; }
From source file:com.abhijitvalluri.android.fitnotifications.AppChoicesActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.app_search, menu); MenuItem searchItem = menu.findItem(R.id.menu_app_search); MenuItem filterEnabledAppsItem = menu.findItem(R.id.menu_filter_enabled); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setQueryHint(getString(R.string.search_query_hint)); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override/* w ww .j av a 2 s.c om*/ public boolean onQueryTextSubmit(String query) { return recyclerViewShowSearchResult(query); } @Override public boolean onQueryTextChange(String newText) { return recyclerViewShowSearchResult(newText); } }); searchItem.setEnabled(false); filterEnabledAppsItem.setEnabled(false); filterEnabledAppsItem.setChecked(mShowOnlyEnabledApps); return true; }
From source file:org.andstatus.app.account.AccountSettingsActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { MenuItem item = menu.findItem(R.id.remove_account_menu_id); item.setEnabled(state.builder.isPersistent()); item.setVisible(state.builder.isPersistent()); return super.onPrepareOptionsMenu(menu); }
From source file:org.ozonecity.gpslogger2.GpsMainActivity.java
private void enableDisableMenuItems() { OnWaitingForLocation(Session.isWaitingForLocation()); SetBulbStatus(Session.isStarted());/*from ww w. j ava2 s.c o m*/ Toolbar toolbar = (Toolbar) findViewById(R.id.toolbarBottom); MenuItem mnuAnnotate = toolbar.getMenu().findItem(R.id.mnuAnnotate); MenuItem mnuOnePoint = toolbar.getMenu().findItem(R.id.mnuOnePoint); MenuItem mnuAutoSendNow = toolbar.getMenu().findItem(R.id.mnuAutoSendNow); if (mnuOnePoint != null) { mnuOnePoint.setEnabled(!Session.isStarted()); mnuOnePoint.setIcon((Session.isStarted() ? R.drawable.singlepoint_disabled : R.drawable.singlepoint)); } if (mnuAutoSendNow != null) { mnuAutoSendNow.setEnabled(Session.isStarted()); } if (mnuAnnotate != null) { if (!AppSettings.shouldLogToGpx() && !AppSettings.shouldLogToKml() && !AppSettings.shouldLogToCustomUrl()) { mnuAnnotate.setIcon(R.drawable.annotate2_disabled); mnuAnnotate.setEnabled(false); } else { if (Session.isAnnotationMarked()) { mnuAnnotate.setIcon(R.drawable.annotate2_active); } else { mnuAnnotate.setIcon(R.drawable.annotate2); } } } }