Search in sources :

Example 1 with XmppUri

use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.

the class VerifyOTRActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    if ((requestCode & 0xFFFF) == IntentIntegrator.REQUEST_CODE) {
        IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
        if (scanResult != null && scanResult.getFormatName() != null) {
            String data = scanResult.getContents();
            XmppUri uri = new XmppUri(data);
            if (xmppConnectionServiceBound) {
                verifyWithUri(uri);
                finish();
            } else {
                this.mPendingUri = uri;
            }
        } else {
            finish();
        }
    }
    super.onActivityResult(requestCode, requestCode, intent);
}
Also used : IntentResult(com.google.zxing.integration.android.IntentResult) XmppUri(eu.siacs.conversations.utils.XmppUri)

Example 2 with XmppUri

use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.

the class WelcomeActivity method onInstallReferrerDiscovered.

public void onInstallReferrerDiscovered(final Uri referrer) {
    Log.d(Config.LOGTAG, "welcome activity: on install referrer discovered " + referrer);
    if ("xmpp".equalsIgnoreCase(referrer.getScheme())) {
        final XmppUri xmppUri = new XmppUri(referrer);
        runOnUiThread(() -> processXmppUri(xmppUri));
    } else {
        Log.i(Config.LOGTAG, "install referrer was not an XMPP uri");
    }
}
Also used : XmppUri(eu.siacs.conversations.utils.XmppUri)

Example 3 with XmppUri

use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.

the class StartConversationActivity method onJoinDialogPositiveClick.

@Override
public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout layout, AutoCompleteTextView jid, boolean isBookmarkChecked) {
    if (!xmppConnectionServiceBound) {
        return;
    }
    final Account account = getSelectedAccount(this, spinner);
    if (account == null) {
        return;
    }
    final String input = jid.getText().toString();
    Jid conferenceJid;
    try {
        conferenceJid = Jid.ofEscaped(input);
    } catch (final IllegalArgumentException e) {
        final XmppUri xmppUri = new XmppUri(input);
        if (xmppUri.isValidJid() && xmppUri.isAction(XmppUri.ACTION_JOIN)) {
            final Editable editable = jid.getEditableText();
            editable.clear();
            editable.append(xmppUri.getJid().toEscapedString());
            conferenceJid = xmppUri.getJid();
        } else {
            layout.setError(getString(R.string.invalid_jid));
            return;
        }
    }
    if (isBookmarkChecked) {
        Bookmark bookmark = account.getBookmark(conferenceJid);
        if (bookmark != null) {
            dialog.dismiss();
            openConversationsForBookmark(bookmark);
        } else {
            bookmark = new Bookmark(account, conferenceJid.asBareJid());
            bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin));
            final String nick = conferenceJid.getResource();
            if (nick != null && !nick.isEmpty() && !nick.equals(MucOptions.defaultNick(account))) {
                bookmark.setNick(nick);
            }
            xmppConnectionService.createBookmark(account, bookmark);
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
            bookmark.setConversation(conversation);
            dialog.dismiss();
            switchToConversation(conversation);
        }
    } else {
        final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
        dialog.dismiss();
        switchToConversation(conversation);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.Jid) XmppUri(eu.siacs.conversations.utils.XmppUri) Bookmark(eu.siacs.conversations.entities.Bookmark) Editable(android.text.Editable) Conversation(eu.siacs.conversations.entities.Conversation)

Example 4 with XmppUri

use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.

the class UriHandlerActivity method handleUri.

