Search in sources :

Example 6 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class ShareViaAccountActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_accounts);
    accountListView = findViewById(R.id.account_list);
    this.mAccountAdapter = new AccountAdapter(this, accountList);
    accountListView.setAdapter(this.mAccountAdapter);
    accountListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
            final Account account = accountList.get(position);
            final String body = getIntent().getStringExtra(EXTRA_BODY);
            try {
                final Jid contact = Jid.fromString(getIntent().getStringExtra(EXTRA_CONTACT));
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, contact, false, false);
                switchToConversation(conversation, body, false);
            } catch (InvalidJidException e) {
            // ignore error
            }
            finish();
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) AccountAdapter(de.pixart.messenger.ui.adapter.AccountAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 7 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class ManageAccountActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_manage_accounts);
    if (savedInstanceState != null) {
        String jid = savedInstanceState.getString(STATE_SELECTED_ACCOUNT);
        if (jid != null) {
            try {
                this.selectedAccountJid = Jid.fromString(jid);
            } catch (InvalidJidException e) {
                this.selectedAccountJid = null;
            }
        }
    }
    accountListView = findViewById(R.id.account_list);
    this.mAccountAdapter = new AccountAdapter(this, accountList);
    accountListView.setAdapter(this.mAccountAdapter);
    accountListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
            switchToAccount(accountList.get(position));
        }
    });
    registerForContextMenu(accountListView);
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) AccountAdapter(de.pixart.messenger.ui.adapter.AccountAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 8 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class SettingsActivity method deleteOmemoIdentities.

private boolean deleteOmemoIdentities() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.pref_delete_omemo_identities);
    final List<CharSequence> accounts = new ArrayList<>();
    for (Account account : xmppConnectionService.getAccounts()) {
        if (account.isEnabled()) {
            accounts.add(account.getJid().toBareJid().toString());
        }
    }
    final boolean[] checkedItems = new boolean[accounts.size()];
    builder.setMultiChoiceItems(accounts.toArray(new CharSequence[accounts.size()]), checkedItems, (dialog, which, isChecked) -> {
        checkedItems[which] = isChecked;
        final AlertDialog alertDialog = (AlertDialog) dialog;
        for (boolean item : checkedItems) {
            if (item) {
                alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
                return;
            }
        }
        alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
    });
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.delete_selected_keys, (dialog, which) -> {
        for (int i = 0; i < checkedItems.length; ++i) {
            if (checkedItems[i]) {
                try {
                    Jid jid = Jid.fromString(accounts.get(i).toString());
                    Account account = xmppConnectionService.findAccountByJid(jid);
                    if (account != null) {
                        account.getAxolotlService().regenerateKeys(true);
                    }
                } catch (InvalidJidException e) {
                // 
                }
            }
        }
    });
    AlertDialog dialog = builder.create();
    dialog.show();
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
    return true;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) ArrayList(java.util.ArrayList)

Example 9 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class CryptoHelper method extractJidAndName.

public static Pair<Jid, String> extractJidAndName(X509Certificate certificate) throws CertificateEncodingException, InvalidJidException, CertificateParsingException {
    Collection<List<?>> alternativeNames = certificate.getSubjectAlternativeNames();
    List<String> emails = new ArrayList<>();
    if (alternativeNames != null) {
        for (List<?> san : alternativeNames) {
            Integer type = (Integer) san.get(0);
            if (type == 1) {
                emails.add((String) san.get(1));
            }
        }
    }
    X500Name x500name = new JcaX509CertificateHolder(certificate).getSubject();
    if (emails.size() == 0 && x500name.getRDNs(BCStyle.EmailAddress).length > 0) {
        emails.add(IETFUtils.valueToString(x500name.getRDNs(BCStyle.EmailAddress)[0].getFirst().getValue()));
    }
    String name = x500name.getRDNs(BCStyle.CN).length > 0 ? IETFUtils.valueToString(x500name.getRDNs(BCStyle.CN)[0].getFirst().getValue()) : null;
    if (emails.size() >= 1) {
        return new Pair<>(Jid.fromString(emails.get(0)), name);
    } else if (name != null) {
        try {
            Jid jid = Jid.fromString(name);
            if (jid.isBareJid() && !jid.isDomainJid()) {
                return new Pair<>(jid, null);
            }
        } catch (InvalidJidException e) {
            return null;
        }
    }
    return null;
}
Also used : Jid(de.pixart.messenger.xmpp.jid.Jid) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) ArrayList(java.util.ArrayList) X500Name(org.bouncycastle.asn1.x500.X500Name) JcaX509CertificateHolder(org.bouncycastle.cert.jcajce.JcaX509CertificateHolder) ArrayList(java.util.ArrayList) List(java.util.List) Pair(android.util.Pair)

