--- a/src/com/beem/project/beem/service/ChatAdapter.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/ChatAdapter.java Thu Apr 23 20:25:17 2009 +0200
@@ -4,16 +4,11 @@
package com.beem.project.beem.service;
import org.jivesoftware.smack.Chat;
-import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.packet.Message;
-import android.os.RemoteCallbackList;
import android.os.RemoteException;
-import android.util.Log;
import com.beem.project.beem.service.aidl.IChat;
-import com.beem.project.beem.service.aidl.IMessageListener;
/**
* An adapter for smack's Chat class.
--- a/src/com/beem/project/beem/service/Contact.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/Contact.java Thu Apr 23 20:25:17 2009 +0200
@@ -7,7 +7,6 @@
import java.util.List;
import org.jivesoftware.smack.packet.Presence;
-import org.jivesoftware.smack.packet.Presence.Mode;
import com.beem.project.beem.utils.Status;
--- a/src/com/beem/project/beem/service/PresenceAdapter.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/PresenceAdapter.java Thu Apr 23 20:25:17 2009 +0200
@@ -2,13 +2,17 @@
import org.jivesoftware.smack.packet.Presence;
-import android.os.IBinder;
+import com.beem.project.beem.utils.PresenceType;
+import com.beem.project.beem.utils.Status;
+
import android.os.Parcel;
import android.os.Parcelable;
public class PresenceAdapter implements Parcelable {
- private Presence mPresence;
+ private int mType;
+ private int mStatus;
+ private String mTo;
/**
* Parcelable.Creator needs by Android.
@@ -27,12 +31,16 @@
};
public PresenceAdapter(Presence presence) {
- mPresence = presence;
+ mType = PresenceType.getPresenceType(presence);
+ mStatus = Status.getStatusFromPresence(presence);
+ mTo = presence.getTo();
}
public PresenceAdapter(Parcel source) {
- // TODO Auto-generated constructor stub
+ mType = source.readInt();
+ mStatus = source.readInt();
+ mTo = source.readString();
}
@Override
@@ -43,7 +51,55 @@
@Override
public void writeToParcel(Parcel dest, int flags) {
- // TODO Auto-generated method stub
-
+ dest.writeInt(mType);
+ dest.writeInt(mStatus);
+ dest.writeString(mTo);
+ }
+
+
+ /**
+ * @param mStatus the mStatus to set
+ */
+ public void setStatus(int mStatus) {
+ this.mStatus = mStatus;
+ }
+
+
+ /**
+ * @return the mStatus
+ */
+ public int getStatus() {
+ return mStatus;
+ }
+
+
+ /**
+ * @param mType the mType to set
+ */
+ public void setType(int mType) {
+ this.mType = mType;
+ }
+
+
+ /**
+ * @return the mType
+ */
+ public int getType() {
+ return mType;
+ }
+
+
+ /**
+ * @param mTo the mTo to set
+ */
+ public void setTo(String mTo) {
+ this.mTo = mTo;
+ }
+
+ /**
+ * @return the mTo
+ */
+ public String getTo() {
+ return mTo;
}
}
--- a/src/com/beem/project/beem/service/RosterAdapter.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Thu Apr 23 20:25:17 2009 +0200
@@ -15,8 +15,11 @@
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smack.packet.Presence.Type;
import org.jivesoftware.smack.util.StringUtils;
+import com.beem.project.beem.BeemApplication;
+import com.beem.project.beem.BeemService;
import com.beem.project.beem.service.aidl.IBeemRosterListener;
import android.os.RemoteCallbackList;
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Thu Apr 23 20:25:17 2009 +0200
@@ -4,19 +4,16 @@
package com.beem.project.beem.service;
import org.jivesoftware.smack.ConnectionConfiguration;
-import org.jivesoftware.smack.ConnectionCreationListener;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.packet.XMPPError;
import org.jivesoftware.smackx.ChatStateManager;
import org.jivesoftware.smackx.ServiceDiscoveryManager;
import org.jivesoftware.smackx.jingle.JingleManager;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
-import com.beem.project.beem.BeemException;
import com.beem.project.beem.BeemService;
import com.beem.project.beem.service.aidl.IBeemConnectionListener;
import com.beem.project.beem.service.aidl.IChatManager;
@@ -35,7 +32,6 @@
private String mLogin;
private String mPassword;
private RosterAdapter mRoster;
- private Object mLastException;
private BeemService mService;
private RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
@@ -88,7 +84,6 @@
// TODO find why this cause a null pointer exception
this.initFeatures(); // pour declarer les features xmpp qu'on supporte
ChatStateManager.getInstance(mAdaptee);
- mLastException = null;
triggerAsynchronousConnectEvent();
return true;
} catch (XMPPException e) {
@@ -104,7 +99,6 @@
@Override
public boolean disconnect() {
mAdaptee.disconnect();
- mLastException = null;
return true;
}
--- a/src/com/beem/project/beem/service/XmppFacade.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppFacade.java Thu Apr 23 20:25:17 2009 +0200
@@ -5,7 +5,6 @@
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Intent;
-import android.graphics.Bitmap.CompressFormat;
import android.os.RemoteException;
import com.beem.project.beem.BeemService;
@@ -14,6 +13,7 @@
import com.beem.project.beem.service.aidl.IXmppConnection;
import com.beem.project.beem.service.aidl.IXmppFacade;
import com.beem.project.beem.ui.ChangeStatus;
+import com.beem.project.beem.utils.PresenceType;
/**
* This class is a facade for the Beem Service.
@@ -101,10 +101,16 @@
mStatusNotification.defaults = Notification.DEFAULT_ALL;
mStatusNotification.flags = Notification.FLAG_NO_CLEAR;
- // TODO
// mStatusNotification.contentView = ;
mStatusNotification.setLatestEventInfo(mBeemService, "Beem Status", text, PendingIntent.getActivity(
mBeemService, 0, new Intent(mBeemService,ChangeStatus.class), 0));
mBeemService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
}
+
+ @Override
+ public void sendPresencePacket(PresenceAdapter presence) throws RemoteException {
+ Presence presence2 = new Presence(PresenceType.getPresenceTypeFrom(presence.getType()));
+ presence2.setTo(presence.getTo());
+ mConnexion.getAdaptee().sendPacket(presence2);
+ }
}
--- a/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/service/aidl/IXmppFacade.aidl Thu Apr 23 20:25:17 2009 +0200
@@ -3,6 +3,7 @@
import com.beem.project.beem.service.aidl.IXmppConnection;
import com.beem.project.beem.service.aidl.IRoster;
import com.beem.project.beem.service.aidl.IChatManager;
+import com.beem.project.beem.service.PresenceAdapter;
interface IXmppFacade {
@@ -43,4 +44,6 @@
*/
void changeStatus(in int status, in String msg);
+ void sendPresencePacket(in PresenceAdapter presence);
+
}
--- a/src/com/beem/project/beem/ui/AddContact.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/ui/AddContact.java Thu Apr 23 20:25:17 2009 +0200
@@ -43,7 +43,7 @@
}
private OnClickListener mOkListener = new OnClickListener() {
-
+
@Override
public void onClick(View v) {
boolean valid = true;
--- a/src/com/beem/project/beem/ui/Subscription.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/ui/Subscription.java Thu Apr 23 20:25:17 2009 +0200
@@ -3,21 +3,73 @@
*/
package com.beem.project.beem.ui;
+import org.jivesoftware.smack.packet.Presence;
+import org.jivesoftware.smack.packet.Presence.Type;
+
+import com.beem.project.beem.BeemApplication;
import com.beem.project.beem.R;
+import com.beem.project.beem.service.PresenceAdapter;
+import com.beem.project.beem.service.aidl.IXmppFacade;
+import com.beem.project.beem.utils.PresenceType;
import android.app.Activity;
import android.os.Bundle;
-import android.widget.Button;
+import android.os.Parcelable;
+import android.os.RemoteException;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.Toast;
/**
* @author nikita
*
*/
public class Subscription extends Activity {
+
+ private IXmppFacade mService;
+ private String mContact;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.subscription);
- //mOk = (Button) findViewById(R.id.SubscriptionAccept);
+ findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
+ findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
+ mContact = getIntent().getStringExtra("from");
+ mService = BeemApplication.getApplication(this).getXmppFacade();
}
+
+ private OnClickListener mClickListener = new OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ switch (v.getId()) {
+ case R.id.SubscriptionAccept:
+ Presence presence = new Presence(Type.subscribed);
+ presence.setTo(mContact);
+ PresenceAdapter preAdapt = new PresenceAdapter(presence);
+ try {
+ mService.sendPresencePacket(preAdapt);
+ Toast.makeText(Subscription.this, "Subscription accept",
+ Toast.LENGTH_SHORT).show();
+ finish();
+ } catch (RemoteException e) {
+ Toast.makeText(Subscription.this, "Subscription error",
+ Toast.LENGTH_SHORT).show();
+ e.printStackTrace();
+ }
+ break ;
+ case R.id.SubscriptionRefuse:
+ Toast.makeText(Subscription.this, "Subscription refused",
+ Toast.LENGTH_SHORT).show();
+
+ break ;
+ default:
+ Toast.makeText(Subscription.this, "Subscription error",
+ Toast.LENGTH_SHORT).show();
+ };
+
+ }
+
+ };
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/utils/PresenceType.java Thu Apr 23 20:25:17 2009 +0200
@@ -0,0 +1,117 @@
+/**
+ *
+ */
+package com.beem.project.beem.utils;
+
+import org.jivesoftware.smack.packet.Presence;
+
+/**
+ * @author nikita
+ *
+ */
+public class PresenceType {
+
+ /**
+ * The user is available to receive messages (default).
+ */
+ public static final int AVAILABLE = 100;
+
+ /**
+ * The user is unavailable to receive messages.
+ */
+ public static final int UNAVAILABLE = 200;
+
+ /**
+ * Request subscription to recipient's presence.
+ */
+
+ public static final int SUBSCRIBE = 300;
+
+ /**
+ * Grant subscription to sender's presence.
+ */
+ public static final int SUBSCRIBED = 400;
+
+ /**
+ * Request removal of subscription to sender's presence.
+ */
+ public static final int UNSUBSCRIBE = 500;
+
+ /**
+ * Grant removal of subscription to sender's presence.
+ */
+ public static final int UNSUBSCRIBED = 600;
+
+ /**
+ * The presence packet contains an error message.
+ */
+ public static final int ERROR = 701;
+
+ /**
+ * Get the presence type from a presence packet.
+ * @param presence the presence type
+ */
+ public static int getPresenceType(Presence presence) {
+ int res = PresenceType.ERROR;
+ switch (presence.getType()) {
+ case available:
+ res = PresenceType.AVAILABLE;
+ break;
+ case unavailable:
+ res = PresenceType.UNAVAILABLE;
+ break;
+ case subscribe:
+ res = PresenceType.SUBSCRIBE;
+ break;
+ case subscribed:
+ res = PresenceType.SUBSCRIBED;
+ break;
+ case unsubscribe:
+ res = PresenceType.UNSUBSCRIBE;
+ break;
+ case unsubscribed:
+ res = PresenceType.UNSUBSCRIBED;
+ break;
+ case error:
+ default:
+ res = PresenceType.ERROR;
+ };
+ return res;
+ }
+
+ /**
+ * Get the smack presence mode for a status
+ * @param status the status in beem
+ * @return the presence mode to use in presence packet
+ * or null if there is no mode to use
+ */
+ public static Presence.Type getPresenceTypeFrom(int type){
+ Presence.Type res;
+ switch (type) {
+ case AVAILABLE:
+ res = Presence.Type.available;
+ break;
+ case UNAVAILABLE:
+ res = Presence.Type.unavailable;
+ break;
+ case SUBSCRIBE:
+ res = Presence.Type.subscribe;
+ break;
+ case SUBSCRIBED:
+ res = Presence.Type.subscribed;
+ break;
+ case UNSUBSCRIBE:
+ res = Presence.Type.unsubscribe;
+ break;
+ case UNSUBSCRIBED:
+ res = Presence.Type.unsubscribed;
+ break;
+ case ERROR:
+ res = Presence.Type.error;
+ break;
+ default:
+ return null;
+ }
+ return res;
+ }
+}
--- a/src/com/beem/project/beem/utils/Status.java Thu Apr 23 15:37:24 2009 +0200
+++ b/src/com/beem/project/beem/utils/Status.java Thu Apr 23 20:25:17 2009 +0200
@@ -7,7 +7,7 @@
import org.jivesoftware.smack.packet.Presence.Mode;
/**
- * @author darisk
+ * @author caribou
*/
public class Status {