Merge pull request #622 from emdete/p1

P1
This commit is contained in:
Daniel Gultsch 2014-11-04 17:02:46 +01:00
commit 11ecf43da7

View File

@ -23,6 +23,7 @@ import android.support.v13.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -50,6 +51,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Bookmark; import eu.siacs.conversations.entities.Bookmark;
@ -574,41 +576,35 @@ public class StartConversationActivity extends XmppActivity {
if (intent == null || intent.getAction() == null) { if (intent == null || intent.getAction() == null) {
return false; return false;
} }
Invite invite = null;
switch (intent.getAction()) { switch (intent.getAction()) {
case Intent.ACTION_SENDTO: case Intent.ACTION_SENDTO:
try {
// TODO use Intent.parse ?!?
String jid = URLDecoder.decode(
intent.getData().getEncodedPath(), "UTF-8").split(
"/")[1];
return handleJid(jid);
} catch (UnsupportedEncodingException e) {
return false;
}
case Intent.ACTION_VIEW: case Intent.ACTION_VIEW:
invite = new Invite(intent.getData()); Log.d(Config.LOGTAG, "received uri=" + intent.getData());
return invite.invite(); return new Invite(intent.getData()).invite();
case NfcAdapter.ACTION_NDEF_DISCOVERED: case NfcAdapter.ACTION_NDEF_DISCOVERED:
Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); for (Parcelable message : getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)) {
NdefMessage message = (NdefMessage) messages[0]; if (message instanceof NdefMessage) {
NdefRecord record = message.getRecords()[0]; Log.d(Config.LOGTAG, "received message=" + message);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { for (NdefRecord record : ((NdefMessage)message).getRecords()) {
invite = new Invite(record.toUri()); switch (record.getTnf()) {
} else { case NdefRecord.TNF_WELL_KNOWN:
byte[] mPayload = record.getPayload(); if (Arrays.equals(record.getType(), NdefRecord.RTD_URI)) {
if (mPayload[0] == 0) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
invite = new Invite(Uri.parse(new String(Arrays.copyOfRange( return new Invite(record.toUri()).invite();
mPayload, 1, mPayload.length)))); } else {
byte[] payload = record.getPayload();
if (payload[0] == 0) {
return new Invite(Uri.parse(new String(Arrays.copyOfRange(
payload, 1, payload.length)))).invite();
}
}
}
}
}
} }
} }
if (invite != null) {
return invite.invite();
}
return false;
default:
return false;
} }
return false;
} }
private boolean handleJid(String jid) { private boolean handleJid(String jid) {
@ -764,11 +760,21 @@ public class StartConversationActivity extends XmppActivity {
} }
void parse(Uri uri) { void parse(Uri uri) {
muc = uri.getQuery() != null && uri.getQuery().equalsIgnoreCase("join"); String scheme = uri.getScheme();
if (uri.getAuthority() != null) { if ("xmpp".equals(scheme)) {
jid = uri.getAuthority(); // sample: xmpp:jid@foo.com
} else { muc = "join".equalsIgnoreCase(uri.getQuery());
jid = uri.getSchemeSpecificPart().split("\\?")[0]; if (uri.getAuthority() != null) {
jid = uri.getAuthority();
} else {
jid = uri.getSchemeSpecificPart().split("\\?")[0];
}
} else if ("imto".equals(scheme)) {
// sample: imto://xmpp/jid@foo.com
try {
jid = URLDecoder.decode(uri.getEncodedPath(), "UTF-8").split("/")[1];
} catch (UnsupportedEncodingException e) {
}
} }
} }
} }