Bug #180
authornikita@nikita-lab
Sat, 20 Jun 2009 19:43:37 +0200
changeset 254 daf9be1b7b1f
parent 253 8ccdc5cc81e2
child 255 8d0efe92412b
Bug #180 mService initialise comme il faut.
src/com/beem/project/beem/ui/ContactDialog.java
src/com/beem/project/beem/ui/Subscription.java
--- a/src/com/beem/project/beem/ui/ContactDialog.java	Sat Jun 20 19:15:19 2009 +0200
+++ b/src/com/beem/project/beem/ui/ContactDialog.java	Sat Jun 20 19:43:37 2009 +0200
@@ -23,107 +23,107 @@
 
 public class ContactDialog extends Dialog {
 
-    public static final String TAG = "Option Dialog";
-    private final Contact mContact;
-    private final Context mContext;
-    private IXmppFacade xmppFacade = null;
-    private final ServiceConnection mServConn = new BeemServiceConnection();
+	public static final String TAG = "Option Dialog";
+	private final Contact mContact;
+	private final Context mContext;
+	private IXmppFacade xmppFacade = null;
+	private final ServiceConnection mServConn = new BeemServiceConnection();
 
-    public ContactDialog(final Context context, Contact curContact) {
-	super(context);
-	mContext = context;
-
-	setContentView(R.layout.contactdialog);
-	mContact = curContact;
-	setTitle(curContact.getJID());
+	public ContactDialog(final Context context, Contact curContact) {
+		super(context);
+		mContext = context;
 
-	Button button = (Button) findViewById(R.id.CDChat);
-	button.setOnClickListener(new chatListener());
-	button = (Button) findViewById(R.id.CDAlias);
-	button.setOnClickListener(new aliasListener());
-	button = (Button) findViewById(R.id.CDGroup);
-	button.setOnClickListener(new groupListener());
-	button = (Button) findViewById(R.id.CDResend);
-	button.setOnClickListener(new resendListener());
-	button = (Button) findViewById(R.id.CDInfos);
-	button.setOnClickListener(new infosListener());
-	
-	mContext.bindService(new Intent(mContext, BeemService.class), mServConn, Service.BIND_AUTO_CREATE);
-    }
+		setContentView(R.layout.contactdialog);
+		mContact = curContact;
+		setTitle(curContact.getJID());
 
-    class aliasListener implements View.OnClickListener {
-
-	@Override
-	public void onClick(View v) {
+		Button button = (Button) findViewById(R.id.CDChat);
+		button.setOnClickListener(new chatListener());
+		button = (Button) findViewById(R.id.CDAlias);
+		button.setOnClickListener(new aliasListener());
+		button = (Button) findViewById(R.id.CDGroup);
+		button.setOnClickListener(new groupListener());
+		button = (Button) findViewById(R.id.CDResend);
+		button.setOnClickListener(new resendListener());
+		button = (Button) findViewById(R.id.CDInfos);
+		button.setOnClickListener(new infosListener());
 
-	    ContactDialogAliasDialog dialog = new ContactDialogAliasDialog(mContext, mContact);
-	    dialog.setOwnerActivity(ContactDialog.this.getOwnerActivity());
-	    dialog.initService(xmppFacade);
-	    dialog.show();
+		mContext.bindService(new Intent(mContext, BeemService.class), mServConn, Service.BIND_AUTO_CREATE);
 	}
 
-    }
+	class aliasListener implements View.OnClickListener {
 
-    class chatListener implements View.OnClickListener {
+		@Override
+		public void onClick(View v) {
 
-	@Override
-	public void onClick(View v) {
-	    Activity a = ContactDialog.this.getOwnerActivity();
-	    Intent i = new Intent(mContext, SendIM.class);
-	    i.setData(mContact.toUri());
-	    a.startActivity(i);
-	    dismiss();
+			ContactDialogAliasDialog dialog = new ContactDialogAliasDialog(mContext, mContact);
+			dialog.setOwnerActivity(ContactDialog.this.getOwnerActivity());
+			dialog.initService(xmppFacade);
+			dialog.show();
+		}
+
 	}
 
-    }
-
-    class groupListener implements View.OnClickListener {
+	class chatListener implements View.OnClickListener {
 
-	@Override
-	public void onClick(View v) {
-	    // TODO Auto-generated method stub
-	    dismiss();
+		@Override
+		public void onClick(View v) {
+			Activity a = ContactDialog.this.getOwnerActivity();
+			Intent i = new Intent(mContext, SendIM.class);
+			i.setData(mContact.toUri());
+			a.startActivity(i);
+			dismiss();
+		}
+
 	}
 
-    }
-
-    class infosListener implements View.OnClickListener {
+	class groupListener implements View.OnClickListener {
 
-	@Override
-	public void onClick(View v) {
-	    // TODO Auto-generated method stub
-	    dismiss();
+		@Override
+		public void onClick(View v) {
+			// TODO Auto-generated method stub
+			dismiss();
+		}
+
 	}
 
-    }
-
-    class resendListener implements View.OnClickListener {
+	class infosListener implements View.OnClickListener {
 
-	@Override
-	public void onClick(View v) {
-	    Presence presencePacket = new Presence(Presence.Type.subscribe);
-	    presencePacket.setTo(mContact.getJID());
-	    try {
-		xmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
-	    } catch (RemoteException e) {
-		Log.e(TAG, "resend subscription error", e);
-	    }
-	    dismiss();
+		@Override
+		public void onClick(View v) {
+			// TODO Auto-generated method stub
+			dismiss();
+		}
+
 	}
 
-    }
-
-    private class BeemServiceConnection implements ServiceConnection {
+	class resendListener implements View.OnClickListener {
 
-	@Override
-	public void onServiceConnected(ComponentName name, IBinder service) {
-	    xmppFacade = IXmppFacade.Stub.asInterface(service);
+		@Override
+		public void onClick(View v) {
+			Presence presencePacket = new Presence(Presence.Type.subscribe);
+			presencePacket.setTo(mContact.getJID());
+			try {
+				xmppFacade.sendPresencePacket(new PresenceAdapter(presencePacket));
+			} catch (RemoteException e) {
+				Log.e(TAG, "resend subscription error", e);
+			}
+			dismiss();
+		}
+
 	}
 
-	@Override
-	public void onServiceDisconnected(ComponentName name) {
-	    xmppFacade = null;
+	private class BeemServiceConnection implements ServiceConnection {
+
+		@Override
+		public void onServiceConnected(ComponentName name, IBinder service) {
+			xmppFacade = IXmppFacade.Stub.asInterface(service);
+		}
+
+		@Override
+		public void onServiceDisconnected(ComponentName name) {
+			xmppFacade = null;
+		}
 	}
-    }
 
 }
--- a/src/com/beem/project/beem/ui/Subscription.java	Sat Jun 20 19:15:19 2009 +0200
+++ b/src/com/beem/project/beem/ui/Subscription.java	Sat Jun 20 19:43:37 2009 +0200
@@ -7,13 +7,19 @@
 import org.jivesoftware.smack.packet.Presence.Type;
 
 import com.beem.project.beem.BeemApplication;
+import com.beem.project.beem.BeemService;
 import com.beem.project.beem.R;
 import com.beem.project.beem.service.PresenceAdapter;
 import com.beem.project.beem.service.aidl.IXmppFacade;
 
 import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
 import android.os.Bundle;
+import android.os.IBinder;
 import android.os.RemoteException;
+import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.widget.TextView;
@@ -25,53 +31,72 @@
  */
 public class Subscription extends Activity {
 
-    private IXmppFacade mService;
-    private String mContact;
+	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);
-	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);
-	mService = BeemApplication.getApplication(this).getXmppFacade();
-    }
-
-    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);
+	}
 
 	@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();
-	    };
-
+	protected void onDestroy() {
+		super.onDestroy();
+		unbindService(mServConn);
 	}
 
-    };
+	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;
+		}
+	}
 }