Java Code Examples for android.view.ContextMenu#findItem()

The following examples show how to use android.view.ContextMenu#findItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FragmentSummary.java    From fingen with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater menuInflater = Objects.requireNonNull(getActivity()).getMenuInflater();
    menuInflater.inflate(R.menu.context_menu_summary, menu);
    final MenuItem item = menu.findItem(R.id.action_show_report);
    ((ToolbarActivity) getActivity()).unsubscribeOnDestroy(
            mBillingService.getReportsIapInfo()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(
                            skuDetailsWrapper -> {
                                if (skuDetailsWrapper.isPurchased()) {
                                    item.setVisible(true);
                                } else {
                                    item.setVisible(false);
                                }
                            },
                            throwable -> item.setVisible(false)));
}
 
Example 2
Source File: WifiListActivity.java    From WiFiKeyShare with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    int itemPosition = ((ContextMenuRecyclerView.RecyclerContextMenuInfo) menuInfo).position;

    menu.setHeaderTitle(wifiNetworks.get(itemPosition).getSsid());
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.context_menu, menu);

    boolean canViewPasword = wifiNetworks.get(itemPosition).isPasswordProtected()
            && !wifiNetworks.get(itemPosition).getKey().isEmpty();
    boolean canClearPassword = canViewPasword;

    MenuItem viewPasswordMenuItem = menu.findItem(R.id.context_menu_wifi_list_view_password);
    viewPasswordMenuItem.setEnabled(canViewPasword);

    MenuItem clearPasswordMenuItem = menu.findItem(R.id.context_menu_wifi_list_clear_password);
    clearPasswordMenuItem.setEnabled(canClearPassword);
    clearPasswordMenuItem.setVisible(!isDeviceRooted);
}
 
Example 3
Source File: SearchActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
    final Message message = this.messages.get(acmi.position);
    this.selectedMessageReference = new WeakReference<>(message);
    getMenuInflater().inflate(R.menu.search_result_context, menu);
    MenuItem copy = menu.findItem(R.id.copy_message);
    MenuItem quote = menu.findItem(R.id.quote_message);
    MenuItem copyUrl = menu.findItem(R.id.copy_url);
    if (message.isGeoUri()) {
        copy.setVisible(false);
        quote.setVisible(false);
    } else {
        copyUrl.setVisible(false);
    }
    super.onCreateContextMenu(menu, v, menuInfo);
}
 
Example 4
Source File: SearchActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
	AdapterView.AdapterContextMenuInfo acmi = (AdapterView.AdapterContextMenuInfo) menuInfo;
	final Message message = this.messages.get(acmi.position);
	this.selectedMessageReference = new WeakReference<>(message);
	getMenuInflater().inflate(R.menu.search_result_context, menu);
	MenuItem copy = menu.findItem(R.id.copy_message);
	MenuItem quote = menu.findItem(R.id.quote_message);
	MenuItem copyUrl = menu.findItem(R.id.copy_url);
	if (message.isGeoUri()) {
		copy.setVisible(false);
		quote.setVisible(false);
	} else {
		copyUrl.setVisible(false);
	}
	super.onCreateContextMenu(menu, v, menuInfo);
}
 
Example 5
Source File: FragmentAccounts.java    From fingen with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (getActivity() != null) {
        MenuInflater menuInflater = getActivity().getMenuInflater();
        switch (v.getId()) {
            case R.id.recycler_view:
                contextMenuTarget = CONTEXT_MENU_ACCOUNTS;
                menuInflater.inflate(R.menu.context_menu_accounts, menu);
                break;
            case R.id.recycler_view_accounts_sets:
                contextMenuTarget = CONTEXT_MENU_SETS;
                menuInflater.inflate(R.menu.context_menu_accounts_sets, menu);
                break;
        }
        final MenuItem item = menu.findItem(R.id.action_show_report);
        if (item != null) {
            item.setVisible(false);
            ((ToolbarActivity) getActivity()).unsubscribeOnDestroy(
                    mBillingService.get().getReportsIapInfo()
                            .subscribeOn(Schedulers.io())
                            .observeOn(AndroidSchedulers.mainThread())
                            .subscribe(
                                    skuDetailsWrapper -> {
                                        if (skuDetailsWrapper.isPurchased()) {
                                            item.setVisible(true);
                                        } else {
                                            item.setVisible(false);
                                        }
                                    },
                                    throwable -> item.setVisible(false)));
        }
    }
}
 
