deplacement de l'eventListener cote service
authorNikita Kozlov <nikita@beem-project.com>
Thu, 24 Sep 2009 17:35:59 +0200
changeset 377 5f60caa9f85c
parent 376 76d505cbe7db
child 380 9416b5711edd
deplacement de l'eventListener cote service
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/Subscription.java
--- a/src/com/beem/project/beem/BeemService.java	Thu Sep 24 12:30:17 2009 +0200
+++ b/src/com/beem/project/beem/BeemService.java	Thu Sep 24 17:35:59 2009 +0200
@@ -13,6 +13,7 @@
 import android.app.Service;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
 import android.os.IBinder;
 import android.os.RemoteException;
 import android.util.Log;
@@ -169,4 +170,13 @@
 	mNotificationManager.notify(id, notif);
     }
 
+    /**
+     * Reset the status to online after a deconnection.
+     */
+    public void resetStatus() {
+	Editor edit = mSettings.edit();
+	edit.putInt(getString(R.string.PreferenceStatus), 1);
+	edit.commit();
+    }
+
 }
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Sep 24 12:30:17 2009 +0200
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Sep 24 17:35:59 2009 +0200
@@ -7,8 +7,7 @@
 import org.jivesoftware.smack.Roster;
 import org.jivesoftware.smack.XMPPConnection;
 import org.jivesoftware.smack.XMPPException;
-import org.jivesoftware.smack.PacketListener;
-
+import org.jivesoftware.smack.filter.PacketFilter;
 import org.jivesoftware.smack.packet.Packet;
 import org.jivesoftware.smack.packet.Presence;
 import org.jivesoftware.smackx.ChatStateManager;
@@ -358,10 +357,7 @@
 		}
 	    }, filter);
 
-	    /*  Editor edit = mSettings.edit();
-	    edit.putInt(getString(R.string.PreferenceStatus), 1);
-	    edit.commit();*/
-
+	    mService.resetStatus();
 
 	    final int n = mRemoteConnListeners.beginBroadcast();
 
--- a/src/com/beem/project/beem/ui/Subscription.java	Thu Sep 24 12:30:17 2009 +0200
+++ b/src/com/beem/project/beem/ui/Subscription.java	Thu Sep 24 17:35:59 2009 +0200
@@ -29,72 +29,72 @@
  */
 public class Subscription extends Activity {
 
-	public static final String TAG = "Subscription";
-	private IXmppFacade mService;
-	private String mContact;
-	private ServiceConnection mServConn = new BeemServiceConnection();
+    public static final String TAG = "Subscription";
+    private IXmppFacade mService;
+    private String mContact;
+    private ServiceConnection mServConn = new BeemServiceConnection();
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+	super.onCreate(savedInstanceState);
+	setContentView(R.layout.subscription);
+	bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
+	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);
+    }
+
+    @Override
+    protected void onDestroy() {
+	super.onDestroy();
+	unbindService(mServConn);
+    }
+
+    private OnClickListener mClickListener = new OnClickListener() {
 
 	@Override
-	protected void onCreate(Bundle savedInstanceState) {
-		super.onCreate(savedInstanceState);
-		setContentView(R.layout.subscription);
-		bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE);
-		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);
+	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();
+	    };
+	}
+    };
+
+    private class BeemServiceConnection implements ServiceConnection {
+
+	@Override
+	public void onServiceConnected(ComponentName name, IBinder service) {
+	    mService = IXmppFacade.Stub.asInterface(service);			
 	}
 
 	@Override
-	protected void onDestroy() {
-		super.onDestroy();
-		unbindService(mServConn);
+	public void onServiceDisconnected(ComponentName name) {
+	    mService = null;
 	}
-
-	private OnClickListener mClickListener = new OnClickListener() {
-
-		@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();
-			};
-		}
-	};
-
-	private class BeemServiceConnection implements ServiceConnection {
-
-		@Override
-		public void onServiceConnected(ComponentName name, IBinder service) {
-			mService = IXmppFacade.Stub.asInterface(service);			
-		}
-
-		@Override
-		public void onServiceDisconnected(ComponentName name) {
-			mService = null;
-		}
-	}
+    }
 }