List of usage examples for android.view Menu findItem
public MenuItem findItem(int id);
From source file:biz.wiz.android.wallet.ui.TransactionsListFragment.java
private void handleTransactionClick(@Nonnull final Transaction tx) { activity.startActionMode(new ActionMode.Callback() { private Address address; private byte[] serializedTx; private static final int SHOW_QR_THRESHOLD_BYTES = 2500; @Override/*from ww w .j a v a 2s.c o m*/ public boolean onCreateActionMode(final ActionMode mode, final Menu menu) { final MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.wallet_transactions_context, menu); return true; } @Override public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) { try { final Date time = tx.getUpdateTime(); final DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(activity); final DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(activity); mode.setTitle(time != null ? (DateUtils.isToday(time.getTime()) ? getString(R.string.time_today) : dateFormat.format(time)) + ", " + timeFormat.format(time) : null); final Coin value = tx.getValue(wallet); final boolean sent = value.signum() < 0; address = sent ? WalletUtils.getWalletAddressOfReceived(tx, wallet) : WalletUtils.getFirstFromAddress(tx); final String label; if (tx.isCoinBase()) label = getString(R.string.wallet_transactions_fragment_coinbase); else if (address != null) label = AddressBookProvider.resolveLabel(activity, address.toString()); else label = "?"; final String prefix = getString(sent ? R.string.symbol_to : R.string.symbol_from) + " "; if (tx.getPurpose() != Purpose.KEY_ROTATION) mode.setSubtitle(label != null ? prefix + label : WalletUtils.formatAddress(prefix, address, Constants.ADDRESS_FORMAT_GROUP_SIZE, Constants.ADDRESS_FORMAT_LINE_SIZE)); else mode.setSubtitle(null); menu.findItem(R.id.wallet_transactions_context_edit_address).setVisible(address != null); serializedTx = tx.unsafeBitcoinSerialize(); menu.findItem(R.id.wallet_transactions_context_show_qr) .setVisible(serializedTx.length < SHOW_QR_THRESHOLD_BYTES); return true; } catch (final ScriptException x) { return false; } } @Override public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) { switch (item.getItemId()) { case R.id.wallet_transactions_context_edit_address: handleEditAddress(tx); mode.finish(); return true; case R.id.wallet_transactions_context_show_qr: handleShowQr(); mode.finish(); return true; case R.id.wallet_transactions_context_browse: startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Constants.EXPLORE_BASE_URL + "tx/" + tx.getHashAsString()))); mode.finish(); return true; } return false; } @Override public void onDestroyActionMode(final ActionMode mode) { } private void handleEditAddress(@Nonnull final Transaction tx) { EditAddressBookEntryFragment.edit(getFragmentManager(), address.toString()); } private void handleShowQr() { final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size); final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(serializedTx), size); BitmapFragment.show(getFragmentManager(), qrCodeBitmap); } }); }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.listmenu, menu); this.menu = menu; // adjust value in menu button to value in use MenuItem MenuItem_dur = menu.findItem(R.id.action_45min); MenuItem_dur.setTitle("" + appPRE + " Min"); // adjust visibility of some menu tabs String v[] = appFLG.split(";"); //Log.d(TAG,"p1 " + isInit + " p2 "+ Boolean.parseBoolean(v[1])); menu.findItem(R.id.action_db_start)//from w w w . jav a 2s .c o m .setVisible(((isInit == true) && Boolean.parseBoolean(v[1])) ? false : true); menu.findItem(R.id.action_ezac).setVisible(Boolean.parseBoolean(v[2])); menu.findItem(R.id.action_meteo_group).setVisible(Boolean.parseBoolean(v[3])); menu.findItem(R.id.action_ntm_nld).setVisible(Boolean.parseBoolean(v[4])); menu.findItem(R.id.action_ntm_blx).setVisible(Boolean.parseBoolean(v[4])); menu.findItem(R.id.action_ogn_flarm).setVisible(Boolean.parseBoolean(v[5])); menu.findItem(R.id.action_adsb).setVisible(Boolean.parseBoolean(v[6])); menu.findItem(R.id.action_adsb_lcl).setVisible(Boolean.parseBoolean(v[7])); // adjust value in menu button to current date MenuItem MenuItem_date = menu.findItem(R.id.action_date); String s[] = ToDay.split("-"); MenuItem_date.setTitle(s[0] + " " + month_list[Integer.parseInt(s[1]) - 1]); return true; }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { if (menu == null || mEditText == null || mTextCount == null) return false; final String text_orig = parseString(mEditText.getText()); final String text = mIsPhotoAttached || mIsImageAttached ? mUploadUseExtension ? getImageUploadStatus(this, FAKE_IMAGE_LINK, text_orig) : text_orig + " " + FAKE_IMAGE_LINK : text_orig;//from ww w . java2 s .com final int count = mValidator.getTweetLength(text); final float hue = count < 140 ? count >= 130 ? 5 * (140 - count) : 50 : 0; final float[] hsv = new float[] { hue, 1.0f, 1.0f }; mTextCount.setTextColor(count >= 130 ? Color.HSVToColor(0x80, hsv) : 0x80808080); mTextCount.setText(parseString(140 - count)); final MenuItem sendItem = menu.findItem(MENU_SEND); if (sendItem != null) { sendItem.setEnabled(text_orig.length() > 0); } return super.onPrepareOptionsMenu(menu); }
From source file:com.dwdesign.tweetings.util.Utils.java
public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) { if (context == null || menu == null || status == null) return;//from w w w . j av a 2s.c om final int activated_color = context.getResources().getColor(R.color.holo_blue_bright); final MenuItem itemDelete = menu.findItem(R.id.delete_submenu); if (itemDelete != null) { itemDelete.setVisible(status.account_id == status.user_id && !isMyRetweet(status)); } final MenuItem itemRetweet = menu.findItem(MENU_RETWEET); if (itemRetweet != null) { final Drawable icon = itemRetweet.getIcon().mutate(); itemRetweet.setVisible( (!status.is_protected && status.account_id != status.user_id) || isMyRetweet(status)); if (isMyRetweet(status)) { icon.setColorFilter(activated_color, Mode.MULTIPLY); itemRetweet.setTitle(R.string.cancel_retweet); } else { icon.clearColorFilter(); itemRetweet.setTitle(R.string.retweet); } } final MenuItem itemFav = menu.findItem(MENU_FAV); if (itemFav != null) { final Drawable iconFav = itemFav.getIcon().mutate(); if (status.is_favorite) { iconFav.setColorFilter(activated_color, Mode.MULTIPLY); itemFav.setTitle(R.string.unfav); } else { iconFav.clearColorFilter(); itemFav.setTitle(R.string.fav); } } final MenuItem itemConversation = menu.findItem(MENU_CONVERSATION); if (itemConversation != null) { itemConversation.setVisible(status.in_reply_to_status_id > 0); } }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { int userId = Util.getUserId(Process.myUid()); boolean mounted = Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()); boolean updates = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingUpdates, false); menu.findItem(R.id.menu_export).setEnabled(mounted); menu.findItem(R.id.menu_import).setEnabled(mounted); menu.findItem(R.id.menu_submit).setEnabled(Util.hasValidFingerPrint(this)); menu.findItem(R.id.menu_pro).setVisible(!Util.isProEnabled() && Util.hasProLicense(this) == null); menu.findItem(R.id.menu_dump).setVisible(Util.isDebuggable(this)); menu.findItem(R.id.menu_update).setVisible(updates); menu.findItem(R.id.menu_update).setEnabled(mounted); // Update filter count // Get settings boolean fUsed = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUsed, false); boolean fInternet = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFInternet, false); boolean fRestriction = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFRestriction, false); boolean fPermission = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFPermission, true); boolean fOnDemand = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFOnDemand, false); boolean fUser = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFUser, true); boolean fSystem = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFSystem, false); // Count number of active filters int numberOfFilters = 0; if (fUsed)// w w w. j a va 2s . co m numberOfFilters++; if (fInternet) numberOfFilters++; if (fRestriction) numberOfFilters++; if (fPermission) numberOfFilters++; if (fOnDemand) numberOfFilters++; if (fUser) numberOfFilters++; if (fSystem) numberOfFilters++; if (numberOfFilters > 0) { Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon_filter) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(); paint.setStyle(Style.FILL); paint.setColor(Color.GRAY); paint.setTextSize(bitmap.getWidth() / 3); paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); String text = Integer.toString(numberOfFilters); Canvas canvas = new Canvas(bitmap); canvas.drawText(text, bitmap.getWidth() - paint.measureText(text), bitmap.getHeight(), paint); MenuItem fMenu = menu.findItem(R.id.menu_filter); fMenu.setIcon(new BitmapDrawable(getResources(), bitmap)); } return super.onPrepareOptionsMenu(menu); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); if (inflater != null && PrivacyService.checkClient()) { // Inflate menu inflater.inflate(R.menu.main, menu); // Searchable SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search)); if (searchView != null) { searchView.setIconifiedByDefault(false); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override//www . jav a 2s. c om public boolean onQueryTextChange(String newText) { searchQuery = newText; applyFilter(); return true; } @Override public boolean onQueryTextSubmit(String query) { searchQuery = query; applyFilter(); return true; } }); searchView.setOnCloseListener(new SearchView.OnCloseListener() { @Override public boolean onClose() { searchQuery = ""; applyFilter(); return true; } }); } return true; } else return false; }
From source file:cgeo.geocaching.CacheDetailActivity.java
@Override public boolean onCreateOptionsMenu(final Menu menu) { CacheMenuHandler.addMenuItems(this, menu, cache); final MenuItem menuItem = menu.findItem(R.id.menu_default_navigation); final NavigationActionProvider navAction = (NavigationActionProvider) MenuItemCompat .getActionProvider(menuItem); if (navAction != null) { navAction.setNavigationSource(this); }//from w w w . j a va 2s . c om NavigationSelectionActionProvider.initialize(menu.findItem(R.id.menu_navigate), cache); return true; }
From source file:cgeo.geocaching.CacheDetailActivity.java
@Override public void onSupportActionModeStarted(final ActionMode mode) { if (mSelectionModeActive && selectedTextView != null) { mSelectionModeActive = false;//from www .j a v a2s. com mActionMode = mode; final Menu menu = mode.getMenu(); mode.getMenuInflater().inflate(R.menu.details_context, menu); menu.findItem(R.id.menu_copy).setVisible(false); menu.findItem(R.id.menu_cache_share_field).setOnMenuItemClickListener(new TextMenuItemClickListener()); menu.findItem(R.id.menu_translate_to_sys_lang) .setOnMenuItemClickListener(new TextMenuItemClickListener()); menu.findItem(R.id.menu_translate_to_english) .setOnMenuItemClickListener(new TextMenuItemClickListener()); final MenuItem extWpts = menu.findItem(R.id.menu_extract_waypoints); extWpts.setVisible(true); extWpts.setOnMenuItemClickListener(new TextMenuItemClickListener()); buildDetailsContextMenu(mode, menu, res.getString(R.string.cache_description), false); selectedTextView.setWindowFocusWait(true); } super.onSupportActionModeStarted(mode); }
From source file:cgeo.geocaching.CacheDetailActivity.java
@Override public boolean onPrepareOptionsMenu(final Menu menu) { CacheMenuHandler.onPrepareOptionsMenu(menu, cache); LoggingUI.onPrepareOptionsMenu(menu, cache); menu.findItem(R.id.menu_edit_fieldnote).setVisible(true); menu.findItem(R.id.menu_store_in_list).setVisible(cache != null); menu.findItem(R.id.menu_delete).setVisible(cache != null && cache.isOffline()); menu.findItem(R.id.menu_refresh).setVisible(cache != null && cache.supportsRefresh()); menu.findItem(R.id.menu_gcvote).setVisible(cache != null && GCVote.isVotingPossible(cache)); menu.findItem(R.id.menu_checker)// w w w . ja va 2s . co m .setVisible(cache != null && StringUtils.isNotEmpty(CheckerUtils.getCheckerUrl(cache))); menu.findItem(R.id.menu_app_invite).setVisible(cache != null && AppInvite.isAvailable()); menu.findItem(R.id.menu_extract_waypoints).setVisible(cache != null); menu.findItem(R.id.menu_export).setVisible(cache != null); if (cache != null) { final IConnector connector = ConnectorFactory.getConnector(cache); if (connector instanceof IgnoreCapability) { menu.findItem(R.id.menu_ignore).setVisible(((IgnoreCapability) connector).canIgnoreCache(cache)); } if (connector instanceof PgcChallengeCheckerCapability) { menu.findItem(R.id.menu_challenge_checker) .setVisible(((PgcChallengeCheckerCapability) connector).isChallengeCache(cache)); } } return super.onPrepareOptionsMenu(menu); }
From source file:com.android.contacts.quickcontact.QuickContactActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { if (mContactData != null) { final MenuItem starredMenuItem = menu.findItem(R.id.menu_star); ContactDisplayUtils.configureStarredMenuItem(starredMenuItem, mContactData.isDirectoryEntry(), mContactData.isUserProfile(), mContactData.getStarred()); // Configure edit MenuItem final MenuItem editMenuItem = menu.findItem(R.id.menu_edit); editMenuItem.setVisible(true);//from ww w.j a v a 2 s . c o m if (DirectoryContactUtil.isDirectoryContact(mContactData) || InvisibleContactUtil.isInvisibleAndAddable(mContactData, this)) { editMenuItem.setIcon(R.drawable.ic_person_add_tinted_24dp); editMenuItem.setTitle(R.string.menu_add_contact); } else if (isContactEditable()) { editMenuItem.setIcon(R.drawable.ic_create_24dp); editMenuItem.setTitle(R.string.menu_editContact); } else { editMenuItem.setVisible(false); } final MenuItem deleteMenuItem = menu.findItem(R.id.menu_delete); deleteMenuItem.setVisible(isContactEditable() && !mContactData.isUserProfile()); final MenuItem shareMenuItem = menu.findItem(R.id.menu_share); shareMenuItem.setVisible(isContactShareable()); final MenuItem shortcutMenuItem = menu.findItem(R.id.menu_create_contact_shortcut); shortcutMenuItem.setVisible(isShortcutCreatable()); final MenuItem helpMenu = menu.findItem(R.id.menu_help); helpMenu.setVisible(HelpUtils.isHelpAndFeedbackAvailable()); return true; } return false; }