Example 6
Source File: StartConversationActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    final StartConversationActivity activity = (StartConversationActivity) getActivity();
    if (activity == null) {
        return;
    }
    activity.getMenuInflater().inflate(mResContextMenu, menu);
    final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
    if (mResContextMenu == R.menu.conference_context) {
        activity.conference_context_id = acmi.position;
        final Bookmark bookmark = (Bookmark) activity.conferences.get(acmi.position);
        final Conversation conversation = bookmark.getConversation();
        final MenuItem share = menu.findItem(R.id.context_share_uri);
        share.setVisible(conversation == null || !conversation.isPrivateAndNonAnonymous());
    } else if (mResContextMenu == R.menu.contact_context) {
        activity.contact_context_id = acmi.position;
        final Contact contact = (Contact) activity.contacts.get(acmi.position);
        final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
        final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
        final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
        if (contact.isSelf()) {
            showContactDetailsItem.setVisible(false);
        }
        deleteContactMenuItem.setVisible(contact.showInRoster() && !contact.getOption(Contact.Options.SYNCED_VIA_OTHER));
        final XmppConnection xmpp = contact.getAccount().getXmppConnection();
        if (xmpp != null && xmpp.getFeatures().blocking() && !contact.isSelf()) {
            if (contact.isBlocked()) {
                blockUnblockItem.setTitle(R.string.unblock_contact);
            } else {
                blockUnblockItem.setTitle(R.string.block_contact);
            }
        } else {
            blockUnblockItem.setVisible(false);
        }
    }
}
 
Example 7
Source File: OmemoActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    Object account = v.getTag(R.id.TAG_ACCOUNT);
    Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
    Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
    if (account != null
            && fingerprint != null
            && account instanceof Account
            && fingerprintStatus != null
            && fingerprint instanceof String
            && fingerprintStatus instanceof FingerprintStatus) {
        getMenuInflater().inflate(R.menu.omemo_key_context, menu);
        MenuItem distrust = menu.findItem(R.id.distrust_key);
        MenuItem verifyScan = menu.findItem(R.id.verify_scan);
        if (this instanceof TrustKeysActivity) {
            distrust.setVisible(false);
            verifyScan.setVisible(false);
        } else {
            FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
            if (!status.isActive() || status.isVerified()) {
                verifyScan.setVisible(false);
            }
            distrust.setVisible(status.isVerified() || (!status.isActive() && status.isTrusted()));
        }
        this.mSelectedAccount = (Account) account;
        this.mSelectedFingerprint = (String) fingerprint;
    }
}
 
