# HG changeset patch # User Da Risk # Date 1258240266 -3600 # Node ID e1a9ba4611dc153ea5c051f05462d268f8cd8f36 # Parent 1bd07ab7a1ad935f0d3482297891237298f75980 Ajout d'options pour definir sa ressource et sa priorité diff -r 1bd07ab7a1ad -r e1a9ba4611dc res/layout/preferences.xml --- a/res/layout/preferences.xml Sat Nov 14 00:45:45 2009 +0100 +++ b/res/layout/preferences.xml Sun Nov 15 00:11:06 2009 +0100 @@ -37,7 +37,17 @@ android:summary="@string/SettingsPassword" android:title="@string/settings_account_password" android:key="settings_key_account_password" /> - + + Cochez cette option pour utiliser un serveur spécifique Saisissez l\'adresse du serveur à joindre Saisissez le port du serveur + Ressource + Priorité + Saisissez la resource à partir de laquelle vous vous connectez + Saisissez la priorité de votre client Inscription acceptée @@ -116,7 +120,7 @@ Vous avez été déconnecté(e) - %s vient de vous ajouter à sa liste d'amis. + %s vient de vous ajouter à sa liste d\'amis. Autoriser %s à vous contacter. Subscription accepted diff -r 1bd07ab7a1ad -r e1a9ba4611dc src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sat Nov 14 00:45:45 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Sun Nov 15 00:11:06 2009 +0100 @@ -202,8 +202,16 @@ public void initJingle(XMPPConnection adaptee) { mJingle.initWhenConntected(adaptee); } - + public IXmppFacade getBind() { return mBind; } + + /** + * Get the preference of the service. + * @return the preference + */ + public SharedPreferences getServicePreference() { + return mSettings; + } } diff -r 1bd07ab7a1ad -r e1a9ba4611dc src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sat Nov 14 00:45:45 2009 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Sun Nov 15 00:11:06 2009 +0100 @@ -17,6 +17,7 @@ import android.app.Notification; import android.app.PendingIntent; import android.content.Intent; +import android.content.SharedPreferences; import android.os.RemoteCallbackList; import android.os.RemoteException; import android.util.Log; @@ -29,6 +30,8 @@ import com.beem.project.beem.service.aidl.IXmppConnection; import com.beem.project.beem.ui.Subscription; import com.beem.project.beem.utils.BeemBroadcastReceiver; +import com.beem.project.beem.ui.ChangeStatus; +import com.beem.project.beem.utils.Status; /** * This class implements an adapter for XMPPConnection. @@ -47,7 +50,9 @@ private IChatManager mChatManager; private final String mLogin; private final String mPassword; + private String mResource; private RosterAdapter mRoster; + private int mPreviousPriority; private PrivacyListManagerAdapter mPrivacyList; private final BeemService mService; private final RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); @@ -92,6 +97,13 @@ mLogin = login; mPassword = password; mService = service; + SharedPreferences pref = mService.getServicePreference(); + try { + mPreviousPriority = Integer.parseInt(pref.getString("settings_key_priority", "0")); + mResource = pref.getString("settings_key_resource", "BEEM"); + } catch (NumberFormatException ex) { + mPreviousPriority = 0; + } } /** @@ -130,7 +142,7 @@ try { mAdaptee.connect(); mAdaptee.addConnectionListener(mConListener); - mAdaptee.login(mLogin, mPassword, "BEEM"); + mAdaptee.login(mLogin, mPassword, mResource); mChatManager = new BeemChatManager(mAdaptee.getChatManager(), mService); mPrivacyList = new PrivacyListManagerAdapter(mAdaptee); @@ -140,10 +152,7 @@ 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); + changeStatus(Status.CONTACT_STATUS_AVAILABLE, mService.getServicePreference().getString("status_text", "")); return true; } catch (XMPPException e) { Log.d(TAG, "Error while connecting", e); @@ -163,6 +172,59 @@ * {@inheritDoc} */ @Override + public void changeStatusAndPriority(int status, String msg, int priority) { + Presence pres = new Presence(Presence.Type.available); + if (msg != null) + pres.setStatus(msg); + else + msg = ""; + Presence.Mode mode = Status.getPresenceModeFromStatus(status); + if (mode != null) + pres.setMode(mode); + // Smack limit : Priority between -128 and 128 + if (priority < -128) priority = -128; + if (priority > 128) priority = 128; + mPreviousPriority = priority; + pres.setPriority(priority); + mAdaptee.sendPacket(pres); + updateNotification(msg); + } + + /** + * {@inheritDoc} + */ + @Override + public void changeStatus(int status, String msg) { + Presence pres = new Presence(Presence.Type.available); + if (msg != null) + pres.setStatus(msg); + else + msg = ""; + Presence.Mode mode = Status.getPresenceModeFromStatus(status); + if (mode != null) + pres.setMode(mode); + pres.setPriority(mPreviousPriority); + mAdaptee.sendPacket(pres); + updateNotification(msg); + } + + private void updateNotification(String text) { + Notification mStatusNotification; + mStatusNotification = new Notification(com.beem.project.beem.R.drawable.beem_status_icon, text, System + .currentTimeMillis()); + mStatusNotification.defaults = Notification.DEFAULT_LIGHTS; + mStatusNotification.flags = Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; + + mStatusNotification.setLatestEventInfo(mService, "Beem Status", text, PendingIntent.getActivity( + mService, 0, new Intent(mService, ChangeStatus.class), 0)); + mService.sendNotification(BeemService.NOTIFICATION_STATUS_ID, mStatusNotification); + + } + + /** + * {@inheritDoc} + */ + @Override public boolean disconnect() { if (mAdaptee != null && mAdaptee.isConnected()) mAdaptee.disconnect(); diff -r 1bd07ab7a1ad -r e1a9ba4611dc src/com/beem/project/beem/service/XmppFacade.java --- a/src/com/beem/project/beem/service/XmppFacade.java Sat Nov 14 00:45:45 2009 +0100 +++ b/src/com/beem/project/beem/service/XmppFacade.java Sun Nov 15 00:11:06 2009 +0100 @@ -46,26 +46,7 @@ */ @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); - - 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); + mConnexion.changeStatus(status, msg); } /** diff -r 1bd07ab7a1ad -r e1a9ba4611dc src/com/beem/project/beem/service/aidl/IXmppConnection.aidl --- a/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Sat Nov 14 00:45:45 2009 +0100 +++ b/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Sun Nov 15 00:11:06 2009 +0100 @@ -5,19 +5,23 @@ import com.beem.project.beem.service.aidl.IChatManager; interface IXmppConnection { - + boolean connectSync(); - + void connectAsync(); - + boolean disconnect(); - + IRoster getRoster(); void addConnectionListener(in IBeemConnectionListener listen); void removeConnectionListener(in IBeemConnectionListener listen); - + boolean isAuthentificated(); - + IChatManager getChatManager(); -} \ No newline at end of file + + void changeStatusAndPriority(in int status, in String msg, in int priority); + + void changeStatus(in int status, in String msg); +}