Fixes #207
Use the BroadcastReceiver to closes activities on disconnection event.
--- a/res/values-en/strings.xml Wed Oct 28 15:32:35 2009 +0100
+++ b/res/values-en/strings.xml Wed Oct 28 20:17:04 2009 +0100
@@ -3,6 +3,7 @@
<string name="app_name">Beem</string>
<string name="OkButton">Ok</string>
<string name="ClearButton">Clear</string>
+ <string name="CancelButton">Cancel</string>
<string name="AcceptButton">Accept</string>
<string name="RefuseButton">Refuse</string>
--- a/res/values-fr/strings.xml Wed Oct 28 15:32:35 2009 +0100
+++ b/res/values-fr/strings.xml Wed Oct 28 20:17:04 2009 +0100
@@ -2,7 +2,8 @@
<resources>
<string name="app_name">Beem</string>
<string name="OkButton">Valider</string>
- <string name="ClearButton">Annuler</string>
+ <string name="ClearButton">Effacer</string>
+ <string name="CancelButton">Annuler</string>
<string name="AcceptButton">Accepter</string>
<string name="RefuseButton">Refuser</string>
--- a/src/com/beem/project/beem/BeemService.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/BeemService.java Wed Oct 28 20:17:04 2009 +0100
@@ -139,6 +139,7 @@
Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
mJingle = new JingleService(mConnection.getAdaptee());
mBind = new XmppFacade(mConnection, this, mJingle);
+ Log.d("BEEEMSERVICE", "ONCREATE");
}
/**
@@ -148,6 +149,8 @@
public void onDestroy() {
super.onDestroy();
mNotificationManager.cancel(NOTIFICATION_STATUS_ID);
+ if (mConnection.isAuthentificated())
+ mConnection.disconnect();
Log.d("BEEEMSERVICE", "ONDESTROY");
}
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Wed Oct 28 20:17:04 2009 +0100
@@ -278,6 +278,7 @@
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();
}
--- a/src/com/beem/project/beem/ui/AddContact.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/AddContact.java Wed Oct 28 20:17:04 2009 +0100
@@ -59,6 +59,12 @@
mReceiver = new BeemBroadcastReceiver(mServConn);
}
+ @Override
+ protected void onStart() {
+ super.onStart();
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ }
+
/**
* {@inheritDoc}
*/
@@ -67,7 +73,7 @@
super.onResume();
this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded();
+ mReceiver.setBinded(true);
}
/**
@@ -76,9 +82,16 @@
@Override
protected void onPause() {
super.onPause();
- this.unregisterReceiver(mReceiver);
- if (mReceiver.isBinded())
+ if (mReceiver.isBinded()) {
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
/**
@@ -95,6 +108,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
}
@Override
--- a/src/com/beem/project/beem/ui/ChangeStatus.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/ChangeStatus.java Wed Oct 28 20:17:04 2009 +0100
@@ -85,6 +85,7 @@
mReceiver = new BeemBroadcastReceiver(mServConn);
mStatusText.setText(getPreferenceString(R.string.PreferenceStatusText));
mSpinner.setSelection(getPreferenceStatusIndex());
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
}
/**
@@ -94,8 +95,7 @@
protected void onResume() {
super.onResume();
bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded();
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
+ mReceiver.setBinded(true);
}
/**
@@ -105,9 +105,16 @@
protected void onPause() {
super.onPause();
Log.d("TAG", "pause");
- this.unregisterReceiver(mReceiver);
- if (mReceiver.isBinded())
+ if (mReceiver.isBinded()) {
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
/**
@@ -151,9 +158,6 @@
}
}
-
-
-
/**
* connection to service.
* @author nikita
@@ -208,7 +212,6 @@
edit.commit();
if (status == Status.CONTACT_STATUS_DISCONNECT) {
stopService(new Intent(ChangeStatus.this, BeemService.class));
- startActivity(new Intent(ChangeStatus.this, Login.class));
} else {
try {
mXmppFacade.changeStatus(status, msg.toString());
--- a/src/com/beem/project/beem/ui/ContactList.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java Wed Oct 28 20:17:04 2009 +0100
@@ -88,27 +88,10 @@
mAdapterBanner = new BeemBanner(this);
mHandler = new Handler();
mReceiver = new BeemBroadcastReceiver(mServConn);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
}
/**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- this.unregisterReceiver(mReceiver);
- }
-
- /**
* Callback for menu creation.
* @param menu the menu created
* @return true on success, false otherwise
@@ -159,7 +142,6 @@
protected void onStart() {
super.onStart();
bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded();
}
/**
@@ -170,6 +152,13 @@
super.onStop();
if (mReceiver.isBinded())
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
/**
@@ -643,6 +632,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
try {
mRoster = mXmppFacade.getRoster();
if (mRoster != null) {
@@ -691,6 +681,7 @@
}
mXmppFacade = null;
mRoster = null;
+ mReceiver.setBinded(false);
}
}
}
--- a/src/com/beem/project/beem/ui/GroupList.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/GroupList.java Wed Oct 28 20:17:04 2009 +0100
@@ -70,6 +70,7 @@
mText = (TextView) findViewById(R.id.GroupListText);
mText.setOnKeyListener(new GroupListOnKeyListener());
+ this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
}
/**
@@ -78,9 +79,8 @@
@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();
+ mReceiver.setBinded(true);
}
/**
@@ -89,9 +89,16 @@
@Override
protected void onPause() {
super.onPause();
- this.unregisterReceiver(mReceiver);
- if (mReceiver.isBinded())
+ if (mReceiver.isBinded()){
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
/**
@@ -191,6 +198,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
try {
mRoster = mXmppFacade.getRoster();
setAdapter();
--- a/src/com/beem/project/beem/ui/SendIM.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/SendIM.java Wed Oct 28 20:17:04 2009 +0100
@@ -111,18 +111,12 @@
mToSend.setOnKeyListener(this);
mStatusIcon = (ImageView) findViewById(R.id.sendimstatus);
mLogin = (TextView) findViewById(R.id.sendimlogin);
- try {
- mContact = new Contact(getIntent().getData());
- if (mRoster != null)
- mContact = mRoster.getContact(mContact.getJID());
- } catch (RemoteException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ 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));
}
/**
@@ -142,6 +136,7 @@
@Override
protected void onDestroy() {
super.onDestroy();
+ this.unregisterReceiver(mReceiver);
if (mChatManager != null) {
try {
mChatManager.removeChatCreationListener(mChatManagerListener);
@@ -247,29 +242,19 @@
* {@inheritDoc}
*/
@Override
- protected void onPause() {
- super.onPause();
- this.unregisterReceiver(mReceiver);
+ 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())
+ if (mReceiver.isBinded()){
unbindService(mServConn);
- }
-
- /**
- * {@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();
- mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
+ mReceiver.setBinded(false);
+ }
+ mRoster = null;
}
/**
@@ -278,7 +263,8 @@
@Override
protected void onStart() {
super.onStart();
- // TODO cancel the notification if any
+ bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+ mScrolling.fullScroll(ScrollView.FOCUS_DOWN);
try {
if (mRoster != null)
mContact = mRoster.getContact(mContact.getJID());
@@ -288,6 +274,7 @@
}
}
+
/**
* The service connection used to connect with the BeemService.
*/
@@ -303,6 +290,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
try {
if (mChatManager == null) {
mChatManager = mXmppFacade.getChatManager();
@@ -327,12 +315,14 @@
@Override
public void onServiceDisconnected(ComponentName name) {
+ mReceiver.setBinded(false);
mXmppFacade = null;
try {
mRoster.removeRosterListener(mBeemRosterListener);
} catch (RemoteException e) {
e.printStackTrace();
}
+ mRoster = null;
}
}
--- a/src/com/beem/project/beem/ui/Subscription.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/Subscription.java Wed Oct 28 20:17:04 2009 +0100
@@ -56,24 +56,31 @@
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();
- this.registerReceiver(mReceiver, new IntentFilter(BeemBroadcastReceiver.BEEM_CONNECTION_CLOSED));
bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
- mReceiver.setBinded();
+ mReceiver.setBinded(true);
}
@Override
protected void onPause() {
super.onPause();
- this.unregisterReceiver(mReceiver);
- if (mReceiver.isBinded())
+ if (mReceiver.isBinded()){
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
+ }
+
/**
* Event simple click on buttons.
*/
@@ -127,6 +134,7 @@
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
mService = IXmppFacade.Stub.asInterface(service);
+ mReceiver.setBinded(true);
}
@Override
--- a/src/com/beem/project/beem/ui/UserInfo.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/ui/UserInfo.java Wed Oct 28 20:17:04 2009 +0100
@@ -77,6 +77,7 @@
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));
}
/**
@@ -85,9 +86,7 @@
@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();
}
/**
@@ -96,9 +95,16 @@
@Override
protected void onPause() {
super.onPause();
- this.unregisterReceiver(mReceiver);
- if (mReceiver.isBinded())
+ if (mReceiver.isBinded()){
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ this.unregisterReceiver(mReceiver);
}
/**
@@ -337,6 +343,7 @@
@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");
--- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Wed Oct 28 15:32:35 2009 +0100
+++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Wed Oct 28 20:17:04 2009 +0100
@@ -1,5 +1,6 @@
package com.beem.project.beem.utils;
+import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -37,18 +38,25 @@
@Override
public void onReceive(Context context, Intent intent) {
Log.d("Broadcast","onREceive");
- context.unbindService(mService);
- mIsBinded = false;
- context.startActivity(new Intent(context, Login.class));
+ 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.
*/
- public void setBinded() {
- mIsBinded = true;
+ public void setBinded(boolean binded) {
+ mIsBinded = binded;
}
/**