Example 8
Source File: StartConversationActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
	final StartConversationActivity activity = (StartConversationActivity) getActivity();
	if (activity == null) {
		return;
	}
	activity.getMenuInflater().inflate(mResContextMenu, menu);
	final AdapterView.AdapterContextMenuInfo acmi = (AdapterContextMenuInfo) menuInfo;
	if (mResContextMenu == R.menu.conference_context) {
		activity.conference_context_id = acmi.position;
		final Bookmark bookmark = (Bookmark) activity.conferences.get(acmi.position);
		final Conversation conversation = bookmark.getConversation();
		final MenuItem share = menu.findItem(R.id.context_share_uri);
		share.setVisible(conversation == null || !conversation.isPrivateAndNonAnonymous());
	} else if (mResContextMenu == R.menu.contact_context) {
		activity.contact_context_id = acmi.position;
		final Contact contact = (Contact) activity.contacts.get(acmi.position);
		final MenuItem blockUnblockItem = menu.findItem(R.id.context_contact_block_unblock);
		final MenuItem showContactDetailsItem = menu.findItem(R.id.context_contact_details);
		final MenuItem deleteContactMenuItem = menu.findItem(R.id.context_delete_contact);
		if (contact.isSelf()) {
			showContactDetailsItem.setVisible(false);
		}
		deleteContactMenuItem.setVisible(contact.showInRoster() && !contact.getOption(Contact.Options.SYNCED_VIA_OTHER));
		final XmppConnection xmpp = contact.getAccount().getXmppConnection();
		if (xmpp != null && xmpp.getFeatures().blocking() && !contact.isSelf()) {
			if (contact.isBlocked()) {
				blockUnblockItem.setTitle(R.string.unblock_contact);
			} else {
				blockUnblockItem.setTitle(R.string.block_contact);
			}
		} else {
			blockUnblockItem.setVisible(false);
		}
	}
}
 
Example 9
Source File: OmemoActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
	Object account = v.getTag(R.id.TAG_ACCOUNT);
	Object fingerprint = v.getTag(R.id.TAG_FINGERPRINT);
	Object fingerprintStatus = v.getTag(R.id.TAG_FINGERPRINT_STATUS);
	if (account != null
			&& fingerprint != null
			&& account instanceof Account
			&& fingerprintStatus != null
			&& fingerprint instanceof String
			&& fingerprintStatus instanceof FingerprintStatus) {
		getMenuInflater().inflate(R.menu.omemo_key_context, menu);
		MenuItem distrust = menu.findItem(R.id.distrust_key);
		MenuItem verifyScan = menu.findItem(R.id.verify_scan);
		if (this instanceof TrustKeysActivity) {
			distrust.setVisible(false);
			verifyScan.setVisible(false);
		} else {
			FingerprintStatus status = (FingerprintStatus) fingerprintStatus;
			if (!status.isActive() || status.isVerified()) {
				verifyScan.setVisible(false);
			}
			distrust.setVisible(status.isVerified() || (!status.isActive() && status.isTrusted()));
		}
		this.mSelectedAccount = (Account) account;
		this.mSelectedFingerprint = (String) fingerprint;
	}
}
 
Example 10
Source File: BrowserActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected void createFileMenu(final ContextMenu menu, final String path) {
    final BookSettings bs = SettingsManager.getBookSettings(path);
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);
    menu.setHeaderTitle(path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(false);
    menu.findItem(R.id.bookmenu_openbookfolder).setVisible(false);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
        return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
        if (LengthUtils.isNotEmpty(bs.bookmarks)) {
            list.addAll(bs.bookmarks);
        }
        list.add(new Bookmark(true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
        addBookmarkMenuItem(osm, b);
    }
}
 
Example 11
Source File: RecentActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected void onCreateBookMenu(final ContextMenu menu, final BookNode node) {
    final BookSettings bs = node.settings;
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);

    menu.setHeaderTitle(node.path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);

    final BookShelfAdapter bookShelf = getController().getBookShelf(node);
    final BookShelfAdapter current = bookcaseView != null ? getController().getBookShelf(
            bookcaseView.getCurrentList()) : null;
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(
            bookShelf != null && current != null && bookShelf != current);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
        return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
        if (LengthUtils.isNotEmpty(bs.bookmarks)) {
            list.addAll(bs.bookmarks);
        }
        list.add(new Bookmark(true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
        addBookmarkMenuItem(osm, b);
    }
}
 
Example 12
Source File: PlaylistFragment.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    if (menuInfo instanceof AdapterContextMenuInfo) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        PlaylistItem item = mAdapter.getItem(info.position);

        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.playlist_context, menu);

        MenuItem searchItem = menu.findItem(R.id.playlist_context_search);
        searchItem.setVisible(isSearchable(item));
    }
}
 
