basic beam code / untested

This commit is contained in:
iNPUTmice 2014-11-03 20:00:20 +01:00
parent 4614ff343e
commit 28a186cd6c
4 changed files with 208 additions and 150 deletions

View file

@ -12,16 +12,17 @@
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.NFC" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
tools:replace="android:label" android:theme="@style/ConversationsTheme"
android:theme="@style/ConversationsTheme" > tools:replace="android:label">
<service android:name="eu.siacs.conversations.services.XmppConnectionService" /> <service android:name="eu.siacs.conversations.services.XmppConnectionService" />
<receiver android:name="eu.siacs.conversations.services.EventReceiver" > <receiver android:name="eu.siacs.conversations.services.EventReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
@ -33,7 +34,7 @@
android:name="eu.siacs.conversations.ui.ConversationActivity" android:name="eu.siacs.conversations.ui.ConversationActivity"
android:label="@string/title_activity_conversations" android:label="@string/title_activity_conversations"
android:launchMode="singleTask" android:launchMode="singleTask"
android:windowSoftInputMode="stateHidden" > android:windowSoftInputMode="stateHidden">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -43,8 +44,7 @@
<activity <activity
android:name="eu.siacs.conversations.ui.StartConversationActivity" android:name="eu.siacs.conversations.ui.StartConversationActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:label="@string/title_activity_start_conversation" android:label="@string/title_activity_start_conversation">
android:logo="@drawable/ic_activity" >
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SENDTO" /> <action android:name="android.intent.action.SENDTO" />
@ -61,42 +61,40 @@
<data android:scheme="xmpp" /> <data android:scheme="xmpp" />
</intent-filter> </intent-filter>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/vnd.eu.siacs.conversations.jid" />
</intent-filter>
</activity> </activity>
<activity <activity
android:name="eu.siacs.conversations.ui.SettingsActivity" android:name="eu.siacs.conversations.ui.SettingsActivity"
android:label="@string/title_activity_settings" > android:label="@string/title_activity_settings"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.ChooseContactActivity" android:name="eu.siacs.conversations.ui.ChooseContactActivity"
android:label="@string/title_activity_choose_contact" > android:label="@string/title_activity_choose_contact"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.ManageAccountActivity" android:name="eu.siacs.conversations.ui.ManageAccountActivity"
android:configChanges="orientation|screenSize" android:configChanges="orientation|screenSize"
android:label="@string/title_activity_manage_accounts" > android:label="@string/title_activity_manage_accounts"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.EditAccountActivity" android:name="eu.siacs.conversations.ui.EditAccountActivity"
android:windowSoftInputMode="stateHidden|adjustResize" > android:windowSoftInputMode="stateHidden|adjustResize"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.ConferenceDetailsActivity" android:name="eu.siacs.conversations.ui.ConferenceDetailsActivity"
android:label="@string/title_activity_conference_details" android:label="@string/title_activity_conference_details"
android:windowSoftInputMode="stateHidden" > android:windowSoftInputMode="stateHidden"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.ContactDetailsActivity" android:name="eu.siacs.conversations.ui.ContactDetailsActivity"
android:label="@string/title_activity_contact_details" android:label="@string/title_activity_contact_details"
android:windowSoftInputMode="stateHidden" > android:windowSoftInputMode="stateHidden"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.PublishProfilePictureActivity" android:name="eu.siacs.conversations.ui.PublishProfilePictureActivity"
android:label="@string/mgmt_account_publish_avatar" android:label="@string/mgmt_account_publish_avatar"
android:windowSoftInputMode="stateHidden" > android:windowSoftInputMode="stateHidden"></activity>
</activity>
<activity <activity
android:name="eu.siacs.conversations.ui.ShareWithActivity" android:name="eu.siacs.conversations.ui.ShareWithActivity"
android:label="@string/title_activity_conversations" > android:label="@string/title_activity_conversations">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />

View file

@ -1,21 +1,5 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper;
import android.net.Uri;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.AlertDialog; import android.app.AlertDialog;
@ -23,8 +7,16 @@ import android.app.FragmentTransaction;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.IntentSender.SendIntentException;
import android.content.Intent; import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.nfc.NfcEvent;
import android.os.Bundle;
import android.os.SystemClock;
import android.provider.MediaStore;
import android.support.v4.widget.SlidingPaneLayout; import android.support.v4.widget.SlidingPaneLayout;
import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener; import android.support.v4.widget.SlidingPaneLayout.PanelSlideListener;
import android.view.KeyEvent; import android.view.KeyEvent;
@ -40,6 +32,19 @@ import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener; import android.widget.PopupMenu.OnMenuItemClickListener;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.services.XmppConnectionService.OnAccountUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnConversationUpdate;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.ConversationAdapter;
import eu.siacs.conversations.utils.ExceptionHelper;
public class ConversationActivity extends XmppActivity implements public class ConversationActivity extends XmppActivity implements
OnAccountUpdate, OnConversationUpdate, OnRosterUpdate { OnAccountUpdate, OnConversationUpdate, OnRosterUpdate {
@ -78,6 +83,18 @@ public class ConversationActivity extends XmppActivity implements
private Uri pendingImageUri = null; private Uri pendingImageUri = null;
private NfcAdapter.CreateNdefMessageCallback mNdefPushMessageCallback = new NfcAdapter.CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent nfcEvent) {
Conversation conversation = getSelectedConversation();
NdefMessage msg = new NdefMessage(new NdefRecord[]{
NdefRecord.createUri("xmpp:"+conversation.getAccount().getJid().getBytes()),
NdefRecord.createApplicationRecord("eu.siacs.conversations")
});
return msg;
}
};
public List<Conversation> getConversationList() { public List<Conversation> getConversationList() {
return this.conversationList; return this.conversationList;
} }
@ -147,6 +164,8 @@ public class ConversationActivity extends XmppActivity implements
getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setDisplayHomeAsUpEnabled(false);
getActionBar().setHomeButtonEnabled(false); getActionBar().setHomeButtonEnabled(false);
registerNdefPushMessageCallback(this.mNdefPushMessageCallback);
this.listAdapter = new ConversationAdapter(this, conversationList); this.listAdapter = new ConversationAdapter(this, conversationList);
listView.setAdapter(this.listAdapter); listView.setAdapter(this.listAdapter);

