# HG changeset patch # User Nikita Kozlov # Date 1262103814 -3600 # Node ID 52e24c3386f34926d1a1b0f2027873c8ca279c56 # Parent 3697d163c2bd076772a7a10e5a694fa451c561a8 SDK target set to 6 since google have said that 2.0 will be totaly replaced the 1st 2010 The service is destroyed when all connections are losts. diff -r 3697d163c2bd -r 52e24c3386f3 AndroidManifest.xml --- a/AndroidManifest.xml Sat Dec 26 17:52:47 2009 +0100 +++ b/AndroidManifest.xml Tue Dec 29 17:23:34 2009 +0100 @@ -79,6 +79,6 @@ - + diff -r 3697d163c2bd -r 52e24c3386f3 default.properties --- a/default.properties Sat Dec 26 17:52:47 2009 +0100 +++ b/default.properties Tue Dec 29 17:23:34 2009 +0100 @@ -10,5 +10,5 @@ # Indicates whether an apk should be generated for each density. split.density=false # Project target. -target=android-5 +target=android-6 apk-configurations= diff -r 3697d163c2bd -r 52e24c3386f3 src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sat Dec 26 17:52:47 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Tue Dec 29 17:23:34 2009 +0100 @@ -82,8 +82,10 @@ import android.app.NotificationManager; import android.app.Service; import android.content.Intent; +import android.content.IntentFilter; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.net.ConnectivityManager; import android.os.IBinder; import android.os.RemoteException; import android.preference.PreferenceManager; @@ -93,8 +95,9 @@ import com.beem.project.beem.service.XmppConnectionAdapter; import com.beem.project.beem.service.XmppFacade; import com.beem.project.beem.service.aidl.IXmppFacade; +import com.beem.project.beem.utils.BeemBroadcastReceiver; +import com.beem.project.beem.utils.BeemConnectivity; -// TODO: Auto-generated Javadoc /** * This class is for the Beem service. The connection to the xmpp server will be made asynchronously when the service * will start. @@ -123,6 +126,8 @@ private boolean mUseProxy; private IXmppFacade.Stub mBind; + private BeemBroadcastReceiver mReceiver= new BeemBroadcastReceiver(); + /** * Constructor. */ @@ -188,8 +193,8 @@ */ @Override public void onCreate() { - super.onCreate(); + registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)); mSettings = PreferenceManager.getDefaultSharedPreferences(this); String tmpJid = mSettings.getString("settings_key_account_username", ""); mLogin = StringUtils.parseName(tmpJid); @@ -225,8 +230,10 @@ @Override public void onDestroy() { super.onDestroy(); + Log.d("Service", "onDestroy"); mNotificationManager.cancelAll(); - if (mConnection.isAuthentificated()) + unregisterReceiver(mReceiver); + if (mConnection.isAuthentificated() && BeemConnectivity.isConnected(this)) mConnection.disconnect(); Log.d(TAG, "ONDESTROY"); } @@ -239,7 +246,7 @@ super.onStart(intent, startId); Log.d(TAG, "onStart"); try { - mConnection.connectAsync(); + mConnection.connectAsync(); } catch (RemoteException e) { e.printStackTrace(); } diff -r 3697d163c2bd -r 52e24c3386f3 src/com/beem/project/beem/ui/CreateAccount.java --- a/src/com/beem/project/beem/ui/CreateAccount.java Sat Dec 26 17:52:47 2009 +0100 +++ b/src/com/beem/project/beem/ui/CreateAccount.java Tue Dec 29 17:23:34 2009 +0100 @@ -74,7 +74,6 @@ 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; diff -r 3697d163c2bd -r 52e24c3386f3 src/com/beem/project/beem/utils/BeemBroadcastReceiver.java --- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Sat Dec 26 17:52:47 2009 +0100 +++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Tue Dec 29 17:23:34 2009 +0100 @@ -47,10 +47,12 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.net.ConnectivityManager; import android.util.Log; import android.widget.Toast; -// TODO: Auto-generated Javadoc +import com.beem.project.beem.BeemService; + /** * Manage broadcast disconnect intent. * @author nikita @@ -76,6 +78,7 @@ // start activity if unexpected disconnection // if (!intent.getBooleanExtra("normally", false)) // context.startActivity(new Intent(context, Login.class)); + if (intent.getAction().equals(BEEM_CONNECTION_CLOSED)) { CharSequence message = intent.getCharSequenceExtra("message"); Toast.makeText(context, message, Toast.LENGTH_SHORT).show(); if (context instanceof Activity) { @@ -83,5 +86,11 @@ act.finish(); // The service will be unbinded in the destroy of the activity. } + } else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) { + if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) { + Log.d("Broadcast", "stopService"); + context.stopService(new Intent(context, BeemService.class)); + } + } } }