Example 13
Source File: EditorActivity.java    From spline with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, v, info);

    boolean shouldShowContextMenu = true;
    boolean showCurrentLayerItems = false;
    boolean hasClipboardContents = mViewModel.hasClipboardContents();

    if (v instanceof DocumentView) {
        DocumentView dv = (DocumentView) v;
        shouldShowContextMenu = dv.shouldShowContextMenu();
        showCurrentLayerItems = dv.shouldShowCurrentLayerContextItems();
    } else if (v instanceof LayerListView) {
        //LayerListView llv = (LayerListView) v;
        showCurrentLayerItems = true;
    }

    if (shouldShowContextMenu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_context, menu);

        MenuItem item = menu.findItem(CUT);
        item.setVisible(showCurrentLayerItems);

        item = menu.findItem(COPY);
        item.setVisible(showCurrentLayerItems);

        item = menu.findItem(PASTE);
        item.setVisible(showCurrentLayerItems || hasClipboardContents);
        item.setEnabled(hasClipboardContents);

        item = menu.findItem(DUPLICATE);
        item.setVisible(showCurrentLayerItems);

        item = menu.findItem(DELETE);
        item.setVisible(showCurrentLayerItems);

        item = menu.findItem(GROUP);
        item.setVisible(showCurrentLayerItems);
    }
}
 
Example 14
Source File: AdapterBaseImpl.java    From microMathematics with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void populateContextMenu(ContextMenu menu, AdapterView.AdapterContextMenuInfo acmi, int num)
{
    try
    {
        if (readWriteAdapter)
        {
            menu.add(0, R.id.fman_action_refresh, 0, R.string.fman_refresh_title);
            menu.add(0, R.id.fman_action_create_folder, 0, R.string.fman_create_folder_title);
            if (num > 0)
            {
                menu.add(0, R.id.fman_action_rename, 0, R.string.fman_rename_title);
                menu.add(0, R.id.fman_action_delete, 0, R.string.fman_delete_title);
            }
        }
        MenuItem activeSort = null;
        menu.add(0, R.id.fman_action_sort_by_name, 0, R.string.fman_sort_by_name);
        if ((mode & MODE_SORTING) == SORT_NAME)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_name);
        }
        menu.add(0, R.id.fman_action_sort_by_ext, 0, R.string.fman_sort_by_ext);
        if ((mode & MODE_SORTING) == SORT_EXT)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_ext);
        }
        menu.add(0, R.id.fman_action_sort_by_size, 0, R.string.fman_sort_by_size);
        if ((mode & MODE_SORTING) == SORT_SIZE)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_size);
        }
        menu.add(0, R.id.fman_action_sort_by_date, 0, R.string.fman_sort_by_date);
        if ((mode & MODE_SORTING) == SORT_DATE)
        {
            activeSort = menu.findItem(R.id.fman_action_sort_by_date);
        }
        if (activeSort != null)
        {
            activeSort.setCheckable(true);
            activeSort.setChecked(true);
        }
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }
}
 
