diff options
author | Daniel Gultsch <daniel@gultsch.de> | 2014-03-13 18:18:41 +0100 |
---|---|---|
committer | Daniel Gultsch <daniel@gultsch.de> | 2014-03-13 18:18:41 +0100 |
commit | 748582e3aba7f4feb931dd266de0b6b0e1f3206d (patch) | |
tree | cbd724cdcd7867c420fb711caf27a9cdd1b2dbbe | |
parent | 678dbd37c660c0754f75ef0fd882bfe049859344 (diff) |
start converstaion from address book (sendto)
Diffstat (limited to '')
-rw-r--r-- | AndroidManifest.xml | 26 | ||||
-rw-r--r-- | src/eu/siacs/conversations/ui/NewConversationActivity.java | 76 |
2 files changed, 73 insertions, 29 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 25e79a77..4e5042c1 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -11,10 +11,10 @@ <uses-permission android:name="android.permission.READ_CONTACTS" /> <uses-permission android:name="android.permission.READ_PROFILE" /> <uses-permission android:name="android.permission.INTERNET" /> - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> - <uses-permission android:name="android.permission.VIBRATE"/> + <uses-permission android:name="android.permission.VIBRATE" /> <application android:allowBackup="true" @@ -26,7 +26,7 @@ <receiver android:name="eu.siacs.conversations.services.EventReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> - <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> + <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver> @@ -40,14 +40,6 @@ <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> - <intent-filter> - <action android:name="android.intent.action.SENDTO" /> - - <category android:name="android.intent.category.DEFAULT" /> - - <data android:scheme="imto" /> - <data android:host="jabber" /> - </intent-filter> </activity> <activity android:name="eu.siacs.conversations.ui.SettingsActivity" @@ -77,6 +69,18 @@ <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="de.gultsch.chat.ui.ConversationActivity" /> + + <intent-filter> + <action android:name="android.intent.action.SEND" /> + <category android:name="android.intent.category.DEFAULT" /> + <data android:mimeType="text/plain" /> + </intent-filter> + <intent-filter> + <action android:name="android.intent.action.SENDTO" /> + <category android:name="android.intent.category.DEFAULT" /> + <data android:scheme="imto" /> + <data android:host="jabber" /> + </intent-filter> </activity> </application> diff --git a/src/eu/siacs/conversations/ui/NewConversationActivity.java b/src/eu/siacs/conversations/ui/NewConversationActivity.java index 0ad830ec..e275cea7 100644 --- a/src/eu/siacs/conversations/ui/NewConversationActivity.java +++ b/src/eu/siacs/conversations/ui/NewConversationActivity.java @@ -1,9 +1,12 @@ package eu.siacs.conversations.ui; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; @@ -15,6 +18,7 @@ import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; +import android.util.Log; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -151,23 +155,14 @@ public class NewConversationActivity extends XmppActivity { final Contact clickedContact = aggregatedContacts.get(pos); if ((clickedContact.getAccount()==null)&&(accounts.size()>1)) { - String[] accountList = new String[accounts.size()]; - for (int i = 0; i < accounts.size(); ++i) { - accountList[i] = accounts.get(i).getJid(); - } - - AlertDialog.Builder accountChooser = new AlertDialog.Builder( - activity); - accountChooser.setTitle("Choose account"); - accountChooser.setItems(accountList, new OnClickListener() { - - @Override - public void onClick(DialogInterface dialog, int which) { - clickedContact.setAccount(accounts.get(which)); - showIsMucDialogIfNeeded(clickedContact); - } - }); - accountChooser.create().show(); + getAccountChooser(new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + clickedContact.setAccount(accounts.get(which)); + showIsMucDialogIfNeeded(clickedContact); + } + }).show(); } else { if (clickedContact.getAccount()==null) { clickedContact.setAccount(accounts.get(0)); @@ -190,6 +185,19 @@ public class NewConversationActivity extends XmppActivity { }); } + protected AlertDialog getAccountChooser(OnClickListener listener) { + String[] accountList = new String[accounts.size()]; + for (int i = 0; i < accounts.size(); ++i) { + accountList[i] = accounts.get(i).getJid(); + } + + AlertDialog.Builder accountChooser = new AlertDialog.Builder( + this); + accountChooser.setTitle("Choose account"); + accountChooser.setItems(accountList, listener); + return accountChooser.create(); + } + public void showIsMucDialogIfNeeded(final Contact clickedContact) { if (clickedContact.couldBeMuc()) { AlertDialog.Builder dialog = new AlertDialog.Builder(this); @@ -222,6 +230,10 @@ public class NewConversationActivity extends XmppActivity { Conversation conversation = xmppConnectionService .findOrCreateConversation(account, contact.getJid(), muc); + switchToConversation(conversation); + } + + public void switchToConversation(Conversation conversation) { Intent viewConversationIntent = new Intent(this, ConversationActivity.class); viewConversationIntent.setAction(Intent.ACTION_VIEW); @@ -235,11 +247,39 @@ public class NewConversationActivity extends XmppActivity { @Override void onBackendConnected() { + this.accounts = xmppConnectionService.getAccounts(); + if (Intent.ACTION_SENDTO.equals(getIntent().getAction())) { + getActionBar().setDisplayHomeAsUpEnabled(false); + getActionBar().setHomeButtonEnabled(false); + String jid; + try { + jid = URLDecoder.decode(getIntent().getData().getEncodedPath(),"UTF-8").split("/")[1]; + } catch (UnsupportedEncodingException e) { + jid = null; + } + if (jid!=null) { + final String finalJid = jid; + if (this.accounts.size() > 1) { + getAccountChooser(new OnClickListener() { + + @Override + public void onClick(DialogInterface dialog, int which) { + Conversation conversation = xmppConnectionService.findOrCreateConversation(accounts.get(which), finalJid, false); + switchToConversation(conversation); + } + }).show(); + } else { + Conversation conversation = xmppConnectionService.findOrCreateConversation(this.accounts.get(0), jid, false); + switchToConversation(conversation); + } + } + } + + if (xmppConnectionService.getConversationCount() == 0) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); } - this.accounts = xmppConnectionService.getAccounts(); this.rosterContacts.clear(); for (int i = 0; i < accounts.size(); ++i) { xmppConnectionService.getRoster(accounts.get(i), |