# HG changeset patch # User Da Risk # Date 1266542781 -3600 # Node ID 03d61b8faa0d83b1c426621c812c9111ce921a78 # Parent bd5bddda04ddcd2badb9896e479582c403fe7826# Parent 99931d858ac0910ebf6230044337855d836028ef Merge diff -r bd5bddda04dd -r 03d61b8faa0d .classpath --- a/.classpath Fri Feb 19 02:21:35 2010 +0100 +++ b/.classpath Fri Feb 19 02:26:21 2010 +0100 @@ -1,9 +1,8 @@ - - - + + diff -r bd5bddda04dd -r 03d61b8faa0d AndroidManifest.xml --- a/AndroidManifest.xml Fri Feb 19 02:21:35 2010 +0100 +++ b/AndroidManifest.xml Fri Feb 19 02:26:21 2010 +0100 @@ -76,6 +76,8 @@ android:label="Beem Service" android:permission="com.beem.project.beem.BEEM_SERVICE"> + + diff -r bd5bddda04dd -r 03d61b8faa0d res/layout/preferences.xml --- a/res/layout/preferences.xml Fri Feb 19 02:21:35 2010 +0100 +++ b/res/layout/preferences.xml Fri Feb 19 02:26:21 2010 +0100 @@ -10,6 +10,13 @@ + + diff -r bd5bddda04dd -r 03d61b8faa0d res/values-fr/strings.xml --- a/res/values-fr/strings.xml Fri Feb 19 02:21:35 2010 +0100 +++ b/res/values-fr/strings.xml Fri Feb 19 02:26:21 2010 +0100 @@ -83,8 +83,6 @@ Saisissez votre identifiant de connexion Saisissez votre mot de passe - Utilisation de Gmail - Cochez cette option si vous souhaitez utiliser votre compte Gmail Proxy Utiliser un proxy Connectez vous à travers un serveur proxy @@ -104,6 +102,39 @@ Priorité Saisissez la resource à partir de laquelle vous vous connectez Saisissez la priorité de votre client + Liste d\'ami(e)s + Une série d\'options d\'affichage de votre liste + d\'ami(e)s + Cachez les groupes + Cochez cette option pour cacher les groupes + Cachez les contacts + Cochez cette option pour cacher les contacts déconnectés + Nom d\'utilisateur + beem@beem-project.com + Mot de passe + Serveur + Port + Comportement du service + Une série d\'options pour les utilisateurs avertis + Serveur + example.com + Port + Default: 5222 + SSL/TLS obligatoire + Délai de reconnexion + Paramètrez un serveur proxy + Utiliser un proxy + Choisir un type de proxy + Serveur + Port + Default: 1080 + Nom d\'utilisateur + Mot de passe + Activer l'absence automatique + Change votre status en Absent automatiquement quand l\'écran du telephone s\'éteind + Message d'asbence + Votre Message d'absence + Je suis absent car mon ecran est éteind Inscription acceptée @@ -199,44 +230,6 @@ edit_settings_tab_proxy Proxy - - Liste d\'ami(e)s - Une série d\'options d\'affichage de votre liste - d\'ami(e)s - - Cachez les groupes - Cochez cette option pour cacher les groupes - Cachez les contacts - Cochez cette option pour cacher les contacts déconnectés - - - Nom d\'utilisateur - beem@beem-project.com - Mot de passe - Serveur - Port - - - Comportement du service - Une série d\'options pour les utilisateurs avertis - Serveur - example.com - Port - Default: 5222 - SSL/TLS obligatoire - Délai de reconnexion - - - - Paramètrez un serveur proxy - Utiliser un proxy - Choisir un type de proxy - Serveur - Port - Default: 1080 - Nom d\'utilisateur - Mot de passe - diff -r bd5bddda04dd -r 03d61b8faa0d res/values/strings.xml --- a/res/values/strings.xml Fri Feb 19 02:21:35 2010 +0100 +++ b/res/values/strings.xml Fri Feb 19 02:26:21 2010 +0100 @@ -71,7 +71,6 @@ My status My personal message Open contact list - Add new contact Beem Project @@ -83,8 +82,6 @@ Edit your username Edit your password - Using Gmail - Use my Gmail account Proxy Use a proxy server Login through a proxy server @@ -104,6 +101,40 @@ Priority Set the XMPP resource of your client Set the priority of your client + Buddy list + A set of display options for your buddy list + + Hide groups + Check this option to hide groups + Hide buddies + Check this option to hide unconnected buddies + + Username + beem@beem-project.com + Password + Server + Port + Service behaviour + A set of options for advanced users + Address + example.com + Port + Require SSL/TLS + Reconnection delay + Default: 5222 + Settings for proxy usage + Connect using a proxy + Choose a type of proxy + Server + Port + Default: 1080 + Username + Password + Enable Auto-away + Change status to Away when the screen is turned off + Away message + The away message that will be displayed + I'm away, my cellphone screen is off Subscription accepted @@ -190,42 +221,10 @@ Proxy - Buddy list - A set of display options for your buddy list - - - Hide groups - Check this option to hide groups - Hide buddies - Check this option to hide unconnected buddies - - - - Username - beem@beem-project.com - Password - Server - Port - - Service behaviour - A set of options for advanced users - Address - example.com - Port - Require SSL/TLS - Reconnection delay - Default: 5222 + - - Settings for proxy usage - Connect using a proxy - Choose a type of proxy - Server - Port - Default: 1080 - Username - Password + Create an account - Instructions diff -r bd5bddda04dd -r 03d61b8faa0d src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Fri Feb 19 02:21:35 2010 +0100 +++ b/src/com/beem/project/beem/BeemService.java Fri Feb 19 02:26:21 2010 +0100 @@ -57,6 +57,8 @@ import android.app.Notification; import android.app.NotificationManager; import android.app.Service; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; @@ -72,6 +74,7 @@ import com.beem.project.beem.service.aidl.IXmppFacade; import com.beem.project.beem.utils.BeemBroadcastReceiver; import com.beem.project.beem.utils.BeemConnectivity; +import com.beem.project.beem.utils.Status; /** * This class is for the Beem service. The connection to the xmpp server will be made asynchronously when the service @@ -85,7 +88,7 @@ private static final String TAG = "BeemService"; private static final int DEFAULT_XMPP_PORT = 5222; - private static final String COMMAND_NAMESPACE = "http://jabber.org/protocol/commands"; + //private static final String COMMAND_NAMESPACE = "http://jabber.org/protocol/commands"; private NotificationManager mNotificationManager; private XmppConnectionAdapter mConnection; @@ -101,6 +104,10 @@ private IXmppFacade.Stub mBind; private BeemBroadcastReceiver mReceiver = new BeemBroadcastReceiver(); + private BeemServiceBroadcastReceiver mOnOffReceiver = new BeemServiceBroadcastReceiver(); + private BeemServicePreferenceListener mPreferenceListener = new BeemServicePreferenceListener(); + + private boolean mOnOffReceiverIsRegistered; /** * Constructor. @@ -109,10 +116,9 @@ } /** - * Initialise la configuration de la connexion. + * Initialize the connection. */ 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"); @@ -160,6 +166,8 @@ return true; } + + /** * {@inheritDoc} */ @@ -168,6 +176,12 @@ super.onCreate(); registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mSettings = PreferenceManager.getDefaultSharedPreferences(this); + mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener); + if (mSettings.getBoolean("settings_away_chk", false)) { + mOnOffReceiverIsRegistered = true; + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); + } String tmpJid = mSettings.getString("settings_key_account_username", ""); mLogin = StringUtils.parseName(tmpJid); mPassword = mSettings.getString("settings_key_account_password", ""); @@ -180,7 +194,7 @@ if ("".equals(mHost)) mHost = StringUtils.parseServer(tmpJid); String tmpPort = mSettings.getString("settings_key_xmpp_port", "5222"); - mPort = ("".equals(tmpPort)) ? DEFAULT_XMPP_PORT : Integer.parseInt(tmpPort) ; + mPort = ("".equals(tmpPort)) ? DEFAULT_XMPP_PORT : Integer.parseInt(tmpPort); } if ("gmail.com".equals(mService) || "googlemail.com".equals(mService)) { mLogin = tmpJid; @@ -206,6 +220,9 @@ Log.d("Service", "onDestroy"); mNotificationManager.cancelAll(); unregisterReceiver(mReceiver); + mSettings.unregisterOnSharedPreferenceChangeListener(mPreferenceListener); + if (mOnOffReceiverIsRegistered) + unregisterReceiver(mOnOffReceiver); if (mConnection.isAuthentificated() && BeemConnectivity.isConnected(this)) mConnection.disconnect(); Log.d(TAG, "ONDESTROY"); @@ -243,7 +260,7 @@ } /** - * Reset the status to online after a deconnection. + * Reset the status to online after a disconnect. */ public void resetStatus() { Editor edit = mSettings.edit(); @@ -364,5 +381,64 @@ new AdHocCommandDataProvider.SessionExpiredError()); */ } + + /** + * Listen on preference changes. + */ + private class BeemServicePreferenceListener implements SharedPreferences.OnSharedPreferenceChangeListener { + + /** + * ctor. + */ + public BeemServicePreferenceListener() { + } + + /** + * {@inheritDoc} + */ + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if ("settings_away_chk".equals(key)) { + if (sharedPreferences.getBoolean("settings_away_chk", false)) { + mOnOffReceiverIsRegistered = true; + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF)); + registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON)); + } else { + mOnOffReceiverIsRegistered = false; + unregisterReceiver(mOnOffReceiver); + } + } + } + } + + /** + * Listen on some Intent broadcast, ScreenOn and ScreenOff. + */ + private class BeemServiceBroadcastReceiver extends BroadcastReceiver { + + private String mOldStatus; + private int mOldMode; + + /** + * ctor. + */ + public BeemServiceBroadcastReceiver() { + } + + /** + * {@inheritDoc} + */ + @Override + public void onReceive(final Context context, final Intent intent) { + String intentAction = intent.getAction(); + if (intentAction.equals(Intent.ACTION_SCREEN_OFF)) { + mOldMode = mConnection.getPreviousMode(); + mOldStatus = mConnection.getPreviousStatus(); + mConnection.changeStatus(Status.CONTACT_STATUS_AWAY, mSettings.getString("settings_away_message", "Away")); + } else if (intentAction.equals(Intent.ACTION_SCREEN_ON)) { + mConnection.changeStatus(mOldMode, mOldStatus); + } + } + } } diff -r bd5bddda04dd -r 03d61b8faa0d src/com/beem/project/beem/service/XmppConnectionAdapter.java --- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Fri Feb 19 02:21:35 2010 +0100 +++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Fri Feb 19 02:26:21 2010 +0100 @@ -99,6 +99,8 @@ private String mErrorMsg; private RosterAdapter mRoster; private int mPreviousPriority; + private int mPreviousMode; + private String mPreviousStatus; private PrivacyListManagerAdapter mPrivacyListManager; private final BeemService mService; private BeemApplication mApplication; @@ -184,7 +186,7 @@ mService.getResources().getIdentifier( e.getXMPPError().getCondition().replace("-", "_"), "string", "com.beem.project.beem")); mErrorMsg = str; - } catch(NullPointerException e2) { + } catch (NullPointerException e2) { if (!"".equals(e.getMessage())) mErrorMsg = e.getMessage(); else @@ -277,11 +279,16 @@ if (msg != null) m = msg; else - m = ""; + m = mPreviousStatus; pres.setStatus(m); + mPreviousStatus = m; Presence.Mode mode = Status.getPresenceModeFromStatus(status); - if (mode != null) + if (mode != null) { pres.setMode(mode); + mPreviousMode = status; + } else { + pres.setMode(Status.getPresenceModeFromStatus(mPreviousMode)); + } int p = priority; if (priority < SMACK_PRIORITY_MIN) p = SMACK_PRIORITY_MIN; @@ -298,19 +305,23 @@ */ @Override public void changeStatus(int status, String msg) { - Presence pres = new Presence(Presence.Type.available); - String m; - if (msg != null) - m = msg; - else - m = ""; - pres.setStatus(m); - Presence.Mode mode = Status.getPresenceModeFromStatus(status); - if (mode != null) - pres.setMode(mode); - pres.setPriority(mPreviousPriority); - mAdaptee.sendPacket(pres); - updateNotification(msg); + changeStatusAndPriority(status, msg, mPreviousPriority); + } + + /** + * get the previous status. + * @return previous status. + */ + public String getPreviousStatus() { + return mPreviousStatus; + } + + /** + * get the previous mode. + * @return previous mode. + */ + public int getPreviousMode() { + return mPreviousMode; } /** @@ -356,14 +367,6 @@ } /** - * Get the context of the adapter. - * @return The context of the adapter - */ - public BeemService getContext() { - return mService; - } - - /** * {@inheritDoc} */ @Override diff -r bd5bddda04dd -r 03d61b8faa0d src/com/beem/project/beem/utils/BeemBroadcastReceiver.java --- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Fri Feb 19 02:21:35 2010 +0100 +++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Fri Feb 19 02:26:21 2010 +0100 @@ -51,6 +51,7 @@ import android.widget.Toast; import com.beem.project.beem.BeemService; +import com.beem.project.beem.R; /** * Manage broadcast disconnect intent. @@ -83,6 +84,7 @@ } } else if (intentAction.equals(ConnectivityManager.CONNECTIVITY_ACTION)) { if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { + Toast.makeText(context, context.getString(R.string.BeemBroadcastReceiverDisconnect), Toast.LENGTH_SHORT).show(); context.stopService(new Intent(context, BeemService.class)); } }