Example 15
Source File: ConversationFragment.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
private void populateContextMenu(ContextMenu menu) {
    final Message m = this.selectedMessage;
    final Transferable t = m.getTransferable();
    Message relevantForCorrection = m;
    while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
        relevantForCorrection = relevantForCorrection.next();
    }
    if (m.getType() != Message.TYPE_STATUS && m.getType() != Message.TYPE_RTP_SESSION) {

        if (m.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE || m.getEncryption() == Message.ENCRYPTION_AXOLOTL_FAILED) {
            return;
        }
        if (m.getStatus() == Message.STATUS_RECEIVED && t != null && (t.getStatus() == Transferable.STATUS_CANCELLED || t.getStatus() == Transferable.STATUS_FAILED)) {
            return;
        }
        final boolean deleted = m.isFileDeleted();
        final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED
                || m.getEncryption() == Message.ENCRYPTION_PGP;
        final boolean receiving = m.getStatus() == Message.STATUS_RECEIVED && (t instanceof JingleFileTransferConnection || t instanceof HttpDownloadConnection);
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem openWith = menu.findItem(R.id.open_with);
        MenuItem copyMessage = menu.findItem(R.id.copy_message);
        MenuItem copyLink = menu.findItem(R.id.copy_link);
        MenuItem quoteMessage = menu.findItem(R.id.quote_message);
        MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
        MenuItem correctMessage = menu.findItem(R.id.correct_message);
        MenuItem deleteMessage = menu.findItem(R.id.delete_message);
        MenuItem shareWith = menu.findItem(R.id.share_with);
        MenuItem sendAgain = menu.findItem(R.id.send_again);
        MenuItem copyUrl = menu.findItem(R.id.copy_url);
        MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
        MenuItem downloadFile = menu.findItem(R.id.download_file);
        MenuItem deleteFile = menu.findItem(R.id.delete_file);
        MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
        final boolean showError = m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
        deleteMessage.setVisible(true);
        if (!m.isFileOrImage() && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
            copyMessage.setVisible(true);
            quoteMessage.setVisible(!showError && MessageUtils.prepareQuote(m).length() > 0);
            String body = m.getMergedBody().toString();
            if (ShareUtil.containsXmppUri(body)) {
                copyLink.setTitle(R.string.copy_jabber_id);
                copyLink.setVisible(true);
            } else if (Patterns.AUTOLINK_WEB_URL.matcher(body).find()) {
                copyLink.setVisible(true);
            }
        }
        if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED && !deleted) {
            retryDecryption.setVisible(true);
        }
        if (!showError
                && relevantForCorrection.getType() == Message.TYPE_TEXT
                && !m.isGeoUri()
                && relevantForCorrection.isLastCorrectableMessage()
                && m.getConversation() instanceof Conversation) {
            correctMessage.setVisible(true);
        }
        if ((m.isFileOrImage() && !deleted && !receiving) || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
            shareWith.setVisible(true);

        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost()
                || m.isGeoUri()
                || m.isXmppUri()
                || m.treatAsDownloadable()
                || t instanceof HttpDownloadConnection) {
            copyUrl.setVisible(true);
        }
        if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) {
            downloadFile.setVisible(true);
            downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
        }
        final boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING
                || m.getStatus() == Message.STATUS_UNSEND
                || m.getStatus() == Message.STATUS_OFFERED;
        final boolean cancelable = (t != null && !deleted) || waitingOfferedSending && m.needsUploading();
        if (cancelable) {
            cancelTransmission.setVisible(true);
        }
        if (m.isFileOrImage() && !deleted && !cancelable) {
            String path = m.getRelativeFilePath();
            Log.d(Config.LOGTAG, "Path = " + path);
            if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null"))) {
                deleteFile.setVisible(true);
                deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
            }
        }
        showErrorMessage.setVisible(showError);
        final String mime = m.isFileOrImage() ? m.getMimeType() : null;
        if ((m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(), m)) || (mime != null && mime.startsWith("audio/"))) {
            openWith.setVisible(true);
        }
    }
}
 