Example 10 with InvalidJidException

use of de.pixart.messenger.xmpp.jid.InvalidJidException in project Pix-Art-Messenger by kriztan.

the class PresenceSelector method showPresenceSelectionDialog.

public static void showPresenceSelectionDialog(Activity activity, final Conversation conversation, final OnPresenceSelected listener) {
    final Contact contact = conversation.getContact();
    final Presences presences = contact.getPresences();
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(activity.getString(R.string.choose_presence));
    final String[] resourceArray = presences.toResourceArray();
    Pair<Map<String, String>, Map<String, String>> typeAndName = presences.toTypeAndNameMap();
    final Map<String, String> resourceTypeMap = typeAndName.first;
    final Map<String, String> resourceNameMap = typeAndName.second;
    final String[] readableIdentities = new String[resourceArray.length];
    final AtomicInteger selectedResource = new AtomicInteger(0);
    for (int i = 0; i < resourceArray.length; ++i) {
        String resource = resourceArray[i];
        if (resource.equals(contact.getLastResource())) {
            selectedResource.set(i);
        }
        String type = resourceTypeMap.get(resource);
        String name = resourceNameMap.get(resource);
        if (type != null) {
            if (Collections.frequency(resourceTypeMap.values(), type) == 1) {
                readableIdentities[i] = translateType(activity, type);
            } else if (name != null) {
                if (Collections.frequency(resourceNameMap.values(), name) == 1 || CryptoHelper.UUID_PATTERN.matcher(resource).matches()) {
                    readableIdentities[i] = translateType(activity, type) + "  (" + name + ")";
                } else {
                    readableIdentities[i] = translateType(activity, type) + " (" + name + " / " + resource + ")";
                }
            } else {
                readableIdentities[i] = translateType(activity, type) + " (" + resource + ")";
            }
        } else {
            readableIdentities[i] = resource;
        }
    }
    builder.setSingleChoiceItems(readableIdentities, selectedResource.get(), (dialog, which) -> selectedResource.set(which));
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.ok, (dialog, which) -> {
        try {
            Jid next = Jid.fromParts(contact.getJid().getLocalpart(), contact.getJid().getDomainpart(), resourceArray[selectedResource.get()]);
            conversation.setNextCounterpart(next);
        } catch (InvalidJidException e) {
            conversation.setNextCounterpart(null);
        }
        listener.onPresenceSelected();
    });
    builder.create().show();
}
Also used : AlertDialog(android.app.AlertDialog) Jid(de.pixart.messenger.xmpp.jid.Jid) Presences(de.pixart.messenger.entities.Presences) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Contact(de.pixart.messenger.entities.Contact) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map)

Aggregations

InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)33 Jid (de.pixart.messenger.xmpp.jid.Jid)25 Account (de.pixart.messenger.entities.Account)14 Conversation (de.pixart.messenger.entities.Conversation)13 MessagePacket (de.pixart.messenger.xmpp.stanzas.MessagePacket)5 AlertDialog (android.support.v7.app.AlertDialog)4 Contact (de.pixart.messenger.entities.Contact)4 Message (de.pixart.messenger.entities.Message)4 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)4 View (android.view.View)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)3 ArrayList (java.util.ArrayList)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2 SpannableString (android.text.SpannableString)2 Pair (android.util.Pair)2 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)2 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)2