# HG changeset patch # User marseille@marseille-desktop # Date 1245405824 -7200 # Node ID 7c67ea0a501c7b399f4ed4bd022a1c518112c796 # Parent 644ead6eaf670d016908afa3e978eb9fe994ab7f Suppression beemapplication dans addcontact. diff -r 644ead6eaf67 -r 7c67ea0a501c src/com/beem/project/beem/ui/AddContact.java --- a/src/com/beem/project/beem/ui/AddContact.java Thu Jun 18 21:14:43 2009 +0200 +++ b/src/com/beem/project/beem/ui/AddContact.java Fri Jun 19 12:03:44 2009 +0200 @@ -7,7 +7,11 @@ import java.util.List; 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.view.View; import android.view.View.OnClickListener; @@ -15,7 +19,7 @@ import android.widget.EditText; import android.widget.Toast; -import com.beem.project.beem.BeemApplication; +import com.beem.project.beem.BeemService; import com.beem.project.beem.R; import com.beem.project.beem.service.aidl.IXmppFacade; @@ -24,55 +28,50 @@ */ public class AddContact extends Activity { - protected static final String TAG = "AddContact"; - private String mLogin; - private String mAlias; - private final List mGroup = new ArrayList(); - private IXmppFacade mService; + protected static final String TAG = "AddContact"; + private String mLogin; + private String mAlias; + private final List mGroup = new ArrayList(); + private IXmppFacade xmppFacade; + private final ServiceConnection mServConn = new BeemServiceConnection(); - private final OnClickListener mOkListener = new OnClickListener() { + private final OnClickListener mOkListener = new OnClickListener() { - @Override - public void onClick(View v) { - boolean valid = true; - if (getWidgetText(R.id.addc_login).length() == 0) { - valid = false; - } else { - mLogin = getWidgetText(R.id.addc_login); - } - if (getWidgetText(R.id.addc_alias).length() == 0) { - valid = false; - } else { - mAlias = getWidgetText(R.id.addc_alias); - } - if (getWidgetText(R.id.addc_group).length() == 0) { - valid = false; - } else { - mGroup.add(getWidgetText(R.id.addc_group)); - } - if (valid) { - try { - mService.getRoster().addContact(mLogin, mAlias, - mGroup.toArray(new String[mGroup.size()])); - Toast.makeText(AddContact.this, - getString(R.string.AddCContactAdded), - Toast.LENGTH_SHORT).show(); - finish(); - } catch (RemoteException e) { - Toast.makeText(AddContact.this, e.getMessage(), - Toast.LENGTH_SHORT).show(); - e.printStackTrace(); - } - setResult(RESULT_OK); - } else { - Toast.makeText(AddContact.this, - getString(R.string.AddCBadForm), Toast.LENGTH_SHORT) - .show(); - setResult(RESULT_CANCELED); - } + @Override + public void onClick(View v) { + boolean valid = true; + if (getWidgetText(R.id.addc_login).length() == 0) { + valid = false; + } else { + mLogin = getWidgetText(R.id.addc_login); + } + if (getWidgetText(R.id.addc_alias).length() == 0) { + valid = false; + } else { + mAlias = getWidgetText(R.id.addc_alias); + } + if (getWidgetText(R.id.addc_group).length() == 0) { + valid = false; + } else { + mGroup.add(getWidgetText(R.id.addc_group)); + } + if (valid) { + try { + xmppFacade.getRoster().addContact(mLogin, mAlias, mGroup.toArray(new String[mGroup.size()])); + Toast.makeText(AddContact.this, getString(R.string.AddCContactAdded), Toast.LENGTH_SHORT).show(); + finish(); + } catch (RemoteException e) { + Toast.makeText(AddContact.this, e.getMessage(), Toast.LENGTH_SHORT).show(); + e.printStackTrace(); + } + setResult(RESULT_OK); + } else { + Toast.makeText(AddContact.this, getString(R.string.AddCBadForm), Toast.LENGTH_SHORT).show(); + setResult(RESULT_CANCELED); + } - } - }; + } + }; private String getWidgetText(int id) { EditText widget = (EditText) this.findViewById(id); @@ -85,6 +84,19 @@ setContentView(R.layout.addcontact); Button ok = (Button) findViewById(R.id.addc_ok); ok.setOnClickListener(mOkListener); - mService = BeemApplication.getApplication(this).getXmppFacade(); + bindService(new Intent(this, BeemService.class), mServConn, BIND_AUTO_CREATE); + } + + 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; + } } }