Example 16
Source File: ConversationFragment.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
private void populateContextMenu(ContextMenu menu) {
    final Message m = this.selectedMessage;
    final Transferable t = m.getTransferable();
    Message relevantForCorrection = m;
    while (relevantForCorrection.mergeable(relevantForCorrection.next())) {
        relevantForCorrection = relevantForCorrection.next();
    }
    if (m.getType() != Message.TYPE_STATUS && m.getType() != Message.TYPE_RTP_SESSION) {

        if (m.getEncryption() == Message.ENCRYPTION_AXOLOTL_NOT_FOR_THIS_DEVICE || m.getEncryption() == Message.ENCRYPTION_AXOLOTL_FAILED) {
            return;
        }

        if (m.getStatus() == Message.STATUS_RECEIVED && t != null && (t.getStatus() == Transferable.STATUS_CANCELLED || t.getStatus() == Transferable.STATUS_FAILED)) {
            return;
        }

        final boolean deleted = m.isDeleted();
        final boolean encrypted = m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED
                || m.getEncryption() == Message.ENCRYPTION_PGP;
        final boolean receiving = m.getStatus() == Message.STATUS_RECEIVED && (t instanceof JingleFileTransferConnection || t instanceof HttpDownloadConnection);
        activity.getMenuInflater().inflate(R.menu.message_context, menu);
        menu.setHeaderTitle(R.string.message_options);
        MenuItem openWith = menu.findItem(R.id.open_with);
        MenuItem copyMessage = menu.findItem(R.id.copy_message);
        MenuItem copyLink = menu.findItem(R.id.copy_link);
        MenuItem quoteMessage = menu.findItem(R.id.quote_message);
        MenuItem retryDecryption = menu.findItem(R.id.retry_decryption);
        MenuItem correctMessage = menu.findItem(R.id.correct_message);
        MenuItem shareWith = menu.findItem(R.id.share_with);
        MenuItem sendAgain = menu.findItem(R.id.send_again);
        MenuItem copyUrl = menu.findItem(R.id.copy_url);
        MenuItem downloadFile = menu.findItem(R.id.download_file);
        MenuItem cancelTransmission = menu.findItem(R.id.cancel_transmission);
        MenuItem deleteFile = menu.findItem(R.id.delete_file);
        MenuItem showErrorMessage = menu.findItem(R.id.show_error_message);
        final boolean showError = m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage());
        if (!m.isFileOrImage() && !encrypted && !m.isGeoUri() && !m.treatAsDownloadable()) {
            copyMessage.setVisible(true);
            quoteMessage.setVisible(!showError && MessageUtils.prepareQuote(m).length() > 0);
            String body = m.getMergedBody().toString();
            if (ShareUtil.containsXmppUri(body)) {
                copyLink.setTitle(R.string.copy_jabber_id);
                copyLink.setVisible(true);
            } else if (Patterns.AUTOLINK_WEB_URL.matcher(body).find()) {
                copyLink.setVisible(true);
            }
        }
        if (m.getEncryption() == Message.ENCRYPTION_DECRYPTION_FAILED && !deleted) {
            retryDecryption.setVisible(true);
        }
        if (!showError
                && relevantForCorrection.getType() == Message.TYPE_TEXT
                && !m.isGeoUri()
                && relevantForCorrection.isLastCorrectableMessage()
                && m.getConversation() instanceof Conversation) {
            correctMessage.setVisible(true);
        }
        if ((m.isFileOrImage() && !deleted && !receiving) || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) {
            shareWith.setVisible(true);
        }
        if (m.getStatus() == Message.STATUS_SEND_FAILED) {
            sendAgain.setVisible(true);
        }
        if (m.hasFileOnRemoteHost()
                || m.isGeoUri()
                || m.treatAsDownloadable()
                || t instanceof HttpDownloadConnection) {
            copyUrl.setVisible(true);
        }
        if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) {
            downloadFile.setVisible(true);
            downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m)));
        }
        final boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING
                || m.getStatus() == Message.STATUS_UNSEND
                || m.getStatus() == Message.STATUS_OFFERED;
        final boolean cancelable = (t != null && !deleted) || waitingOfferedSending && m.needsUploading();
        if (cancelable) {
            cancelTransmission.setVisible(true);
        }
        if (m.isFileOrImage() && !deleted && !cancelable) {
            String path = m.getRelativeFilePath();
            if (path == null || !path.startsWith("/") || FileBackend.isInDirectoryThatShouldNotBeScanned(getActivity(), path)) {
                deleteFile.setVisible(true);
                deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m)));
            }
        }
        if (showError) {
            showErrorMessage.setVisible(true);
        }
        final String mime = m.isFileOrImage() ? m.getMimeType() : null;
        if ((m.isGeoUri() && GeoHelper.openInOsmAnd(getActivity(), m)) || (mime != null && mime.startsWith("audio/"))) {
            openWith.setVisible(true);
        }
    }
}