View file

@ -1,6 +1,8 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -19,11 +21,15 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable;
import android.support.v13.app.FragmentPagerAdapter; 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;
@ -40,6 +46,8 @@ import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ListView; import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
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;
@ -371,7 +379,7 @@ public class StartConversationActivity extends XmppActivity {
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
protected void showJoinConferenceDialog() { protected void showJoinConferenceDialog(String prefilledJid) {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.join_conference); builder.setTitle(R.string.join_conference);
View dialogView = getLayoutInflater().inflate( View dialogView = getLayoutInflater().inflate(
@ -381,6 +389,9 @@ public class StartConversationActivity extends XmppActivity {
.findViewById(R.id.jid); .findViewById(R.id.jid);
jid.setAdapter(new KnownHostsAdapter(this, jid.setAdapter(new KnownHostsAdapter(this,
android.R.layout.simple_list_item_1, mKnownConferenceHosts)); android.R.layout.simple_list_item_1, mKnownConferenceHosts));
if (prefilledJid != null) {
jid.append(prefilledJid);
}
populateAccountSpinner(spinner); populateAccountSpinner(spinner);
final CheckBox bookmarkCheckBox = (CheckBox) dialogView final CheckBox bookmarkCheckBox = (CheckBox) dialogView
.findViewById(R.id.bookmark); .findViewById(R.id.bookmark);
@ -493,7 +504,7 @@ public class StartConversationActivity extends XmppActivity {
showCreateContactDialog(null); showCreateContactDialog(null);
break; break;
case R.id.action_join_conference: case R.id.action_join_conference:
showJoinConferenceDialog(); showJoinConferenceDialog(null);
break; break;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
@ -520,7 +531,7 @@ public class StartConversationActivity extends XmppActivity {
this.mKnownHosts = xmppConnectionService.getKnownHosts(); this.mKnownHosts = xmppConnectionService.getKnownHosts();
this.mKnownConferenceHosts = xmppConnectionService this.mKnownConferenceHosts = xmppConnectionService
.getKnownConferenceHosts(); .getKnownConferenceHosts();
if (!startByIntent()) { if (!handleIntent(getIntent())) {
if (mSearchEditText != null) { if (mSearchEditText != null) {
filter(mSearchEditText.getText().toString()); filter(mSearchEditText.getText().toString());
} else { } else {
@ -529,27 +540,49 @@ public class StartConversationActivity extends XmppActivity {
} }
} }
protected boolean startByIntent() { protected boolean handleIntent(Intent intent) {
if (getIntent() != null if (intent==null || intent.getAction() == null) {
&& Intent.ACTION_SENDTO.equals(getIntent().getAction())) { return false;
}
String jid;
switch(intent.getAction()) {
case Intent.ACTION_SENDTO:
try { try {
String jid = URLDecoder.decode( jid = URLDecoder.decode(
getIntent().getData().getEncodedPath(), "UTF-8").split( intent.getData().getEncodedPath(), "UTF-8").split(
"/")[1]; "/")[1];
setIntent(null);
return handleJid(jid); return handleJid(jid);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
setIntent(null);
return false; return false;
} }
} else if (getIntent() != null case Intent.ACTION_VIEW:
&& Intent.ACTION_VIEW.equals(getIntent().getAction())) { Uri uri = intent.getData();
Uri uri = getIntent().getData(); boolean muc = uri.getQuery() != null && uri.getQuery().equalsIgnoreCase("join");
String jid = uri.getSchemeSpecificPart().split("\\?")[0]; if (uri.getAuthority() != null) {
jid = uri.getAuthority();
} else {
jid = uri.getSchemeSpecificPart().split("\\?")[0];
}
if (muc) {
showJoinConferenceDialog(jid);
return false;
} else {
return handleJid(jid); return handleJid(jid);
} }
case NfcAdapter.ACTION_NDEF_DISCOVERED:
Parcelable[] messages = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
NdefMessage message = (NdefMessage) messages[0];
String payload = message.getRecords()[0].toString();
if (payload.startsWith("xmpp:")) {
jid = payload.substring(5);
return handleJid(jid);
} else {
return false; return false;
} }
default:
return false;
}
}
private boolean handleJid(String jid) { private boolean handleJid(String jid) {
List<Contact> contacts = xmppConnectionService.findContacts(jid); List<Contact> contacts = xmppConnectionService.findContacts(jid);

View file

@ -38,6 +38,7 @@ import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.nfc.NfcAdapter;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
@ -543,6 +544,13 @@ public abstract class XmppActivity extends Activity {
return false; return false;
} }
protected void registerNdefPushMessageCallback(NfcAdapter.CreateNdefMessageCallback callback) {
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter!=null && nfcAdapter.isEnabled()) {
nfcAdapter.setNdefPushMessageCallback(callback,this);
}
}
public AvatarService avatarService() { public AvatarService avatarService() {
return xmppConnectionService.getAvatarService(); return xmppConnectionService.getAvatarService();
} }