private boolean handleUri(final Uri uri, final boolean scanned) {
    final Intent intent;
    final XmppUri xmppUri = new XmppUri(uri);
    final List<Jid> accounts = DatabaseBackend.getInstance(this).getAccountJids(true);
    if (SignupUtils.isSupportTokenRegistry() && xmppUri.isValidJid()) {
        final String preAuth = xmppUri.getParameter(XmppUri.PARAMETER_PRE_AUTH);
        final Jid jid = xmppUri.getJid();
        if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
            if (jid.getEscapedLocal() != null && accounts.contains(jid.asBareJid())) {
                showError(R.string.account_already_exists);
                return false;
            }
            intent = SignupUtils.getTokenRegistrationIntent(this, jid, preAuth);
            startActivity(intent);
            return true;
        }
        if (accounts.size() == 0 && xmppUri.isAction(XmppUri.ACTION_ROSTER) && "y".equals(xmppUri.getParameter(XmppUri.PARAMETER_IBR))) {
            intent = SignupUtils.getTokenRegistrationIntent(this, jid.getDomain(), preAuth);
            intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
            startActivity(intent);
            return true;
        }
    } else if (xmppUri.isAction(XmppUri.ACTION_REGISTER)) {
        showError(R.string.account_registrations_are_not_supported);
        return false;
    }
    if (accounts.size() == 0) {
        if (xmppUri.isValidJid()) {
            intent = SignupUtils.getSignUpIntent(this);
            intent.putExtra(StartConversationActivity.EXTRA_INVITE_URI, xmppUri.toString());
            startActivity(intent);
            return true;
        } else {
            showError(R.string.invalid_jid);
            return false;
        }
    }
    if (xmppUri.isAction(XmppUri.ACTION_MESSAGE)) {
        final Jid jid = xmppUri.getJid();
        final String body = xmppUri.getBody();
        if (jid != null) {
            final Class<?> clazz = findShareViaAccountClass();
            if (clazz != null) {
                intent = new Intent(this, clazz);
                intent.putExtra("contact", jid.toEscapedString());
                intent.putExtra("body", body);
            } else {
                intent = new Intent(this, StartConversationActivity.class);
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(uri);
                intent.putExtra("account", accounts.get(0).toEscapedString());
            }
        } else {
            intent = new Intent(this, ShareWithActivity.class);
            intent.setAction(Intent.ACTION_SEND);
            intent.setType("text/plain");
            intent.putExtra(Intent.EXTRA_TEXT, body);
        }
    } else if (accounts.contains(xmppUri.getJid())) {
        intent = new Intent(getApplicationContext(), EditAccountActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.putExtra("jid", xmppUri.getJid().asBareJid().toString());
        intent.setData(uri);
        intent.putExtra("scanned", scanned);
    } else if (xmppUri.isValidJid()) {
        intent = new Intent(getApplicationContext(), StartConversationActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.putExtra("scanned", scanned);
        intent.setData(uri);
    } else {
        showError(R.string.invalid_jid);
        return false;
    }
    startActivity(intent);
    return true;
}
Also used : XmppUri(eu.siacs.conversations.utils.XmppUri) Jid(eu.siacs.conversations.xmpp.Jid) Intent(android.content.Intent)

Example 5 with XmppUri

use of eu.siacs.conversations.utils.XmppUri in project Conversations by siacs.

the class ShareUtil method copyLinkToClipboard.

public static void copyLinkToClipboard(XmppActivity activity, Message message) {
    String body = message.getMergedBody().toString();
    Matcher xmppPatternMatcher = Patterns.XMPP_PATTERN.matcher(body);
    if (xmppPatternMatcher.find()) {
        try {
            Jid jid = new XmppUri(body.substring(xmppPatternMatcher.start(), xmppPatternMatcher.end())).getJid();
            if (activity.copyTextToClipboard(jid.asBareJid().toString(), R.string.account_settings_jabber_id)) {
                Toast.makeText(activity, R.string.jabber_id_copied_to_clipboard, Toast.LENGTH_SHORT).show();
            }
            return;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }
    Matcher webUrlPatternMatcher = Patterns.AUTOLINK_WEB_URL.matcher(body);
    if (webUrlPatternMatcher.find()) {
        String url = body.substring(webUrlPatternMatcher.start(), webUrlPatternMatcher.end());
        if (activity.copyTextToClipboard(url, R.string.web_address)) {
            Toast.makeText(activity, R.string.url_copied_to_clipboard, Toast.LENGTH_SHORT).show();
        }
    }
}
Also used : Jid(eu.siacs.conversations.xmpp.Jid) XmppUri(eu.siacs.conversations.utils.XmppUri) Matcher(java.util.regex.Matcher) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

XmppUri (eu.siacs.conversations.utils.XmppUri)9 Jid (eu.siacs.conversations.xmpp.Jid)4 Intent (android.content.Intent)2 PendingIntent (android.app.PendingIntent)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 Editable (android.text.Editable)1 IntentResult (com.google.zxing.integration.android.IntentResult)1 AxolotlService (eu.siacs.conversations.crypto.axolotl.AxolotlService)1 Account (eu.siacs.conversations.entities.Account)1 Bookmark (eu.siacs.conversations.entities.Bookmark)1 Contact (eu.siacs.conversations.entities.Contact)1 Conversation (eu.siacs.conversations.entities.Conversation)1 MucOptions (eu.siacs.conversations.entities.MucOptions)1 Element (eu.siacs.conversations.xml.Element)1 InvalidJid (eu.siacs.conversations.xmpp.InvalidJid)1 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)1 Matcher (java.util.regex.Matcher)1