Ajout d´un status par default quelque soit l´activité.
--- a/res/layout/contactlistcontact.xml Wed Nov 11 17:58:26 2009 +0100
+++ b/res/layout/contactlistcontact.xml Wed Nov 11 19:21:44 2009 +0100
@@ -4,12 +4,9 @@
android:layout_height="wrap_content" android:paddingLeft="10px"
android:paddingRight="10px" android:paddingTop="4px"
android:paddingBottom="4px" android:gravity="center_vertical">
-
<ImageView android:id="@+id/contactliststatus"
- android:adjustViewBounds="true" android:maxWidth="15dip"
- android:maxHeight="12px" android:layout_width="wrap_content"
+ android:adjustViewBounds="true" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:gravity="center_vertical" />
-
<LinearLayout android:orientation="vertical"
android:layout_weight="1" android:layout_width="fill_parent"
android:layout_height="wrap_content">
@@ -22,7 +19,7 @@
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:paddingLeft="16px" android:singleLine="true"
android:maxLines="1" android:linksClickable="false" android:autoLink="all"
- android:scrollHorizontally="true" android:textColor="@color/white"
+ android:scrollHorizontally="true"
android:textColorLink="@color/white" android:textSize="12px" />
</LinearLayout>
</LinearLayout>
--- a/src/com/beem/project/beem/BeemService.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/BeemService.java Wed Nov 11 19:21:44 2009 +0100
@@ -26,180 +26,188 @@
import com.beem.project.beem.service.aidl.IXmppFacade;
/**
- * This class is for the Beem service. The connection to the xmpp server will be made asynchronously when the service
- * will start.
+ * This class is for the Beem service. The connection to the xmpp server will be
+ * made asynchronously when the service will start.
+ *
* @author darisk
*/
public class BeemService extends Service {
- /**
- * The id to use for status notification.
- */
- public static final int NOTIFICATION_STATUS_ID = 100;
- private static final int DEFAULT_XMPP_PORT = 5222;
-
- private NotificationManager mNotificationManager;
- private XmppConnectionAdapter mConnection;
- private JingleService mJingle;
- private SharedPreferences mSettings;
- private String mLogin;
- private String mPassword;
- private String mHost;
- private String mService;
- private int mPort;
- private ConnectionConfiguration mConnectionConfiguration;
- private ProxyInfo mProxyInfo;
- private boolean mUseProxy;
- private IXmppFacade.Stub mBind;
+ /**
+ * The id to use for status notification.
+ */
+ public static final int NOTIFICATION_STATUS_ID = 100;
+ private static final int DEFAULT_XMPP_PORT = 5222;
- /**
- * Constructor.
- */
- public BeemService() {
- }
+ private NotificationManager mNotificationManager;
+ private XmppConnectionAdapter mConnection;
+ private JingleService mJingle;
+ private SharedPreferences mSettings;
+ private String mLogin;
+ private String mPassword;
+ private String mHost;
+ private String mService;
+ private int mPort;
+ private ConnectionConfiguration mConnectionConfiguration;
+ private ProxyInfo mProxyInfo;
+ private boolean mUseProxy;
+ private IXmppFacade.Stub mBind;
- /**
- * Initialise la configuration de la connexion.
- */
- private void initConnectionConfig() {
- java.security.Security.addProvider(new com.sun.security.sasl.Provider());
- mUseProxy = mSettings.getBoolean("settings_key_proxy_use", false);
- if (mUseProxy) {
- String stype = mSettings.getString("settings_key_proxy_type", "HTTP");
- String phost = mSettings.getString("settings_key_proxy_server", "");
- String puser = mSettings.getString("settings_key_proxy_username", "");
- String ppass = mSettings.getString("settings_key_proxy_password", "");
- int pport = Integer.parseInt(mSettings.getString("settings_key_proxy_port", "1080"));
- ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
- mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
- if (mService != null)
- mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService, mProxyInfo);
- else
- mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mProxyInfo);
- } else {
- if (mService != null)
- mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService);
- else
- mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort);
+ /**
+ * Constructor.
+ */
+ public BeemService() {
}
- if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)
- || mSettings.getBoolean("settings_key_gmail", false)) {
- mConnectionConfiguration.setSecurityMode(SecurityMode.required);
- }
- mConnectionConfiguration.setDebuggerEnabled(false);
- mConnectionConfiguration.setSendPresence(true);
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public IBinder onBind(Intent intent) {
- Log.d("BEEMSERVICE", "ONBIND()");
- return mBind;
- }
-
- @Override
- public boolean onUnbind(Intent intent) {
- Log.d("BEEMSERVICE", "ONUNBIND()");
- if (!mConnection.getAdaptee().isConnected()) {
- Log.d("BEEMSERVICE","DESTROYED");
- this.stopSelf();
+ /**
+ * Initialise la configuration de la connexion.
+ */
+ private void initConnectionConfig() {
+ java.security.Security.addProvider(new com.sun.security.sasl.Provider());
+ mUseProxy = mSettings.getBoolean("settings_key_proxy_use", false);
+ if (mUseProxy) {
+ String stype = mSettings.getString("settings_key_proxy_type", "HTTP");
+ String phost = mSettings.getString("settings_key_proxy_server", "");
+ String puser = mSettings.getString("settings_key_proxy_username", "");
+ String ppass = mSettings.getString("settings_key_proxy_password", "");
+ int pport = Integer.parseInt(mSettings.getString("settings_key_proxy_port", "1080"));
+ ProxyInfo.ProxyType type = ProxyType.valueOf(stype);
+ mProxyInfo = new ProxyInfo(type, phost, pport, puser, ppass);
+ if (mService != null)
+ mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService, mProxyInfo);
+ else
+ mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mProxyInfo);
+ } else {
+ if (mService != null)
+ mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort, mService);
+ else
+ mConnectionConfiguration = new ConnectionConfiguration(mHost, mPort);
+ }
+ if (mSettings.getBoolean("settings_key_xmpp_tls_use", false)
+ || mSettings.getBoolean("settings_key_gmail", false)) {
+ mConnectionConfiguration.setSecurityMode(SecurityMode.required);
+ }
+ mConnectionConfiguration.setDebuggerEnabled(false);
+ mConnectionConfiguration.setSendPresence(true);
}
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onCreate() {
- super.onCreate();
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
- String tmpJid = mSettings.getString("settings_key_account_username", "");
- mLogin = StringUtils.parseName(tmpJid);
- mPassword = mSettings.getString("settings_key_account_password", "");
- mPort = DEFAULT_XMPP_PORT;
- mService = StringUtils.parseServer(tmpJid);
- mHost = StringUtils.parseServer(tmpJid);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IBinder onBind(Intent intent) {
+ Log.d("BEEMSERVICE", "ONBIND()");
+ return mBind;
+ }
- if (mSettings.getBoolean("settings_key_specific_server", false)) {
- mHost = mSettings.getString("settings_key_xmpp_server", "");
- mPort = Integer.parseInt(mSettings.getString("settings_key_xmpp_port", "5222"));
- }
- if (mSettings.getBoolean("settings_key_gmail", false)) {
- mHost = "talk.google.com";
- mLogin = tmpJid;
+ @Override
+ public boolean onUnbind(Intent intent) {
+ Log.d("BEEMSERVICE", "ONUNBIND()");
+ if (!mConnection.getAdaptee().isConnected()) {
+ Log.d("BEEMSERVICE", "DESTROYED");
+ this.stopSelf();
+ }
+ return true;
}
- initConnectionConfig();
- mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
- mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreate() {
- Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
- mJingle = new JingleService(mConnection.getAdaptee());
- mBind = new XmppFacade(mConnection, this, mJingle);
- Log.d("BEEEMSERVICE", "ONCREATE");
- }
+ super.onCreate();
+ mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+ String tmpJid = mSettings.getString("settings_key_account_username", "");
+ mLogin = StringUtils.parseName(tmpJid);
+ mPassword = mSettings.getString("settings_key_account_password", "");
+ mPort = DEFAULT_XMPP_PORT;
+ mService = StringUtils.parseServer(tmpJid);
+ mHost = StringUtils.parseServer(tmpJid);
- /**
- * {@inheritDoc}
- */
- @Override
- public void onDestroy() {
- super.onDestroy();
- mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
- if (mConnection.isAuthentificated())
- mConnection.disconnect();
- Log.d("BEEEMSERVICE", "ONDESTROY");
- }
+ if (mSettings.getBoolean("settings_key_specific_server", false)) {
+ mHost = mSettings.getString("settings_key_xmpp_server", "");
+ mPort = Integer.parseInt(mSettings.getString("settings_key_xmpp_port", "5222"));
+ }
+ if (mSettings.getBoolean("settings_key_gmail", false)) {
+ mHost = "talk.google.com";
+ mLogin = tmpJid;
+ }
+
+ initConnectionConfig();
+ mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
+ mConnection = new XmppConnectionAdapter(mConnectionConfiguration, mLogin, mPassword, this);
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStart(Intent intent, int startId) {
- super.onStart(intent, startId);
- Log.d("BEEMSERVICE","onStart");
- try {
- mConnection.connectAsync();
- } catch (RemoteException e) {
- e.printStackTrace();
+ Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
+ mJingle = new JingleService(mConnection.getAdaptee());
+ mBind = new XmppFacade(mConnection, this, mJingle);
+ Log.d("BEEEMSERVICE", "ONCREATE");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
+ if (mConnection.isAuthentificated())
+ mConnection.disconnect();
+ Log.d("BEEEMSERVICE", "ONDESTROY");
}
- }
- /**
- * Show a notification.
- * @param id the id of the notification.
- * @param notif the notification to show
- */
- public void sendNotification(int id, Notification notif) {
- mNotificationManager.notify(id, notif);
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStart(Intent intent, int startId) {
+ super.onStart(intent, startId);
+ Log.d("BEEMSERVICE", "onStart");
+ try {
+ mConnection.connectAsync();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Show a notification.
+ *
+ * @param id
+ * the id of the notification.
+ * @param notif
+ * the notification to show
+ */
+ public void sendNotification(int id, Notification notif) {
+ mNotificationManager.notify(id, notif);
+ }
- /**
- * Delete a notification.
- * @param id the id of the notification
- */
- public void deleteNotification(int id) {
- mNotificationManager.cancel(id);
- }
+ /**
+ * Delete a notification.
+ *
+ * @param id
+ * the id of the notification
+ */
+ public void deleteNotification(int id) {
+ mNotificationManager.cancel(id);
+ }
- /**
- * Reset the status to online after a deconnection.
- */
- public void resetStatus() {
- Editor edit = mSettings.edit();
- edit.putInt(getString(R.string.PreferenceStatus), 1);
- edit.commit();
- }
+ /**
+ * Reset the status to online after a deconnection.
+ */
+ public void resetStatus() {
+ Editor edit = mSettings.edit();
+ edit.putInt(getString(R.string.PreferenceStatus), 1);
+ edit.commit();
+ }
- /**
- * init jingle from XmppConnectionAdapter.
- * @param adaptee XmppConntection used for jingle.
- */
- public void initJingle(XMPPConnection adaptee) {
- mJingle.initWhenConntected(adaptee);
- }
+ /**
+ * init jingle from XmppConnectionAdapter.
+ *
+ * @param adaptee
+ * XmppConntection used for jingle.
+ */
+ public void initJingle(XMPPConnection adaptee) {
+ mJingle.initWhenConntected(adaptee);
+ }
}
--- a/src/com/beem/project/beem/jingle/JingleService.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/JingleService.java Wed Nov 11 19:21:44 2009 +0100
@@ -22,209 +22,221 @@
/**
* Beem Jingle Service, manage jingle call.
+ *
* @author nikita
*/
public class JingleService {
- private static final String TAG = "JingleService";
- private JingleManager mJingleManager;
- private final List<JingleMediaManager> mMediaManagers;
- private JingleSession mIn;
- private JingleSession mOut;
-
- /**
- * JingleService constructor.
- * @param xmppConnection a valid XMPPConnection
- */
- public JingleService(final XMPPConnection xmppConnection) {
- BasicTransportManager bt = new BasicTransportManager();
- // JingleTransportManager tm = new ICETransportManager();
-
- mMediaManagers = new ArrayList<JingleMediaManager>();
- mMediaManagers.add(new MicrophoneRTPManager(bt));
- }
-
- /**
- * finish to construct the instance.
- * @param conn the xmppConnection used with constructor
- */
- public void initWhenConntected(XMPPConnection conn) {
- mJingleManager = new JingleManager(conn, mMediaManagers);
- mJingleManager.addJingleSessionRequestListener(new BeemJingleSessionRequestListener());
- }
+ private static final String TAG = "JingleService";
+ private JingleManager mJingleManager;
+ private final List<JingleMediaManager> mMediaManagers;
+ private JingleSession mIn;
+ private JingleSession mOut;
- /**
- * begin a jingle call.
- * @param receiver the call receiver
- */
- public void call(final String receiver) {
- try {
- mOut = mJingleManager.createOutgoingJingleSession(receiver);
- // TODO configure out avec addMediaSession et addNegociator
- mOut.addListener(new BeemJingleCallerSessionListener());
- mOut.startOutgoing();
- } catch (XMPPException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ /**
+ * JingleService constructor.
+ *
+ * @param xmppConnection
+ * a valid XMPPConnection
+ */
+ public JingleService(final XMPPConnection xmppConnection) {
+ BasicTransportManager bt = new BasicTransportManager();
+ // JingleTransportManager tm = new ICETransportManager();
+
+ mMediaManagers = new ArrayList<JingleMediaManager>();
+ mMediaManagers.add(new MicrophoneRTPManager(bt));
}
- }
-
- /*
- * private void receiveData(String ip, int port) throws IOException { Socket s = null; try { s = new Socket(ip,
- * port); System.out.println("Waiting data"); InputStream in = s.getInputStream(); int a; while ((a = in.read()) !=
- * -1) { System.out.println("Received " + a); } System.out.println("End receiving data"); } finally { if (s != null)
- * s.close(); } }
- */
- /**
- * Listen on receiver session events.
- * @author nikita
- */
- private class BeemJingleReceiverSessionListener implements JingleSessionListener {
/**
- * constructor.
+ * finish to construct the instance.
+ *
+ * @param conn
+ * the xmppConnection used with constructor
*/
- public BeemJingleReceiverSessionListener() {
- super();
- // TODO Auto-generated constructor stub
- }
-
- @Override
- public void sessionClosed(String reason, JingleSession jingleSession) {
- // System.out.println("Session " + jingleSession.getResponder() +
- // "closedd because " + reason);
- }
-
- @Override
- public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
- // TODO Auto-generated method stub
- // System.out.println("Session " + jingleSession.getResponder() +
- // " closed");
-
+ public void initWhenConntected(XMPPConnection conn) {
+ mJingleManager = new JingleManager(conn, mMediaManagers);
+ mJingleManager.addJingleSessionRequestListener(new BeemJingleSessionRequestListener());
}
- @Override
- public void sessionDeclined(String reason, JingleSession jingleSession) {
- Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
- }
-
- @Override
- public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate,
- TransportCandidate localCandidate, JingleSession jingleSession) {
- // System.out.println("Session established");
- // System.out.println("Je recois sur " + remoteCandidate.getIp() +
- // ":" + remoteCandidate.getPort());
- // TODO choose the right RTPReceiver depending on the payload type
- // RTPReceiver rtpReceiver = new
- // RTPReceiver(remoteCandidate.getPort());
- Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
- }
-
- @Override
- public void sessionMediaReceived(JingleSession jingleSession, String participant) {
- // System.out.println("Session Media received from " + participant);
+ /**
+ * begin a jingle call.
+ *
+ * @param receiver
+ * the call receiver
+ */
+ public void call(final String receiver) {
+ try {
+ mOut = mJingleManager.createOutgoingJingleSession(receiver);
+ // TODO configure out avec addMediaSession et addNegociator
+ mOut.addListener(new BeemJingleCallerSessionListener());
+ mOut.startOutgoing();
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- @Override
- public void sessionRedirected(String redirection, JingleSession jingleSession) {
- }
- }
-
- /**
- * Listen on caller session events.
- * @author nikita
- */
- private class BeemJingleCallerSessionListener implements JingleSessionListener {
-
- private static final int SLP_DURATION = 20000;
-
+ /*
+ * private void receiveData(String ip, int port) throws IOException { Socket
+ * s = null; try { s = new Socket(ip, port);
+ * System.out.println("Waiting data"); InputStream in = s.getInputStream();
+ * int a; while ((a = in.read()) != -1) { System.out.println("Received " +
+ * a); } System.out.println("End receiving data"); } finally { if (s !=
+ * null) s.close(); } }
+ */
/**
- * constructor.
+ * Listen on receiver session events.
+ *
+ * @author nikita
*/
- public BeemJingleCallerSessionListener() {
- super();
- // TODO Auto-generated constructor stub
- }
+ private class BeemJingleReceiverSessionListener implements JingleSessionListener {
+
+ /**
+ * constructor.
+ */
+ public BeemJingleReceiverSessionListener() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
- @Override
- public void sessionClosed(final String reason, final JingleSession jingleSession) {
- // System.out.println("Session " + jingleSession.getResponder() +
- // "closed because " + reason);
- }
+ @Override
+ public void sessionClosed(String reason, JingleSession jingleSession) {
+ // System.out.println("Session " + jingleSession.getResponder() +
+ // "closedd because " + reason);
+ }
+
+ @Override
+ public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ // System.out.println("Session " + jingleSession.getResponder() +
+ // " closed");
+
+ }
- @Override
- public void sessionClosedOnError(final XMPPException e, final JingleSession jingleSession) {
- // System.out.println("Session " + jingleSession.getResponder() +
- // " closed on error");
+ @Override
+ public void sessionDeclined(String reason, JingleSession jingleSession) {
+ Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
+ }
- }
+ @Override
+ public void sessionEstablished(PayloadType pt, TransportCandidate remoteCandidate,
+ TransportCandidate localCandidate, JingleSession jingleSession) {
+ // System.out.println("Session established");
+ // System.out.println("Je recois sur " + remoteCandidate.getIp() +
+ // ":" + remoteCandidate.getPort());
+ // TODO choose the right RTPReceiver depending on the payload type
+ // RTPReceiver rtpReceiver = new
+ // RTPReceiver(remoteCandidate.getPort());
+ Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
+ }
- @Override
- public void sessionDeclined(final String reason, final JingleSession jingleSession) {
- // System.out.println("Session " + jingleSession.getResponder() +
- // "declined because " + reason);
- Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
+ @Override
+ public void sessionMediaReceived(JingleSession jingleSession, String participant) {
+ // System.out.println("Session Media received from " + participant);
+ }
+
+ @Override
+ public void sessionRedirected(String redirection, JingleSession jingleSession) {
+ }
}
- @Override
- public void sessionEstablished(final PayloadType pt, final TransportCandidate remoteCandidate,
- final TransportCandidate localCandidate, final JingleSession jingleSession) {
- Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
- // String name = localCandidate.getName();
- String ip = localCandidate.getIp();
- int port = localCandidate.getPort();
- // System.out.println("Session established waiting connection on " +
- // ip + ":" + port);
+ /**
+ * Listen on caller session events.
+ *
+ * @author nikita
+ */
+ private class BeemJingleCallerSessionListener implements JingleSessionListener {
+
+ private static final int SLP_DURATION = 20000;
- RTPTransmitter transm = new PCMTransmitter(ip, port);
+ /**
+ * constructor.
+ */
+ public BeemJingleCallerSessionListener() {
+ super();
+ // TODO Auto-generated constructor stub
+ }
+
+ @Override
+ public void sessionClosed(final String reason, final JingleSession jingleSession) {
+ // System.out.println("Session " + jingleSession.getResponder() +
+ // "closed because " + reason);
+ }
+
+ @Override
+ public void sessionClosedOnError(final XMPPException e, final JingleSession jingleSession) {
+ // System.out.println("Session " + jingleSession.getResponder() +
+ // " closed on error");
+
+ }
- transm.run();
- try {
- Thread.sleep(SLP_DURATION);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- transm.stop();
- // System.out.println("End of transfer");
+ @Override
+ public void sessionDeclined(final String reason, final JingleSession jingleSession) {
+ // System.out.println("Session " + jingleSession.getResponder() +
+ // "declined because " + reason);
+ Log.d(TAG, "Session " + jingleSession.getResponder() + "declined because " + reason);
+ }
+
+ @Override
+ public void sessionEstablished(final PayloadType pt, final TransportCandidate remoteCandidate,
+ final TransportCandidate localCandidate, final JingleSession jingleSession) {
+ Log.d(TAG, "Session " + jingleSession.getResponder() + "established");
+ // String name = localCandidate.getName();
+ String ip = localCandidate.getIp();
+ int port = localCandidate.getPort();
+ // System.out.println("Session established waiting connection on " +
+ // ip + ":" + port);
+
+ RTPTransmitter transm = new PCMTransmitter(ip, port);
- }
+ transm.run();
+ try {
+ Thread.sleep(SLP_DURATION);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ transm.stop();
+ // System.out.println("End of transfer");
- @Override
- public void sessionMediaReceived(final JingleSession jingleSession, final String participant) {
- // TODO Auto-generated method stub
- System.out.println("Session Media received from " + participant);
+ }
+
+ @Override
+ public void sessionMediaReceived(final JingleSession jingleSession, final String participant) {
+ // TODO Auto-generated method stub
+ System.out.println("Session Media received from " + participant);
+ }
+
+ @Override
+ public void sessionRedirected(final String redirection, final JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ }
}
- @Override
- public void sessionRedirected(final String redirection, final JingleSession jingleSession) {
- // TODO Auto-generated method stub
- }
- }
+ /**
+ * Listen for a Jingle session request.
+ *
+ * @author nikita
+ */
+ private class BeemJingleSessionRequestListener implements JingleSessionRequestListener {
- /**
- * Listen for a Jingle session request.
- * @author nikita
- */
- private class BeemJingleSessionRequestListener implements JingleSessionRequestListener {
+ /**
+ * Constructor.
+ */
+ public BeemJingleSessionRequestListener() {
+ super();
+ }
- /**
- * Constructor.
- */
- public BeemJingleSessionRequestListener() {
- super();
+ @Override
+ public void sessionRequested(JingleSessionRequest request) {
+ System.out.println("Jingle Session request from " + request.getFrom());
+ try {
+ mIn = request.accept();
+ mIn.addListener(new BeemJingleReceiverSessionListener());
+ mIn.startIncoming();
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ }
+ }
}
- @Override
- public void sessionRequested(JingleSessionRequest request) {
- System.out.println("Jingle Session request from " + request.getFrom());
- try {
- mIn = request.accept();
- mIn.addListener(new BeemJingleReceiverSessionListener());
- mIn.startIncoming();
- } catch (XMPPException e) {
- e.printStackTrace();
- }
- }
- }
-
}
--- a/src/com/beem/project/beem/jingle/MicrophoneRTPManager.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/MicrophoneRTPManager.java Wed Nov 11 19:21:44 2009 +0100
@@ -12,50 +12,53 @@
/**
* RTPMediaManager, gere les payloads et renvoie une session RTP.
+ *
* @author nikita
*/
public class MicrophoneRTPManager extends JingleMediaManager {
- /**
- * RTP media name.
- */
- public static final String MEDIA_NAME = "Microphone";
+ /**
+ * RTP media name.
+ */
+ public static final String MEDIA_NAME = "Microphone";
- private List<PayloadType> mPayloads;
+ private List<PayloadType> mPayloads;
- /**
- * Manage Microphone data transmission trough RTP.
- * @param transportManager current jingle transport manager(basic,upnp,ice...).
- */
- public MicrophoneRTPManager(final JingleTransportManager transportManager) {
- super(transportManager);
- // TODO Auto-generated constructor stub
- setupPayloads();
- }
+ /**
+ * Manage Microphone data transmission trough RTP.
+ *
+ * @param transportManager
+ * current jingle transport manager(basic,upnp,ice...).
+ */
+ public MicrophoneRTPManager(final JingleTransportManager transportManager) {
+ super(transportManager);
+ // TODO Auto-generated constructor stub
+ setupPayloads();
+ }
- @Override
- public JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
- TransportCandidate local, JingleSession jingleSession) {
- // TODO Auto-generated method stub
- return new MicrophoneRTPSession(payloadType, remote, local, null, jingleSession);
- }
+ @Override
+ public JingleMediaSession createMediaSession(PayloadType payloadType, TransportCandidate remote,
+ TransportCandidate local, JingleSession jingleSession) {
+ // TODO Auto-generated method stub
+ return new MicrophoneRTPSession(payloadType, remote, local, null, jingleSession);
+ }
- @Override
- public String getName() {
- return MEDIA_NAME;
- }
+ @Override
+ public String getName() {
+ return MEDIA_NAME;
+ }
- @Override
- public List<PayloadType> getPayloads() {
- // TODO Auto-generated method stub
- return mPayloads;
- }
+ @Override
+ public List<PayloadType> getPayloads() {
+ // TODO Auto-generated method stub
+ return mPayloads;
+ }
- /**
- * Supported payload list.
- */
- private void setupPayloads() {
- mPayloads = new ArrayList<PayloadType>();
- mPayloads.add(new PayloadType.Audio(0, "PCMU"));
- mPayloads.add(new PayloadType.Audio(8, "PCMA"));
- }
+ /**
+ * Supported payload list.
+ */
+ private void setupPayloads() {
+ mPayloads = new ArrayList<PayloadType>();
+ mPayloads.add(new PayloadType.Audio(0, "PCMU"));
+ mPayloads.add(new PayloadType.Audio(8, "PCMA"));
+ }
}
--- a/src/com/beem/project/beem/jingle/MicrophoneRTPSession.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/MicrophoneRTPSession.java Wed Nov 11 19:21:44 2009 +0100
@@ -7,62 +7,69 @@
/**
* Manage microphone RTP session.
+ *
* @author nikita
*/
public class MicrophoneRTPSession extends JingleMediaSession {
- private RTPTransmitter mTransmitter;
- private RTPReceiver mReceiver;
+ private RTPTransmitter mTransmitter;
+ private RTPReceiver mReceiver;
- /**
- * constructor.
- * @param payloadType the payload typ used
- * @param remote the remote transport info
- * @param local the local tranport info
- * @param mediaLocator don't know
- * @param jingleSession the current jingle session
- */
- public MicrophoneRTPSession(final PayloadType payloadType, final TransportCandidate remote,
- final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession) {
- super(payloadType, remote, local, mediaLocator, jingleSession);
+ /**
+ * constructor.
+ *
+ * @param payloadType
+ * the payload typ used
+ * @param remote
+ * the remote transport info
+ * @param local
+ * the local tranport info
+ * @param mediaLocator
+ * don't know
+ * @param jingleSession
+ * the current jingle session
+ */
+ public MicrophoneRTPSession(final PayloadType payloadType, final TransportCandidate remote,
+ final TransportCandidate local, final String mediaLocator, final JingleSession jingleSession) {
+ super(payloadType, remote, local, mediaLocator, jingleSession);
- // TODO le transmitter ne devrait peut etre pas etre init ici, c'est
- // peut etre encore un peu tot, a voir.
- mTransmitter = new PCMTransmitter(remote.getIp(), getRemote().getPort());
- // mReceiver = new MicroRTPReceiver(getLocal().getPort());
- }
+ // TODO le transmitter ne devrait peut etre pas etre init ici, c'est
+ // peut etre encore un peu tot, a voir.
+ mTransmitter = new PCMTransmitter(remote.getIp(), getRemote().getPort());
+ // mReceiver = new MicroRTPReceiver(getLocal().getPort());
+ }
- @Override
- public void initialize() {
- // TODO Auto-generated method stub
-
- }
+ @Override
+ public void initialize() {
+ // TODO Auto-generated method stub
- @Override
- public void setTrasmit(boolean active) {
- }
+ }
- @Override
- public void startReceive() {
+ @Override
+ public void setTrasmit(boolean active) {
+ }
- }
+ @Override
+ public void startReceive() {
- @Override
- public void startTrasmit() {
+ }
- }
+ @Override
+ public void startTrasmit() {
- @Override
- public void stopReceive() {
- if (mReceiver != null) {
- mReceiver.stop();
}
- }
- @Override
- public void stopTrasmit() {
- if (mTransmitter != null) {
- mTransmitter.stop();
+ @Override
+ public void stopReceive() {
+ if (mReceiver != null) {
+ mReceiver.stop();
+ }
}
- }
+
+ @Override
+ public void stopTrasmit() {
+ if (mTransmitter != null) {
+ mTransmitter.stop();
+ }
+ }
}
--- a/src/com/beem/project/beem/jingle/PCMTransmitter.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/PCMTransmitter.java Wed Nov 11 19:21:44 2009 +0100
@@ -6,40 +6,44 @@
/**
* Transmit Microphone data through RTP.
+ *
* @author nikita
*/
public class PCMTransmitter extends RTPTransmitter {
- private static final int BUFF_SIZE = 1024;
- private static final int RATE_IN_HZ = 8000;
- private static final int SLP_DURATION = 200;
+ private static final int BUFF_SIZE = 1024;
+ private static final int RATE_IN_HZ = 8000;
+ private static final int SLP_DURATION = 200;
- /**
- * Constructor.
- * @param remoteIP receiver IP.
- * @param remotePort receiver port.
- */
- public PCMTransmitter(final String remoteIP, final int remotePort) {
- super(remoteIP, remotePort);
- }
+ /**
+ * Constructor.
+ *
+ * @param remoteIP
+ * receiver IP.
+ * @param remotePort
+ * receiver port.
+ */
+ public PCMTransmitter(final String remoteIP, final int remotePort) {
+ super(remoteIP, remotePort);
+ }
- @Override
- void start() {
- AudioRecord audRec = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, RATE_IN_HZ,
- AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(
- RATE_IN_HZ, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4);
- byte[] audioData = new byte[BUFF_SIZE];
- int byteReaded = 0;
- while (!isKillme()) {
- byteReaded = audRec.read(audioData, byteReaded, BUFF_SIZE);
- System.out.println("readed " + byteReaded);
- getRtpSession().sendData(audioData);
+ @Override
+ void start() {
+ AudioRecord audRec = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, RATE_IN_HZ,
+ AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, AudioRecord.getMinBufferSize(
+ RATE_IN_HZ, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4);
+ byte[] audioData = new byte[BUFF_SIZE];
+ int byteReaded = 0;
+ while (!isKillme()) {
+ byteReaded = audRec.read(audioData, byteReaded, BUFF_SIZE);
+ System.out.println("readed " + byteReaded);
+ getRtpSession().sendData(audioData);
+ }
+ try {
+ Thread.sleep(SLP_DURATION);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ this.getRtpSession().endSession();
}
- try {
- Thread.sleep(SLP_DURATION);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- this.getRtpSession().endSession();
- }
}
--- a/src/com/beem/project/beem/jingle/RTPReceiver.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/RTPReceiver.java Wed Nov 11 19:21:44 2009 +0100
@@ -9,72 +9,78 @@
/**
* abstract RTP receiver class.
+ *
* @author nikita
*/
public abstract class RTPReceiver implements Runnable, RTPAppIntf {
- private boolean mKillme;
- private RTPSession mRtpSession;
+ private boolean mKillme;
+ private RTPSession mRtpSession;
- /**
- * constructor.
- * @param rtpPort local or distant?.
- */
- public RTPReceiver(final int rtpPort) {
- DatagramSocket rtpSocket = null;
+ /**
+ * constructor.
+ *
+ * @param rtpPort
+ * local or distant?.
+ */
+ public RTPReceiver(final int rtpPort) {
+ DatagramSocket rtpSocket = null;
- try {
- rtpSocket = new DatagramSocket(rtpPort);
- } catch (SocketException e) {
- e.printStackTrace();
- return;
+ try {
+ rtpSocket = new DatagramSocket(rtpPort);
+ } catch (SocketException e) {
+ e.printStackTrace();
+ return;
+ }
+ mRtpSession = new RTPSession(rtpSocket, null);
+ mRtpSession.naivePktReception(true);
+ mRtpSession.RTPSessionRegister(this, null, null);
}
- mRtpSession = new RTPSession(rtpSocket, null);
- mRtpSession.naivePktReception(true);
- mRtpSession.RTPSessionRegister(this, null, null);
- }
+
+ @Override
+ public int frameSize(int payloadType) {
+ return 1;
+ }
- @Override
- public int frameSize(int payloadType) {
- return 1;
- }
-
- @Override
- public void run() {
- start();
- this.mRtpSession.endSession();
- }
+ @Override
+ public void run() {
+ start();
+ this.mRtpSession.endSession();
+ }
- /**
- * main reception loop.
- */
- protected abstract void start();
+ /**
+ * main reception loop.
+ */
+ protected abstract void start();
- /**
- * Stop the reception.
- */
- public void stop() {
- this.setKillme(true);
- }
+ /**
+ * Stop the reception.
+ */
+ public void stop() {
+ this.setKillme(true);
+ }
- @Override
- public void userEvent(int arg0, Participant[] arg1) {
- // TODO Auto-generated method stub
- }
+ @Override
+ public void userEvent(int arg0, Participant[] arg1) {
+ // TODO Auto-generated method stub
+ }
- /**
- * mKillme setter.
- * @param killme the mKillme to set
- */
- public void setKillme(final boolean killme) {
- this.mKillme = killme;
- }
+ /**
+ * mKillme setter.
+ *
+ * @param killme
+ * the mKillme to set
+ */
+ public void setKillme(final boolean killme) {
+ this.mKillme = killme;
+ }
- /**
- * mKillme getter.
- * @return the mKillme
- */
- public boolean isKillme() {
- return mKillme;
- }
+ /**
+ * mKillme getter.
+ *
+ * @return the mKillme
+ */
+ public boolean isKillme() {
+ return mKillme;
+ }
}
--- a/src/com/beem/project/beem/jingle/RTPTransmitter.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/RTPTransmitter.java Wed Nov 11 19:21:44 2009 +0100
@@ -12,103 +12,113 @@
/**
* abstract RTP transmitter class.
+ *
* @author nikita
*/
public abstract class RTPTransmitter implements Runnable, RTPAppIntf {
- /**
- * RTPSession instance.
- */
- private RTPSession mRtpSession;
- /**
- * process status manipulation.
- */
- private boolean mKillme;
+ /**
+ * RTPSession instance.
+ */
+ private RTPSession mRtpSession;
+ /**
+ * process status manipulation.
+ */
+ private boolean mKillme;
- /**
- * constructor.
- * @param remoteIP receiver IP.
- * @param remotePort receiver port.
- */
- public RTPTransmitter(final String remoteIP, final int remotePort) {
- DatagramSocket rtpSocket = null;
- int rtpPort = 0;
+ /**
+ * constructor.
+ *
+ * @param remoteIP
+ * receiver IP.
+ * @param remotePort
+ * receiver port.
+ */
+ public RTPTransmitter(final String remoteIP, final int remotePort) {
+ DatagramSocket rtpSocket = null;
+ int rtpPort = 0;
- try {
- rtpPort = FreePort.getFreePort();
- rtpSocket = new DatagramSocket(rtpPort);
- } catch (SocketException e) {
- e.printStackTrace();
- return;
+ try {
+ rtpPort = FreePort.getFreePort();
+ rtpSocket = new DatagramSocket(rtpPort);
+ } catch (SocketException e) {
+ e.printStackTrace();
+ return;
+ }
+ setRtpSession(new RTPSession(rtpSocket, null));
+ getRtpSession().naivePktReception(true);
+ getRtpSession().RTPSessionRegister(this, null, null);
+ getRtpSession().addParticipant(new Participant(remoteIP, remotePort, 0));
}
- setRtpSession(new RTPSession(rtpSocket, null));
- getRtpSession().naivePktReception(true);
- getRtpSession().RTPSessionRegister(this, null, null);
- getRtpSession().addParticipant(new Participant(remoteIP, remotePort, 0));
- }
- @Override
- public int frameSize(int payloadType) {
- return 1;
- }
+ @Override
+ public int frameSize(int payloadType) {
+ return 1;
+ }
- @Override
- public void receiveData(DataFrame frame, Participant participant) {
- // On envoie uniquement
- }
+ @Override
+ public void receiveData(DataFrame frame, Participant participant) {
+ // On envoie uniquement
+ }
- @Override
- public void run() {
- start();
- }
+ @Override
+ public void run() {
+ start();
+ }
- /**
- * A implementer pour chaque type d'envoi specifique.
- */
- abstract void start();
+ /**
+ * A implementer pour chaque type d'envoi specifique.
+ */
+ abstract void start();
+
+ /**
+ * Stop the transmission.
+ */
+ public void stop() {
+ mKillme = true;
+ }
- /**
- * Stop the transmission.
- */
- public void stop() {
- mKillme = true;
- }
+ @Override
+ public void userEvent(int type, Participant[] participant) {
+ // je sais pas ce que c'est
+
+ }
- @Override
- public void userEvent(int type, Participant[] participant) {
- // je sais pas ce que c'est
-
- }
+ /**
+ * mKillme setter.
+ *
+ * @param killme
+ * the mKillme to set
+ */
+ public void setKillme(final boolean killme) {
+ this.mKillme = killme;
+ }
- /**
- * mKillme setter.
- * @param killme the mKillme to set
- */
- public void setKillme(final boolean killme) {
- this.mKillme = killme;
- }
-
- /**
- * mKillme getter.
- * @return the mKillme.
- */
- public boolean isKillme() {
- return mKillme;
- }
+ /**
+ * mKillme getter.
+ *
+ * @return the mKillme.
+ */
+ public boolean isKillme() {
+ return mKillme;
+ }
- /**
- * mRtpSession setter.
- * @param rtpSession the mRtpSession to set.
- */
- public void setRtpSession(RTPSession rtpSession) {
- this.mRtpSession = rtpSession;
- }
+ /**
+ * mRtpSession setter.
+ *
+ * @param rtpSession
+ * the mRtpSession to set.
+ */
+ public void setRtpSession(RTPSession rtpSession) {
+ this.mRtpSession = rtpSession;
+ }
- /**
- * mRtpSession getter.
- * @return the mRtpSession
- */
- public RTPSession getRtpSession() {
- return mRtpSession;
- }
+ /**
+ * mRtpSession getter.
+ *
+ * @return the mRtpSession
+ */
+ public RTPSession getRtpSession() {
+ return mRtpSession;
+ }
}
--- a/src/com/beem/project/beem/jingle/demo/JingleCallActivity.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/jingle/demo/JingleCallActivity.java Wed Nov 11 19:21:44 2009 +0100
@@ -19,81 +19,83 @@
/**
* Activity used to test Jingle call.
+ *
* @author darisk
*/
public class JingleCallActivity extends Activity {
- private static final int SLP_DURATION = 3000;
- private static final int DEFAULT_XMPP_PORT = 5222;
+ private static final int SLP_DURATION = 3000;
+ private static final int DEFAULT_XMPP_PORT = 5222;
- private XMPPConnection mConnection;
- private ConnectionConfiguration mConf;
- private JingleService mJingle;
+ private XMPPConnection mConnection;
+ private ConnectionConfiguration mConf;
+ private JingleService mJingle;
- private Button mBtconnect;
- private Button mBtcall;
- private EditText mEdJID;
- private EditText mEdPassword;
- private EditText mEdReceiver;
+ private Button mBtconnect;
+ private Button mBtcall;
+ private EditText mEdJID;
+ private EditText mEdPassword;
+ private EditText mEdReceiver;
- /**
- * Constructor.
- */
- public JingleCallActivity() {
- }
+ /**
+ * Constructor.
+ */
+ public JingleCallActivity() {
+ }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- java.security.Security.addProvider(new com.sun.security.sasl.Provider());
- super.onCreate(savedInstanceState);
- setContentView(R.layout.jingle_call_activity);
- mConf = new ConnectionConfiguration("10.0.2.2", 5222);
- //mConf = new ConnectionConfiguration("elyzion.net", DEFAULT_XMPP_PORT);
- mConf.setSecurityMode(SecurityMode.required);
- mEdJID = (EditText) findViewById(R.id.jingledemocalljid);
- mEdPassword = (EditText) findViewById(R.id.jingledemocallpassword);
- mEdReceiver = (EditText) findViewById(R.id.jingledemocallreceiver);
- mBtconnect = (Button) findViewById(R.id.jingledemocallconnectbutton);
- mBtconnect.setOnClickListener(new OnClickListener() {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ java.security.Security.addProvider(new com.sun.security.sasl.Provider());
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.jingle_call_activity);
+ mConf = new ConnectionConfiguration("10.0.2.2", 5222);
+ // mConf = new ConnectionConfiguration("elyzion.net",
+ // DEFAULT_XMPP_PORT);
+ mConf.setSecurityMode(SecurityMode.required);
+ mEdJID = (EditText) findViewById(R.id.jingledemocalljid);
+ mEdPassword = (EditText) findViewById(R.id.jingledemocallpassword);
+ mEdReceiver = (EditText) findViewById(R.id.jingledemocallreceiver);
+ mBtconnect = (Button) findViewById(R.id.jingledemocallconnectbutton);
+ mBtconnect.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- String jid = mEdJID.getText().toString();
- String login = StringUtils.parseName(jid);
- mConnection = new XMPPConnection(mConf);
- String password = mEdPassword.getText().toString();
- try {
- mConnection.connect();
- Thread.sleep(SLP_DURATION);
- mConnection.login(login, password);
- mJingle = new JingleService(mConnection);
- mJingle.initWhenConntected(mConnection);
- mBtcall.setEnabled(true);
- Toast.makeText(JingleCallActivity.this, "Connected", Toast.LENGTH_SHORT);
- } catch (XMPPException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ @Override
+ public void onClick(View arg0) {
+ String jid = mEdJID.getText().toString();
+ String login = StringUtils.parseName(jid);
+ mConnection = new XMPPConnection(mConf);
+ String password = mEdPassword.getText().toString();
+ try {
+ mConnection.connect();
+ Thread.sleep(SLP_DURATION);
+ mConnection.login(login, password);
+ mJingle = new JingleService(mConnection);
+ mJingle.initWhenConntected(mConnection);
+ mBtcall.setEnabled(true);
+ Toast.makeText(JingleCallActivity.this, "Connected", Toast.LENGTH_SHORT);
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
- });
- mBtcall = (Button) findViewById(R.id.jingledemocallbutton);
- mBtcall.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View arg0) {
- String jid = mEdReceiver.getText().toString();
- if (!"".equals(jid)) {
- mJingle.call(jid);
- Toast.makeText(JingleCallActivity.this, "Appel en cours", Toast.LENGTH_SHORT);
- } else
- Toast.makeText(JingleCallActivity.this, "Remplir le champ (JID complet en toto@tutu.com/truc)",
- Toast.LENGTH_SHORT);
- }
- });
+ });
+ mBtcall = (Button) findViewById(R.id.jingledemocallbutton);
+ mBtcall.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View arg0) {
+ String jid = mEdReceiver.getText().toString();
+ if (!"".equals(jid)) {
+ mJingle.call(jid);
+ Toast.makeText(JingleCallActivity.this, "Appel en cours", Toast.LENGTH_SHORT);
+ } else
+ Toast.makeText(JingleCallActivity.this, "Remplir le champ (JID complet en toto@tutu.com/truc)",
+ Toast.LENGTH_SHORT);
+ }
+ });
- }
+ }
}
--- a/src/com/beem/project/beem/provider/Beem.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/provider/Beem.java Wed Nov 11 19:21:44 2009 +0100
@@ -8,183 +8,186 @@
*/
public final class Beem {
- /**
- * Contacts table.
- */
- public static final class Contacts implements BaseColumns {
-
/**
- * The query used to create the table.
- */
- public static final String QUERY_CREATE = "CREATE TABLE " + Beem.CONTACTS_TABLE_NAME + " (" + BaseColumns._ID
- + " INTEGER PRIMARY KEY AUTOINCREMENT," + Contacts.UID + " INTEGER, " + Contacts.JID + " INTEGER,"
- + Contacts.NICKNAME + " TEXT," + Contacts.ALIAS + " TEXT," + Contacts.DATE_CREATED + " INTEGER,"
- + Contacts.DATE_MODIFIED + " INTEGER" + ");";
-
- /**
- * The content:// style URL for Contacts table.
+ * Contacts table.
*/
- public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/contacts");
+ public static final class Contacts implements BaseColumns {
- /**
- * The MIME type of {@link #CONTENT_URI} providing a directory of contacts.
- */
- public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.contact";
+ /**
+ * The query used to create the table.
+ */
+ public static final String QUERY_CREATE = "CREATE TABLE " + Beem.CONTACTS_TABLE_NAME + " (" + BaseColumns._ID
+ + " INTEGER PRIMARY KEY AUTOINCREMENT," + Contacts.UID + " INTEGER, " + Contacts.JID + " INTEGER,"
+ + Contacts.NICKNAME + " TEXT," + Contacts.ALIAS + " TEXT," + Contacts.DATE_CREATED + " INTEGER,"
+ + Contacts.DATE_MODIFIED + " INTEGER" + ");";
+
+ /**
+ * The content:// style URL for Contacts table.
+ */
+ public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/contacts");
- /**
- * The MIME type of a {@link #CONTENT_URI} sub-directory of a single contact.
- */
- public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.contact";
+ /**
+ * The MIME type of {@link #CONTENT_URI} providing a directory of
+ * contacts.
+ */
+ public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.contact";
+
+ /**
+ * The MIME type of a {@link #CONTENT_URI} sub-directory of a single
+ * contact.
+ */
+ public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.contact";
- /**
- * The default sort order for this table.
- */
- public static final String DEFAULT_SORT_ORDER = "nickname ASC";
+ /**
+ * The default sort order for this table.
+ */
+ public static final String DEFAULT_SORT_ORDER = "nickname ASC";
+
+ /**
+ * The user id having the contact
+ * <P>
+ * Type: INTEGER
+ * </P>
+ * .
+ */
+ public static final String UID = "uid";
- /**
- * The user id having the contact
- * <P>
- * Type: INTEGER
- * </P>
- * .
- */
- public static final String UID = "uid";
+ /**
+ * The JabberID of the contact
+ * <P>
+ * Type: INTEGER
+ * </P>
+ * .
+ */
+ public static final String JID = "jid";
- /**
- * The JabberID of the contact
- * <P>
- * Type: INTEGER
- * </P>
- * .
- */
- public static final String JID = "jid";
+ /**
+ * The nickname of the contact
+ * <P>
+ * Type: TEXT
+ * </P>
+ * .
+ */
+ public static final String NICKNAME = "nickname";
- /**
- * The nickname of the contact
- * <P>
- * Type: TEXT
- * </P>
- * .
- */
- public static final String NICKNAME = "nickname";
+ /**
+ * The alias of the contact
+ * <P>
+ * Type: TEXT
+ * </P>
+ * .
+ */
+ public static final String ALIAS = "alias";
- /**
- * The alias of the contact
- * <P>
- * Type: TEXT
- * </P>
- * .
- */
- public static final String ALIAS = "alias";
+ /**
+ * The timestamp for when the contact was created
+ * <P>
+ * Type: INTEGER (long from System.curentTimeMillis())
+ * </P>
+ * .
+ */
+ public static final String DATE_CREATED = "created";
- /**
- * The timestamp for when the contact was created
- * <P>
- * Type: INTEGER (long from System.curentTimeMillis())
- * </P>
- * .
- */
- public static final String DATE_CREATED = "created";
+ /**
+ * The timestamp for when the contact was last modified
+ * <P>
+ * Type: INTEGER (long from System.curentTimeMillis())
+ * </P>
+ * .
+ */
+ public static final String DATE_MODIFIED = "modified";
+
+ }
/**
- * The timestamp for when the contact was last modified
- * <P>
- * Type: INTEGER (long from System.curentTimeMillis())
- * </P>
- * .
- */
- public static final String DATE_MODIFIED = "modified";
-
- }
-
- /**
- * Users table.
- */
- public static final class Users implements BaseColumns {
-
- /**
- * The query used to create the table.
+ * Users table.
*/
- public static final String QUERY_CREATE = "CREATE TABLE " + Beem.USERS_TABLE_NAME + " (" + BaseColumns._ID
- + " INTEGER PRIMARY KEY AUTOINCREMENT," + Users.JUSERNAME + " TEXT," + Users.DATE_CREATED + " INTEGER,"
- + Users.DATE_MODIFIED + " INTEGER" + ");";
+ public static final class Users implements BaseColumns {
+
+ /**
+ * The query used to create the table.
+ */
+ public static final String QUERY_CREATE = "CREATE TABLE " + Beem.USERS_TABLE_NAME + " (" + BaseColumns._ID
+ + " INTEGER PRIMARY KEY AUTOINCREMENT," + Users.JUSERNAME + " TEXT," + Users.DATE_CREATED + " INTEGER,"
+ + Users.DATE_MODIFIED + " INTEGER" + ");";
- /**
- * The content:// style URL for Contacts table.
- */
- public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/users");
+ /**
+ * The content:// style URL for Contacts table.
+ */
+ public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/users");
+
+ /**
+ * The MIME type of {@link #CONTENT_URI} providing a directory of users.
+ */
+ public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.user";
+
+ /**
+ * The MIME type of a {@link #CONTENT_URI} sub-directory of a single
+ * user.
+ */
+ public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.user";
- /**
- * The MIME type of {@link #CONTENT_URI} providing a directory of users.
- */
- public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.beem.project.user";
+ /**
+ * The default sort order for this table.
+ */
+ public static final String DEFAULT_SORT_ORDER = "_id ASC";
+
+ /**
+ * The Jabber username of the user
+ * <P>
+ * Type: TEXT
+ * </P>
+ * .
+ */
+ public static final String JUSERNAME = "username";
- /**
- * The MIME type of a {@link #CONTENT_URI} sub-directory of a single user.
- */
- public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.beem.project.user";
+ /**
+ * The timestamp for when the user was created
+ * <P>
+ * Type: INTEGER (long from System.curentTimeMillis())
+ * </P>
+ * .
+ */
+ public static final String DATE_CREATED = "created";
- /**
- * The default sort order for this table.
- */
- public static final String DEFAULT_SORT_ORDER = "_id ASC";
+ /**
+ * The timestamp for when the user was last modified
+ * <P>
+ * Type: INTEGER (long from System.curentTimeMillis())
+ * </P>
+ * .
+ */
+ public static final String DATE_MODIFIED = "modified";
+ }
/**
- * The Jabber username of the user
- * <P>
- * Type: TEXT
- * </P>
- * .
+ * AUTHORITY.
*/
- public static final String JUSERNAME = "username";
+ public static final String AUTHORITY = "com.beem.project.provider";
/**
- * The timestamp for when the user was created
- * <P>
- * Type: INTEGER (long from System.curentTimeMillis())
- * </P>
- * .
+ * DB Name.
*/
- public static final String DATE_CREATED = "created";
+ public static final String DB_NAME = "beem.db";
+
+ /**
+ * DB Version.
+ */
+ public static final int DB_VERSION = 2;
/**
- * The timestamp for when the user was last modified
- * <P>
- * Type: INTEGER (long from System.curentTimeMillis())
- * </P>
- * .
+ * Name of the users table.
*/
- public static final String DATE_MODIFIED = "modified";
- }
-
- /**
- * AUTHORITY.
- */
- public static final String AUTHORITY = "com.beem.project.provider";
-
- /**
- * DB Name.
- */
- public static final String DB_NAME = "beem.db";
+ public static final String USERS_TABLE_NAME = "users";
- /**
- * DB Version.
- */
- public static final int DB_VERSION = 2;
-
- /**
- * Name of the users table.
- */
- public static final String USERS_TABLE_NAME = "users";
+ /**
+ * Name of the contacts table.
+ */
+ public static final String CONTACTS_TABLE_NAME = "contacts";
- /**
- * Name of the contacts table.
- */
- public static final String CONTACTS_TABLE_NAME = "contacts";
-
- /**
- * Constructor.
- */
- private Beem() {
- }
+ /**
+ * Constructor.
+ */
+ private Beem() {
+ }
}
--- a/src/com/beem/project/beem/provider/BeemDatabaseHelper.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/provider/BeemDatabaseHelper.java Wed Nov 11 19:21:44 2009 +0100
@@ -7,40 +7,46 @@
/**
* BeemDatabaseHelper class.
+ *
* @author Jamu
*/
public class BeemDatabaseHelper extends SQLiteOpenHelper {
- private final String mTag;
- private final String mTableName;
- private final String mCreationQuery;
-
- /**
- * BeemDatabaseHelper class.
- * @param context the context.
- * @param tag the tag.
- * @param tableName the tableName.
- * @param creationQuery the creation query.
- */
- public BeemDatabaseHelper(final Context context, final String tag, final String tableName,
- final String creationQuery) {
- super(context, Beem.DB_NAME, null, Beem.DB_VERSION);
+ private final String mTag;
+ private final String mTableName;
+ private final String mCreationQuery;
- this.mTag = tag;
- this.mTableName = tableName;
- this.mCreationQuery = creationQuery;
- }
+ /**
+ * BeemDatabaseHelper class.
+ *
+ * @param context
+ * the context.
+ * @param tag
+ * the tag.
+ * @param tableName
+ * the tableName.
+ * @param creationQuery
+ * the creation query.
+ */
+ public BeemDatabaseHelper(final Context context, final String tag, final String tableName,
+ final String creationQuery) {
+ super(context, Beem.DB_NAME, null, Beem.DB_VERSION);
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(this.mCreationQuery);
- }
+ this.mTag = tag;
+ this.mTableName = tableName;
+ this.mCreationQuery = creationQuery;
+ }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- Log.w(this.mTag, "Upgrading database from version " + oldVersion + " to " + newVersion
- + ", which will destroy all old data");
- db.execSQL("DROP TABLE IF EXISTS " + this.mTableName + ";");
- onCreate(db);
- }
+ @Override
+ public void onCreate(SQLiteDatabase db) {
+ db.execSQL(this.mCreationQuery);
+ }
+
+ @Override
+ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
+ Log.w(this.mTag, "Upgrading database from version " + oldVersion + " to " + newVersion
+ + ", which will destroy all old data");
+ db.execSQL("DROP TABLE IF EXISTS " + this.mTableName + ";");
+ onCreate(db);
+ }
}
--- a/src/com/beem/project/beem/provider/ContactProvider.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/provider/ContactProvider.java Wed Nov 11 19:21:44 2009 +0100
@@ -16,191 +16,192 @@
/**
* ContactProvider class.
+ *
* @author dasilvj
*/
public class ContactProvider extends ContentProvider {
- private static final String TAG = "ContactProvider";
-
- private static HashMap<String, String> sContactsProjectionMap;
+ private static final String TAG = "ContactProvider";
- private static final int CONTACTS = 1;
- private static final int CONTACT_ID = 2;
+ private static HashMap<String, String> sContactsProjectionMap;
- private static final UriMatcher S_URI_MATCHER;
- static {
- S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
- S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts", CONTACTS);
- S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts/#", CONTACT_ID);
+ private static final int CONTACTS = 1;
+ private static final int CONTACT_ID = 2;
- sContactsProjectionMap = new HashMap<String, String>();
- sContactsProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
- sContactsProjectionMap.put(Beem.Contacts.UID, Beem.Contacts.UID);
- sContactsProjectionMap.put(Beem.Contacts.JID, Beem.Contacts.JID);
- sContactsProjectionMap.put(Beem.Contacts.NICKNAME, Beem.Contacts.NICKNAME);
- sContactsProjectionMap.put(Beem.Contacts.ALIAS, Beem.Contacts.ALIAS);
- sContactsProjectionMap.put(Beem.Contacts.DATE_CREATED, Beem.Contacts.DATE_CREATED);
- sContactsProjectionMap.put(Beem.Contacts.DATE_MODIFIED, Beem.Contacts.DATE_MODIFIED);
- }
-
- private BeemDatabaseHelper mOpenHelper;
+ private static final UriMatcher S_URI_MATCHER;
+ static {
+ S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
+ S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts", CONTACTS);
+ S_URI_MATCHER.addURI(Beem.AUTHORITY, "contacts/#", CONTACT_ID);
- @Override
- public int delete(Uri uri, String selection, String[] selectionArgs) {
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count;
-
- switch (S_URI_MATCHER.match(uri)) {
- case CONTACTS:
- count = db.delete(Beem.CONTACTS_TABLE_NAME, selection, selectionArgs);
- break;
-
- case CONTACT_ID:
- String contactId = uri.getPathSegments().get(1);
- count = db.delete(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID + "=" + contactId
- + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
- break;
-
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
+ sContactsProjectionMap = new HashMap<String, String>();
+ sContactsProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
+ sContactsProjectionMap.put(Beem.Contacts.UID, Beem.Contacts.UID);
+ sContactsProjectionMap.put(Beem.Contacts.JID, Beem.Contacts.JID);
+ sContactsProjectionMap.put(Beem.Contacts.NICKNAME, Beem.Contacts.NICKNAME);
+ sContactsProjectionMap.put(Beem.Contacts.ALIAS, Beem.Contacts.ALIAS);
+ sContactsProjectionMap.put(Beem.Contacts.DATE_CREATED, Beem.Contacts.DATE_CREATED);
+ sContactsProjectionMap.put(Beem.Contacts.DATE_MODIFIED, Beem.Contacts.DATE_MODIFIED);
}
- getContext().getContentResolver().notifyChange(uri, null);
- return count;
- }
+ private BeemDatabaseHelper mOpenHelper;
- @Override
- public String getType(Uri uri) {
- switch (S_URI_MATCHER.match(uri)) {
- case CONTACTS:
- return Beem.Contacts.CONTENT_TYPE;
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ int count;
+
+ switch (S_URI_MATCHER.match(uri)) {
+ case CONTACTS:
+ count = db.delete(Beem.CONTACTS_TABLE_NAME, selection, selectionArgs);
+ break;
- case CONTACT_ID:
- return Beem.Contacts.CONTENT_ITEM_TYPE;
+ case CONTACT_ID:
+ String contactId = uri.getPathSegments().get(1);
+ count = db.delete(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID + "=" + contactId
+ + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+ break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
- }
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
- @Override
- public Uri insert(Uri uri, ContentValues initialValues) {
- // Validate the requested uri
- if (S_URI_MATCHER.match(uri) != CONTACTS) {
- throw new IllegalArgumentException("Unknown URI " + uri);
+ getContext().getContentResolver().notifyChange(uri, null);
+ return count;
}
- ContentValues values;
- if (initialValues != null) {
- values = new ContentValues(initialValues);
- } else {
- values = new ContentValues();
- }
-
- Long now = Long.valueOf(System.currentTimeMillis());
+ @Override
+ public String getType(Uri uri) {
+ switch (S_URI_MATCHER.match(uri)) {
+ case CONTACTS:
+ return Beem.Contacts.CONTENT_TYPE;
- // Make sure that the fields are all set
- if (!values.containsKey(Beem.Contacts.UID)) {
- // TODO :: Must check that the UID exists using UserProvider
- throw new SQLException("No UID specified. Failed to insert row into " + uri);
- }
+ case CONTACT_ID:
+ return Beem.Contacts.CONTENT_ITEM_TYPE;
- if (!values.containsKey(Beem.Contacts.JID)) {
- values.put(Beem.Contacts.JID, "");
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
}
- if (!values.containsKey(Beem.Contacts.NICKNAME)) {
- values.put(Beem.Contacts.JID, "");
- }
+ @Override
+ public Uri insert(Uri uri, ContentValues initialValues) {
+ // Validate the requested uri
+ if (S_URI_MATCHER.match(uri) != CONTACTS) {
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
+
+ ContentValues values;
+ if (initialValues != null) {
+ values = new ContentValues(initialValues);
+ } else {
+ values = new ContentValues();
+ }
+
+ Long now = Long.valueOf(System.currentTimeMillis());
+
+ // Make sure that the fields are all set
+ if (!values.containsKey(Beem.Contacts.UID)) {
+ // TODO :: Must check that the UID exists using UserProvider
+ throw new SQLException("No UID specified. Failed to insert row into " + uri);
+ }
+
+ if (!values.containsKey(Beem.Contacts.JID)) {
+ values.put(Beem.Contacts.JID, "");
+ }
- if (!values.containsKey(Beem.Contacts.ALIAS)) {
- values.put(Beem.Contacts.JID, "");
+ if (!values.containsKey(Beem.Contacts.NICKNAME)) {
+ values.put(Beem.Contacts.JID, "");
+ }
+
+ if (!values.containsKey(Beem.Contacts.ALIAS)) {
+ values.put(Beem.Contacts.JID, "");
+ }
+
+ if (!values.containsKey(Beem.Contacts.DATE_CREATED)) {
+ values.put(Beem.Contacts.DATE_CREATED, now);
+ }
+
+ if (!values.containsKey(Beem.Contacts.DATE_MODIFIED)) {
+ values.put(Beem.Contacts.DATE_MODIFIED, now);
+ }
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ long rowId = db.insert(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID, values);
+ if (rowId > 0) {
+ Uri contactUri = ContentUris.withAppendedId(Beem.Contacts.CONTENT_URI, rowId);
+ getContext().getContentResolver().notifyChange(contactUri, null);
+ return contactUri;
+ }
+
+ throw new SQLException("Failed to insert row into " + uri);
}
- if (!values.containsKey(Beem.Contacts.DATE_CREATED)) {
- values.put(Beem.Contacts.DATE_CREATED, now);
- }
-
- if (!values.containsKey(Beem.Contacts.DATE_MODIFIED)) {
- values.put(Beem.Contacts.DATE_MODIFIED, now);
- }
-
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- long rowId = db.insert(Beem.CONTACTS_TABLE_NAME, BaseColumns._ID, values);
- if (rowId > 0) {
- Uri contactUri = ContentUris.withAppendedId(Beem.Contacts.CONTENT_URI, rowId);
- getContext().getContentResolver().notifyChange(contactUri, null);
- return contactUri;
+ @Override
+ public boolean onCreate() {
+ mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.CONTACTS_TABLE_NAME, Beem.Contacts.QUERY_CREATE);
+ return true;
}
- throw new SQLException("Failed to insert row into " + uri);
- }
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+ SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- @Override
- public boolean onCreate() {
- mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.CONTACTS_TABLE_NAME, Beem.Contacts.QUERY_CREATE);
- return true;
- }
+ switch (S_URI_MATCHER.match(uri)) {
+ case CONTACTS:
+ qb.setTables(Beem.CONTACTS_TABLE_NAME);
+ qb.setProjectionMap(sContactsProjectionMap);
+ break;
- @Override
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+ case CONTACT_ID:
+ qb.setTables(Beem.USERS_TABLE_NAME);
+ qb.setProjectionMap(sContactsProjectionMap);
+ qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
+ break;
- switch (S_URI_MATCHER.match(uri)) {
- case CONTACTS:
- qb.setTables(Beem.CONTACTS_TABLE_NAME);
- qb.setProjectionMap(sContactsProjectionMap);
- break;
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
- case CONTACT_ID:
- qb.setTables(Beem.USERS_TABLE_NAME);
- qb.setProjectionMap(sContactsProjectionMap);
- qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
- break;
+ // If no sort order is specified use the default
+ String orderBy;
+ if (TextUtils.isEmpty(sortOrder)) {
+ orderBy = Beem.Contacts.DEFAULT_SORT_ORDER;
+ } else {
+ orderBy = sortOrder;
+ }
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
+ // Get the database and run the query
+ SQLiteDatabase db = mOpenHelper.getReadableDatabase();
+ Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
+
+ // Tell the cursor what uri to watch, so it knows when its source data
+ // changes
+ c.setNotificationUri(getContext().getContentResolver(), uri);
+ return c;
}
- // If no sort order is specified use the default
- String orderBy;
- if (TextUtils.isEmpty(sortOrder)) {
- orderBy = Beem.Contacts.DEFAULT_SORT_ORDER;
- } else {
- orderBy = sortOrder;
- }
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ int count;
- // Get the database and run the query
- SQLiteDatabase db = mOpenHelper.getReadableDatabase();
- Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
-
- // Tell the cursor what uri to watch, so it knows when its source data
- // changes
- c.setNotificationUri(getContext().getContentResolver(), uri);
- return c;
- }
+ switch (S_URI_MATCHER.match(uri)) {
+ case CONTACTS:
+ count = db.update(Beem.CONTACTS_TABLE_NAME, values, selection, selectionArgs);
+ break;
- @Override
- public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count;
-
- switch (S_URI_MATCHER.match(uri)) {
- case CONTACTS:
- count = db.update(Beem.CONTACTS_TABLE_NAME, values, selection, selectionArgs);
- break;
+ case CONTACT_ID:
+ String contactId = uri.getPathSegments().get(1);
+ count = db.update(Beem.CONTACTS_TABLE_NAME, values, BaseColumns._ID + "=" + contactId
+ + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+ break;
- case CONTACT_ID:
- String contactId = uri.getPathSegments().get(1);
- count = db.update(Beem.CONTACTS_TABLE_NAME, values, BaseColumns._ID + "=" + contactId
- + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
- break;
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
+ getContext().getContentResolver().notifyChange(uri, null);
+ return count;
}
-
- getContext().getContentResolver().notifyChange(uri, null);
- return count;
- }
}
--- a/src/com/beem/project/beem/provider/UserProvider.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/provider/UserProvider.java Wed Nov 11 19:21:44 2009 +0100
@@ -16,175 +16,176 @@
/**
* UserProvider class.
+ *
* @author Jamu
*/
public class UserProvider extends ContentProvider {
- private static final String TAG = "UserProvider";
-
- private static HashMap<String, String> sUsersProjectionMap;
-
- private static final int USERS = 1;
- private static final int USER_ID = 2;
+ private static final String TAG = "UserProvider";
- private static final UriMatcher S_URI_MATCHER;
- static {
- S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
- S_URI_MATCHER.addURI(Beem.AUTHORITY, "users", USERS);
- S_URI_MATCHER.addURI(Beem.AUTHORITY, "users/#", USER_ID);
+ private static HashMap<String, String> sUsersProjectionMap;
- sUsersProjectionMap = new HashMap<String, String>();
- sUsersProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
- sUsersProjectionMap.put(Beem.Users.JUSERNAME, Beem.Users.JUSERNAME);
- sUsersProjectionMap.put(Beem.Users.DATE_CREATED, Beem.Users.DATE_CREATED);
- sUsersProjectionMap.put(Beem.Users.DATE_MODIFIED, Beem.Users.DATE_MODIFIED);
- }
+ private static final int USERS = 1;
+ private static final int USER_ID = 2;
- private BeemDatabaseHelper mOpenHelper;
-
- @Override
- public int delete(Uri uri, String selection, String[] selectionArgs) {
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count;
+ private static final UriMatcher S_URI_MATCHER;
+ static {
+ S_URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
+ S_URI_MATCHER.addURI(Beem.AUTHORITY, "users", USERS);
+ S_URI_MATCHER.addURI(Beem.AUTHORITY, "users/#", USER_ID);
- switch (S_URI_MATCHER.match(uri)) {
- case USERS:
- count = db.delete(Beem.USERS_TABLE_NAME, selection, selectionArgs);
- break;
-
- case USER_ID:
- String userID = uri.getPathSegments().get(1);
- count = db.delete(Beem.USERS_TABLE_NAME, BaseColumns._ID + "=" + userID
- + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
- break;
-
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
+ sUsersProjectionMap = new HashMap<String, String>();
+ sUsersProjectionMap.put(BaseColumns._ID, BaseColumns._ID);
+ sUsersProjectionMap.put(Beem.Users.JUSERNAME, Beem.Users.JUSERNAME);
+ sUsersProjectionMap.put(Beem.Users.DATE_CREATED, Beem.Users.DATE_CREATED);
+ sUsersProjectionMap.put(Beem.Users.DATE_MODIFIED, Beem.Users.DATE_MODIFIED);
}
- getContext().getContentResolver().notifyChange(uri, null);
- return count;
- }
+ private BeemDatabaseHelper mOpenHelper;
- @Override
- public String getType(Uri uri) {
- switch (S_URI_MATCHER.match(uri)) {
- case USERS:
- return Beem.Users.CONTENT_TYPE;
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ int count;
+
+ switch (S_URI_MATCHER.match(uri)) {
+ case USERS:
+ count = db.delete(Beem.USERS_TABLE_NAME, selection, selectionArgs);
+ break;
- case USER_ID:
- return Beem.Users.CONTENT_ITEM_TYPE;
+ case USER_ID:
+ String userID = uri.getPathSegments().get(1);
+ count = db.delete(Beem.USERS_TABLE_NAME, BaseColumns._ID + "=" + userID
+ + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+ break;
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
- }
- }
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
- @Override
- public Uri insert(Uri uri, ContentValues initialValues) {
- // Validate the requested uri
- if (S_URI_MATCHER.match(uri) != USERS) {
- throw new IllegalArgumentException("Unknown URI " + uri);
+ getContext().getContentResolver().notifyChange(uri, null);
+ return count;
}
- ContentValues values;
- if (initialValues != null) {
- values = new ContentValues(initialValues);
- } else {
- values = new ContentValues();
- }
+ @Override
+ public String getType(Uri uri) {
+ switch (S_URI_MATCHER.match(uri)) {
+ case USERS:
+ return Beem.Users.CONTENT_TYPE;
- Long now = Long.valueOf(System.currentTimeMillis());
+ case USER_ID:
+ return Beem.Users.CONTENT_ITEM_TYPE;
- // Make sure that the fields are all set
- if (!values.containsKey(Beem.Users.JUSERNAME)) {
- throw new SQLException("No JUSERNAME specified. Failed to insert row into " + uri);
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
}
- if (!values.containsKey(Beem.Users.DATE_CREATED)) {
- values.put(Beem.Users.DATE_CREATED, now);
+ @Override
+ public Uri insert(Uri uri, ContentValues initialValues) {
+ // Validate the requested uri
+ if (S_URI_MATCHER.match(uri) != USERS) {
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
+
+ ContentValues values;
+ if (initialValues != null) {
+ values = new ContentValues(initialValues);
+ } else {
+ values = new ContentValues();
+ }
+
+ Long now = Long.valueOf(System.currentTimeMillis());
+
+ // Make sure that the fields are all set
+ if (!values.containsKey(Beem.Users.JUSERNAME)) {
+ throw new SQLException("No JUSERNAME specified. Failed to insert row into " + uri);
+ }
+
+ if (!values.containsKey(Beem.Users.DATE_CREATED)) {
+ values.put(Beem.Users.DATE_CREATED, now);
+ }
+
+ if (!values.containsKey(Beem.Users.DATE_MODIFIED)) {
+ values.put(Beem.Users.DATE_MODIFIED, now);
+ }
+
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ long rowId = db.insert(Beem.USERS_TABLE_NAME, BaseColumns._ID, values);
+ if (rowId > 0) {
+ Uri userUri = ContentUris.withAppendedId(Beem.Users.CONTENT_URI, rowId);
+ getContext().getContentResolver().notifyChange(userUri, null);
+ return userUri;
+ }
+
+ throw new SQLException("Failed to insert row into " + uri);
}
- if (!values.containsKey(Beem.Users.DATE_MODIFIED)) {
- values.put(Beem.Users.DATE_MODIFIED, now);
- }
-
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- long rowId = db.insert(Beem.USERS_TABLE_NAME, BaseColumns._ID, values);
- if (rowId > 0) {
- Uri userUri = ContentUris.withAppendedId(Beem.Users.CONTENT_URI, rowId);
- getContext().getContentResolver().notifyChange(userUri, null);
- return userUri;
+ @Override
+ public boolean onCreate() {
+ mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.USERS_TABLE_NAME, Beem.Users.QUERY_CREATE);
+ return true;
}
- throw new SQLException("Failed to insert row into " + uri);
- }
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+ SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- @Override
- public boolean onCreate() {
- mOpenHelper = new BeemDatabaseHelper(getContext(), TAG, Beem.USERS_TABLE_NAME, Beem.Users.QUERY_CREATE);
- return true;
- }
+ switch (S_URI_MATCHER.match(uri)) {
+ case USERS:
+ qb.setTables(Beem.USERS_TABLE_NAME);
+ qb.setProjectionMap(sUsersProjectionMap);
+ break;
- @Override
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
+ case USER_ID:
+ qb.setTables(Beem.USERS_TABLE_NAME);
+ qb.setProjectionMap(sUsersProjectionMap);
+ qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
+ break;
- switch (S_URI_MATCHER.match(uri)) {
- case USERS:
- qb.setTables(Beem.USERS_TABLE_NAME);
- qb.setProjectionMap(sUsersProjectionMap);
- break;
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
- case USER_ID:
- qb.setTables(Beem.USERS_TABLE_NAME);
- qb.setProjectionMap(sUsersProjectionMap);
- qb.appendWhere(BaseColumns._ID + "=" + uri.getPathSegments().get(1));
- break;
+ // If no sort order is specified use the default
+ String orderBy;
+ if (TextUtils.isEmpty(sortOrder)) {
+ orderBy = Beem.Users.DEFAULT_SORT_ORDER;
+ } else {
+ orderBy = sortOrder;
+ }
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
+ // Get the database and run the query
+ SQLiteDatabase db = mOpenHelper.getReadableDatabase();
+ Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
+
+ // Tell the cursor what uri to watch, so it knows when its source data
+ // changes
+ c.setNotificationUri(getContext().getContentResolver(), uri);
+ return c;
}
- // If no sort order is specified use the default
- String orderBy;
- if (TextUtils.isEmpty(sortOrder)) {
- orderBy = Beem.Users.DEFAULT_SORT_ORDER;
- } else {
- orderBy = sortOrder;
- }
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ SQLiteDatabase db = mOpenHelper.getWritableDatabase();
+ int count;
- // Get the database and run the query
- SQLiteDatabase db = mOpenHelper.getReadableDatabase();
- Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, orderBy);
-
- // Tell the cursor what uri to watch, so it knows when its source data
- // changes
- c.setNotificationUri(getContext().getContentResolver(), uri);
- return c;
- }
+ switch (S_URI_MATCHER.match(uri)) {
+ case USERS:
+ count = db.update(Beem.USERS_TABLE_NAME, values, selection, selectionArgs);
+ break;
- @Override
- public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
- SQLiteDatabase db = mOpenHelper.getWritableDatabase();
- int count;
-
- switch (S_URI_MATCHER.match(uri)) {
- case USERS:
- count = db.update(Beem.USERS_TABLE_NAME, values, selection, selectionArgs);
- break;
+ case USER_ID:
+ String userId = uri.getPathSegments().get(1);
+ count = db.update(Beem.USERS_TABLE_NAME, values, BaseColumns._ID + "=" + userId
+ + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
+ break;
- case USER_ID:
- String userId = uri.getPathSegments().get(1);
- count = db.update(Beem.USERS_TABLE_NAME, values, BaseColumns._ID + "=" + userId
- + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
- break;
+ default:
+ throw new IllegalArgumentException("Unknown URI " + uri);
+ }
- default:
- throw new IllegalArgumentException("Unknown URI " + uri);
+ getContext().getContentResolver().notifyChange(uri, null);
+ return count;
}
-
- getContext().getContentResolver().notifyChange(uri, null);
- return count;
- }
}
--- a/src/com/beem/project/beem/service/BeemChatManager.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/BeemChatManager.java Wed Nov 11 19:21:44 2009 +0100
@@ -69,9 +69,11 @@
}
mRemoteChatCreationListeners.finishBroadcast();
}
-
+
/**
- * Create the PendingIntent to launch our activity if the user select this chat notification.
+ * Create the PendingIntent to launch our activity if the user select
+ * this chat notification.
+ *
* @param chat
* @return
*/
@@ -83,7 +85,8 @@
} catch (RemoteException e) {
Log.e(TAG, e.getMessage());
}
- PendingIntent contentIntent = PendingIntent.getActivity(mService, 0, chatIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent contentIntent = PendingIntent.getActivity(mService, 0, chatIntent,
+ PendingIntent.FLAG_UPDATE_CURRENT);
return (contentIntent);
}
@@ -100,7 +103,8 @@
.currentTimeMillis());
notification.defaults = Notification.DEFAULT_ALL;
notification.flags = Notification.FLAG_AUTO_CANCEL;
- notification.setLatestEventInfo(mService, tickerText, mService.getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat));
+ notification.setLatestEventInfo(mService, tickerText, mService
+ .getString(R.string.BeemChatManagerNewMessage), makeChatIntent(chat));
mService.sendNotification(chat.hashCode(), notification);
} catch (RemoteException e) {
Log.e(TAG, e.getMessage());
--- a/src/com/beem/project/beem/service/Contact.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/Contact.java Wed Nov 11 19:21:44 2009 +0100
@@ -399,5 +399,4 @@
Uri u = Uri.parse(build.toString());
return u;
}
-
}
--- a/src/com/beem/project/beem/service/Message.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/Message.java Wed Nov 11 19:21:44 2009 +0100
@@ -8,247 +8,275 @@
/**
* This class represents a instant message.
+ *
* @author darisk
*/
public class Message implements Parcelable {
- /**
- * Normal message type. Theese messages are like an email, with subject.
- */
- public static final int MSG_TYPE_NORMAL = 100;
+ /**
+ * Normal message type. Theese messages are like an email, with subject.
+ */
+ public static final int MSG_TYPE_NORMAL = 100;
+
+ /**
+ * Chat message type.
+ */
+ public static final int MSG_TYPE_CHAT = 200;
+
+ /**
+ * Group chat message type.
+ */
+ public static final int MSG_TYPE_GROUP_CHAT = 300;
+
+ /**
+ * Error message type.
+ */
+ public static final int MSG_TYPE_ERROR = 400;
+ /**
+ * Parcelable.Creator needs by Android.
+ */
+ public static final Parcelable.Creator<Message> CREATOR = new Parcelable.Creator<Message>() {
+
+ @Override
+ public Message createFromParcel(Parcel source) {
+ return new Message(source);
+ }
- /**
- * Chat message type.
- */
- public static final int MSG_TYPE_CHAT = 200;
+ @Override
+ public Message[] newArray(int size) {
+ return new Message[size];
+ }
+ };
+
+ private int mType;
+ private String mBody;
+ private String mSubject;
+ private String mTo;
+ private String mFrom;
+ private String mThread;
+
+ // TODO ajouter l'erreur
+
+ /**
+ * Constructor.
+ *
+ * @param to
+ * the destinataire of the message
+ * @param type
+ * the message type
+ */
+ public Message(final String to, final int type) {
+ mTo = to;
+ mType = type;
+ mBody = "";
+ mSubject = "";
+ mThread = "";
+ mFrom = null;
+ }
- /**
- * Group chat message type.
- */
- public static final int MSG_TYPE_GROUP_CHAT = 300;
+ /**
+ * Constructor a message of type chat.
+ *
+ * @param to
+ * the destinataire of the message
+ */
+ public Message(final String to) {
+ this(to, MSG_TYPE_CHAT);
+ }
- /**
- * Error message type.
- */
- public static final int MSG_TYPE_ERROR = 400;
- /**
- * Parcelable.Creator needs by Android.
- */
- public static final Parcelable.Creator<Message> CREATOR = new Parcelable.Creator<Message>() {
+ /**
+ * Construct a message from a smack message packet.
+ *
+ * @param smackMsg
+ * Smack message packet
+ */
+ public Message(final org.jivesoftware.smack.packet.Message smackMsg) {
+ this(smackMsg.getTo());
+ switch (smackMsg.getType()) {
+ case chat:
+ mType = MSG_TYPE_CHAT;
+ break;
+ case groupchat:
+ mType = MSG_TYPE_GROUP_CHAT;
+ break;
+ case normal:
+ mType = MSG_TYPE_NORMAL;
+ break;
+ // TODO gerer les message de type error
+ // this a little work around waiting for a better handling of error
+ // messages
+ case error:
+ mType = MSG_TYPE_ERROR;
+ break;
+ default:
+ Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType());
+ break;
+ }
+ this.mFrom = smackMsg.getFrom();
+ if (mType == MSG_TYPE_ERROR) {
+ XMPPError er = smackMsg.getError();
+ String msg = er.getMessage();
+ if (msg != null)
+ mBody = msg;
+ else
+ mBody = er.getCondition();
+ } else {
+ mBody = smackMsg.getBody();
+ mSubject = smackMsg.getSubject();
+ mThread = smackMsg.getThread();
+ }
+ }
- @Override
- public Message createFromParcel(Parcel source) {
- return new Message(source);
+ /**
+ * Construct a message from a parcel.
+ *
+ * @param in
+ * parcel to use for construction
+ */
+ private Message(final Parcel in) {
+ mType = in.readInt();
+ mTo = in.readString();
+ mBody = in.readString();
+ mSubject = in.readString();
+ mThread = in.readString();
+ mFrom = in.readString();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public Message[] newArray(int size) {
- return new Message[size];
+ public void writeToParcel(Parcel dest, int flags) {
+ // TODO Auto-generated method stub
+ dest.writeInt(mType);
+ dest.writeString(mTo);
+ dest.writeString(mBody);
+ dest.writeString(mSubject);
+ dest.writeString(mThread);
+ dest.writeString(mFrom);
}
- };
-
- private int mType;
- private String mBody;
- private String mSubject;
- private String mTo;
- private String mFrom;
- private String mThread;
-
- // TODO ajouter l'erreur
- /**
- * Constructor.
- * @param to the destinataire of the message
- * @param type the message type
- */
- public Message(final String to, final int type) {
- mTo = to;
- mType = type;
- mBody = "";
- mSubject = "";
- mThread = "";
- mFrom = null;
- }
-
- /**
- * Constructor a message of type chat.
- * @param to the destinataire of the message
- */
- public Message(final String to) {
- this(to, MSG_TYPE_CHAT);
- }
+ /**
+ * Get the type of the message.
+ *
+ * @return the type of the message.
+ */
+ public int getType() {
+ return mType;
+ }
- /**
- * Construct a message from a smack message packet.
- * @param smackMsg Smack message packet
- */
- public Message(final org.jivesoftware.smack.packet.Message smackMsg) {
- this(smackMsg.getTo());
- switch (smackMsg.getType()) {
- case chat:
- mType = MSG_TYPE_CHAT;
- break;
- case groupchat:
- mType = MSG_TYPE_GROUP_CHAT;
- break;
- case normal:
- mType = MSG_TYPE_NORMAL;
- break;
- // TODO gerer les message de type error
- // this a little work around waiting for a better handling of error
- // messages
- case error:
- mType = MSG_TYPE_ERROR;
- break;
- default:
- Log.w("BEEM_MESSAGE", "type de message non gerer" + smackMsg.getType());
- break;
+ /**
+ * Set the type of the message.
+ *
+ * @param type
+ * the type to set
+ */
+ public void setType(int type) {
+ mType = type;
+ }
+
+ /**
+ * Get the body of the message.
+ *
+ * @return the Body of the message
+ */
+ public String getBody() {
+ return mBody;
}
- this.mFrom = smackMsg.getFrom();
- if (mType == MSG_TYPE_ERROR) {
- XMPPError er = smackMsg.getError();
- String msg = er.getMessage();
- if (msg != null)
- mBody = msg;
- else
- mBody = er.getCondition();
- } else {
- mBody = smackMsg.getBody();
- mSubject = smackMsg.getSubject();
- mThread = smackMsg.getThread();
- }
- }
- /**
- * Construct a message from a parcel.
- * @param in parcel to use for construction
- */
- private Message(final Parcel in) {
- mType = in.readInt();
- mTo = in.readString();
- mBody = in.readString();
- mSubject = in.readString();
- mThread = in.readString();
- mFrom = in.readString();
- }
+ /**
+ * Set the body of the message.
+ *
+ * @param body
+ * the body to set
+ */
+ public void setBody(String body) {
+ mBody = body;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- // TODO Auto-generated method stub
- dest.writeInt(mType);
- dest.writeString(mTo);
- dest.writeString(mBody);
- dest.writeString(mSubject);
- dest.writeString(mThread);
- dest.writeString(mFrom);
- }
+ /**
+ * Get the subject of the message.
+ *
+ * @return the subject
+ */
+ public String getSubject() {
+ return mSubject;
+ }
- /**
- * Get the type of the message.
- * @return the type of the message.
- */
- public int getType() {
- return mType;
- }
-
- /**
- * Set the type of the message.
- * @param type the type to set
- */
- public void setType(int type) {
- mType = type;
- }
-
- /**
- * Get the body of the message.
- * @return the Body of the message
- */
- public String getBody() {
- return mBody;
- }
+ /**
+ * Set the subject of the message.
+ *
+ * @param subject
+ * the subject to set
+ */
+ public void setSubject(String subject) {
+ mSubject = subject;
+ }
- /**
- * Set the body of the message.
- * @param body the body to set
- */
- public void setBody(String body) {
- mBody = body;
- }
+ /**
+ * Get the destinataire of the message.
+ *
+ * @return the destinataire of the message
+ */
+ public String getTo() {
+ return mTo;
+ }
- /**
- * Get the subject of the message.
- * @return the subject
- */
- public String getSubject() {
- return mSubject;
- }
-
- /**
- * Set the subject of the message.
- * @param subject the subject to set
- */
- public void setSubject(String subject) {
- mSubject = subject;
- }
+ /**
+ * Set the destinataire of the message.
+ *
+ * @param to
+ * the destinataire to set
+ */
+ public void setTo(String to) {
+ mTo = to;
+ }
- /**
- * Get the destinataire of the message.
- * @return the destinataire of the message
- */
- public String getTo() {
- return mTo;
- }
+ /**
+ * Set the from field of the message.
+ *
+ * @param from
+ * the mFrom to set
+ */
+ public void setFrom(String from) {
+ this.mFrom = from;
+ }
- /**
- * Set the destinataire of the message.
- * @param to the destinataire to set
- */
- public void setTo(String to) {
- mTo = to;
- }
-
- /**
- * Set the from field of the message.
- * @param from the mFrom to set
- */
- public void setFrom(String from) {
- this.mFrom = from;
- }
+ /**
+ * Get the from field of the message.
+ *
+ * @return the mFrom
+ */
+ public String getFrom() {
+ return mFrom;
+ }
- /**
- * Get the from field of the message.
- * @return the mFrom
- */
- public String getFrom() {
- return mFrom;
- }
-
- /**
- * Get the thread of the message.
- * @return the thread
- */
- public String getThread() {
- return mThread;
- }
+ /**
+ * Get the thread of the message.
+ *
+ * @return the thread
+ */
+ public String getThread() {
+ return mThread;
+ }
- /**
- * Set the thread of the message.
- * @param thread the thread to set
- */
- public void setThread(String thread) {
- mThread = thread;
- }
+ /**
+ * Set the thread of the message.
+ *
+ * @param thread
+ * the thread to set
+ */
+ public void setThread(String thread) {
+ mThread = thread;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public int describeContents() {
- // TODO Auto-generated method stub
- return 0;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int describeContents() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
}
--- a/src/com/beem/project/beem/service/PresenceAdapter.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/PresenceAdapter.java Wed Nov 11 19:21:44 2009 +0100
@@ -10,148 +10,168 @@
/**
* this class contain contact presence informations.
+ *
* @author nikita
*/
public class PresenceAdapter implements Parcelable {
- /**
- * Parcelable.Creator needs by Android.
- */
- public static final Parcelable.Creator<PresenceAdapter> CREATOR = new Parcelable.Creator<PresenceAdapter>() {
+ /**
+ * Parcelable.Creator needs by Android.
+ */
+ public static final Parcelable.Creator<PresenceAdapter> CREATOR = new Parcelable.Creator<PresenceAdapter>() {
+
+ @Override
+ public PresenceAdapter createFromParcel(Parcel source) {
+ return new PresenceAdapter(source);
+ }
+
+ @Override
+ public PresenceAdapter[] newArray(int size) {
+ return new PresenceAdapter[size];
+ }
+ };
+
+ private int mType;
+ private int mStatus;
+ private String mTo;
+ private String mFrom;
+ private String mStatusText;
- @Override
- public PresenceAdapter createFromParcel(Parcel source) {
- return new PresenceAdapter(source);
+ /**
+ * constructor from Parcel.
+ *
+ * @param source
+ * parcelable presence.
+ */
+ public PresenceAdapter(final Parcel source) {
+ mType = source.readInt();
+ mStatus = source.readInt();
+ mTo = source.readString();
+ mFrom = source.readString();
+ mStatusText = source.readString();
+ }
+
+ /**
+ * constructor from smack Presence.
+ *
+ * @param presence
+ * smack presence.
+ */
+ public PresenceAdapter(final Presence presence) {
+ mType = PresenceType.getPresenceType(presence);
+ mStatus = Status.getStatusFromPresence(presence);
+ mTo = presence.getTo();
+ mFrom = presence.getFrom();
+ mStatusText = presence.getStatus();
}
@Override
- public PresenceAdapter[] newArray(int size) {
- return new PresenceAdapter[size];
+ public int describeContents() {
+ // TODO Auto-generated method stub
+ return 0;
}
- };
-
- private int mType;
- private int mStatus;
- private String mTo;
- private String mFrom;
- private String mStatusText;
- /**
- * constructor from Parcel.
- * @param source parcelable presence.
- */
- public PresenceAdapter(final Parcel source) {
- mType = source.readInt();
- mStatus = source.readInt();
- mTo = source.readString();
- mFrom = source.readString();
- mStatusText = source.readString();
- }
+ /**
+ * mFrom getter.
+ *
+ * @return the mFrom
+ */
+ public String getFrom() {
+ return mFrom;
+ }
+
+ /**
+ * mStatus getter.
+ *
+ * @return the mStatus
+ */
+ public int getStatus() {
+ return mStatus;
+ }
- /**
- * constructor from smack Presence.
- * @param presence smack presence.
- */
- public PresenceAdapter(final Presence presence) {
- mType = PresenceType.getPresenceType(presence);
- mStatus = Status.getStatusFromPresence(presence);
- mTo = presence.getTo();
- mFrom = presence.getFrom();
- mStatusText = presence.getStatus();
- }
-
- @Override
- public int describeContents() {
- // TODO Auto-generated method stub
- return 0;
- }
+ /**
+ * mStatusText getter.
+ *
+ * @return the mStatusText
+ */
+ public String getStatusText() {
+ return mStatusText;
+ }
- /**
- * mFrom getter.
- * @return the mFrom
- */
- public String getFrom() {
- return mFrom;
- }
+ /**
+ * mTo getter.
+ *
+ * @return the mTo
+ */
+ public String getTo() {
+ return mTo;
+ }
- /**
- * mStatus getter.
- * @return the mStatus
- */
- public int getStatus() {
- return mStatus;
- }
-
- /**
- * mStatusText getter.
- * @return the mStatusText
- */
- public String getStatusText() {
- return mStatusText;
- }
+ /**
+ * mType getter.
+ *
+ * @return the mType
+ */
+ public int getType() {
+ return mType;
+ }
- /**
- * mTo getter.
- * @return the mTo
- */
- public String getTo() {
- return mTo;
- }
-
- /**
- * mType getter.
- * @return the mType
- */
- public int getType() {
- return mType;
- }
+ /**
+ * mFrom setter.
+ *
+ * @param from
+ * the mFrom to set
+ */
+ public void setFrom(final String from) {
+ this.mFrom = from;
+ }
- /**
- * mFrom setter.
- * @param from the mFrom to set
- */
- public void setFrom(final String from) {
- this.mFrom = from;
- }
+ /**
+ * mStatus setter.
+ *
+ * @param status
+ * the mStatus to set
+ */
+ public void setStatus(final int status) {
+ this.mStatus = status;
+ }
- /**
- * mStatus setter.
- * @param status the mStatus to set
- */
- public void setStatus(final int status) {
- this.mStatus = status;
- }
+ /**
+ * mStatusText setter.
+ *
+ * @param statusText
+ * the mStatusText to set
+ */
+ public void setStatusText(final String statusText) {
+ this.mStatusText = statusText;
+ }
- /**
- * mStatusText setter.
- * @param statusText the mStatusText to set
- */
- public void setStatusText(final String statusText) {
- this.mStatusText = statusText;
- }
-
- /**
- * mTo setter.
- * @param to the mTo to set
- */
- public void setTo(final String to) {
- this.mTo = to;
- }
+ /**
+ * mTo setter.
+ *
+ * @param to
+ * the mTo to set
+ */
+ public void setTo(final String to) {
+ this.mTo = to;
+ }
- /**
- * mType setter.
- * @param type the type to set
- */
- public void setType(int type) {
- this.mType = type;
- }
+ /**
+ * mType setter.
+ *
+ * @param type
+ * the type to set
+ */
+ public void setType(int type) {
+ this.mType = type;
+ }
- @Override
- public void writeToParcel(Parcel dest, int flags) {
- dest.writeInt(mType);
- dest.writeInt(mStatus);
- dest.writeString(mTo);
- dest.writeString(mFrom);
- dest.writeString(mStatusText);
- }
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mType);
+ dest.writeInt(mStatus);
+ dest.writeString(mTo);
+ dest.writeString(mFrom);
+ dest.writeString(mStatusText);
+ }
}
--- a/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/PrivacyListManagerAdapter.java Wed Nov 11 19:21:44 2009 +0100
@@ -17,122 +17,130 @@
/**
* Privacy list manager in beem.
+ *
* @author nikita
*/
public class PrivacyListManagerAdapter extends IPrivacyListManager.Stub {
- /**
- * Tag.
- */
- public static final String TAG = "PrivacyListManagerAdapter";
- /**
- * default privacy list name.
- */
- public static final String DEFAULT_PRIVACYLIST = "default";
-
- private PrivacyListManager mAdaptee;
- private List<String> mBlockedUser = new ArrayList<String>();
- private XMPPConnection mConnection;
- private MyPrivacyListListener mPrivacyPacketListener = new MyPrivacyListListener();
+ /**
+ * Tag.
+ */
+ public static final String TAG = "PrivacyListManagerAdapter";
+ /**
+ * default privacy list name.
+ */
+ public static final String DEFAULT_PRIVACYLIST = "default";
- /**
- * Privacy list constructor.
- * @param connection xmppconnection used.
- */
- public PrivacyListManagerAdapter(final XMPPConnection connection) {
- mConnection = connection;
- mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
- mAdaptee.addListener(mPrivacyPacketListener);
- }
-
- /**
- * return the blocked user list.
- * @return blocked user list
- */
- public List<String> getBlockedUsers() {
- return mBlockedUser;
- }
+ private PrivacyListManager mAdaptee;
+ private List<String> mBlockedUser = new ArrayList<String>();
+ private XMPPConnection mConnection;
+ private MyPrivacyListListener mPrivacyPacketListener = new MyPrivacyListListener();
- /**
- * add an user to the blocked user list.
- * @param jid blocked user jid
- */
- public synchronized void addBlockedUser(final String jid) {
- if (mAdaptee == null) {
- mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
- mAdaptee.addListener(mPrivacyPacketListener);
+ /**
+ * Privacy list constructor.
+ *
+ * @param connection
+ * xmppconnection used.
+ */
+ public PrivacyListManagerAdapter(final XMPPConnection connection) {
+ mConnection = connection;
+ mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
+ mAdaptee.addListener(mPrivacyPacketListener);
}
- List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
- PrivacyItem pItem = new PrivacyItem("jid", true, 1);
- pItem.setFilterMessage(true);
- pItem.setValue(jid);
- pItemList.add(pItem);
-
- pItem = new PrivacyItem("subscription", true, 2);
- pItem.setValue(PrivacyRule.SUBSCRIPTION_BOTH);
- pItemList.add(pItem);
- try {
- if (mAdaptee.getPrivacyList(DEFAULT_PRIVACYLIST) == null) {
- mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
- }
-
- } catch (XMPPException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassCastException e) {
- e.printStackTrace();
- try {
- mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
- } catch (XMPPException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- }
- try {
- mAdaptee.setActiveListName(DEFAULT_PRIVACYLIST);
- mAdaptee.setDefaultListName(DEFAULT_PRIVACYLIST);
- } catch (XMPPException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ /**
+ * return the blocked user list.
+ *
+ * @return blocked user list
+ */
+ public List<String> getBlockedUsers() {
+ return mBlockedUser;
}
- Log.d(TAG, "addBlockedUser");
- }
+ /**
+ * add an user to the blocked user list.
+ *
+ * @param jid
+ * blocked user jid
+ */
+ public synchronized void addBlockedUser(final String jid) {
+ if (mAdaptee == null) {
+ mAdaptee = PrivacyListManager.getInstanceFor(mConnection);
+ mAdaptee.addListener(mPrivacyPacketListener);
+ }
+ List<PrivacyItem> pItemList = new ArrayList<PrivacyItem>();
+ PrivacyItem pItem = new PrivacyItem("jid", true, 1);
+ pItem.setFilterMessage(true);
+ pItem.setValue(jid);
+ pItemList.add(pItem);
+
+ pItem = new PrivacyItem("subscription", true, 2);
+ pItem.setValue(PrivacyRule.SUBSCRIPTION_BOTH);
+ pItemList.add(pItem);
+
+ try {
+ if (mAdaptee.getPrivacyList(DEFAULT_PRIVACYLIST) == null) {
+ mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
+ }
- /**
- * privacy list listener.
- * @author nikita
- */
- class MyPrivacyListListener implements PrivacyListListener {
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (ClassCastException e) {
+ e.printStackTrace();
+ try {
+ mAdaptee.createPrivacyList(DEFAULT_PRIVACYLIST, pItemList);
+ } catch (XMPPException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ }
+ try {
+ mAdaptee.setActiveListName(DEFAULT_PRIVACYLIST);
+ mAdaptee.setDefaultListName(DEFAULT_PRIVACYLIST);
+ } catch (XMPPException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ Log.d(TAG, "addBlockedUser");
+ }
+
/**
- * constructor.
+ * privacy list listener.
+ *
+ * @author nikita
*/
- public MyPrivacyListListener() {
+ class MyPrivacyListListener implements PrivacyListListener {
+ /**
+ * constructor.
+ */
+ public MyPrivacyListListener() {
+ }
+
+ @Override
+ public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
+ Log.d(TAG, "setPrivacyList");
+ }
+
+ @Override
+ public void updatedPrivacyList(String listName) {
+ Log.d(TAG, "updatedPrivacyList");
+ }
}
@Override
- public void setPrivacyList(String listName, List<PrivacyItem> listItem) {
- Log.d(TAG, "setPrivacyList");
+ public List<String> getBlockedUsersByList(String listName) throws RemoteException {
+ // TODO Auto-generated method stub
+ return null;
}
- @Override
- public void updatedPrivacyList(String listName) {
- Log.d(TAG, "updatedPrivacyList");
+ /**
+ * adaptee getter.
+ *
+ * @return the current PrivacyListManager instance
+ */
+ public PrivacyListManager getManager() {
+ return mAdaptee;
}
- }
-
- @Override
- public List<String> getBlockedUsersByList(String listName) throws RemoteException {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * adaptee getter.
- * @return the current PrivacyListManager instance
- */
- public PrivacyListManager getManager() {
- return mAdaptee;
- }
}
--- a/src/com/beem/project/beem/service/RosterAdapter.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/RosterAdapter.java Wed Nov 11 19:21:44 2009 +0100
@@ -2,7 +2,9 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
@@ -11,311 +13,355 @@
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Presence;
+import android.content.Context;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;
+import com.beem.project.beem.R;
import com.beem.project.beem.service.aidl.IBeemRosterListener;
+import com.beem.project.beem.utils.PresenceType;
+import com.beem.project.beem.utils.Status;
/**
* This class implement a Roster adapter for BEEM.
+ *
* @author darisk
*/
public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub {
- private static final String TAG = "RosterAdapter";
- private Roster mAdaptee;
- private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
-
- private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
-
- /**
- * Constructor.
- * @param roster the roster to adapt
- */
- public RosterAdapter(final Roster roster) {
- mAdaptee = roster;
- roster.addRosterListener(mRosterListener);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
- if (listen != null)
- mRemoteRosListeners.register(listen);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Contact addContact(String user, String name, String[] groups) throws RemoteException {
- RosterEntry contact = mAdaptee.getEntry(user);
- try {
- mAdaptee.createEntry(user, name, groups);
- contact = mAdaptee.getEntry(user);
- } catch (XMPPException e) {
- Log.e(TAG, "Error while adding new contact", e);
- return null;
- }
- if (groups != null) {
- for (String groupStr : groups) {
- RosterGroup group = mAdaptee.getGroup(groupStr);
- if (group == null) {
- group = mAdaptee.createGroup(groupStr);
- }
- try {
- group.addEntry(contact);
- } catch (XMPPException e) {
- e.printStackTrace();
- return null;
- }
- }
- }
- return getContactFromRosterEntry(contact);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void deleteContact(Contact contact) throws RemoteException {
- try {
- RosterEntry entry = mAdaptee.getEntry(contact.getJID());
- mAdaptee.removeEntry(entry);
- } catch (XMPPException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void createGroup(String groupname) throws RemoteException {
- try {
- mAdaptee.createGroup(groupname);
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "Error while creating group", e);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Contact getContact(String jid) throws RemoteException {
- if (mAdaptee.contains(jid))
- return getContactFromRosterEntry(mAdaptee.getEntry(jid));
- return null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<Contact> getContactList() throws RemoteException {
- List<Contact> coList = new ArrayList<Contact>(mAdaptee.getEntries().size());
- for (RosterEntry entry : mAdaptee.getEntries()) {
- coList.add(getContactFromRosterEntry(entry));
- }
- return coList;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public List<String> getGroupsNames() throws RemoteException {
- Collection<RosterGroup> groups = mAdaptee.getGroups();
- List<String> result = new ArrayList<String>(groups.size());
- for (RosterGroup rosterGroup : groups) {
- result.add(rosterGroup.getName());
- }
- return result;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
- if (listen != null)
- mRemoteRosListeners.unregister(listen);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setContactName(String jid, String name) throws RemoteException {
- mAdaptee.getEntry(jid).setName(name);
- }
-
- @Override
- public PresenceAdapter getPresence(String jid) throws RemoteException {
- return new PresenceAdapter(mAdaptee.getPresence(jid));
- }
-
- @Override
- public void addContactToGroup(String groupName, String jid) throws RemoteException {
- createGroup(groupName);
- RosterGroup group = mAdaptee.getGroup(groupName);
- try {
- group.addEntry(mAdaptee.getEntry(jid));
- } catch (XMPPException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void removeContactFromGroup(String groupName, String jid) throws RemoteException {
- RosterGroup group = mAdaptee.getGroup(groupName);
- try {
- group.removeEntry(mAdaptee.getEntry(jid));
- } catch (XMPPException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Get a contact from a RosterEntry.
- * @param entry a roster entry containing information for the contact.
- * @return a contact for this entry.
- */
- private Contact getContactFromRosterEntry(RosterEntry entry) {
- String user = entry.getUser();
- Contact c = new Contact(user);
- c.setStatus(mAdaptee.getPresence(user));
- try {
- c.setGroups(entry.getGroups());
- }catch(NullPointerException e){
- Log.d(TAG, "Group list not ready");
- }
- c.setName(entry.getName());
- return c;
- }
-
- /**
- * Listener for the roster events. It will call the remote listeners registered.
- * @author darisk
- */
- private class RosterListenerAdapter implements RosterListener{
+ private static final String TAG = "RosterAdapter";
+ private Roster mAdaptee;
+ private RemoteCallbackList<IBeemRosterListener> mRemoteRosListeners = new RemoteCallbackList<IBeemRosterListener>();
+ private Map<Integer, String> mDefaultStatusMessages;
+ private RosterListenerAdapter mRosterListener = new RosterListenerAdapter();
/**
* Constructor.
+ *
+ * @param roster
+ * the roster to adapt
*/
- public RosterListenerAdapter() {
+ public RosterAdapter(final Roster roster, Context context) {
+ mAdaptee = roster;
+ roster.addRosterListener(mRosterListener);
+ mDefaultStatusMessages = createDefaultStatusMessagesMap(context);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addRosterListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.register(listen);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Contact addContact(String user, String name, String[] groups) throws RemoteException {
+ RosterEntry contact = mAdaptee.getEntry(user);
+ try {
+ mAdaptee.createEntry(user, name, groups);
+ contact = mAdaptee.getEntry(user);
+ } catch (XMPPException e) {
+ Log.e(TAG, "Error while adding new contact", e);
+ return null;
+ }
+ if (groups != null) {
+ for (String groupStr : groups) {
+ RosterGroup group = mAdaptee.getGroup(groupStr);
+ if (group == null) {
+ group = mAdaptee.createGroup(groupStr);
+ }
+ try {
+ group.addEntry(contact);
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+ return getContactFromRosterEntry(contact);
}
/**
- * Event which is fired when an entry is deleted for a group.
- * @param group the group the entry was.
- * @param jid the jid of the entry which is deleted.
+ * {@inheritDoc}
+ */
+ @Override
+ public void deleteContact(Contact contact) throws RemoteException {
+ try {
+ RosterEntry entry = mAdaptee.getEntry(contact.getJID());
+ mAdaptee.removeEntry(entry);
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void createGroup(String groupname) throws RemoteException {
+ try {
+ mAdaptee.createGroup(groupname);
+ } catch (IllegalArgumentException e) {
+ Log.e(TAG, "Error while creating group", e);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
*/
- @SuppressWarnings("unused")
- public void onEntryDeleteFromGroup(final String group, final String jid) {
- // Log.i(TAG, "entry delete listener");
- final int n = mRemoteRosListeners.beginBroadcast();
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- listener.onEntryDeleteFromGroup(group, jid);
- } catch (RemoteException e) {
- Log.w(TAG, "entry delete listener", e);
+ @Override
+ public Contact getContact(String jid) throws RemoteException {
+ if (mAdaptee.contains(jid))
+ return getContactFromRosterEntry(mAdaptee.getEntry(jid));
+ return null;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<Contact> getContactList() throws RemoteException {
+ List<Contact> coList = new ArrayList<Contact>(mAdaptee.getEntries().size());
+ for (RosterEntry entry : mAdaptee.getEntries()) {
+ coList.add(getContactFromRosterEntry(entry));
}
- }
- mRemoteRosListeners.finishBroadcast();
+ return coList;
+ }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public List<String> getGroupsNames() throws RemoteException {
+ Collection<RosterGroup> groups = mAdaptee.getGroups();
+ List<String> result = new ArrayList<String>(groups.size());
+ for (RosterGroup rosterGroup : groups) {
+ result.add(rosterGroup.getName());
+ }
+ return result;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void removeRosterListener(IBeemRosterListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteRosListeners.unregister(listen);
}
/**
* {@inheritDoc}
*/
@Override
- public void entriesAdded(Collection<String> addresses) {
- // Log.i(TAG, "Ajout de l'entry " + addresses.size() + " " +
- // addresses.toArray()[0]);
- final int n = mRemoteRosListeners.beginBroadcast();
+ public void setContactName(String jid, String name) throws RemoteException {
+ mAdaptee.getEntry(jid).setName(name);
+ }
+
+ @Override
+ public PresenceAdapter getPresence(String jid) throws RemoteException {
+ return new PresenceAdapter(mAdaptee.getPresence(jid));
+ }
- List<String> tab = new ArrayList<String>();
- tab.addAll(addresses);
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ @Override
+ public void addContactToGroup(String groupName, String jid) throws RemoteException {
+ createGroup(groupName);
+ RosterGroup group = mAdaptee.getGroup(groupName);
try {
- listener.onEntriesAdded(tab);
- } catch (RemoteException e) {
- Log.w(TAG, "Error while adding roster entries", e);
+ group.addEntry(mAdaptee.getEntry(jid));
+ } catch (XMPPException e) {
+ e.printStackTrace();
}
- }
- mRemoteRosListeners.finishBroadcast();
+ }
+
+ @Override
+ public void removeContactFromGroup(String groupName, String jid) throws RemoteException {
+ RosterGroup group = mAdaptee.getGroup(groupName);
+ try {
+ group.removeEntry(mAdaptee.getEntry(jid));
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ }
}
/**
- * {@inheritDoc}
+ * Get a contact from a RosterEntry.
+ *
+ * @param entry
+ * a roster entry containing information for the contact.
+ * @return a contact for this entry.
*/
- @Override
- public void entriesDeleted(Collection<String> addresses) {
- // Log.i(TAG, "Suppression de l'entry");
- final int n = mRemoteRosListeners.beginBroadcast();
+ private Contact getContactFromRosterEntry(RosterEntry entry) {
+ String user = entry.getUser();
+ Contact c = new Contact(user);
+ Presence p = mAdaptee.getPresence(user);
+
+ if (p.getStatus() == null || p.getStatus().equals(""))
+ p.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(p)));
+ c.setStatus(p);
+ try {
+ c.setGroups(entry.getGroups());
+ } catch (NullPointerException e) {
+ Log.d(TAG, "Group list not ready");
+ }
+ c.setName(entry.getName());
+ return c;
+ }
- List<String> tab = new ArrayList<String>();
- tab.addAll(addresses);
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- listener.onEntriesDeleted(tab);
- } catch (RemoteException e) {
- Log.w(TAG, "Error while deleting roster entries", e);
- }
- }
- mRemoteRosListeners.finishBroadcast();
+ /**
+ * Create a map which contains default status messages.
+ *
+ * @return
+ */
+ private Map<Integer, String> createDefaultStatusMessagesMap(Context context) {
+ Map<Integer, String> defaultStatusMessages = new HashMap<Integer, String>();
+ defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE, context
+ .getString(R.string.contact_status_msg_available));
+ defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT, context
+ .getString(R.string.contact_status_msg_available_chat));
+ defaultStatusMessages.put(Status.CONTACT_STATUS_AWAY, context.getString(R.string.contact_status_msg_away));
+ defaultStatusMessages.put(Status.CONTACT_STATUS_BUSY, context.getString(R.string.contact_status_msg_dnd));
+ defaultStatusMessages.put(Status.CONTACT_STATUS_DISCONNECT, context
+ .getString(R.string.contact_status_msg_offline));
+ defaultStatusMessages.put(Status.CONTACT_STATUS_UNAVAILABLE, context.getString(R.string.contact_status_msg_xa));
+
+ return (defaultStatusMessages);
}
/**
- * {@inheritDoc}
+ * Listener for the roster events. It will call the remote listeners
+ * registered.
+ *
+ * @author darisk
*/
- @Override
- public void entriesUpdated(Collection<String> addresses) {
- // Log.i(TAG, "Update de l'entry " + addresses.size() + " " +
- // addresses.toArray()[0]);
- final int n = mRemoteRosListeners.beginBroadcast();
+ private class RosterListenerAdapter implements RosterListener {
+
+ /**
+ * Constructor.
+ */
+ public RosterListenerAdapter() {
+ }
- List<String> tab = new ArrayList<String>();
- tab.addAll(addresses);
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- listener.onEntriesUpdated(tab);
- } catch (RemoteException e) {
- Log.w(TAG, "Error while updating roster entries", e);
+ /**
+ * Event which is fired when an entry is deleted for a group.
+ *
+ * @param group
+ * the group the entry was.
+ * @param jid
+ * the jid of the entry which is deleted.
+ */
+ @SuppressWarnings("unused")
+ public void onEntryDeleteFromGroup(final String group, final String jid) {
+ // Log.i(TAG, "entry delete listener");
+ final int n = mRemoteRosListeners.beginBroadcast();
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntryDeleteFromGroup(group, jid);
+ } catch (RemoteException e) {
+ Log.w(TAG, "entry delete listener", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+
}
- }
- mRemoteRosListeners.finishBroadcast();
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void entriesAdded(Collection<String> addresses) {
+ // Log.i(TAG, "Ajout de l'entry " + addresses.size() + " " +
+ // addresses.toArray()[0]);
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ tab.addAll(addresses);
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntriesAdded(tab);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while adding roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void presenceChanged(Presence presence) {
- // Log.i(TAG, "presence Changed");
- /* redispatch vers les IBeemRosterListener */
- final int n = mRemoteRosListeners.beginBroadcast();
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void entriesDeleted(Collection<String> addresses) {
+ // Log.i(TAG, "Suppression de l'entry");
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ List<String> tab = new ArrayList<String>();
+ tab.addAll(addresses);
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntriesDeleted(tab);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while deleting roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void entriesUpdated(Collection<String> addresses) {
+ // Log.i(TAG, "Update de l'entry " + addresses.size() + " " +
+ // addresses.toArray()[0]);
+ final int n = mRemoteRosListeners.beginBroadcast();
- for (int i = 0; i < n; i++) {
- IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
- try {
- listener.onPresenceChanged(new PresenceAdapter(presence));
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while updating roster presence entries", e);
+ List<String> tab = new ArrayList<String>();
+ tab.addAll(addresses);
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ listener.onEntriesUpdated(tab);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Error while updating roster entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
}
- }
- mRemoteRosListeners.finishBroadcast();
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void presenceChanged(Presence presence) {
+ // Log.i(TAG, "presence Changed");
+ /* redispatch vers les IBeemRosterListener */
+ final int n = mRemoteRosListeners.beginBroadcast();
+
+ for (int i = 0; i < n; i++) {
+ IBeemRosterListener listener = mRemoteRosListeners.getBroadcastItem(i);
+ try {
+ Log.d(TAG, ">>> Presence changed.");
+ if (presence.getStatus() == null || presence.getStatus().equals("")) {
+ presence.setStatus(mDefaultStatusMessages.get(Status.getStatusFromPresence(presence)));
+ Log.d(TAG, ">>> Default status added.");
+ }
+ listener.onPresenceChanged(new PresenceAdapter(presence));
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while updating roster presence entries", e);
+ }
+ }
+ mRemoteRosListeners.finishBroadcast();
+ }
}
- }
}
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Nov 11 19:21:44 2009 +0100
@@ -32,446 +32,473 @@
/**
* This class implements an adapter for XMPPConnection.
+ *
* @author darisk
*/
public class XmppConnectionAdapter extends IXmppConnection.Stub {
- /**
- * Beem connection closed Intent name.
- */
-
- private static final String TAG = "XMPPConnectionAdapter";
- private static final int PRESENCE_PRIORITY = 128;
+ /**
+ * Beem connection closed Intent name.
+ */
- private final XMPPConnection mAdaptee;
- private IChatManager mChatManager;
- private final String mLogin;
- private final String mPassword;
- private RosterAdapter mRoster;
- private PrivacyListManagerAdapter mPrivacyList;
- private final BeemService mService;
- private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners =
- new RemoteCallbackList<IBeemConnectionListener>();
-
- private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
+ private static final String TAG = "XMPPConnectionAdapter";
+ private static final int PRESENCE_PRIORITY = 128;
- /**
- * Constructor.
- * @param config Configuration to use in order to connect
- * @param login login to use on connect
- * @param password password to use on connect
- * @param service the background service associated with the connection.
- */
- public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password,
- final BeemService service) {
- this(new XMPPConnection(config), login, password, service);
- }
-
- /**
- * Constructor.
- * @param serviceName name of the service to connect to
- * @param login login to use on connect
- * @param password password to use on connect
- * @param service the background service associated with the connection.
- */
- public XmppConnectionAdapter(final String serviceName, final String login, final String password,
- final BeemService service) {
- this(new XMPPConnection(serviceName), login, password, service);
- }
+ private final XMPPConnection mAdaptee;
+ private IChatManager mChatManager;
+ private final String mLogin;
+ private final String mPassword;
+ private RosterAdapter mRoster;
+ private PrivacyListManagerAdapter mPrivacyList;
+ private final BeemService mService;
+ private final RemoteCallbackList<IBeemConnectionListener> mRemoteConnListeners = new RemoteCallbackList<IBeemConnectionListener>();
- /**
- * Constructor.
- * @param con The connection to adapt
- * @param login The login to use
- * @param password The password to use
- * @param service the background service associated with the connection.
- */
- public XmppConnectionAdapter(final XMPPConnection con, final String login, final String password,
- final BeemService service) {
- mAdaptee = con;
- PrivacyListManager.getInstanceFor(mAdaptee);
- mLogin = login;
- mPassword = password;
- mService = service;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
- if (listen != null)
- mRemoteConnListeners.register(listen);
- }
+ private final ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter();
- /**
- * {@inheritDoc}
- */
- @Override
- public final void connectAsync() throws RemoteException {
- Thread t = new Thread(new Runnable() {
-
- @Override
- public void run() {
- try {
- connectSync();
- } catch (RemoteException e) {
- Log.e(TAG, "Error while connecting asynchronously", e);
- }
- }
- });
- t.start();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean connectSync() throws RemoteException {
- try {
- mAdaptee.connect();
- mAdaptee.addConnectionListener(mConListener);
- mAdaptee.login(mLogin, mPassword, "BEEM");
-
- mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
- mPrivacyList = new PrivacyListManagerAdapter(mAdaptee);
-
- this.initFeatures(); // pour declarer les features xmpp qu'on
- // supporte
- ChatStateManager.getInstance(mAdaptee);
+ /**
+ * Constructor.
+ *
+ * @param config
+ * Configuration to use in order to connect
+ * @param login
+ * login to use on connect
+ * @param password
+ * password to use on connect
+ * @param service
+ * the background service associated with the connection.
+ */
+ public XmppConnectionAdapter(final ConnectionConfiguration config, final String login, final String password,
+ final BeemService service) {
+ this(new XMPPConnection(config), login, password, service);
+ }
- triggerAsynchronousConnectEvent();
- // Priority between -128 and 128
- Presence p = new Presence(Presence.Type.available, "Beem : http://www.beem-project.com", PRESENCE_PRIORITY,
- Presence.Mode.available);
- mAdaptee.sendPacket(p);
- return true;
- } catch (XMPPException e) {
- Log.d(TAG, "Error while connecting", e);
- if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null)
- mConListener.connectionFailed(e.getXMPPError().getMessage());
- else if (e.getMessage() != null)
- mConListener.connectionFailed(e.getMessage());
- else
- mConListener.connectionFailed("Error On Connection");
- } catch (IllegalStateException e) {
- mConListener.connectionFailed(e.getMessage());
+ /**
+ * Constructor.
+ *
+ * @param serviceName
+ * name of the service to connect to
+ * @param login
+ * login to use on connect
+ * @param password
+ * password to use on connect
+ * @param service
+ * the background service associated with the connection.
+ */
+ public XmppConnectionAdapter(final String serviceName, final String login, final String password,
+ final BeemService service) {
+ this(new XMPPConnection(serviceName), login, password, service);
}
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean disconnect() {
- if (mAdaptee != null && mAdaptee.isConnected())
- mAdaptee.disconnect();
- return true;
- }
-
- /**
- * Get the Smack XmppConnection.
- * @return Smack XmppConnection
- */
- public XMPPConnection getAdaptee() {
- return mAdaptee;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public IChatManager getChatManager() throws RemoteException {
- return mChatManager;
- }
-
- /**
- * Get the context of the adapter.
- * @return The context of the adapter
- */
- public BeemService getContext() {
- return mService;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public IRoster getRoster() throws RemoteException {
- if (mRoster != null)
- return mRoster;
- Roster adap = mAdaptee.getRoster();
- if (adap == null)
- return null;
- mRoster = new RosterAdapter(adap);
- return mRoster;
- }
-
- /**
- * enregistre les features dispo dans notre version Liste de features que Telepathy supporte.
- */
- private void initFeatures() {
- ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
- if (sdm == null)
- sdm = new ServiceDiscoveryManager(mAdaptee);
- sdm.addFeature("http://jabber.org/protocol/disco#info");
- JingleManager.setJingleServiceEnabled();
- sdm.addFeature("jabber:iq:privacy");
- }
-
- /**
- * Returns true if currently authenticated by successfully calling the login method.
- * @return true when successfully authenticated
- */
- public boolean isAuthentificated() {
- return mAdaptee.isAuthenticated();
- }
+ /**
+ * Constructor.
+ *
+ * @param con
+ * The connection to adapt
+ * @param login
+ * The login to use
+ * @param password
+ * The password to use
+ * @param service
+ * the background service associated with the connection.
+ */
+ public XmppConnectionAdapter(final XMPPConnection con, final String login, final String password,
+ final BeemService service) {
+ mAdaptee = con;
+ PrivacyListManager.getInstanceFor(mAdaptee);
+ mLogin = login;
+ mPassword = password;
+ mService = service;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
- if (listen != null)
- mRemoteConnListeners.unregister(listen);
- }
-
- /**
- * Trigger Connection event.
- */
- private void triggerAsynchronousConnectEvent() {
- mConListener.onConnect();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void addConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteConnListeners.register(listen);
+ }
- /**
- * Set the privacy list to use.
- * @param privacyList the mPrivacyList to set
- */
- public void setPrivacyList(PrivacyListManagerAdapter privacyList) {
- this.mPrivacyList = privacyList;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final void connectAsync() throws RemoteException {
+ Thread t = new Thread(new Runnable() {
- /**
- * Get the privacy list in use.
- * @return the mPrivacyList
- */
- public PrivacyListManagerAdapter getPrivacyList() {
- return mPrivacyList;
- }
-
- /**
- * Listener for XMPP connection events. It will calls the remote listeners for connection events.
- * @author darisk
- */
- private class ConnexionListenerAdapter implements ConnectionListener {
+ @Override
+ public void run() {
+ try {
+ connectSync();
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error while connecting asynchronously", e);
+ }
+ }
+ });
+ t.start();
+ }
/**
- * Defaut constructor.
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean connectSync() throws RemoteException {
+ try {
+ mAdaptee.connect();
+ mAdaptee.addConnectionListener(mConListener);
+ mAdaptee.login(mLogin, mPassword, "BEEM");
+
+ mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService);
+ mPrivacyList = new PrivacyListManagerAdapter(mAdaptee);
+
+ this.initFeatures(); // pour declarer les features xmpp qu'on
+ // supporte
+ ChatStateManager.getInstance(mAdaptee);
+
+ triggerAsynchronousConnectEvent();
+ // Priority between -128 and 128
+ Presence p = new Presence(Presence.Type.available, "Beem : http://www.beem-project.com", PRESENCE_PRIORITY,
+ Presence.Mode.available);
+ mAdaptee.sendPacket(p);
+ return true;
+ } catch (XMPPException e) {
+ Log.d(TAG, "Error while connecting", e);
+ if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null)
+ mConListener.connectionFailed(e.getXMPPError().getMessage());
+ else if (e.getMessage() != null)
+ mConListener.connectionFailed(e.getMessage());
+ else
+ mConListener.connectionFailed("Error On Connection");
+ } catch (IllegalStateException e) {
+ mConListener.connectionFailed(e.getMessage());
+ }
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean disconnect() {
+ if (mAdaptee != null && mAdaptee.isConnected())
+ mAdaptee.disconnect();
+ return true;
+ }
+
+ /**
+ * Get the Smack XmppConnection.
+ *
+ * @return Smack XmppConnection
*/
- public ConnexionListenerAdapter() {
+ public XMPPConnection getAdaptee() {
+ return mAdaptee;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IChatManager getChatManager() throws RemoteException {
+ return mChatManager;
+ }
+
+ /**
+ * Get the context of the adapter.
+ *
+ * @return The context of the adapter
+ */
+ public BeemService getContext() {
+ return mService;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IRoster getRoster() throws RemoteException {
+ if (mRoster != null)
+ return mRoster;
+ Roster adap = mAdaptee.getRoster();
+ if (adap == null)
+ return null;
+ mRoster = new RosterAdapter(adap, mService.getApplicationContext());
+ return mRoster;
+ }
+
+ /**
+ * enregistre les features dispo dans notre version Liste de features que
+ * Telepathy supporte.
+ */
+ private void initFeatures() {
+ ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mAdaptee);
+ if (sdm == null)
+ sdm = new ServiceDiscoveryManager(mAdaptee);
+ sdm.addFeature("http://jabber.org/protocol/disco#info");
+ JingleManager.setJingleServiceEnabled();
+ sdm.addFeature("jabber:iq:privacy");
+ }
+
+ /**
+ * Returns true if currently authenticated by successfully calling the login
+ * method.
+ *
+ * @return true when successfully authenticated
+ */
+ public boolean isAuthentificated() {
+ return mAdaptee.isAuthenticated();
}
/**
* {@inheritDoc}
*/
@Override
- public void connectionClosed() {
- Log.d(TAG, "closing connection");
- mRoster = null;
- Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
- intent.putExtra("message", mService.getString(R.string.BeemBroadcastReceiverDisconnect));
- intent.putExtra("normally", true);
- mService.sendBroadcast(intent);
- mService.stopSelf();
+ public void removeConnectionListener(IBeemConnectionListener listen) throws RemoteException {
+ if (listen != null)
+ mRemoteConnListeners.unregister(listen);
+ }
+
+ /**
+ * Trigger Connection event.
+ */
+ private void triggerAsynchronousConnectEvent() {
+ mConListener.onConnect();
}
/**
- * {@inheritDoc}
+ * Set the privacy list to use.
+ *
+ * @param privacyList
+ * the mPrivacyList to set
*/
- @Override
- public void connectionClosedOnError(Exception exception) {
- Log.d(TAG, "connectionClosedOnError");
- mRoster = null;
- Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
- intent.putExtra("message", exception.getMessage());
- mService.sendBroadcast(intent);
- mService.stopSelf();
+ public void setPrivacyList(PrivacyListManagerAdapter privacyList) {
+ this.mPrivacyList = privacyList;
}
/**
- * Connection failed callback.
- * @param errorMsg smack failure message
+ * Get the privacy list in use.
+ *
+ * @return the mPrivacyList
*/
- public void connectionFailed(String errorMsg) {
- Log.d(TAG, "Connection Failed");
- final int n = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- if (listener != null)
- listener.connectionFailed(errorMsg);
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
- }
- }
- mRemoteConnListeners.finishBroadcast();
- mService.stopSelf();
+ public PrivacyListManagerAdapter getPrivacyList() {
+ return mPrivacyList;
}
/**
- * Method to execute when a connection event occurs.
+ * Listener for XMPP connection events. It will calls the remote listeners
+ * for connection events.
+ *
+ * @author darisk
*/
- public void onConnect() {
- PacketFilter filter = new PacketFilter() {
+ private class ConnexionListenerAdapter implements ConnectionListener {
+ /**
+ * Defaut constructor.
+ */
+ public ConnexionListenerAdapter() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
- public boolean accept(Packet packet) {
- if (packet instanceof Presence) {
- Presence pres = (Presence) packet;
- if (pres.getType() == Presence.Type.subscribe)
- return true;
- }
- return false;
+ public void connectionClosed() {
+ Log.d(TAG, "closing connection");
+ mRoster = null;
+ Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
+ intent.putExtra("message", mService.getString(R.string.BeemBroadcastReceiverDisconnect));
+ intent.putExtra("normally", true);
+ mService.sendBroadcast(intent);
+ mService.stopSelf();
}
- };
- mAdaptee.addPacketListener(new PacketListener() {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void connectionClosedOnError(Exception exception) {
+ Log.d(TAG, "connectionClosedOnError");
+ mRoster = null;
+ Intent intent = new Intent(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED);
+ intent.putExtra("message", exception.getMessage());
+ mService.sendBroadcast(intent);
+ mService.stopSelf();
+ }
+
+ /**
+ * Connection failed callback.
+ *
+ * @param errorMsg
+ * smack failure message
+ */
+ public void connectionFailed(String errorMsg) {
+ Log.d(TAG, "Connection Failed");
+ final int n = mRemoteConnListeners.beginBroadcast();
- @Override
- public void processPacket(Packet packet) {
- String from = packet.getFrom();
- Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
- .getString(R.string.AcceptContactRequest), System.currentTimeMillis());
- notif.defaults = Notification.DEFAULT_ALL;
- notif.flags = Notification.FLAG_AUTO_CANCEL;
- Intent intent = new Intent(mService, Subscription.class);
- intent.putExtra("from", from);
- notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
- + from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
- int id = packet.hashCode();
- mService.sendNotification(id, notif);
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ if (listener != null)
+ listener.connectionFailed(errorMsg);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ mService.stopSelf();
}
- }, filter);
+
+ /**
+ * Method to execute when a connection event occurs.
+ */
+ public void onConnect() {
+ PacketFilter filter = new PacketFilter() {
+
+ @Override
+ public boolean accept(Packet packet) {
+ if (packet instanceof Presence) {
+ Presence pres = (Presence) packet;
+ if (pres.getType() == Presence.Type.subscribe)
+ return true;
+ }
+ return false;
+ }
+ };
+
+ mAdaptee.addPacketListener(new PacketListener() {
- mService.resetStatus();
- mService.initJingle(mAdaptee);
+ @Override
+ public void processPacket(Packet packet) {
+ String from = packet.getFrom();
+ Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
+ .getString(R.string.AcceptContactRequest), System.currentTimeMillis());
+ notif.defaults = Notification.DEFAULT_ALL;
+ notif.flags = Notification.FLAG_AUTO_CANCEL;
+ Intent intent = new Intent(mService, Subscription.class);
+ intent.putExtra("from", from);
+ notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
+ + from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+ int id = packet.hashCode();
+ mService.sendNotification(id, notif);
+ }
+ }, filter);
+
+ mService.resetStatus();
+ mService.initJingle(mAdaptee);
+
+ final int n = mRemoteConnListeners.beginBroadcast();
- final int n = mRemoteConnListeners.beginBroadcast();
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ if (listener != null)
+ listener.onConnect();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reconnectingIn(int arg0) {
+ Log.d(TAG, "reconnectingIn");
+ final int n = mRemoteConnListeners.beginBroadcast();
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- if (listener != null)
- listener.onConnect();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ if (listener != null)
+ listener.reconnectingIn(arg0);
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
}
- }
- mRemoteConnListeners.finishBroadcast();
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reconnectionFailed(Exception arg0) {
+ Log.d(TAG, "reconnectionFailed");
+ final int r = mRemoteConnListeners.beginBroadcast();
- /**
- * {@inheritDoc}
- */
- @Override
- public void reconnectingIn(int arg0) {
- Log.d(TAG, "reconnectingIn");
- final int n = mRemoteConnListeners.beginBroadcast();
+ for (int i = 0; i < r; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ if (listener != null)
+ listener.reconnectionFailed();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void reconnectionSuccessful() {
+ Log.d(TAG, "reconnectionSuccessful");
+ PacketFilter filter = new PacketFilter() {
+
+ @Override
+ public boolean accept(Packet packet) {
+ if (packet instanceof Presence) {
+ Presence pres = (Presence) packet;
+ if (pres.getType() == Presence.Type.subscribe)
+ return true;
+ }
+ return false;
+ }
+ };
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- if (listener != null)
- listener.reconnectingIn(arg0);
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
+ mAdaptee.addPacketListener(new PacketListener() {
+
+ @Override
+ public void processPacket(Packet packet) {
+ String from = packet.getFrom();
+ Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
+ .getString(R.string.AcceptContactRequest), System.currentTimeMillis());
+ notif.defaults = Notification.DEFAULT_ALL;
+ notif.flags = Notification.FLAG_AUTO_CANCEL;
+ Intent intent = new Intent(mService, Subscription.class);
+ intent.putExtra("from", from);
+ notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
+ + from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
+ int id = packet.hashCode();
+ mService.sendNotification(id, notif);
+ }
+ }, filter);
+
+ final int n = mRemoteConnListeners.beginBroadcast();
+
+ for (int i = 0; i < n; i++) {
+ IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
+ try {
+ if (listener != null)
+ listener.reconnectionSuccessful();
+ } catch (RemoteException e) {
+ // The RemoteCallbackList will take care of removing the
+ // dead listeners.
+ Log.w(TAG, "Error while triggering remote connection listeners", e);
+ }
+ }
+ mRemoteConnListeners.finishBroadcast();
}
- }
- mRemoteConnListeners.finishBroadcast();
}
- /**
- * {@inheritDoc}
- */
- @Override
- public void reconnectionFailed(Exception arg0) {
- Log.d(TAG, "reconnectionFailed");
- final int r = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < r; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- if (listener != null)
- listener.reconnectionFailed();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
- }
- }
- mRemoteConnListeners.finishBroadcast();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void reconnectionSuccessful() {
- Log.d(TAG, "reconnectionSuccessful");
- PacketFilter filter = new PacketFilter() {
-
- @Override
- public boolean accept(Packet packet) {
- if (packet instanceof Presence) {
- Presence pres = (Presence) packet;
- if (pres.getType() == Presence.Type.subscribe)
- return true;
- }
- return false;
- }
- };
-
- mAdaptee.addPacketListener(new PacketListener() {
-
- @Override
- public void processPacket(Packet packet) {
- String from = packet.getFrom();
- Notification notif = new Notification(com.beem.project.beem.R.drawable.signal, mService
- .getString(R.string.AcceptContactRequest), System.currentTimeMillis());
- notif.defaults = Notification.DEFAULT_ALL;
- notif.flags = Notification.FLAG_AUTO_CANCEL;
- Intent intent = new Intent(mService, Subscription.class);
- intent.putExtra("from", from);
- notif.setLatestEventInfo(mService, from, mService.getString(R.string.AcceptContactRequestFrom)
- + from, PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT));
- int id = packet.hashCode();
- mService.sendNotification(id, notif);
- }
- }, filter);
-
- final int n = mRemoteConnListeners.beginBroadcast();
-
- for (int i = 0; i < n; i++) {
- IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i);
- try {
- if (listener != null)
- listener.reconnectionSuccessful();
- } catch (RemoteException e) {
- // The RemoteCallbackList will take care of removing the
- // dead listeners.
- Log.w(TAG, "Error while triggering remote connection listeners", e);
- }
- }
- mRemoteConnListeners.finishBroadcast();
- }
- }
-
}
--- a/src/com/beem/project/beem/service/XmppFacade.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppFacade.java Wed Nov 11 19:21:44 2009 +0100
@@ -21,128 +21,133 @@
/**
* This class is a facade for the Beem Service.
+ *
* @author darisk
*/
public class XmppFacade extends IXmppFacade.Stub {
- private XmppConnectionAdapter mConnexion;
- private BeemService mBeemService;
- private JingleService mJingle;
+ private XmppConnectionAdapter mConnexion;
+ private BeemService mBeemService;
+ private JingleService mJingle;
- /**
- * Constructor for XMPPFacade.
- * @param connection the connection use by the facade
- * @param service the service which holds the facade
- * @param jingle the jingle session
- */
- public XmppFacade(final XmppConnectionAdapter connection, final BeemService service, final JingleService jingle) {
- this.mConnexion = connection;
- this.mBeemService = service;
- this.mJingle = jingle;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void changeStatus(int status, String msg) {
- Presence pres = new Presence(Presence.Type.available);
- if (msg != null)
- pres.setStatus(msg);
- Presence.Mode mode = Status.getPresenceModeFromStatus(status);
- if (mode != null)
- pres.setMode(mode);
- mConnexion.getAdaptee().sendPacket(pres);
+ /**
+ * Constructor for XMPPFacade.
+ *
+ * @param connection
+ * the connection use by the facade
+ * @param service
+ * the service which holds the facade
+ * @param jingle
+ * the jingle session
+ */
+ public XmppFacade(final XmppConnectionAdapter connection, final BeemService service, final JingleService jingle) {
+ this.mConnexion = connection;
+ this.mBeemService = service;
+ this.mJingle = jingle;
+ }
- Notification mStatusNotification;
- String text = "";
- if (msg != null)
- text = msg;
- mStatusNotification = new Notification(com.beem.project.beem.R.drawable.beem_status_icon, text, System
- .currentTimeMillis());
- mStatusNotification.defaults = Notification.DEFAULT_ALL;
- mStatusNotification.flags = Notification.FLAG_NO_CLEAR;
-
- mStatusNotification.setLatestEventInfo(mBeemService, "Beem Status", text, PendingIntent.getActivity(
- mBeemService, 0, new Intent(mBeemService, ChangeStatus.class), 0));
- mBeemService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void changeStatus(int status, String msg) {
+ Presence pres = new Presence(Presence.Type.available);
+ if (msg != null)
+ pres.setStatus(msg);
+ Presence.Mode mode = Status.getPresenceModeFromStatus(status);
+ if (mode != null)
+ pres.setMode(mode);
+ mConnexion.getAdaptee().sendPacket(pres);
- /**
- * {@inheritDoc}
- */
- @Override
- public void connectAsync() throws RemoteException {
- mConnexion.connectAsync();
- }
+ Notification mStatusNotification;
+ String text = "";
+ if (msg != null)
+ text = msg;
+ mStatusNotification = new Notification(com.beem.project.beem.R.drawable.beem_status_icon, text, System
+ .currentTimeMillis());
+ mStatusNotification.defaults = Notification.DEFAULT_ALL;
+ mStatusNotification.flags = Notification.FLAG_NO_CLEAR;
+
+ mStatusNotification.setLatestEventInfo(mBeemService, "Beem Status", text, PendingIntent.getActivity(
+ mBeemService, 0, new Intent(mBeemService, ChangeStatus.class), 0));
+ mBeemService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification);
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void connectSync() throws RemoteException {
- mConnexion.connectSync();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void connectAsync() throws RemoteException {
+ mConnexion.connectAsync();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void connectSync() throws RemoteException {
+ mConnexion.connectSync();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public IXmppConnection createConnection() throws RemoteException {
- return mConnexion;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IXmppConnection createConnection() throws RemoteException {
+ return mConnexion;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void disconnect() throws RemoteException {
- mConnexion.disconnect();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void disconnect() throws RemoteException {
+ mConnexion.disconnect();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public IChatManager getChatManager() throws RemoteException {
- return mConnexion.getChatManager();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IChatManager getChatManager() throws RemoteException {
+ return mConnexion.getChatManager();
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public IRoster getRoster() throws RemoteException {
- return mConnexion.getRoster();
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public IRoster getRoster() throws RemoteException {
+ return mConnexion.getRoster();
+ }
- @Override
- public void sendPresencePacket(PresenceAdapter presence) throws RemoteException {
- Presence presence2 = new Presence(PresenceType.getPresenceTypeFrom(presence.getType()));
- presence2.setTo(presence.getTo());
- mConnexion.getAdaptee().sendPacket(presence2);
- }
+ @Override
+ public void sendPresencePacket(PresenceAdapter presence) throws RemoteException {
+ Presence presence2 = new Presence(PresenceType.getPresenceTypeFrom(presence.getType()));
+ presence2.setTo(presence.getTo());
+ mConnexion.getAdaptee().sendPacket(presence2);
+ }
- @Override
- public void blockUser(String jid) throws RemoteException {
- mConnexion.getPrivacyList().addBlockedUser(jid);
- }
+ @Override
+ public void blockUser(String jid) throws RemoteException {
+ mConnexion.getPrivacyList().addBlockedUser(jid);
+ }
- @Override
- public void call(String jid) throws RemoteException {
- mJingle.call(jid);
- }
+ @Override
+ public void call(String jid) throws RemoteException {
+ mJingle.call(jid);
+ }
- @Override
- public byte[] getVcardAvatar(String jid) throws RemoteException {
- VCard vcard = new VCard();
+ @Override
+ public byte[] getVcardAvatar(String jid) throws RemoteException {
+ VCard vcard = new VCard();
- try {
- vcard.load(mConnexion.getAdaptee(), jid);
- return vcard.getAvatar();
- } catch (XMPPException e) {
- e.printStackTrace();
+ try {
+ vcard.load(mConnexion.getAdaptee(), jid);
+ return vcard.getAvatar();
+ } catch (XMPPException e) {
+ e.printStackTrace();
+ }
+ return null;
}
- return null;
- }
}
--- a/src/com/beem/project/beem/ui/AddContact.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/AddContact.java Wed Nov 11 19:21:44 2009 +0100
@@ -26,151 +26,153 @@
/**
* This activity is used to add a contact.
+ *
* @author nikita
*/
public class AddContact extends Activity {
- private static final Intent SERVICE_INTENT = new Intent();
- private static final String TAG = "AddContact";
- private final List<String> mGroup = new ArrayList<String>();
- private IXmppFacade mXmppFacade;
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private BeemBroadcastReceiver mReceiver;
-
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- /**
- * Constructor.
- */
- public AddContact() {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.addcontact);
- Button ok = (Button) findViewById(R.id.addc_ok);
- ok.setOnClickListener(mOkListener);
- mReceiver = new BeemBroadcastReceiver(mServConn);
- }
+ private static final Intent SERVICE_INTENT = new Intent();
+ private static final String TAG = "AddContact";
+ private final List<String> mGroup = new ArrayList<String>();
+ private IXmppFacade mXmppFacade;
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private BeemBroadcastReceiver mReceiver;
- @Override
- protected void onStart() {
- super.onStart();
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded(true);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- if (mReceiver.isBinded()) {
- unbindService(mServConn);
- mReceiver.setBinded(false);
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * The ServiceConnection used to connect to the Beem service.
- */
- private class BeemServiceConnection implements ServiceConnection {
/**
* Constructor.
*/
- public BeemServiceConnection() {
+ public AddContact() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.addcontact);
+ Button ok = (Button) findViewById(R.id.addc_ok);
+ ok.setOnClickListener(mOkListener);
+ mReceiver = new BeemBroadcastReceiver(mServConn);
}
@Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- mReceiver.setBinded(true);
+ protected void onStart() {
+ super.onStart();
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mReceiver.setBinded(true);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (mReceiver.isBinded()) {
+ unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
@Override
- public void onServiceDisconnected(ComponentName name) {
- mXmppFacade = null;
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
- }
+
+ /**
+ * The ServiceConnection used to connect to the Beem service.
+ */
+ private class BeemServiceConnection implements ServiceConnection {
+
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
- /**
- * Get the text of a widget.
- * @param id the id of the widget.
- * @return the text of the widget.
- */
- private String getWidgetText(int id) {
- EditText widget = (EditText) this.findViewById(id);
- return widget.getText().toString();
- }
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mXmppFacade = null;
+ }
+ }
- private final OnClickListener mOkListener = new OnClickListener() {
+ /**
+ * Get the text of a widget.
+ *
+ * @param id
+ * the id of the widget.
+ * @return the text of the widget.
+ */
+ private String getWidgetText(int id) {
+ EditText widget = (EditText) this.findViewById(id);
+ return widget.getText().toString();
+ }
+
+ private final OnClickListener mOkListener = new OnClickListener() {
- public void onClick(View v) {
- String login;
- login = getWidgetText(R.id.addc_login);
- if (login.length() == 0) {
- Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
- return;
- }
- boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login);
- if (!isEmail) {
- Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT)
- .show();
- return;
- }
- String alias;
- alias = getWidgetText(R.id.addc_alias);
- if (getWidgetText(R.id.addc_group).length() != 0)
- mGroup.add(getWidgetText(R.id.addc_group));
- try {
- if (mXmppFacade != null) {
- if (mXmppFacade.getRoster().getContact(login) != null)
- mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups());
- if (mXmppFacade.getRoster().getContact(login) != null) {
- Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT)
- .show();
- return;
- }
- if (mXmppFacade.getRoster()
- .addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) {
- Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT)
- .show();
- return;
- } else {
- Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT)
- .show();
- finish();
- }
+ public void onClick(View v) {
+ String login;
+ login = getWidgetText(R.id.addc_login);
+ if (login.length() == 0) {
+ Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show();
+ return;
+ }
+ boolean isEmail = Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", login);
+ if (!isEmail) {
+ Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedLoginError), Toast.LENGTH_SHORT)
+ .show();
+ return;
+ }
+ String alias;
+ alias = getWidgetText(R.id.addc_alias);
+ if (getWidgetText(R.id.addc_group).length() != 0)
+ mGroup.add(getWidgetText(R.id.addc_group));
+ try {
+ if (mXmppFacade != null) {
+ if (mXmppFacade.getRoster().getContact(login) != null)
+ mGroup.addAll(mXmppFacade.getRoster().getContact(login).getGroups());
+ if (mXmppFacade.getRoster().getContact(login) != null) {
+ Toast.makeText(AddContact.this, getString(R.string.AddCContactAlready), Toast.LENGTH_SHORT)
+ .show();
+ return;
+ }
+ if (mXmppFacade.getRoster().addContact(login, alias, mGroup.toArray(new String[mGroup.size()])) == null) {
+ Toast.makeText(AddContact.this, getString(R.string.AddCContactAddedError), Toast.LENGTH_SHORT)
+ .show();
+ return;
+ } else {
+ Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT)
+ .show();
+ finish();
+ }
+ }
+ } catch (RemoteException e) {
+ Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show();
+ Log.e(TAG, "Problem adding contact", e);
+ }
+
}
- } catch (RemoteException e) {
- Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show();
- Log.e(TAG, "Problem adding contact", e);
- }
-
- }
- };
+ };
}
--- a/src/com/beem/project/beem/ui/ChangeStatus.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/ChangeStatus.java Wed Nov 11 19:21:44 2009 +0100
@@ -28,203 +28,211 @@
/**
* This Activity is used to change the status.
+ *
* @author nikita
*/
public class ChangeStatus extends Activity {
- private static final Intent SERVICE_INTENT = new Intent();
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- private static final int AVAILABLE_FOR_CHAT_IDX = 0;
- private static final int AVAILABLE_IDX = 1;
- private static final int BUSY_IDX = 2;
- private static final int AWAY_IDX = 3;
- private static final int UNAVAILABLE_IDX = 4;
- private static final int DISCONNECTED_IDX = 5;
- private TextView mStatusText;
- private Toast mToast;
- private Button mOk;
- private Button mClear;
- private Spinner mSpinner;
-
- private SharedPreferences mSettings;
- private ArrayAdapter<CharSequence> mAdapter;
- private IXmppFacade mXmppFacade;
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private final OnClickListener mOnClickOk = new MyOnClickListener();
- private BeemBroadcastReceiver mReceiver;
-
- /**
- * Constructor.
- */
- public ChangeStatus() {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.changestatus);
- mStatusText = (TextView) findViewById(R.id.ChangeStatusText);
- mOk = (Button) findViewById(R.id.ChangeStatusOk);
- mClear = (Button) findViewById(R.id.ChangeStatusClear);
- mOk.setOnClickListener(mOnClickOk);
- mClear.setOnClickListener(mOnClickOk);
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-
- mSpinner = (Spinner) findViewById(R.id.ChangeStatusSpinner);
- mAdapter = ArrayAdapter.createFromResource(this, R.array.status_types, android.R.layout.simple_spinner_item);
- mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- mSpinner.setAdapter(mAdapter);
- mToast = Toast.makeText(this, R.string.ChangeStatusOk, Toast.LENGTH_LONG);
- mReceiver = new BeemBroadcastReceiver(mServConn);
- mStatusText.setText(getPreferenceString(R.string.PreferenceStatusText));
- mSpinner.setSelection(getPreferenceStatusIndex());
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded(true);
- }
+ private static final Intent SERVICE_INTENT = new Intent();
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- Log.d("TAG", "pause");
- if (mReceiver.isBinded()) {
- unbindService(mServConn);
- mReceiver.setBinded(false);
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * Return the status index from status the settings.
- * @return the status index from status the settings.
- */
- private int getPreferenceStatusIndex() {
- return mSettings.getInt(getString(R.string.PreferenceStatus), 0);
- }
+ private static final int AVAILABLE_FOR_CHAT_IDX = 0;
+ private static final int AVAILABLE_IDX = 1;
+ private static final int BUSY_IDX = 2;
+ private static final int AWAY_IDX = 3;
+ private static final int UNAVAILABLE_IDX = 4;
+ private static final int DISCONNECTED_IDX = 5;
+ private TextView mStatusText;
+ private Toast mToast;
+ private Button mOk;
+ private Button mClear;
+ private Spinner mSpinner;
- /**
- * Return the status text from status the settings.
- * @param id status text id.
- * @return the status text from status the settings.
- */
- private String getPreferenceString(int id) {
- return mSettings.getString(getString(id), "");
- }
+ private SharedPreferences mSettings;
+ private ArrayAdapter<CharSequence> mAdapter;
+ private IXmppFacade mXmppFacade;
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private final OnClickListener mOnClickOk = new MyOnClickListener();
+ private BeemBroadcastReceiver mReceiver;
- /**
- * convert status text to.
- * @param item selected item text.
- * @return item position in the array.
- */
- private int getStatusForService(String item) {
- switch (mAdapter.getPosition(item)) {
- case ChangeStatus.DISCONNECTED_IDX:
- return Status.CONTACT_STATUS_DISCONNECT;
- case ChangeStatus.AVAILABLE_FOR_CHAT_IDX:
- return Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
- case ChangeStatus.AVAILABLE_IDX:
- return Status.CONTACT_STATUS_AVAILABLE;
- case ChangeStatus.AWAY_IDX:
- return Status.CONTACT_STATUS_AWAY;
- case ChangeStatus.BUSY_IDX:
- return Status.CONTACT_STATUS_BUSY;
- case ChangeStatus.UNAVAILABLE_IDX:
- return Status.CONTACT_STATUS_UNAVAILABLE;
- default:
- return Status.CONTACT_STATUS_AVAILABLE;
+ /**
+ * Constructor.
+ */
+ public ChangeStatus() {
}
- }
-
- /**
- * connection to service.
- * @author nikita
- */
- private class BeemServiceConnection implements ServiceConnection {
/**
- * constructor.
+ * {@inheritDoc}
*/
- public BeemServiceConnection() {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.changestatus);
+ mStatusText = (TextView) findViewById(R.id.ChangeStatusText);
+ mOk = (Button) findViewById(R.id.ChangeStatusOk);
+ mClear = (Button) findViewById(R.id.ChangeStatusClear);
+ mOk.setOnClickListener(mOnClickOk);
+ mClear.setOnClickListener(mOnClickOk);
+ mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+
+ mSpinner = (Spinner) findViewById(R.id.ChangeStatusSpinner);
+ mAdapter = ArrayAdapter.createFromResource(this, R.array.status_types, android.R.layout.simple_spinner_item);
+ mAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
+ mSpinner.setAdapter(mAdapter);
+ mToast = Toast.makeText(this, R.string.ChangeStatusOk, Toast.LENGTH_LONG);
+ mReceiver = new BeemBroadcastReceiver(mServConn);
+ mStatusText.setText(getPreferenceString(R.string.PreferenceStatusText));
+ mSpinner.setSelection(getPreferenceStatusIndex());
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mReceiver.setBinded(true);
}
/**
* {@inheritDoc}
*/
@Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mXmppFacade = null;
- }
- }
-
- /**
- * User have clicked on ok.
- * @author nikita
- */
- private class MyOnClickListener implements OnClickListener {
-
- /**
- * constructor.
- */
- public MyOnClickListener() {
+ protected void onPause() {
+ super.onPause();
+ Log.d("TAG", "pause");
+ if (mReceiver.isBinded()) {
+ unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
@Override
- public void onClick(View v) {
- if (v == mOk) {
- if (!mStatusText.getText().toString().equals(getPreferenceString(R.string.PreferenceStatusText))
- || getPreferenceStatusIndex() != mSpinner.getSelectedItemPosition()) {
- String msg = mStatusText.getText().toString();
- int status = getStatusForService((String) mSpinner.getSelectedItem());
- Editor edit = mSettings.edit();
- edit.putString(getString(R.string.PreferenceStatusText), msg);
- edit.putInt(getString(R.string.PreferenceStatus), mSpinner.getSelectedItemPosition());
- edit.commit();
- if (status == Status.CONTACT_STATUS_DISCONNECT) {
- stopService(new Intent(ChangeStatus.this, BeemService.class));
- } else {
- try {
- mXmppFacade.changeStatus(status, msg.toString());
- } catch (RemoteException e) {
- e.printStackTrace();
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
+ }
+
+ /**
+ * Return the status index from status the settings.
+ *
+ * @return the status index from status the settings.
+ */
+ private int getPreferenceStatusIndex() {
+ return mSettings.getInt(getString(R.string.PreferenceStatus), 0);
+ }
+
+ /**
+ * Return the status text from status the settings.
+ *
+ * @param id
+ * status text id.
+ * @return the status text from status the settings.
+ */
+ private String getPreferenceString(int id) {
+ return mSettings.getString(getString(id), "");
+ }
+
+ /**
+ * convert status text to.
+ *
+ * @param item
+ * selected item text.
+ * @return item position in the array.
+ */
+ private int getStatusForService(String item) {
+ switch (mAdapter.getPosition(item)) {
+ case ChangeStatus.DISCONNECTED_IDX:
+ return Status.CONTACT_STATUS_DISCONNECT;
+ case ChangeStatus.AVAILABLE_FOR_CHAT_IDX:
+ return Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+ case ChangeStatus.AVAILABLE_IDX:
+ return Status.CONTACT_STATUS_AVAILABLE;
+ case ChangeStatus.AWAY_IDX:
+ return Status.CONTACT_STATUS_AWAY;
+ case ChangeStatus.BUSY_IDX:
+ return Status.CONTACT_STATUS_BUSY;
+ case ChangeStatus.UNAVAILABLE_IDX:
+ return Status.CONTACT_STATUS_UNAVAILABLE;
+ default:
+ return Status.CONTACT_STATUS_AVAILABLE;
+ }
+ }
+
+ /**
+ * connection to service.
+ *
+ * @author nikita
+ */
+ private class BeemServiceConnection implements ServiceConnection {
+
+ /**
+ * constructor.
+ */
+ public BeemServiceConnection() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mXmppFacade = null;
+ }
+ }
+
+ /**
+ * User have clicked on ok.
+ *
+ * @author nikita
+ */
+ private class MyOnClickListener implements OnClickListener {
+
+ /**
+ * constructor.
+ */
+ public MyOnClickListener() {
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mOk) {
+ if (!mStatusText.getText().toString().equals(getPreferenceString(R.string.PreferenceStatusText))
+ || getPreferenceStatusIndex() != mSpinner.getSelectedItemPosition()) {
+ String msg = mStatusText.getText().toString();
+ int status = getStatusForService((String) mSpinner.getSelectedItem());
+ Editor edit = mSettings.edit();
+ edit.putString(getString(R.string.PreferenceStatusText), msg);
+ edit.putInt(getString(R.string.PreferenceStatus), mSpinner.getSelectedItemPosition());
+ edit.commit();
+ if (status == Status.CONTACT_STATUS_DISCONNECT) {
+ stopService(new Intent(ChangeStatus.this, BeemService.class));
+ } else {
+ try {
+ mXmppFacade.changeStatus(status, msg.toString());
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ mToast.show();
+ }
+ }
+ ChangeStatus.this.finish();
+ } else if (v == mClear) {
+ mStatusText.setText(null);
}
- mToast.show();
- }
}
- ChangeStatus.this.finish();
- } else if (v == mClear) {
- mStatusText.setText(null);
- }
}
- }
}
--- a/src/com/beem/project/beem/ui/Chat.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/Chat.java Wed Nov 11 19:21:44 2009 +0100
@@ -56,8 +56,6 @@
static {
SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- private Map<Integer, String> mDefaultStatusMessages;
-
private Handler mHandler = new Handler();
private IRoster mRoster;
@@ -116,7 +114,6 @@
mInputField = (EditText) findViewById(R.id.chat_input);
mInputField.setOnKeyListener(this);
- mDefaultStatusMessages = createDefaultStatusMessagesMap();
prepareIconsStatus();
Log.v(TAG, "END onCreate.");
@@ -234,18 +231,16 @@
mChatManager.deleteChatNotification(mChat);
mContact = mRoster.getContact(contact.getJID());
- if (mContact.getMsgState() == null || mContact.getMsgState().equals(""))
- mContact.setMsgState(mDefaultStatusMessages.get(mContact.getStatus()));
updateContactInformations();
updateContactStatusIcon();
-
+
playRegisteredTranscript();
Log.v(TAG, "END changeCurrentChat.");
}
-
+
/**
- * Get all messages from the current chat and refresh
- * the activity with them.
+ * Get all messages from the current chat and refresh the activity with
+ * them.
*
* @throws RemoteException
*/
@@ -253,7 +248,7 @@
String fromBareJid = null;
String fromName = null;
List<Message> chatMessages = mChat.getMessages();
-
+
Log.v(TAG, "BEGIN playRegisteredTranscript.");
mListMessages.clear();
if (chatMessages.size() > 0) {
@@ -261,7 +256,7 @@
for (Message m : chatMessages) {
fromBareJid = StringUtils.parseBareAddress(m.getFrom());
fromName = mContact.getName();
-
+
if (fromBareJid == null) {
fromBareJid = getString(R.string.chat_self);
fromName = getString(R.string.chat_self);
@@ -275,8 +270,7 @@
if (!lastMessage.getBareJid().equals(fromBareJid)) {
mListMessages.add(lastMessage);
lastMessage = new MessageText(fromBareJid, fromName, m.getBody());
- }
- else
+ } else
lastMessage.setMessage(lastMessage.getMessage().concat("\n" + m.getBody()));
}
mListMessages.add(lastMessage);
@@ -385,10 +379,7 @@
@Override
public void run() {
mContact.setStatus(presence.getStatus());
- if (presence.getStatusText() == null)
- mContact.setMsgState(mDefaultStatusMessages.get(presence.getStatus()));
- else
- mContact.setMsgState(presence.getStatusText());
+ mContact.setMsgState(presence.getStatusText());
updateContactInformations();
updateContactStatusIcon();
@@ -595,10 +586,12 @@
return mMessage;
}
+ @SuppressWarnings("unused")
public void setBareJid(String bareJid) {
mBareJid = bareJid;
}
+ @SuppressWarnings("unused")
public void setName(String name) {
mName = name;
}
@@ -699,22 +692,4 @@
}
Log.v(TAG, "END sendMessage.");
}
-
- /**
- * Create a map which contains default status messages.
- *
- * @return
- */
- private Map<Integer, String> createDefaultStatusMessagesMap() {
- Map<Integer, String> defaultStatusMessages = new HashMap<Integer, String>();
- defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE, getString(R.string.contact_status_msg_available));
- defaultStatusMessages.put(Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT,
- getString(R.string.contact_status_msg_available_chat));
- defaultStatusMessages.put(Status.CONTACT_STATUS_AWAY, getString(R.string.contact_status_msg_away));
- defaultStatusMessages.put(Status.CONTACT_STATUS_BUSY, getString(R.string.contact_status_msg_dnd));
- defaultStatusMessages.put(Status.CONTACT_STATUS_DISCONNECT, getString(R.string.contact_status_msg_offline));
- defaultStatusMessages.put(Status.CONTACT_STATUS_UNAVAILABLE, getString(R.string.contact_status_msg_xa));
-
- return (defaultStatusMessages);
- }
}
--- a/src/com/beem/project/beem/ui/ContactDialog.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactDialog.java Wed Nov 11 19:21:44 2009 +0100
@@ -18,137 +18,142 @@
import com.beem.project.beem.service.aidl.IXmppFacade;
/**
- * This activity class provides the view to show dialog when long click on contact list.
+ * This activity class provides the view to show dialog when long click on
+ * contact list.
+ *
* @author marseille
*/
public class ContactDialog extends Dialog {
- private static final Intent SERVICE_INTENT = new Intent();
- private final Contact mContact;
- private final Context mContext;
- private IXmppFacade mXmppFacade;
- private final ServiceConnection mServConn = new BeemServiceConnection();
-
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- /**
- * Constructor.
- * @param context context where is call the dialog.
- * @param curContact current contact.
- */
- public ContactDialog(final Context context, final Contact curContact) {
- super(context);
- mContext = context;
+ private static final Intent SERVICE_INTENT = new Intent();
+ private final Contact mContact;
+ private final Context mContext;
+ private IXmppFacade mXmppFacade;
+ private final ServiceConnection mServConn = new BeemServiceConnection();
- setContentView(R.layout.contactdialog);
- mContact = curContact;
- setTitle(curContact.getJID());
-
- Button button = (Button) findViewById(R.id.CDChat);
- button.setOnClickListener(new ChatListener());
- button = (Button) findViewById(R.id.CDInfos);
- button.setOnClickListener(new InfosListener());
- button = (Button) findViewById(R.id.CDCall);
- button.setOnClickListener(new CallListener());
- mContext.bindService(SERVICE_INTENT, mServConn, Service.BIND_AUTO_CREATE);
- }
-
- @Override
- public void dismiss() {
- super.dismiss();
- mContext.unbindService(mServConn);
- }
-
- /**
- * Event simple click on call button.
- */
- class CallListener implements View.OnClickListener {
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+ }
/**
* Constructor.
+ *
+ * @param context
+ * context where is call the dialog.
+ * @param curContact
+ * current contact.
*/
- public CallListener() {
+ public ContactDialog(final Context context, final Contact curContact) {
+ super(context);
+ mContext = context;
+
+ setContentView(R.layout.contactdialog);
+ mContact = curContact;
+ setTitle(curContact.getJID());
+
+ Button button = (Button) findViewById(R.id.CDChat);
+ button.setOnClickListener(new ChatListener());
+ button = (Button) findViewById(R.id.CDInfos);
+ button.setOnClickListener(new InfosListener());
+ button = (Button) findViewById(R.id.CDCall);
+ button.setOnClickListener(new CallListener());
+ mContext.bindService(SERVICE_INTENT, mServConn, Service.BIND_AUTO_CREATE);
}
@Override
- public void onClick(View v) {
- try {
- // TODO permettre a l'user de choisir a quel ressource il veut
- // faire le call.
- mXmppFacade.call(mContact.getJID() + "/psi");
- } catch (RemoteException e) {
- e.printStackTrace();
- }
+ public void dismiss() {
+ super.dismiss();
+ mContext.unbindService(mServConn);
}
- }
-
- /**
- * Event simple click on chat button.
- */
- class ChatListener implements View.OnClickListener {
/**
- * Constructor.
+ * Event simple click on call button.
*/
- public ChatListener() {
- }
+ class CallListener implements View.OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public CallListener() {
+ }
- @Override
- public void onClick(View v) {
- Activity a = ContactDialog.this.getOwnerActivity();
- Intent i = new Intent(mContext, Chat.class);
- i.setData(mContact.toUri());
- a.startActivity(i);
- dismiss();
+ @Override
+ public void onClick(View v) {
+ try {
+ // TODO permettre a l'user de choisir a quel ressource il veut
+ // faire le call.
+ mXmppFacade.call(mContact.getJID() + "/psi");
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
}
- }
-
- /**
- * Event simple click on info button.
- */
- class InfosListener implements View.OnClickListener {
-
/**
- * Constructor.
+ * Event simple click on chat button.
*/
- public InfosListener() {
- }
+ class ChatListener implements View.OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public ChatListener() {
+ }
- @Override
- public void onClick(View v) {
- Activity a = ContactDialog.this.getOwnerActivity();
- Intent i = new Intent(mContext, UserInfo.class);
- Log.i("OOO", mContact.getJID());
- i.putExtra("contact_contactdialog", mContact.getJID());
- a.startActivity(i);
- dismiss();
+ @Override
+ public void onClick(View v) {
+ Activity a = ContactDialog.this.getOwnerActivity();
+ Intent i = new Intent(mContext, Chat.class);
+ i.setData(mContact.toUri());
+ a.startActivity(i);
+ dismiss();
+ }
+
}
- }
+ /**
+ * Event simple click on info button.
+ */
+ class InfosListener implements View.OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public InfosListener() {
+ }
- /**
- * The service connection used to connect to the Beem service.
- */
- private class BeemServiceConnection implements ServiceConnection {
+ @Override
+ public void onClick(View v) {
+ Activity a = ContactDialog.this.getOwnerActivity();
+ Intent i = new Intent(mContext, UserInfo.class);
+ Log.i("OOO", mContact.getJID());
+ i.putExtra("contact_contactdialog", mContact.getJID());
+ a.startActivity(i);
+ dismiss();
+ }
- /**
- * Constructor.
- */
- public BeemServiceConnection() {
}
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ /**
+ * The service connection used to connect to the Beem service.
+ */
+ private class BeemServiceConnection implements ServiceConnection {
+
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mXmppFacade = null;
+ }
}
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mXmppFacade = null;
- }
- }
-
}
--- a/src/com/beem/project/beem/ui/CreateAccount.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/CreateAccount.java Wed Nov 11 19:21:44 2009 +0100
@@ -25,255 +25,275 @@
import com.beem.project.beem.R;
/**
- * This class represents an activity which allows the user to create an account on the XMPP server saved in settings.
+ * This class represents an activity which allows the user to create an account
+ * on the XMPP server saved in settings.
+ *
* @author dasilvj
*/
public class CreateAccount extends Activity {
- private static final boolean DEFAULT_BOOLEAN_VALUE = false;
- private static final String DEFAULT_STRING_VALUE = "";
- private static final int DEFAULT_INT_VALUE = 0;
- private static final int DEFAULT_XMPP_PORT = 5222;
-
- private static final int NOTIFICATION_DURATION = Toast.LENGTH_SHORT;
-
- private SharedPreferences mSettings;
- private Button mCreateAccountButton;
+ private static final boolean DEFAULT_BOOLEAN_VALUE = false;
+ private static final String DEFAULT_STRING_VALUE = "";
+ private static final int DEFAULT_INT_VALUE = 0;
+ private static final int DEFAULT_XMPP_PORT = 5222;
- /**
- * Constructor.
- */
- public CreateAccount() {
- }
+ private static final int NOTIFICATION_DURATION = Toast.LENGTH_SHORT;
- /**
- * {@inheritDoc}
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.create_account);
- initCreateAccountButton();
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
- }
+ private SharedPreferences mSettings;
+ private Button mCreateAccountButton;
- /**
- * Create an account on the XMPP server specified in settings.
- * @param username the username of the account.
- * @param password the password of the account.
- * @return true if the account was created successfully.
- */
- private boolean createAccount(String username, String password) {
- XMPPConnection xmppConnection = null;
- ConnectionConfiguration connectionConfiguration = null;
-
- if (getRegisteredProxy() != null) {
- connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT,
- getRegisteredProxy());
- } else {
- connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT);
+ /**
+ * Constructor.
+ */
+ public CreateAccount() {
}
- if (getRegisteredXMPPTLSUse())
- connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
- xmppConnection = new XMPPConnection(connectionConfiguration);
- try {
- xmppConnection.connect();
- AccountManager accountManager = new AccountManager(xmppConnection);
- accountManager.createAccount(username, password);
- Toast toast = Toast.makeText(getApplicationContext(), "Account " + username + " "
- + getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION);
- toast.show();
- } catch (XMPPException e) {
- Log.e(getString(R.string.create_account_tag), e.getMessage());
- createErrorDialog(e.getMessage());
- return false;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.create_account);
+ initCreateAccountButton();
+ mSettings = PreferenceManager.getDefaultSharedPreferences(this);
}
- xmppConnection.disconnect();
- return true;
- }
+
+ /**
+ * Create an account on the XMPP server specified in settings.
+ *
+ * @param username
+ * the username of the account.
+ * @param password
+ * the password of the account.
+ * @return true if the account was created successfully.
+ */
+ private boolean createAccount(String username, String password) {
+ XMPPConnection xmppConnection = null;
+ ConnectionConfiguration connectionConfiguration = null;
- /**
- * Create a dialog containing an error message.
- * @param errMsg the error message
- */
- private void createErrorDialog(String errMsg) {
- Log.v(getString(R.string.create_account_tag), errMsg);
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.create_account_err_dialog_title).setMessage(errMsg).setCancelable(false);
- builder.setNeutralButton(R.string.create_account_close_dialog_button, new DialogInterface.OnClickListener() {
+ if (getRegisteredProxy() != null) {
+ connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT,
+ getRegisteredProxy());
+ } else {
+ connectionConfiguration = new ConnectionConfiguration(getXMPPServer(), DEFAULT_XMPP_PORT);
+ }
+ if (getRegisteredXMPPTLSUse())
+ connectionConfiguration.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
- @Override
- public void onClick(DialogInterface dialog, int which) {
- dialog.cancel();
- }
- });
- AlertDialog settingsErrDialog = builder.create();
- settingsErrDialog.show();
- }
+ xmppConnection = new XMPPConnection(connectionConfiguration);
+ try {
+ xmppConnection.connect();
+ AccountManager accountManager = new AccountManager(xmppConnection);
+ accountManager.createAccount(username, password);
+ Toast toast = Toast.makeText(getApplicationContext(), "Account " + username + " "
+ + getString(R.string.create_account_successfull_after), NOTIFICATION_DURATION);
+ toast.show();
+ } catch (XMPPException e) {
+ Log.e(getString(R.string.create_account_tag), e.getMessage());
+ createErrorDialog(e.getMessage());
+ return false;
+ }
+ xmppConnection.disconnect();
+ return true;
+ }
- /**
- * Retrive proxy informations from the preferences.
- * @return Registered proxy informations
- */
- private ProxyInfo getRegisteredProxy() {
- if (getRegisteredProxyUse()) {
- ProxyInfo proxyInfo = new ProxyInfo(getRegisteredProxyType(), getRegisteredProxyServer(),
- getRegisteredProxyPort(), getRegisteredProxyUsername(), getRegisteredProxyPassword());
- return proxyInfo;
+ /**
+ * Create a dialog containing an error message.
+ *
+ * @param errMsg
+ * the error message
+ */
+ private void createErrorDialog(String errMsg) {
+ Log.v(getString(R.string.create_account_tag), errMsg);
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.create_account_err_dialog_title).setMessage(errMsg).setCancelable(false);
+ builder.setNeutralButton(R.string.create_account_close_dialog_button, new DialogInterface.OnClickListener() {
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog settingsErrDialog = builder.create();
+ settingsErrDialog.show();
}
- return null;
- }
- /**
- * Retrieve proxy password from the preferences.
- * @return Registered proxy password
- */
- private String getRegisteredProxyPassword() {
- return mSettings.getString(getString(R.string.settings_key_proxy_password), DEFAULT_STRING_VALUE);
- }
+ /**
+ * Retrive proxy informations from the preferences.
+ *
+ * @return Registered proxy informations
+ */
+ private ProxyInfo getRegisteredProxy() {
+ if (getRegisteredProxyUse()) {
+ ProxyInfo proxyInfo = new ProxyInfo(getRegisteredProxyType(), getRegisteredProxyServer(),
+ getRegisteredProxyPort(), getRegisteredProxyUsername(), getRegisteredProxyPassword());
+ return proxyInfo;
+ }
+ return null;
+ }
- /**
- * Retrieve proxy port from the preferences.
- * @return Registered proxy port
- */
- private int getRegisteredProxyPort() {
- return Integer.parseInt(mSettings.getString(getString(R.string.settings_key_proxy_port), DEFAULT_STRING_VALUE));
- }
+ /**
+ * Retrieve proxy password from the preferences.
+ *
+ * @return Registered proxy password
+ */
+ private String getRegisteredProxyPassword() {
+ return mSettings.getString(getString(R.string.settings_key_proxy_password), DEFAULT_STRING_VALUE);
+ }
- /**
- * Retrieve proxy server from the preferences.
- * @return Registered proxy server
- */
- private String getRegisteredProxyServer() {
- return mSettings.getString(getString(R.string.settings_key_proxy_server), DEFAULT_STRING_VALUE);
- }
+ /**
+ * Retrieve proxy port from the preferences.
+ *
+ * @return Registered proxy port
+ */
+ private int getRegisteredProxyPort() {
+ return Integer.parseInt(mSettings.getString(getString(R.string.settings_key_proxy_port), DEFAULT_STRING_VALUE));
+ }
+
+ /**
+ * Retrieve proxy server from the preferences.
+ *
+ * @return Registered proxy server
+ */
+ private String getRegisteredProxyServer() {
+ return mSettings.getString(getString(R.string.settings_key_proxy_server), DEFAULT_STRING_VALUE);
+ }
- /**
- * Retrieve proxy type from the preferences.
- * @return Registered proxy type
- */
- private ProxyInfo.ProxyType getRegisteredProxyType() {
- ProxyInfo.ProxyType result;
- switch (mSettings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE)) {
- case 0:
- result = ProxyInfo.ProxyType.HTTP;
- break;
- case 1:
- result = ProxyInfo.ProxyType.SOCKS4;
- break;
- case 2:
- Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY");
- result = ProxyInfo.ProxyType.SOCKS5;
- break;
- default:
- result = ProxyInfo.ProxyType.NONE;
- break;
+ /**
+ * Retrieve proxy type from the preferences.
+ *
+ * @return Registered proxy type
+ */
+ private ProxyInfo.ProxyType getRegisteredProxyType() {
+ ProxyInfo.ProxyType result;
+ switch (mSettings.getInt(getString(R.string.settings_key_proxy_type), DEFAULT_INT_VALUE)) {
+ case 0:
+ result = ProxyInfo.ProxyType.HTTP;
+ break;
+ case 1:
+ result = ProxyInfo.ProxyType.SOCKS4;
+ break;
+ case 2:
+ Log.i(getString(R.string.create_account_tag), "SOCKS5 PROXY");
+ result = ProxyInfo.ProxyType.SOCKS5;
+ break;
+ default:
+ result = ProxyInfo.ProxyType.NONE;
+ break;
+ }
+ return result;
}
- return result;
- }
- /**
- * Retrieve proxy use from the preferences.
- * @return Registered proxy use
- */
- private boolean getRegisteredProxyUse() {
- return mSettings.getBoolean(getString(R.string.settings_key_proxy_use), DEFAULT_BOOLEAN_VALUE);
- }
+ /**
+ * Retrieve proxy use from the preferences.
+ *
+ * @return Registered proxy use
+ */
+ private boolean getRegisteredProxyUse() {
+ return mSettings.getBoolean(getString(R.string.settings_key_proxy_use), DEFAULT_BOOLEAN_VALUE);
+ }
- /**
- * Retrieve proxy username from the preferences.
- * @return Registered proxy username
- */
- private String getRegisteredProxyUsername() {
- return mSettings.getString(getString(R.string.settings_key_proxy_username), DEFAULT_STRING_VALUE);
- }
+ /**
+ * Retrieve proxy username from the preferences.
+ *
+ * @return Registered proxy username
+ */
+ private String getRegisteredProxyUsername() {
+ return mSettings.getString(getString(R.string.settings_key_proxy_username), DEFAULT_STRING_VALUE);
+ }
- /**
- * Retrieve xmpp server from the preferences.
- * @return Registered xmpp server
- */
- private String getXMPPServer() {
- TextView xmppServerTextView = (TextView) findViewById(R.id.create_account_username);
- String xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString());
- return xmppServer;
- }
+ /**
+ * Retrieve xmpp server from the preferences.
+ *
+ * @return Registered xmpp server
+ */
+ private String getXMPPServer() {
+ TextView xmppServerTextView = (TextView) findViewById(R.id.create_account_username);
+ String xmppServer = StringUtils.parseServer(xmppServerTextView.getText().toString());
+ return xmppServer;
+ }
- /**
- * Retrieve TLS use from the preferences.
- * @return Registered TLS use
- */
- private boolean getRegisteredXMPPTLSUse() {
- return mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), DEFAULT_BOOLEAN_VALUE);
- }
+ /**
+ * Retrieve TLS use from the preferences.
+ *
+ * @return Registered TLS use
+ */
+ private boolean getRegisteredXMPPTLSUse() {
+ return mSettings.getBoolean(getString(R.string.settings_key_xmpp_tls_use), DEFAULT_BOOLEAN_VALUE);
+ }
- /**
- * Check if the fields password and confirm password match.
- * @return return true if password & confirm password fields match, else false
- */
- private boolean checkPasswords() {
- final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString();
- final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password))
- .getText().toString();
+ /**
+ * Check if the fields password and confirm password match.
+ *
+ * @return return true if password & confirm password fields match, else
+ * false
+ */
+ private boolean checkPasswords() {
+ final String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText().toString();
+ final String passwordConfirmFielddValue = ((EditText) findViewById(R.id.create_account_confirm_password))
+ .getText().toString();
- return passwordFieldValue.equals(passwordConfirmFielddValue);
- }
+ return passwordFieldValue.equals(passwordConfirmFielddValue);
+ }
- /**
- * Check the format of the email.
- * @return true if the email is valid.
- */
- private boolean checkEmail() {
- String email = ((TextView) findViewById(R.id.create_account_username)).getText().toString();
- return Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", email);
- }
+ /**
+ * Check the format of the email.
+ *
+ * @return true if the email is valid.
+ */
+ private boolean checkEmail() {
+ String email = ((TextView) findViewById(R.id.create_account_username)).getText().toString();
+ return Pattern.matches("[a-zA-Z0-9._%+-]+@(?:[a-zA-Z0-9-]+.)+[a-zA-Z]{2,4}", email);
+ }
- /**
- * Initialize the "Create this account" button which allows the user to create an account.
- */
- private void initCreateAccountButton() {
- mCreateAccountButton = (Button) findViewById(R.id.create_account_button);
- mCreateAccountButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
- .toString();
- String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
- .toString();
- String username = StringUtils.parseName(usernameFieldValue);
- if (!checkEmail())
- createErrorDialog(getString(R.string.create_account_err_username));
- else if (!checkPasswords())
- createErrorDialog(getString(R.string.create_account_err_passwords));
- else {
- if (createAccount(username, passwordFieldValue))
- finish();
- }
+ /**
+ * Initialize the "Create this account" button which allows the user to
+ * create an account.
+ */
+ private void initCreateAccountButton() {
+ mCreateAccountButton = (Button) findViewById(R.id.create_account_button);
+ mCreateAccountButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
+ .toString();
+ String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
+ .toString();
+ String username = StringUtils.parseName(usernameFieldValue);
+ if (!checkEmail())
+ createErrorDialog(getString(R.string.create_account_err_username));
+ else if (!checkPasswords())
+ createErrorDialog(getString(R.string.create_account_err_passwords));
+ else {
+ if (createAccount(username, passwordFieldValue))
+ finish();
+ }
- }
- });
- Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);
- createAccountLoginButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
- .toString();
- String username = StringUtils.parseName(usernameFieldValue);
- String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
- .toString();
- if (!checkEmail())
- createErrorDialog(getString(R.string.create_account_err_username));
- else if (!checkPasswords())
- createErrorDialog(getString(R.string.create_account_err_passwords));
- else {
- if (createAccount(username, passwordFieldValue)) {
- SharedPreferences.Editor settingsEditor = mSettings.edit();
- settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue);
- settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue);
- settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true);
- settingsEditor.commit();
- finish();
- }
- }
- }
- });
- }
+ }
+ });
+ Button createAccountLoginButton = (Button) findViewById(R.id.create_account_login_button);
+ createAccountLoginButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+ String usernameFieldValue = ((EditText) findViewById(R.id.create_account_username)).getText()
+ .toString();
+ String username = StringUtils.parseName(usernameFieldValue);
+ String passwordFieldValue = ((EditText) findViewById(R.id.create_account_password)).getText()
+ .toString();
+ if (!checkEmail())
+ createErrorDialog(getString(R.string.create_account_err_username));
+ else if (!checkPasswords())
+ createErrorDialog(getString(R.string.create_account_err_passwords));
+ else {
+ if (createAccount(username, passwordFieldValue)) {
+ SharedPreferences.Editor settingsEditor = mSettings.edit();
+ settingsEditor.putString(getString(R.string.settings_key_account_username), usernameFieldValue);
+ settingsEditor.putString(getString(R.string.settings_key_account_password), passwordFieldValue);
+ settingsEditor.putBoolean(getString(R.string.PreferenceIsConfigured), true);
+ settingsEditor.commit();
+ finish();
+ }
+ }
+ }
+ });
+ }
}
--- a/src/com/beem/project/beem/ui/GroupList.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/GroupList.java Wed Nov 11 19:21:44 2009 +0100
@@ -30,191 +30,192 @@
/**
* That activity permit to manage user groups.
+ *
* @author nikita
*/
public class GroupList extends ListActivity {
- private static final Intent SERVICE_INTENT = new Intent();
-
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private BeemBroadcastReceiver mReceiver;
- private IXmppFacade mXmppFacade;
- private IRoster mRoster;
- private String mJID;
- private ArrayAdapter<String> mGroups;
- private Contact mContact;
- private TextView mText;
- private final List<String> mStrings = new ArrayList<String>();
-
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- /**
- * Constructor.
- */
- public GroupList() {
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.group_list);
- mReceiver = new BeemBroadcastReceiver(mServConn);
- mContact = getIntent().getParcelableExtra("contact");
- mJID = mContact.getJID();
- final ListView listView = getListView();
-
- listView.setItemsCanFocus(false);
- listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
- listView.setOnItemClickListener(new GroupOnItemClickListener());
-
- mText = (TextView) findViewById(R.id.GroupListText);
- mText.setOnKeyListener(new GroupListOnKeyListener());
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
+ private static final Intent SERVICE_INTENT = new Intent();
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded(true);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- if (mReceiver.isBinded()) {
- unbindService(mServConn);
- mReceiver.setBinded(false);
- }
- }
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private BeemBroadcastReceiver mReceiver;
+ private IXmppFacade mXmppFacade;
+ private IRoster mRoster;
+ private String mJID;
+ private ArrayAdapter<String> mGroups;
+ private Contact mContact;
+ private TextView mText;
+ private final List<String> mStrings = new ArrayList<String>();
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * init activity list adapter.
- */
- private void setAdapter() {
- try {
- for (String group : mRoster.getGroupsNames()) {
- mStrings.add(group);
- }
- mGroups = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, mStrings);
- setListAdapter(mGroups);
- mContact = mRoster.getContact(mJID);
- for (String group : mContact.getGroups()) {
- getListView().setItemChecked(mGroups.getPosition(group), true);
- }
- } catch (RemoteException e) {
- e.printStackTrace();
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- }
-
- /**
- * Event when group is added.
- */
- private class GroupListOnKeyListener implements OnKeyListener {
/**
* Constructor.
*/
- public GroupListOnKeyListener() {
+ public GroupList() {
}
@Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- boolean result = false;
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_ENTER:
- if (mText.getText().length() == 0)
- return false;
- String groupname = mText.getText().toString();
- mGroups.add(groupname);
- mText.setText(null);
- result = true;
- break;
- default:
- result = false;
- }
- }
- return result;
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.group_list);
+ mReceiver = new BeemBroadcastReceiver(mServConn);
+ mContact = getIntent().getParcelableExtra("contact");
+ mJID = mContact.getJID();
+ final ListView listView = getListView();
+
+ listView.setItemsCanFocus(false);
+ listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
+ listView.setOnItemClickListener(new GroupOnItemClickListener());
+
+ mText = (TextView) findViewById(R.id.GroupListText);
+ mText.setOnKeyListener(new GroupListOnKeyListener());
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
}
- }
-
- /**
- * Event click on list group contact.
- */
- private class GroupOnItemClickListener implements OnItemClickListener {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mReceiver.setBinded(true);
+ }
/**
- * Constructor.
+ * {@inheritDoc}
*/
- public GroupOnItemClickListener() {
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (mReceiver.isBinded()) {
+ unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
@Override
- public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
- CheckedTextView textView = (CheckedTextView) v;
- if (!textView.isChecked()) {
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
+ }
+
+ /**
+ * init activity list adapter.
+ */
+ private void setAdapter() {
try {
- mRoster.addContactToGroup(textView.getText().toString(), mJID);
+ for (String group : mRoster.getGroupsNames()) {
+ mStrings.add(group);
+ }
+ mGroups = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, mStrings);
+ setListAdapter(mGroups);
+ mContact = mRoster.getContact(mJID);
+ for (String group : mContact.getGroups()) {
+ getListView().setItemChecked(mGroups.getPosition(group), true);
+ }
} catch (RemoteException e) {
- e.printStackTrace();
+ e.printStackTrace();
}
- } else {
- try {
- mRoster.removeContactFromGroup(textView.getText().toString(), mJID);
- } catch (RemoteException e) {
- e.printStackTrace();
+ }
+
+ /**
+ * Event when group is added.
+ */
+ private class GroupListOnKeyListener implements OnKeyListener {
+
+ /**
+ * Constructor.
+ */
+ public GroupListOnKeyListener() {
}
- }
+
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ boolean result = false;
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ case KeyEvent.KEYCODE_ENTER:
+ if (mText.getText().length() == 0)
+ return false;
+ String groupname = mText.getText().toString();
+ mGroups.add(groupname);
+ mText.setText(null);
+ result = true;
+ break;
+ default:
+ result = false;
+ }
+ }
+ return result;
+ }
}
- }
+ /**
+ * Event click on list group contact.
+ */
+ private class GroupOnItemClickListener implements OnItemClickListener {
+
+ /**
+ * Constructor.
+ */
+ public GroupOnItemClickListener() {
+ }
- /**
- * The ServiceConnection used to connect to the Beem service.
- */
- private class BeemServiceConnection implements ServiceConnection {
+ @Override
+ public void onItemClick(AdapterView<?> arg0, View v, int arg2, long arg3) {
+ CheckedTextView textView = (CheckedTextView) v;
+ if (!textView.isChecked()) {
+ try {
+ mRoster.addContactToGroup(textView.getText().toString(), mJID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ mRoster.removeContactFromGroup(textView.getText().toString(), mJID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
- /**
- * Constructor.
- */
- public BeemServiceConnection() {
+ }
+
}
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- mReceiver.setBinded(true);
- try {
- mRoster = mXmppFacade.getRoster();
- setAdapter();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
+ /**
+ * The ServiceConnection used to connect to the Beem service.
+ */
+ private class BeemServiceConnection implements ServiceConnection {
+
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
+ try {
+ mRoster = mXmppFacade.getRoster();
+ setAdapter();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mXmppFacade = null;
+ mRoster = null;
+ }
}
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mXmppFacade = null;
- mRoster = null;
- }
- }
-
}
--- a/src/com/beem/project/beem/ui/Login.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/Login.java Wed Nov 11 19:21:44 2009 +0100
@@ -28,352 +28,360 @@
import com.beem.project.beem.utils.Status;
/**
- * This class represents an activity which allows the user to connect to an XMPP server with his username/password.
+ * This class represents an activity which allows the user to connect to an XMPP
+ * server with his username/password.
+ *
* @author dasilvj
*/
public class Login extends Activity {
- private static final String TAG = "LOG_AS";
- private static final int REQUEST_CODE = 1;
- private static final Intent SERVICE_INTENT = new Intent();
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- private final Handler mConnectionHandler = new Handler();
- private ConnectionRunnable mConnectionRunnable = new ConnectionRunnable();
- private ProgressDialog mProgressDialog;
-
- private boolean mIsConnectedService;
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private IXmppFacade mXmppFacade;
-
- private SharedPreferences mSettings;
- private boolean mIsConfigured;
- private int mRetry;
- private IXmppConnection mXmppConnection;
-
- /**
- * Constructor.
- */
- public Login() {
- }
-
- /**
- * Create an about "BEEM" dialog.
- */
- public void createAboutDialog() {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false);
- builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() {
-
- public void onClick(DialogInterface dialog, int whichButton) {
- dialog.cancel();
- }
- });
- AlertDialog aboutDialog = builder.create();
- aboutDialog.show();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Log.d(TAG, "onCreate");
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
- setContentView(R.layout.login);
- mProgressDialog = new ProgressDialog(this);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onStop() {
- super.onStop();
- Log.d(TAG, "onStop " + mIsConnectedService);
- if (mIsConfigured && (mIsConnectedService || mXmppFacade != null)) {
- boolean isConnected = false;
- if (mXmppConnection != null) {
- try {
- isConnected = mXmppConnection.isAuthentificated();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- unbindService(mServConn);
- if (!isConnected) {
- stopService(SERVICE_INTENT);
- }
- mXmppFacade = null;
+ private static final String TAG = "LOG_AS";
+ private static final int REQUEST_CODE = 1;
+ private static final Intent SERVICE_INTENT = new Intent();
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- }
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- Log.d(TAG, "onPause");
- mConnectionHandler.removeCallbacks(mConnectionRunnable);
- mProgressDialog.dismiss();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- Log.d(TAG, "onResume");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStart() {
- super.onStart();
- Log.d(TAG, "onStart " + mIsConnectedService);
- mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
- if (mIsConfigured && !mIsConnectedService) {
- try {
- Thread.sleep(1000); //HACK: Pour éviter de rebinder un service pas encore arreter.
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
- mIsConnectedService = true;
- }
- }
+ private final Handler mConnectionHandler = new Handler();
+ private ConnectionRunnable mConnectionRunnable = new ConnectionRunnable();
+ private ProgressDialog mProgressDialog;
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_CODE) {
- if (resultCode == RESULT_OK) {
- stopService(SERVICE_INTENT);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.login, menu);
- return true;
- }
+ private boolean mIsConnectedService;
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private IXmppFacade mXmppFacade;
- /**
- * Callback for menu item selected.
- * @param item the item selected
- * @return true on success, false otherwise
- */
- @Override
- public final boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.login_menu_settings:
- startActivity(new Intent(Login.this, Settings.class));
- return true;
- case R.id.login_menu_about:
- createAboutDialog();
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Connection runnable.
- * @author nikita
- */
- private class ConnectionRunnable implements Runnable {
+ private SharedPreferences mSettings;
+ private boolean mIsConfigured;
+ private int mRetry;
+ private IXmppConnection mXmppConnection;
/**
* Constructor.
*/
- public ConnectionRunnable() {
+ public Login() {
+ }
+
+ /**
+ * Create an about "BEEM" dialog.
+ */
+ public void createAboutDialog() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false);
+ builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() {
+
+ public void onClick(DialogInterface dialog, int whichButton) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog aboutDialog = builder.create();
+ aboutDialog.show();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Log.d(TAG, "onCreate");
+ mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+ setContentView(R.layout.login);
+ mProgressDialog = new ProgressDialog(this);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onStop() {
+ super.onStop();
+ Log.d(TAG, "onStop " + mIsConnectedService);
+ if (mIsConfigured && (mIsConnectedService || mXmppFacade != null)) {
+ boolean isConnected = false;
+ if (mXmppConnection != null) {
+ try {
+ isConnected = mXmppConnection.isAuthentificated();
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+ unbindService(mServConn);
+ if (!isConnected) {
+ stopService(SERVICE_INTENT);
+ }
+ mXmppFacade = null;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ Log.d(TAG, "onPause");
+ mConnectionHandler.removeCallbacks(mConnectionRunnable);
+ mProgressDialog.dismiss();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onResume() {
+ super.onResume();
+ Log.d(TAG, "onResume");
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStart() {
+ super.onStart();
+ Log.d(TAG, "onStart " + mIsConnectedService);
+ mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
+ if (mIsConfigured && !mIsConnectedService) {
+ try {
+ Thread.sleep(1000); // HACK: Pour éviter de rebinder un service
+ // pas encore arreter.
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+ mIsConnectedService = true;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (requestCode == REQUEST_CODE) {
+ if (resultCode == RESULT_OK) {
+ stopService(SERVICE_INTENT);
+ }
+ }
}
/**
* {@inheritDoc}
*/
@Override
- public void run() {
- if (mRetry++ > 3) {
- Toast.makeText(Login.this, R.string.login_max_retry, Toast.LENGTH_LONG).show();
- mConnectionHandler.removeCallbacks(mConnectionRunnable);
- } else {
- mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
- if (mIsConfigured) {
- bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
- }
- }
-
- }
- }
-
- /**
- * Listener use to check the state of the connection with the server.
- */
- private class BeemConnectionListener extends IBeemConnectionListener.Stub {
-
- /**
- * Constructor.
- */
- public BeemConnectionListener() {
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.login, menu);
+ return true;
}
/**
- * {@inheritDoc}
+ * Callback for menu item selected.
+ *
+ * @param item
+ * the item selected
+ * @return true on success, false otherwise
*/
@Override
- public void connectionClosed() throws RemoteException {
- if (mXmppFacade != null) {
- launchReconnectionHandler();
- mXmppFacade = null;
- }
- }
-
- @Override
- public void connectionClosedOnError() throws RemoteException {
- if (mXmppFacade != null) {
- launchReconnectionHandler();
- mXmppFacade = null;
- }
- }
-
- @Override
- public void connectionFailed(String errorMsg) throws RemoteException {
- Log.d(TAG, "CONNECTIONFAILLED");
- if (mXmppFacade != null) {
- Login.this.unbindService(mServConn);
- Login.this.stopService(SERVICE_INTENT);
- mIsConnectedService = false;
- mXmppFacade = null;
- }
- dismissProgressDialog();
- showToast(errorMsg);
- launchReconnectionHandler();
+ public final boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.login_menu_settings:
+ startActivity(new Intent(Login.this, Settings.class));
+ return true;
+ case R.id.login_menu_about:
+ createAboutDialog();
+ return true;
+ default:
+ return false;
+ }
}
/**
- * launch reconnection handler.
+ * Connection runnable.
+ *
+ * @author nikita
*/
- private void launchReconnectionHandler() {
- mConnectionHandler.postAtTime(mConnectionRunnable,
- Integer.parseInt(mSettings.getString("settings_key_reco_delay", "10")) * 1000
- + SystemClock.uptimeMillis());
- }
+ private class ConnectionRunnable implements Runnable {
- /**
- * Show an error message with a toast.
- * @param errorMsg The message to display.
- */
- private void showToast(final String errorMsg) {
- mConnectionHandler.post(new Runnable() {
/**
- * @{inheritDoc
+ * Constructor.
+ */
+ public ConnectionRunnable() {
+ }
+
+ /**
+ * {@inheritDoc}
*/
@Override
public void run() {
- Toast.makeText(Login.this, errorMsg, Toast.LENGTH_LONG).show();
- TextView labelError = (TextView) findViewById(R.id.log_as_msg);
- labelError.setText(getString(R.string.login_error_msg, errorMsg));
+ if (mRetry++ > 3) {
+ Toast.makeText(Login.this, R.string.login_max_retry, Toast.LENGTH_LONG).show();
+ mConnectionHandler.removeCallbacks(mConnectionRunnable);
+ } else {
+ mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
+ if (mIsConfigured) {
+ bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+ }
+ }
+
}
- });
}
/**
- * Dismiss the progress dialog.
+ * Listener use to check the state of the connection with the server.
*/
- private void dismissProgressDialog() {
- mConnectionHandler.post(new Runnable() {
+ private class BeemConnectionListener extends IBeemConnectionListener.Stub {
/**
- * @{inheritDoc
+ * Constructor.
+ */
+ public BeemConnectionListener() {
+ }
+
+ /**
+ * {@inheritDoc}
*/
@Override
- public void run() {
- mProgressDialog.dismiss();
+ public void connectionClosed() throws RemoteException {
+ if (mXmppFacade != null) {
+ launchReconnectionHandler();
+ mXmppFacade = null;
+ }
+ }
+
+ @Override
+ public void connectionClosedOnError() throws RemoteException {
+ if (mXmppFacade != null) {
+ launchReconnectionHandler();
+ mXmppFacade = null;
+ }
}
- });
- }
+
+ @Override
+ public void connectionFailed(String errorMsg) throws RemoteException {
+ Log.d(TAG, "CONNECTIONFAILLED");
+ if (mXmppFacade != null) {
+ Login.this.unbindService(mServConn);
+ Login.this.stopService(SERVICE_INTENT);
+ mIsConnectedService = false;
+ mXmppFacade = null;
+ }
+ dismissProgressDialog();
+ showToast(errorMsg);
+ launchReconnectionHandler();
+ }
+
+ /**
+ * launch reconnection handler.
+ */
+ private void launchReconnectionHandler() {
+ mConnectionHandler.postAtTime(mConnectionRunnable, Integer.parseInt(mSettings.getString(
+ "settings_key_reco_delay", "10"))
+ * 1000 + SystemClock.uptimeMillis());
+ }
- @Override
- public void onConnect() throws RemoteException {
- dismissProgressDialog();
- Log.i(TAG, "Connected.");
- mXmppFacade.changeStatus(Status.CONTACT_STATUS_AVAILABLE, null);
- mRetry = 0;
- startActivity(new Intent(Login.this, ContactList.class));
- finish();
- }
+ /**
+ * Show an error message with a toast.
+ *
+ * @param errorMsg
+ * The message to display.
+ */
+ private void showToast(final String errorMsg) {
+ mConnectionHandler.post(new Runnable() {
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public void run() {
+ Toast.makeText(Login.this, errorMsg, Toast.LENGTH_LONG).show();
+ TextView labelError = (TextView) findViewById(R.id.log_as_msg);
+ labelError.setText(getString(R.string.login_error_msg, errorMsg));
+ }
+ });
+ }
+
+ /**
+ * Dismiss the progress dialog.
+ */
+ private void dismissProgressDialog() {
+ mConnectionHandler.post(new Runnable() {
- @Override
- public void reconnectingIn(int seconds) throws RemoteException {
- }
+ /**
+ * @{inheritDoc
+ */
+ @Override
+ public void run() {
+ mProgressDialog.dismiss();
+ }
+ });
+ }
- @Override
- public void reconnectionFailed() throws RemoteException {
+ @Override
+ public void onConnect() throws RemoteException {
+ dismissProgressDialog();
+ Log.i(TAG, "Connected.");
+ mXmppFacade.changeStatus(Status.CONTACT_STATUS_AVAILABLE, null);
+ mRetry = 0;
+ startActivity(new Intent(Login.this, ContactList.class));
+ finish();
+ }
+
+ @Override
+ public void reconnectingIn(int seconds) throws RemoteException {
+ }
+
+ @Override
+ public void reconnectionFailed() throws RemoteException {
+ }
+
+ @Override
+ public void reconnectionSuccessful() throws RemoteException {
+ }
}
- @Override
- public void reconnectionSuccessful() throws RemoteException {
- }
- }
-
- /**
- * ServiceConnection use to connect to the Beem Service.
- */
- private class BeemServiceConnection implements ServiceConnection {
/**
- * Constructor.
+ * ServiceConnection use to connect to the Beem Service.
*/
- public BeemServiceConnection() {
- }
+ private class BeemServiceConnection implements ServiceConnection {
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- Log.d(TAG, "service connected");
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- mIsConnectedService = true;
- try {
- mXmppConnection = mXmppFacade.createConnection();
- mXmppConnection.addConnectionListener(new BeemConnectionListener());
- if (!mXmppConnection.isAuthentificated()) {
- mConnectionHandler.post(new Runnable() {
- @Override
- public void run() {
- mProgressDialog.setMessage(getString(R.string.login_login_progress));
- mProgressDialog.show();
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ Log.d(TAG, "service connected");
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mIsConnectedService = true;
+ try {
+ mXmppConnection = mXmppFacade.createConnection();
+ mXmppConnection.addConnectionListener(new BeemConnectionListener());
+ if (!mXmppConnection.isAuthentificated()) {
+ mConnectionHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ mProgressDialog.setMessage(getString(R.string.login_login_progress));
+ mProgressDialog.show();
+ }
+ });
+ Login.this.startService(Login.SERVICE_INTENT);
+ } else {
+ startActivity(new Intent(Login.this, ContactList.class));
+ finish();
+ }
+ } catch (RemoteException e) {
+ Log.e(TAG, "REMOTE EXCEPTION $" + e.getMessage());
}
- });
- Login.this.startService(Login.SERVICE_INTENT);
- } else {
- startActivity(new Intent(Login.this, ContactList.class));
- finish();
}
- } catch (RemoteException e) {
- Log.e(TAG, "REMOTE EXCEPTION $" + e.getMessage());
- }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ Log.d(TAG, "service disconnected");
+ mIsConnectedService = false;
+ mXmppFacade = null;
+ }
}
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- Log.d(TAG, "service disconnected");
- mIsConnectedService = false;
- mXmppFacade = null;
- }
- }
}
--- a/src/com/beem/project/beem/ui/SendIM.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/SendIM.java Wed Nov 11 19:21:44 2009 +0100
@@ -45,495 +45,505 @@
import com.beem.project.beem.utils.Status;
/**
- * This activity class provides the view for instant messaging after selecting a correspondant.
+ * This activity class provides the view for instant messaging after selecting a
+ * correspondant.
+ *
* @author barbu
*/
public class SendIM extends Activity implements OnClickListener, OnKeyListener {
- private static final String TAG = "SEND_IM";
- private static final Intent SERVICE_INTENT = new Intent();
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- private IRoster mRoster;
- private EditText mToSend;
- private SendIMDialogSmiley mSmyDialog;
- private SharedPreferences mSet;
- private Handler mHandler;
- private Contact mContact;
- private ImageView mStatusIcon;
- private IChatManager mChatManager;
- private IChatManagerListener mChatManagerListener;
- private IMessageListener mMessageListener;
- private IChat mChat;
- private TextView mText;
- private TextView mLogin;
- private ScrollView mScrolling;
- private char mSpeak;
-
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private IXmppFacade mXmppFacade;
- private TextView mStatusText;
- private BeemBroadcastReceiver mReceiver;
-
- /**
- * Constructor.
- */
- public SendIM() {
- super();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onClick(View view) {
- sendText();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onCreate(Bundle saveBundle) {
- super.onCreate(saveBundle);
- // setTheme(R.style.OldTheme);
- setContentView(R.layout.sendim);
- mHandler = new Handler();
- mChatManagerListener = new OnChatListener();
- mMessageListener = new OnMessageListener();
- mToSend = (EditText) findViewById(R.id.userText);
- mSet = getSharedPreferences("lol", MODE_PRIVATE);
- mSmyDialog = new SendIMDialogSmiley(this, mSet);
- mToSend.setOnClickListener(this);
- mToSend.setOnKeyListener(this);
- mStatusIcon = (ImageView) findViewById(R.id.sendimstatus);
- mLogin = (TextView) findViewById(R.id.sendimlogin);
- mContact = new Contact(getIntent().getData());
- mText = (TextView) findViewById(R.id.sendimlist);
- mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
- mStatusText = (TextView) findViewById(R.id.sendimstatusmsg);
- mReceiver = new BeemBroadcastReceiver(mServConn);
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public final boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.sendimmenu, menu);
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- if (mChatManager != null) {
- try {
- mChatManager.removeChatCreationListener(mChatManagerListener);
- // TODO trouver quand detruire le chat
- // mChatManager.destroyChat(mChat);
- } catch (RemoteException e) {
- Log.e(TAG, "mchat manager and SendIM destroy", e);
- }
+ private static final String TAG = "SEND_IM";
+ private static final Intent SERVICE_INTENT = new Intent();
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- }
- /**
- * Update the status icon of our contact.
- */
- protected void updateStatusIcon() {
- Drawable statusIcon = null;
- switch (mContact.getStatus()) {
- case Status.CONTACT_STATUS_AVAILABLE:
- statusIcon = getResources().getDrawable(R.drawable.status_available);
- break;
- case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
- statusIcon = getResources().getDrawable(R.drawable.status_available);
- break;
- case Status.CONTACT_STATUS_AWAY:
- statusIcon = getResources().getDrawable(R.drawable.status_away);
- break;
- case Status.CONTACT_STATUS_BUSY:
- statusIcon = getResources().getDrawable(R.drawable.status_dnd);
- break;
- case Status.CONTACT_STATUS_DISCONNECT:
- statusIcon = getResources().getDrawable(R.drawable.status_offline);
- break;
- case Status.CONTACT_STATUS_UNAVAILABLE:
- statusIcon = getResources().getDrawable(R.drawable.status_requested);
- break;
- default:
- statusIcon = getResources().getDrawable(R.drawable.status_error);
- break;
- }
- Log.d("SENDIM -- UPDATE STATUS ICON", "Contact current status: " + mContact.getStatus() + "");
- mStatusIcon.setImageDrawable(statusIcon);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if (event.getAction() == KeyEvent.ACTION_DOWN) {
- switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_CENTER:
- case KeyEvent.KEYCODE_ENTER:
- sendText();
- return true;
- default:
- return false;
- }
- }
- return false;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- mContact = new Contact(intent.getData());
- try {
- if (mRoster != null)
- mContact = mRoster.getContact(mContact.getJID());
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ private IRoster mRoster;
+ private EditText mToSend;
+ private SendIMDialogSmiley mSmyDialog;
+ private SharedPreferences mSet;
+ private Handler mHandler;
+ private Contact mContact;
+ private ImageView mStatusIcon;
+ private IChatManager mChatManager;
+ private IChatManagerListener mChatManagerListener;
+ private IMessageListener mMessageListener;
+ private IChat mChat;
+ private TextView mText;
+ private TextView mLogin;
+ private ScrollView mScrolling;
+ private char mSpeak;
- /**
- * {@inheritDoc}
- */
- @Override
- public final boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.sendim_smiley:
- mSmyDialog.show();
- return true;
- case R.id.sendim_call:
- // TODO start the jingle call
- // Bug a besoin du jid complet (resource compris)
- try {
- mXmppFacade.call(mContact.getJID());
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- return true;
- default:
- return false;
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onStop() {
- super.onStop();
- try {
- if (mChat != null)
- mChat.setOpen(false);
- } catch (RemoteException e) {
- Log.d(TAG, "Error while closing chat", e);
- }
- if (mReceiver.isBinded()) {
- unbindService(mServConn);
- mReceiver.setBinded(false);
- }
- mRoster = null;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onStart() {
- super.onStart();
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- try {
- if (mRoster != null)
- mContact = mRoster.getContact(mContact.getJID());
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- /**
- * The service connection used to connect with the BeemService.
- */
- private final class BeemServiceConnection implements ServiceConnection {
- private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private IXmppFacade mXmppFacade;
+ private TextView mStatusText;
+ private BeemBroadcastReceiver mReceiver;
/**
* Constructor.
*/
- public BeemServiceConnection() {
+ public SendIM() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onClick(View view) {
+ sendText();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- mReceiver.setBinded(true);
- try {
- if (mChatManager == null) {
- mChatManager = mXmppFacade.getChatManager();
- mChatManager.addChatCreationListener(mChatManagerListener);
+ protected void onCreate(Bundle saveBundle) {
+ super.onCreate(saveBundle);
+ // setTheme(R.style.OldTheme);
+ setContentView(R.layout.sendim);
+ mHandler = new Handler();
+ mChatManagerListener = new OnChatListener();
+ mMessageListener = new OnMessageListener();
+ mToSend = (EditText) findViewById(R.id.userText);
+ mSet = getSharedPreferences("lol", MODE_PRIVATE);
+ mSmyDialog = new SendIMDialogSmiley(this, mSet);
+ mToSend.setOnClickListener(this);
+ mToSend.setOnKeyListener(this);
+ mStatusIcon = (ImageView) findViewById(R.id.sendimstatus);
+ mLogin = (TextView) findViewById(R.id.sendimlogin);
+ mContact = new Contact(getIntent().getData());
+ mText = (TextView) findViewById(R.id.sendimlist);
+ mScrolling = (ScrollView) findViewById(R.id.sendimscroll);
+ mStatusText = (TextView) findViewById(R.id.sendimstatusmsg);
+ mReceiver = new BeemBroadcastReceiver(mServConn);
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public final boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.sendimmenu, menu);
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
+ if (mChatManager != null) {
+ try {
+ mChatManager.removeChatCreationListener(mChatManagerListener);
+ // TODO trouver quand detruire le chat
+ // mChatManager.destroyChat(mChat);
+ } catch (RemoteException e) {
+ Log.e(TAG, "mchat manager and SendIM destroy", e);
+ }
}
- mRoster = mXmppFacade.getRoster();
- if (mRoster != null) {
- mRoster.addRosterListener(mBeemRosterListener);
- // mContact.setStatus(mRoster.getPresence(mContact.getJID()));
- if (mRoster.getContact(mContact.getJID()) != null) {
- mContact = mRoster.getContact(mContact.getJID());
- mStatusText.setText(mContact.getMsgState());
- mLogin.setText(mContact.getName());
- }
- updateStatusIcon();
- }
- switchChat(mContact);
- } catch (RemoteException e) {
- Log.e(TAG, "Error during chat manager creation", e);
- }
}
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mReceiver.setBinded(false);
- mXmppFacade = null;
- try {
- mRoster.removeRosterListener(mBeemRosterListener);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- mRoster = null;
+ /**
+ * Update the status icon of our contact.
+ */
+ protected void updateStatusIcon() {
+ Drawable statusIcon = null;
+ switch (mContact.getStatus()) {
+ case Status.CONTACT_STATUS_AVAILABLE:
+ statusIcon = getResources().getDrawable(R.drawable.status_available);
+ break;
+ case Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+ statusIcon = getResources().getDrawable(R.drawable.status_available);
+ break;
+ case Status.CONTACT_STATUS_AWAY:
+ statusIcon = getResources().getDrawable(R.drawable.status_away);
+ break;
+ case Status.CONTACT_STATUS_BUSY:
+ statusIcon = getResources().getDrawable(R.drawable.status_dnd);
+ break;
+ case Status.CONTACT_STATUS_DISCONNECT:
+ statusIcon = getResources().getDrawable(R.drawable.status_offline);
+ break;
+ case Status.CONTACT_STATUS_UNAVAILABLE:
+ statusIcon = getResources().getDrawable(R.drawable.status_requested);
+ break;
+ default:
+ statusIcon = getResources().getDrawable(R.drawable.status_error);
+ break;
+ }
+ Log.d("SENDIM -- UPDATE STATUS ICON", "Contact current status: " + mContact.getStatus() + "");
+ mStatusIcon.setImageDrawable(statusIcon);
}
- }
-
- /**
- * Send a message to the contact over the XMPP connection. Also display it on activity view. TODO : Gerer
- * l'exception si la connexion se coupe pendant la conversation
- */
- private void sendText() {
- String text = mToSend.getText().toString();
- if (!"".equals(text)) {
- Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
- msg.setBody(text);
- try {
- mChat.sendMessage(msg);
- if (mSpeak != 1)
- mText.append(getString(R.string.SendIMYouSay, text));
- else
- mText.append(getString(R.string.SendIMSameSpeaker, text));
- mToSend.setText(null);
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- mToSend.requestFocus();
- mSpeak = 1;
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * Show the message history.
- * @param messages list of message to display
- */
- private void showMessageList(List<Message> messages) {
- mText.setText("");
- mSpeak = 0;
- for (Message message : messages) {
- String from = message.getFrom();
- if (from == null) {
- if (mSpeak != 1)
- mText.append(getString(R.string.SendIMYouSay, message.getBody()));
- else
- mText.append(getString(R.string.SendIMYouSay, message.getBody()));
- mSpeak = 1;
- } else {
- if (mSpeak != 2)
- mText.append(getString(R.string.SendIMSays, mContact.getName(), message.getBody()));
- else
- mText.append(getString(R.string.SendIMSameSpeaker, message.getBody()));
- mSpeak = 2;
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onKey(View v, int keyCode, KeyEvent event) {
+ if (event.getAction() == KeyEvent.ACTION_DOWN) {
+ switch (keyCode) {
+ case KeyEvent.KEYCODE_DPAD_CENTER:
+ case KeyEvent.KEYCODE_ENTER:
+ sendText();
+ return true;
+ default:
+ return false;
+ }
+ }
+ return false;
}
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- }
-
- /**
- * Change the correspondant of the chat.
- * @param newContact New contact to chat with
- * @throws RemoteException if an errors occurs in the connection with the service
- */
- private void switchChat(Contact newContact) throws RemoteException {
- if (mChat != null)
- mChat.setOpen(false);
- mChat = mChatManager.createChat(newContact, mMessageListener);
- showMessageList(mChat.getMessages());
- mChat.setOpen(true);
- mChatManager.deleteChatNotification(mChat);
- mContact = newContact;
- mToSend.requestFocus();
- }
-
- /**
- * Listener for chat creation. (maybe not necessary).
- * @author darisk
- */
- private class OnChatListener extends IChatManagerListener.Stub {
/**
- * Constructor.
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onNewIntent(Intent intent) {
+ super.onNewIntent(intent);
+ mContact = new Contact(intent.getData());
+ try {
+ if (mRoster != null)
+ mContact = mRoster.getContact(mContact.getJID());
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
*/
- public OnChatListener() {
+ @Override
+ public final boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.sendim_smiley:
+ mSmyDialog.show();
+ return true;
+ case R.id.sendim_call:
+ // TODO start the jingle call
+ // Bug a besoin du jid complet (resource compris)
+ try {
+ mXmppFacade.call(mContact.getJID());
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onStop() {
+ super.onStop();
+ try {
+ if (mChat != null)
+ mChat.setOpen(false);
+ } catch (RemoteException e) {
+ Log.d(TAG, "Error while closing chat", e);
+ }
+ if (mReceiver.isBinded()) {
+ unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
+ mRoster = null;
}
/**
* {@inheritDoc}
*/
@Override
- public void chatCreated(IChat chat, boolean locally) throws RemoteException {
- Log.i("LOG", "chatCreated");
+ protected void onStart() {
+ super.onStart();
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+ try {
+ if (mRoster != null)
+ mContact = mRoster.getContact(mContact.getJID());
+ } catch (RemoteException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- }
+ /**
+ * The service connection used to connect with the BeemService.
+ */
+ private final class BeemServiceConnection implements ServiceConnection {
+ private final BeemRosterListener mBeemRosterListener = new BeemRosterListener();
- /**
- * Listener use to change the status displayed.
- */
- private class BeemRosterListener extends IBeemRosterListener.Stub {
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
- /**
- * Constructor.
- */
- public BeemRosterListener() {
- }
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
+ try {
+ if (mChatManager == null) {
+ mChatManager = mXmppFacade.getChatManager();
+ mChatManager.addChatCreationListener(mChatManagerListener);
+ }
+ mRoster = mXmppFacade.getRoster();
+ if (mRoster != null) {
+ mRoster.addRosterListener(mBeemRosterListener);
+ // mContact.setStatus(mRoster.getPresence(mContact.getJID()));
+ if (mRoster.getContact(mContact.getJID()) != null) {
+ mContact = mRoster.getContact(mContact.getJID());
+ mStatusText.setText(mContact.getMsgState());
+ mLogin.setText(mContact.getName());
+ }
+ updateStatusIcon();
+ }
+ switchChat(mContact);
+ } catch (RemoteException e) {
+ Log.e(TAG, "Error during chat manager creation", e);
+ }
+ }
- @Override
- public void onEntriesAdded(List<String> addresses) throws RemoteException {
- // TODO Auto-generated method stub
-
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mReceiver.setBinded(false);
+ mXmppFacade = null;
+ try {
+ mRoster.removeRosterListener(mBeemRosterListener);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ mRoster = null;
+ }
}
- @Override
- public void onEntriesDeleted(List<String> addresses) throws RemoteException {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void onEntriesUpdated(List<String> addresses) throws RemoteException {
- // TODO Auto-generated method stub
-
+ /**
+ * Send a message to the contact over the XMPP connection. Also display it
+ * on activity view. TODO : Gerer l'exception si la connexion se coupe
+ * pendant la conversation
+ */
+ private void sendText() {
+ String text = mToSend.getText().toString();
+ if (!"".equals(text)) {
+ Message msg = new Message(mContact.getJID(), Message.MSG_TYPE_CHAT);
+ msg.setBody(text);
+ try {
+ mChat.sendMessage(msg);
+ if (mSpeak != 1)
+ mText.append(getString(R.string.SendIMYouSay, text));
+ else
+ mText.append(getString(R.string.SendIMSameSpeaker, text));
+ mToSend.setText(null);
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+ mToSend.requestFocus();
+ mSpeak = 1;
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
}
- @Override
- public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
- // TODO Auto-generated method stub
-
+ /**
+ * Show the message history.
+ *
+ * @param messages
+ * list of message to display
+ */
+ private void showMessageList(List<Message> messages) {
+ mText.setText("");
+ mSpeak = 0;
+ for (Message message : messages) {
+ String from = message.getFrom();
+ if (from == null) {
+ if (mSpeak != 1)
+ mText.append(getString(R.string.SendIMYouSay, message.getBody()));
+ else
+ mText.append(getString(R.string.SendIMYouSay, message.getBody()));
+ mSpeak = 1;
+ } else {
+ if (mSpeak != 2)
+ mText.append(getString(R.string.SendIMSays, mContact.getName(), message.getBody()));
+ else
+ mText.append(getString(R.string.SendIMSameSpeaker, message.getBody()));
+ mSpeak = 2;
+ }
+ }
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
}
- @Override
- public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
- if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
- mContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
- Log.d("SENDIM -- onPresenceChanged", "Contact current status: " + mContact.getStatus() + "");
- mHandler.post(new RunnableChange());
- }
+ /**
+ * Change the correspondant of the chat.
+ *
+ * @param newContact
+ * New contact to chat with
+ * @throws RemoteException
+ * if an errors occurs in the connection with the service
+ */
+ private void switchChat(Contact newContact) throws RemoteException {
+ if (mChat != null)
+ mChat.setOpen(false);
+ mChat = mChatManager.createChat(newContact, mMessageListener);
+ showMessageList(mChat.getMessages());
+ mChat.setOpen(true);
+ mChatManager.deleteChatNotification(mChat);
+ mContact = newContact;
+ mToSend.requestFocus();
}
/**
- * Runnable to change the status displayed.
+ * Listener for chat creation. (maybe not necessary).
+ *
+ * @author darisk
*/
- private class RunnableChange implements Runnable {
-
- /**
- * Constructor.
- */
- public RunnableChange() {
- }
+ private class OnChatListener extends IChatManagerListener.Stub {
- @Override
- public void run() {
- updateStatusIcon();
- mStatusText.setText(mContact.getMsgState());
- Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
- }
- }
- }
+ /**
+ * Constructor.
+ */
+ public OnChatListener() {
+ }
- /**
- * Listener for new chat messages.
- * @author darisk
- */
- private class OnMessageListener extends IMessageListener.Stub {
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void chatCreated(IChat chat, boolean locally) throws RemoteException {
+ Log.i("LOG", "chatCreated");
+ }
- /**
- * Constructor.
- */
- public OnMessageListener() {
}
/**
- * {@inheritDoc}
+ * Listener use to change the status displayed.
*/
- @Override
- public void processMessage(IChat chat, Message msg) throws RemoteException {
+ private class BeemRosterListener extends IBeemRosterListener.Stub {
+
+ /**
+ * Constructor.
+ */
+ public BeemRosterListener() {
+ }
+
+ @Override
+ public void onEntriesAdded(List<String> addresses) throws RemoteException {
+ // TODO Auto-generated method stub
- if (chat != mChat)
- return;
- final Message m = msg;
- Log.d("Message Type", "Le type du message : " + m.getType());
- mHandler.post(new Runnable() {
+ }
+
+ @Override
+ public void onEntriesDeleted(List<String> addresses) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onEntriesUpdated(List<String> addresses) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
@Override
- public void run() {
- if (m.getBody() != null) {
- if (m.getType() == Message.MSG_TYPE_ERROR) {
- mText.append(getString(R.string.SendIMErrorMsg, m.getBody()));
- mSpeak = 0;
- } else if (mSpeak == 2)
- mText.append(getString(R.string.SendIMSameSpeaker, m.getBody()));
- else
- mText.append(getString(R.string.SendIMSays, mContact.getName(), m.getBody()));
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
- mToSend.requestFocus();
- mSpeak = 2;
- }
+ public void onEntryDeleteFromGroup(String group, String jid) throws RemoteException {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void onPresenceChanged(PresenceAdapter presence) throws RemoteException {
+ if (mContact.getJID().equals(StringUtils.parseBareAddress(presence.getFrom()))) {
+ mContact.setStatus(mRoster.getPresence(StringUtils.parseBareAddress(presence.getFrom())));
+ Log.d("SENDIM -- onPresenceChanged", "Contact current status: " + mContact.getStatus() + "");
+ mHandler.post(new RunnableChange());
+ }
}
- });
+
+ /**
+ * Runnable to change the status displayed.
+ */
+ private class RunnableChange implements Runnable {
+
+ /**
+ * Constructor.
+ */
+ public RunnableChange() {
+ }
+
+ @Override
+ public void run() {
+ updateStatusIcon();
+ mStatusText.setText(mContact.getMsgState());
+ Linkify.addLinks(mStatusText, Linkify.WEB_URLS);
+ }
+ }
}
/**
- * {@inheritDoc}
+ * Listener for new chat messages.
+ *
+ * @author darisk
*/
- @Override
- public void stateChanged(IChat chat) throws RemoteException {
- if (chat != mChat)
- return;
- Log.d("ChatState", "Action du correspondant : <--- " + chat.getState() + " --->");
- mHandler.post(new Runnable() {
+ private class OnMessageListener extends IMessageListener.Stub {
+
+ /**
+ * Constructor.
+ */
+ public OnMessageListener() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void processMessage(IChat chat, Message msg) throws RemoteException {
+
+ if (chat != mChat)
+ return;
+ final Message m = msg;
+ Log.d("Message Type", "Le type du message : " + m.getType());
+ mHandler.post(new Runnable() {
- @Override
- public void run() {
+ @Override
+ public void run() {
+ if (m.getBody() != null) {
+ if (m.getType() == Message.MSG_TYPE_ERROR) {
+ mText.append(getString(R.string.SendIMErrorMsg, m.getBody()));
+ mSpeak = 0;
+ } else if (mSpeak == 2)
+ mText.append(getString(R.string.SendIMSameSpeaker, m.getBody()));
+ else
+ mText.append(getString(R.string.SendIMSays, mContact.getName(), m.getBody()));
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+ mToSend.requestFocus();
+ mSpeak = 2;
+ }
+ }
+ });
}
- });
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void stateChanged(IChat chat) throws RemoteException {
+ if (chat != mChat)
+ return;
+ Log.d("ChatState", "Action du correspondant : <--- " + chat.getState() + " --->");
+ mHandler.post(new Runnable() {
+
+ @Override
+ public void run() {
+ }
+ });
+ }
}
- }
}
--- a/src/com/beem/project/beem/ui/SendIMDialogSmiley.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/SendIMDialogSmiley.java Wed Nov 11 19:21:44 2009 +0100
@@ -10,26 +10,29 @@
*/
public class SendIMDialogSmiley extends Dialog {
- @SuppressWarnings("unused")
- private SendIM mSendIM;
- @SuppressWarnings("unused")
- private SharedPreferences mSet;
+ @SuppressWarnings("unused")
+ private SendIM mSendIM;
+ @SuppressWarnings("unused")
+ private SharedPreferences mSet;
- /**
- * Constructor.
- * @param sendim unused
- * @param settings unused
- */
- public SendIMDialogSmiley(final SendIM sendim, final SharedPreferences settings) {
- super(sendim);
- this.mSendIM = sendim;
- this.mSet = settings;
- }
+ /**
+ * Constructor.
+ *
+ * @param sendim
+ * unused
+ * @param settings
+ * unused
+ */
+ public SendIMDialogSmiley(final SendIM sendim, final SharedPreferences settings) {
+ super(sendim);
+ this.mSendIM = sendim;
+ this.mSet = settings;
+ }
- @Override
- protected void onStart() {
- super.onStart();
- setContentView(R.layout.sendimdialogsmiley);
- setTitle("Select a smiley");
- }
+ @Override
+ protected void onStart() {
+ super.onStart();
+ setContentView(R.layout.sendimdialogsmiley);
+ setTitle("Select a smiley");
+ }
}
--- a/src/com/beem/project/beem/ui/Settings.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/Settings.java Wed Nov 11 19:21:44 2009 +0100
@@ -16,111 +16,113 @@
import com.beem.project.beem.utils.BeemBroadcastReceiver;
/**
- * This class represents an activity which allows the user to change his account or proxy parameters.
+ * This class represents an activity which allows the user to change his account
+ * or proxy parameters.
+ *
* @author nikita
*/
public class Settings extends PreferenceActivity {
- private static final Intent SERVICE_INTENT = new Intent();
- private SettingsBroadcastReceiver mReceiver;
-
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- /**
- * Constructor.
- */
- public Settings() {
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.layout.preferences);
- mReceiver = new SettingsBroadcastReceiver();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onResume() {
- super.onResume();
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
+ private static final Intent SERVICE_INTENT = new Intent();
+ private SettingsBroadcastReceiver mReceiver;
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStop() {
- super.onStop();
- SharedPreferences settings = getPreferenceManager().getSharedPreferences();
- settings.edit().putBoolean(
- "PreferenceIsConfigured",
- !"".equals(settings.getString("settings_key_account_username", ""))
- || !"".equals(settings.getString("settings_key_account_password", ""))).commit();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater mInflater = getMenuInflater();
- mInflater.inflate(R.menu.edit_settings, menu);
- return true;
- }
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- Intent i = null;
- switch (item.getItemId()) {
- case R.id.settings_menu_create_account:
- i = new Intent(this, CreateAccount.class);
- startActivity(i);
- return true;
- case R.id.settings_menu_login:
- setResult(RESULT_OK);
- SharedPreferences settings = getPreferenceManager().getSharedPreferences();
- settings.edit().putBoolean(
- "PreferenceIsConfigured",
- !"".equals(settings.getString("settings_key_account_username", ""))
- || !"".equals(settings.getString("settings_key_account_password", ""))).commit();
- this.stopService(SERVICE_INTENT);
- finish();
- return true;
- default:
- return false;
- }
- }
-
- /**
- * disconnect Broadcast receiver.
- */
- private class SettingsBroadcastReceiver extends BroadcastReceiver {
/**
* Constructor.
*/
- public SettingsBroadcastReceiver() {
+ public Settings() {
}
@Override
- public void onReceive(Context context, Intent intent) {
- Settings.this.setResult(RESULT_CANCELED);
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.layout.preferences);
+ mReceiver = new SettingsBroadcastReceiver();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected void onPause() {
+ super.onPause();
+ this.unregisterReceiver(mReceiver);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onResume() {
+ super.onResume();
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onStop() {
+ super.onStop();
+ SharedPreferences settings = getPreferenceManager().getSharedPreferences();
+ settings.edit().putBoolean(
+ "PreferenceIsConfigured",
+ !"".equals(settings.getString("settings_key_account_username", ""))
+ || !"".equals(settings.getString("settings_key_account_password", ""))).commit();
}
- }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater mInflater = getMenuInflater();
+ mInflater.inflate(R.menu.edit_settings, menu);
+ return true;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ Intent i = null;
+ switch (item.getItemId()) {
+ case R.id.settings_menu_create_account:
+ i = new Intent(this, CreateAccount.class);
+ startActivity(i);
+ return true;
+ case R.id.settings_menu_login:
+ setResult(RESULT_OK);
+ SharedPreferences settings = getPreferenceManager().getSharedPreferences();
+ settings.edit().putBoolean(
+ "PreferenceIsConfigured",
+ !"".equals(settings.getString("settings_key_account_username", ""))
+ || !"".equals(settings.getString("settings_key_account_password", ""))).commit();
+ this.stopService(SERVICE_INTENT);
+ finish();
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ /**
+ * disconnect Broadcast receiver.
+ */
+ private class SettingsBroadcastReceiver extends BroadcastReceiver {
+ /**
+ * Constructor.
+ */
+ public SettingsBroadcastReceiver() {
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Settings.this.setResult(RESULT_CANCELED);
+ }
+ }
}
--- a/src/com/beem/project/beem/ui/Subscription.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/Subscription.java Wed Nov 11 19:21:44 2009 +0100
@@ -24,122 +24,121 @@
/**
* This activity is used to accept a subscription request.
+ *
* @author nikita
*/
public class Subscription extends Activity {
- private static final Intent SERVICE_INTENT = new Intent();
- private IXmppFacade mService;
- private String mContact;
- private ServiceConnection mServConn = new BeemServiceConnection();
- private BeemBroadcastReceiver mReceiver;
- private MyOnClickListener mClickListener = new MyOnClickListener();
-
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- /**
- * Constructor.
- */
- public Subscription() {
- }
+ private static final Intent SERVICE_INTENT = new Intent();
+ private IXmppFacade mService;
+ private String mContact;
+ private ServiceConnection mServConn = new BeemServiceConnection();
+ private BeemBroadcastReceiver mReceiver;
+ private MyOnClickListener mClickListener = new MyOnClickListener();
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.subscription);
- mReceiver = new BeemBroadcastReceiver(mServConn);
- findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
- findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
- mContact = getIntent().getStringExtra("from");
- TextView tv = (TextView) findViewById(R.id.SubscriptionText);
- String str = String.format(getString(R.string.SubscriptText), mContact);
- tv.setText(str);
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded(true);
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- if (mReceiver.isBinded()) {
- unbindService(mServConn);
- mReceiver.setBinded(false);
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * Event simple click on buttons.
- */
- private class MyOnClickListener implements OnClickListener {
/**
* Constructor.
*/
- public MyOnClickListener() {
+ public Subscription() {
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.subscription);
+ mReceiver = new BeemBroadcastReceiver(mServConn);
+ findViewById(R.id.SubscriptionAccept).setOnClickListener(mClickListener);
+ findViewById(R.id.SubscriptionRefuse).setOnClickListener(mClickListener);
+ mContact = getIntent().getStringExtra("from");
+ TextView tv = (TextView) findViewById(R.id.SubscriptionText);
+ String str = String.format(getString(R.string.SubscriptText), mContact);
+ tv.setText(str);
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mReceiver.setBinded(true);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (mReceiver.isBinded()) {
+ unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
@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, getString(R.string.SubscriptAccept), Toast.LENGTH_SHORT)
- .show();
- finish();
- } catch (RemoteException e) {
- Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT)
- .show();
- e.printStackTrace();
- }
- break;
- case R.id.SubscriptionRefuse:
- Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused), Toast.LENGTH_SHORT).show();
-
- break;
- default:
- Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
- }
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
- };
-
- /**
- * The ServiceConnection used to connect to the Beem service.
- */
- private class BeemServiceConnection implements ServiceConnection {
/**
- * Constructor.
+ * Event simple click on buttons.
*/
- public BeemServiceConnection() {
- }
+ private class MyOnClickListener implements OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public MyOnClickListener() {
+ }
+
+ @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, getString(R.string.SubscriptAccept), Toast.LENGTH_SHORT).show();
+ finish();
+ } catch (RemoteException e) {
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
+ e.printStackTrace();
+ }
+ break;
+ case R.id.SubscriptionRefuse:
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptRefused), Toast.LENGTH_SHORT).show();
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mService = IXmppFacade.Stub.asInterface(service);
- mReceiver.setBinded(true);
- }
+ break;
+ default:
+ Toast.makeText(Subscription.this, getString(R.string.SubscriptError), Toast.LENGTH_SHORT).show();
+ }
+ }
+ };
+
+ /**
+ * The ServiceConnection used to connect to the Beem service.
+ */
+ private class BeemServiceConnection implements ServiceConnection {
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mService = null;
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mService = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mService = null;
+ }
}
- }
}
--- a/src/com/beem/project/beem/ui/UserInfo.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/UserInfo.java Wed Nov 11 19:21:44 2009 +0100
@@ -34,337 +34,342 @@
import com.beem.project.beem.utils.BeemBroadcastReceiver;
/**
- * This activity class provides the view for user infos after long click on a correspondant.
+ * This activity class provides the view for user infos after long click on a
+ * correspondant.
+ *
* @author marseille
*/
public class UserInfo extends Activity {
- private static final Intent SERVICE_INTENT = new Intent();
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private TextView mTextAlias;
- private Gallery mGalleryGroups;
- private Contact mContact;
- private IXmppFacade mXmppFacade;
- private BeemBroadcastReceiver mReceiver;
- private String mJID;
- private IRoster mRoster;
-
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- /**
- * Constructor.
- */
- public UserInfo() {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.userinfo);
- View v = (View) findViewById(R.id.userinfo_layout_alias);
- v.setOnClickListener(new AliasListener());
- v = findViewById(R.id.userinfo_layout_delete);
- v.setOnClickListener(new DeleteListener());
- v = findViewById(R.id.userinfo_layout_chg_group);
- v.setOnClickListener(new GroupListener());
- v = findViewById(R.id.userinfo_layout_re_suscription);
- v.setOnClickListener(new ResendListener());
- mTextAlias = (TextView) findViewById(R.id.userinfo_alias);
- mGalleryGroups = (Gallery) findViewById(R.id.userinfo_groups);
- mReceiver = new BeemBroadcastReceiver(mServConn);
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- }
+ private static final Intent SERVICE_INTENT = new Intent();
+ private final ServiceConnection mServConn = new BeemServiceConnection();
+ private TextView mTextAlias;
+ private Gallery mGalleryGroups;
+ private Contact mContact;
+ private IXmppFacade mXmppFacade;
+ private BeemBroadcastReceiver mReceiver;
+ private String mJID;
+ private IRoster mRoster;
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- if (mReceiver.isBinded()){
- unbindService(mServConn);
- mReceiver.setBinded(false);
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
- * Event simple click on layout alias.
- */
- private class AliasListener implements View.OnClickListener {
- /**
- * Constructor.
- */
- public AliasListener() {
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
}
- @Override
- public void onClick(View v) {
- Dialog d = new DialogAlias();
- d.show();
- }
- }
-
- /**
- * Event simple click on layout group.
- */
- private class GroupListener implements View.OnClickListener {
- /**
- * Constructor.
- */
- public GroupListener() {
- }
-
- @Override
- public void onClick(View v) {
- Intent i = new Intent(UserInfo.this, GroupList.class);
- i.putExtra("contact", mContact);
- startActivity(i);
- }
-
- }
-
- /**
- * Create dialog alias.
- */
- public class DialogAlias extends Dialog {
-
/**
* Constructor.
*/
- public DialogAlias() {
- super(UserInfo.this);
- setContentView(R.layout.contactdialogaliasdialog);
- setTitle(mContact.getJID());
- EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
- if (mContact.getName().length() == 0)
- nameText.setText(mContact.getJID());
- else
- nameText.setText(mContact.getName());
- Button ok = (Button) findViewById(R.id.CDAliasDialogOk);
- ok.setOnClickListener(new ContactDialogAliasDialogOK());
+ public UserInfo() {
}
/**
- * Event click on the button OK.
+ * {@inheritDoc}
*/
- private class ContactDialogAliasDialogOK implements View.OnClickListener {
-
- /**
- * Constructor.
- */
- public ContactDialogAliasDialogOK() {
- }
-
- @Override
- public void onClick(View v) {
- try {
- EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
- String name = nameText.getText().toString();
- if (name.length() == 0)
- name = mContact.getJID();
- mRoster.setContactName(mContact.getJID(), name);
- mContact.setName(name);
- mTextAlias.setText(name);
-
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- dismiss();
- }
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.userinfo);
+ View v = (View) findViewById(R.id.userinfo_layout_alias);
+ v.setOnClickListener(new AliasListener());
+ v = findViewById(R.id.userinfo_layout_delete);
+ v.setOnClickListener(new DeleteListener());
+ v = findViewById(R.id.userinfo_layout_chg_group);
+ v.setOnClickListener(new GroupListener());
+ v = findViewById(R.id.userinfo_layout_re_suscription);
+ v.setOnClickListener(new ResendListener());
+ mTextAlias = (TextView) findViewById(R.id.userinfo_alias);
+ mGalleryGroups = (Gallery) findViewById(R.id.userinfo_groups);
+ mReceiver = new BeemBroadcastReceiver(mServConn);
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
}
- }
-
- /**
- * Adapter group horizontal list.
- */
- public class BeemGroups extends BaseAdapter {
- private Context mContext;
- private List<String> mListGroup;
/**
- * Constructor.
- * @param c context activity.
- * @param listGroup the user group list.
+ * {@inheritDoc}
*/
- public BeemGroups(final Context c, final List<String> listGroup) {
- mContext = c;
- if (listGroup.size() == 0)
- listGroup.add(getString(R.string.contact_list_no_group));
- mListGroup = listGroup;
+ @Override
+ protected void onResume() {
+ super.onResume();
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
}
/**
* {@inheritDoc}
*/
@Override
- public int getCount() {
- return mListGroup.size();
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Object getItem(int position) {
- return position;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- TextView textView = new TextView(mContext);
- textView.setText(mListGroup.get(position));
- return textView;
- }
-
- }
-
- /**
- * Event simple click on layout resend suscription.
- */
- class ResendListener implements View.OnClickListener {
-
- /**
- * Constructor.
- */
- public ResendListener() {
+ protected void onPause() {
+ super.onPause();
+ if (mReceiver.isBinded()) {
+ unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
@Override
- public void onClick(View v) {
-
- AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
- builder.setMessage(UserInfo.this.getString(R.string.userinfo_sureresend)).setCancelable(false)
- .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- Presence presencePacket = new Presence(Presence.Type.subscribe);
- presencePacket.setTo(mContact.getJID());
- try {
- mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- Toast.makeText(UserInfo.this, getString(R.string.userinfo_resend), Toast.LENGTH_SHORT)
- .show();
- }
- }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
- }
+ /**
+ * Event simple click on layout alias.
+ */
+ private class AliasListener implements View.OnClickListener {
+ /**
+ * Constructor.
+ */
+ public AliasListener() {
+ }
+
+ @Override
+ public void onClick(View v) {
+ Dialog d = new DialogAlias();
+ d.show();
+ }
+ }
- /**
- * Event simple click on layout delete.
- */
- class DeleteListener implements View.OnClickListener {
+ /**
+ * Event simple click on layout group.
+ */
+ private class GroupListener implements View.OnClickListener {
+ /**
+ * Constructor.
+ */
+ public GroupListener() {
+ }
+
+ @Override
+ public void onClick(View v) {
+ Intent i = new Intent(UserInfo.this, GroupList.class);
+ i.putExtra("contact", mContact);
+ startActivity(i);
+ }
+
+ }
/**
- * Constructor.
+ * Create dialog alias.
*/
- public DeleteListener() {
- }
+ public class DialogAlias extends Dialog {
- @Override
- public void onClick(View v) {
- AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
- builder.setMessage(UserInfo.this.getString(R.string.userinfo_sure2delete)).setCancelable(false)
- .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- try {
- mRoster.deleteContact(mContact);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- finish();
+ /**
+ * Constructor.
+ */
+ public DialogAlias() {
+ super(UserInfo.this);
+ setContentView(R.layout.contactdialogaliasdialog);
+ setTitle(mContact.getJID());
+ EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
+ if (mContact.getName().length() == 0)
+ nameText.setText(mContact.getJID());
+ else
+ nameText.setText(mContact.getName());
+ Button ok = (Button) findViewById(R.id.CDAliasDialogOk);
+ ok.setOnClickListener(new ContactDialogAliasDialogOK());
+ }
+
+ /**
+ * Event click on the button OK.
+ */
+ private class ContactDialogAliasDialogOK implements View.OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public ContactDialogAliasDialogOK() {
}
- }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
- new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- dialog.cancel();
+
+ @Override
+ public void onClick(View v) {
+ try {
+ EditText nameText = (EditText) findViewById(R.id.CDAliasDialogName);
+ String name = nameText.getText().toString();
+ if (name.length() == 0)
+ name = mContact.getJID();
+ mRoster.setContactName(mContact.getJID(), name);
+ mContact.setName(name);
+ mTextAlias.setText(name);
+
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ dismiss();
}
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
- }
-
- /**
- * The ServiceConnection used to connect to the Beem service.
- */
- private class BeemServiceConnection implements ServiceConnection {
-
- /**
- * Constructor.
- */
- public BeemServiceConnection() {
+ }
}
/**
- * {@inheritDoc}
+ * Adapter group horizontal list.
*/
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- mReceiver.setBinded(true);
- try {
- mRoster = mXmppFacade.getRoster();
- mJID = getIntent().getStringExtra("contact_contactdialog");
- mContact = mRoster.getContact(mJID);
- if (mContact.getName() != null)
- mTextAlias.setText(mContact.getName());
- else
- mTextAlias.setText(mContact.getJID());
- mGalleryGroups.setAdapter(new BeemGroups(UserInfo.this, mContact.getGroups()));
- setTitle(mJID);
- } catch (RemoteException e) {
- e.printStackTrace();
- }
+ public class BeemGroups extends BaseAdapter {
+ private Context mContext;
+ private List<String> mListGroup;
+
+ /**
+ * Constructor.
+ *
+ * @param c
+ * context activity.
+ * @param listGroup
+ * the user group list.
+ */
+ public BeemGroups(final Context c, final List<String> listGroup) {
+ mContext = c;
+ if (listGroup.size() == 0)
+ listGroup.add(getString(R.string.contact_list_no_group));
+ mListGroup = listGroup;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int getCount() {
+ return mListGroup.size();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public Object getItem(int position) {
+ return position;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public long getItemId(int position) {
+ return position;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ TextView textView = new TextView(mContext);
+ textView.setText(mListGroup.get(position));
+ return textView;
+ }
+
}
/**
- * {@inheritDoc}
+ * Event simple click on layout resend suscription.
+ */
+ class ResendListener implements View.OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public ResendListener() {
+ }
+
+ @Override
+ public void onClick(View v) {
+
+ AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
+ builder.setMessage(UserInfo.this.getString(R.string.userinfo_sureresend)).setCancelable(false)
+ .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ Presence presencePacket = new Presence(Presence.Type.subscribe);
+ presencePacket.setTo(mContact.getJID());
+ try {
+ mXmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ Toast.makeText(UserInfo.this, getString(R.string.userinfo_resend),
+ Toast.LENGTH_SHORT).show();
+ }
+ }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ }
+
+ }
+
+ /**
+ * Event simple click on layout delete.
*/
- @Override
- public void onServiceDisconnected(ComponentName name) {
- mXmppFacade = null;
+ class DeleteListener implements View.OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ public DeleteListener() {
+ }
+
+ @Override
+ public void onClick(View v) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(UserInfo.this);
+ builder.setMessage(UserInfo.this.getString(R.string.userinfo_sure2delete)).setCancelable(false)
+ .setPositiveButton(UserInfo.this.getString(R.string.userinfo_yes),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ try {
+ mRoster.deleteContact(mContact);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ finish();
+ }
+ }).setNegativeButton(UserInfo.this.getString(R.string.userinfo_no),
+ new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ }
+ });
+ AlertDialog alert = builder.create();
+ alert.show();
+ }
}
- }
+
+ /**
+ * The ServiceConnection used to connect to the Beem service.
+ */
+ private class BeemServiceConnection implements ServiceConnection {
+
+ /**
+ * Constructor.
+ */
+ public BeemServiceConnection() {
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
+ try {
+ mRoster = mXmppFacade.getRoster();
+ mJID = getIntent().getStringExtra("contact_contactdialog");
+ mContact = mRoster.getContact(mJID);
+ if (mContact.getName() != null)
+ mTextAlias.setText(mContact.getName());
+ else
+ mTextAlias.setText(mContact.getJID());
+ mGalleryGroups.setAdapter(new BeemGroups(UserInfo.this, mContact.getGroups()));
+ setTitle(mJID);
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mXmppFacade = null;
+ }
+ }
}
--- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Wed Nov 11 19:21:44 2009 +0100
@@ -12,59 +12,65 @@
/**
* Manage broadcast disconnect intent.
+ *
* @author nikita
*/
public class BeemBroadcastReceiver extends BroadcastReceiver {
- /**
- * Broadcast intent type.
- */
- public static final String BEEM_CONNECTION_CLOSED = "BeemConnectionClosed";
- private ServiceConnection mService;
- private boolean mIsBinded;
+ /**
+ * Broadcast intent type.
+ */
+ public static final String BEEM_CONNECTION_CLOSED = "BeemConnectionClosed";
+ private ServiceConnection mService;
+ private boolean mIsBinded;
- /**
- * constructor.
- * @param service service observed
- */
- public BeemBroadcastReceiver(final ServiceConnection service) {
- mService = service;
- mIsBinded = false;
- }
+ /**
+ * constructor.
+ *
+ * @param service
+ * service observed
+ */
+ public BeemBroadcastReceiver(final ServiceConnection service) {
+ mService = service;
+ mIsBinded = false;
+ }
- /**
- * {@inheritDoc}
- */
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.d("Broadcast", "onReceive");
- if (mIsBinded)
- context.unbindService(mService);
- setBinded(false);
- // start activity if unexpected disconnection
- if (!intent.getBooleanExtra("normally", false))
- context.startActivity(new Intent(context, Login.class));
- CharSequence message = intent.getCharSequenceExtra("message");
- Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
- if (context instanceof Activity) {
- Activity act = (Activity) context;
- act.finish();
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Log.d("Broadcast", "onReceive");
+ if (mIsBinded)
+ context.unbindService(mService);
+ setBinded(false);
+ // start activity if unexpected disconnection
+ if (!intent.getBooleanExtra("normally", false))
+ context.startActivity(new Intent(context, Login.class));
+ CharSequence message = intent.getCharSequenceExtra("message");
+ Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
+ if (context instanceof Activity) {
+ Activity act = (Activity) context;
+ act.finish();
+ }
}
- }
- /**
- * service is binded.
- * @param binded the state of the bind.
- */
- public void setBinded(boolean binded) {
- mIsBinded = binded;
- }
+ /**
+ * service is binded.
+ *
+ * @param binded
+ * the state of the bind.
+ */
+ public void setBinded(boolean binded) {
+ mIsBinded = binded;
+ }
- /**
- * return service bind status.
- * @return service bind status.
- */
- public boolean isBinded() {
- return mIsBinded;
- }
+ /**
+ * return service bind status.
+ *
+ * @return service bind status.
+ */
+ public boolean isBinded() {
+ return mIsBinded;
+ }
}
--- a/src/com/beem/project/beem/utils/FreePort.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/utils/FreePort.java Wed Nov 11 19:21:44 2009 +0100
@@ -5,45 +5,47 @@
/**
* Utility class to get a free port.
+ *
* @author nikita
*/
public final class FreePort {
- private static final int MAGIC_10 = 10;
- private static final int MAGIC_10000 = 10000;
+ private static final int MAGIC_10 = 10;
+ private static final int MAGIC_10000 = 10000;
+
+ /**
+ * Private default constructor.
+ */
+ private FreePort() {
+ }
- /**
- * Private default constructor.
- */
- private FreePort() {
- }
-
- /**
- * return a free port.
- * @return free socket port.
- */
- public static int getFreePort() {
- ServerSocket ss;
- int freePort = 0;
+ /**
+ * return a free port.
+ *
+ * @return free socket port.
+ */
+ public static int getFreePort() {
+ ServerSocket ss;
+ int freePort = 0;
- for (int i = 0; i < MAGIC_10; i++) {
- freePort = (int) (MAGIC_10000 + Math.round(Math.random() * MAGIC_10000));
- try {
- ss = new ServerSocket(freePort);
- freePort = ss.getLocalPort();
- ss.close();
+ for (int i = 0; i < MAGIC_10; i++) {
+ freePort = (int) (MAGIC_10000 + Math.round(Math.random() * MAGIC_10000));
+ try {
+ ss = new ServerSocket(freePort);
+ freePort = ss.getLocalPort();
+ ss.close();
+ return freePort;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ try {
+ ss = new ServerSocket(0);
+ freePort = ss.getLocalPort();
+ ss.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
return freePort;
- } catch (IOException e) {
- e.printStackTrace();
- }
}
- try {
- ss = new ServerSocket(0);
- freePort = ss.getLocalPort();
- ss.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return freePort;
- }
}
--- a/src/com/beem/project/beem/utils/PresenceType.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/utils/PresenceType.java Wed Nov 11 19:21:44 2009 +0100
@@ -7,117 +7,123 @@
/**
* Utility class to deal with Presence type.
+ *
* @author nikita
*/
public final class PresenceType {
- /**
- * The user is available to receive messages (default).
- */
- public static final int AVAILABLE = 100;
+ /**
+ * 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;
+ /**
+ * The user is unavailable to receive messages.
+ */
+ public static final int UNAVAILABLE = 200;
- /**
- * Request subscription to recipient's presence.
- */
+ /**
+ * Request subscription to recipient's presence.
+ */
- public static final int SUBSCRIBE = 300;
+ public static final int SUBSCRIBE = 300;
- /**
- * Grant subscription to sender's presence.
- */
- public static final int SUBSCRIBED = 400;
+ /**
+ * 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;
+ /**
+ * 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;
+ /**
+ * 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;
+ /**
+ * The presence packet contains an error message.
+ */
+ public static final int ERROR = 701;
- /**
- * Private default constructor.
- */
- private PresenceType() {
- }
+ /**
+ * Private default constructor.
+ */
+ private PresenceType() {
+ }
- /**
- * Get the presence type from a presence packet.
- * @param presence the presence type
- * @return an int representing 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;
+ /**
+ * Get the presence type from a presence packet.
+ *
+ * @param presence
+ * the presence type
+ * @return an int representing 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;
}
- return res;
- }
- /**
- * Get the smack presence mode for a status.
- * @param type the status type 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;
+ /**
+ * Get the smack presence mode for a status.
+ *
+ * @param type
+ * the status type 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;
}
- return res;
- }
}
--- a/src/com/beem/project/beem/utils/Status.java Wed Nov 11 17:58:26 2009 +0100
+++ b/src/com/beem/project/beem/utils/Status.java Wed Nov 11 19:21:44 2009 +0100
@@ -8,121 +8,129 @@
/**
* Utility class to deal with status and presence value.
+ *
* @author marseille
*/
public final class Status {
- /**
- * Status of a disconnected contact.
- */
- public static final int CONTACT_STATUS_DISCONNECT = 100;
+ /**
+ * Status of a disconnected contact.
+ */
+ public static final int CONTACT_STATUS_DISCONNECT = 100;
- /**
- * Status of a unavailable (long away) contact.
- */
- public static final int CONTACT_STATUS_UNAVAILABLE = 200;
+ /**
+ * Status of a unavailable (long away) contact.
+ */
+ public static final int CONTACT_STATUS_UNAVAILABLE = 200;
- /**
- * Status of a away contact.
- */
- public static final int CONTACT_STATUS_AWAY = 300;
+ /**
+ * Status of a away contact.
+ */
+ public static final int CONTACT_STATUS_AWAY = 300;
- /**
- * Status of a busy contact.
- */
- public static final int CONTACT_STATUS_BUSY = 400;
+ /**
+ * Status of a busy contact.
+ */
+ public static final int CONTACT_STATUS_BUSY = 400;
- /**
- * Status of a available contact.
- */
- public static final int CONTACT_STATUS_AVAILABLE = 500;
+ /**
+ * Status of a available contact.
+ */
+ public static final int CONTACT_STATUS_AVAILABLE = 500;
- /**
- * Status of a available for chat contact.
- */
- public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
+ /**
+ * Status of a available for chat contact.
+ */
+ public static final int CONTACT_STATUS_AVAILABLE_FOR_CHAT = 600;
- /**
- * Default constructor masked.
- */
- private Status() {
- }
+ /**
+ * Default constructor masked.
+ */
+ private Status() {
+ }
- /**
- * 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.Mode getPresenceModeFromStatus(int status) {
- Presence.Mode res;
- switch (status) {
- case CONTACT_STATUS_AVAILABLE:
- res = Presence.Mode.available;
- break;
- case CONTACT_STATUS_AVAILABLE_FOR_CHAT:
- res = Presence.Mode.chat;
- break;
- case CONTACT_STATUS_AWAY:
- res = Presence.Mode.away;
- break;
- case CONTACT_STATUS_BUSY:
- res = Presence.Mode.dnd;
- break;
- case CONTACT_STATUS_UNAVAILABLE:
- res = Presence.Mode.xa;
- break;
- default:
- return null;
+ /**
+ * 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.Mode getPresenceModeFromStatus(int status) {
+ Presence.Mode res;
+ switch (status) {
+ case CONTACT_STATUS_AVAILABLE:
+ res = Presence.Mode.available;
+ break;
+ case CONTACT_STATUS_AVAILABLE_FOR_CHAT:
+ res = Presence.Mode.chat;
+ break;
+ case CONTACT_STATUS_AWAY:
+ res = Presence.Mode.away;
+ break;
+ case CONTACT_STATUS_BUSY:
+ res = Presence.Mode.dnd;
+ break;
+ case CONTACT_STATUS_UNAVAILABLE:
+ res = Presence.Mode.xa;
+ break;
+ default:
+ return null;
+ }
+ return res;
}
- return res;
- }
- /**
- * Get the status of from a presence packet.
- * @param presence the presence containing status
- * @return an int representing the status
- */
- public static int getStatusFromPresence(Presence presence) {
- int res = Status.CONTACT_STATUS_DISCONNECT;
- if (presence.getType().equals(Presence.Type.unavailable)) {
- res = Status.CONTACT_STATUS_DISCONNECT;
- } else {
- Mode mode = presence.getMode();
- if (mode == null) {
- res = Status.CONTACT_STATUS_AVAILABLE;
- } else {
- switch (mode) {
- case available:
- res = Status.CONTACT_STATUS_AVAILABLE;
- break;
- case away:
- res = Status.CONTACT_STATUS_AWAY;
- break;
- case chat:
- res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
- break;
- case dnd:
- res = Status.CONTACT_STATUS_BUSY;
- break;
- case xa:
- res = Status.CONTACT_STATUS_UNAVAILABLE;
- break;
- default:
+ /**
+ * Get the status of from a presence packet.
+ *
+ * @param presence
+ * the presence containing status
+ * @return an int representing the status
+ */
+ public static int getStatusFromPresence(Presence presence) {
+ int res = Status.CONTACT_STATUS_DISCONNECT;
+ if (presence.getType().equals(Presence.Type.unavailable)) {
res = Status.CONTACT_STATUS_DISCONNECT;
- break;
+ } else {
+ Mode mode = presence.getMode();
+ if (mode == null) {
+ res = Status.CONTACT_STATUS_AVAILABLE;
+ } else {
+ switch (mode) {
+ case available:
+ res = Status.CONTACT_STATUS_AVAILABLE;
+ break;
+ case away:
+ res = Status.CONTACT_STATUS_AWAY;
+ break;
+ case chat:
+ res = Status.CONTACT_STATUS_AVAILABLE_FOR_CHAT;
+ break;
+ case dnd:
+ res = Status.CONTACT_STATUS_BUSY;
+ break;
+ case xa:
+ res = Status.CONTACT_STATUS_UNAVAILABLE;
+ break;
+ default:
+ res = Status.CONTACT_STATUS_DISCONNECT;
+ break;
+ }
+ }
}
- }
+ return res;
}
- return res;
- }
-
- /**
- * Check if contact is online by his status.
- * @param status contact status
- * @return is obline
- */
- public static boolean statusOnline(int status) {
- return (status != Status.CONTACT_STATUS_DISCONNECT && status != Status.CONTACT_STATUS_UNAVAILABLE);
- }
-
+
+ /**
+ * Check if contact is online by his status.
+ *
+ * @param status
+ * contact status
+ * @return is obline
+ */
+ public static boolean statusOnline(int status) {
+ return (status != Status.CONTACT_STATUS_DISCONNECT && status != Status.CONTACT_STATUS_UNAVAILABLE);
+ }
+
}