Search in sources :

Example 1 with OnMenuItemClickListener

use of android.widget.PopupMenu.OnMenuItemClickListener in project Conversations by siacs.

the class ConversationActivity method selectEncryptionDialog.

protected void selectEncryptionDialog(final Conversation conversation) {
    View menuItemView = findViewById(R.id.action_security);
    if (menuItemView == null) {
        return;
    }
    PopupMenu popup = new PopupMenu(this, menuItemView);
    final ConversationFragment fragment = (ConversationFragment) getFragmentManager().findFragmentByTag("conversation");
    if (fragment != null) {
        popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch(item.getItemId()) {
                    case R.id.encryption_choice_none:
                        conversation.setNextEncryption(Message.ENCRYPTION_NONE);
                        item.setChecked(true);
                        break;
                    case R.id.encryption_choice_otr:
                        conversation.setNextEncryption(Message.ENCRYPTION_OTR);
                        item.setChecked(true);
                        break;
                    case R.id.encryption_choice_pgp:
                        if (hasPgp()) {
                            if (conversation.getAccount().getPgpSignature() != null) {
                                conversation.setNextEncryption(Message.ENCRYPTION_PGP);
                                item.setChecked(true);
                            } else {
                                announcePgp(conversation.getAccount(), conversation, onOpenPGPKeyPublished);
                            }
                        } else {
                            showInstallPgpDialog();
                        }
                        break;
                    case R.id.encryption_choice_axolotl:
                        Log.d(Config.LOGTAG, AxolotlService.getLogprefix(conversation.getAccount()) + "Enabled axolotl for Contact " + conversation.getContact().getJid());
                        conversation.setNextEncryption(Message.ENCRYPTION_AXOLOTL);
                        item.setChecked(true);
                        break;
                    default:
                        conversation.setNextEncryption(Message.ENCRYPTION_NONE);
                        break;
                }
                xmppConnectionService.updateConversation(conversation);
                fragment.updateChatMsgHint();
                invalidateOptionsMenu();
                refreshUi();
                return true;
            }
        });
        popup.inflate(R.menu.encryption_choices);
        MenuItem otr = popup.getMenu().findItem(R.id.encryption_choice_otr);
        MenuItem none = popup.getMenu().findItem(R.id.encryption_choice_none);
        MenuItem pgp = popup.getMenu().findItem(R.id.encryption_choice_pgp);
        MenuItem axolotl = popup.getMenu().findItem(R.id.encryption_choice_axolotl);
        pgp.setVisible(Config.supportOpenPgp());
        none.setVisible(Config.supportUnencrypted() || conversation.getMode() == Conversation.MODE_MULTI);
        otr.setVisible(Config.supportOtr());
        axolotl.setVisible(Config.supportOmemo());
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            otr.setVisible(false);
        }
        if (!conversation.getAccount().getAxolotlService().isConversationAxolotlCapable(conversation)) {
            axolotl.setEnabled(false);
        }
        switch(conversation.getNextEncryption()) {
            case Message.ENCRYPTION_NONE:
                none.setChecked(true);
                break;
            case Message.ENCRYPTION_OTR:
                otr.setChecked(true);
                break;
            case Message.ENCRYPTION_PGP:
                pgp.setChecked(true);
                break;
            case Message.ENCRYPTION_AXOLOTL:
                axolotl.setChecked(true);
                break;
            default:
                none.setChecked(true);
                break;
        }
        popup.show();
    }
}
Also used : OnMenuItemClickListener(android.widget.PopupMenu.OnMenuItemClickListener) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) EnhancedListView(de.timroes.android.listview.EnhancedListView) PopupMenu(android.widget.PopupMenu)

Example 2 with OnMenuItemClickListener

use of android.widget.PopupMenu.OnMenuItemClickListener in project Conversations by siacs.

the class ConversationActivity method verifyOtrSessionDialog.

public void verifyOtrSessionDialog(final Conversation conversation, View view) {
    if (!conversation.hasValidOtrSession() || conversation.getOtrSession().getSessionStatus() != SessionStatus.ENCRYPTED) {
        Toast.makeText(this, R.string.otr_session_not_started, Toast.LENGTH_LONG).show();
        return;
    }
    if (view == null) {
        return;
    }
    PopupMenu popup = new PopupMenu(this, view);
    popup.inflate(R.menu.verification_choices);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            Intent intent = new Intent(ConversationActivity.this, VerifyOTRActivity.class);
            intent.setAction(VerifyOTRActivity.ACTION_VERIFY_CONTACT);
            intent.putExtra("contact", conversation.getContact().getJid().toBareJid().toString());
            intent.putExtra(EXTRA_ACCOUNT, conversation.getAccount().getJid().toBareJid().toString());
            switch(menuItem.getItemId()) {
                case R.id.scan_fingerprint:
                    intent.putExtra("mode", VerifyOTRActivity.MODE_SCAN_FINGERPRINT);
                    break;
                case R.id.ask_question:
                    intent.putExtra("mode", VerifyOTRActivity.MODE_ASK_QUESTION);
                    break;
                case R.id.manual_verification:
                    intent.putExtra("mode", VerifyOTRActivity.MODE_MANUAL_VERIFICATION);
                    break;
            }
            startActivity(intent);
            return true;
        }
    });
    popup.show();
}
Also used : OnMenuItemClickListener(android.widget.PopupMenu.OnMenuItemClickListener) MenuItem(android.view.MenuItem) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) PopupMenu(android.widget.PopupMenu)

Example 3 with OnMenuItemClickListener

use of android.widget.PopupMenu.OnMenuItemClickListener in project Conversations by siacs.

the class ConversationActivity method attachFileDialog.

protected void attachFileDialog() {
    View menuAttachFile = findViewById(R.id.action_attach_file);
    if (menuAttachFile == null) {
        return;
    }
    PopupMenu attachFilePopup = new PopupMenu(this, menuAttachFile);
    attachFilePopup.inflate(R.menu.attachment_choices);
    if (new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null) {
        attachFilePopup.getMenu().findItem(R.id.attach_record_voice).setVisible(false);
    }
    if (new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null) {
        attachFilePopup.getMenu().findItem(R.id.attach_location).setVisible(false);
    }
    attachFilePopup.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch(item.getItemId()) {
                case R.id.attach_choose_picture:
                    attachFile(ATTACHMENT_CHOICE_CHOOSE_IMAGE);
                    break;
                case R.id.attach_take_picture:
                    attachFile(ATTACHMENT_CHOICE_TAKE_PHOTO);
                    break;
                case R.id.attach_choose_file:
                    attachFile(ATTACHMENT_CHOICE_CHOOSE_FILE);
                    break;
                case R.id.attach_record_voice:
                    attachFile(ATTACHMENT_CHOICE_RECORD_VOICE);
                    break;
                case R.id.attach_location:
                    attachFile(ATTACHMENT_CHOICE_LOCATION);
                    break;
            }
            return false;
        }
    });
    UIHelper.showIconsInPopup(attachFilePopup);
    attachFilePopup.show();
}
Also used : OnMenuItemClickListener(android.widget.PopupMenu.OnMenuItemClickListener) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) AdapterView(android.widget.AdapterView) EnhancedListView(de.timroes.android.listview.EnhancedListView) PopupMenu(android.widget.PopupMenu)

Aggregations

MenuItem (android.view.MenuItem)3 PopupMenu (android.widget.PopupMenu)3 OnMenuItemClickListener (android.widget.PopupMenu.OnMenuItemClickListener)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 EnhancedListView (de.timroes.android.listview.EnhancedListView)2