# HG changeset patch # User Da Risk # Date 1237597745 -3600 # Node ID 0e65d5f55d2ff6cc14787016b5be38762dc081f8 # Parent 4d26854143e22d9226b06f3ac39c0af12d309ab0# Parent b915994d895e6f7e85517156e45cfa56c49feaef Merge with ui. Synchronous connection worked. Add some checkstyle xml rules to use with the checkstyle plugin for eclipse and also a formatter for eclipse. Still work needs on asynchrounous connect diff -r b915994d895e -r 0e65d5f55d2f AndroidManifest.xml diff -r b915994d895e -r 0e65d5f55d2f Beem-ecipse-formatter.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Beem-ecipse-formatter.xml Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,267 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b915994d895e -r 0e65d5f55d2f checkstyle.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/checkstyle.xml Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,225 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/BeemException.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/BeemException.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,67 @@ +/** + * + */ +package com.beem.project.beem; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * @author darisk + * + */ +public class BeemException extends Exception implements Parcelable { + + public static final Parcelable.Creator CREATOR = new Creator() { + + @Override + public BeemException[] newArray(int size) { + // TODO Auto-generated method stub + return new BeemException[size]; + } + + @Override + public BeemException createFromParcel(Parcel source) { + // TODO Auto-generated method stub + return new BeemException(source); + } + }; + + public BeemException() { + super(); + // TODO Auto-generated constructor stub + } + + public BeemException(String detailMessage, Throwable throwable) { + super(detailMessage, throwable); + // TODO Auto-generated constructor stub + } + + public BeemException(String detailMessage) { + super(detailMessage); + // TODO Auto-generated constructor stub + } + + public BeemException(Throwable throwable) { + super(throwable); + // TODO Auto-generated constructor stub + } + + private BeemException(Parcel parcel){ + this(parcel.readString()); + } + + @Override + public int describeContents() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + // TODO Auto-generated method stub + dest.writeString(getLocalizedMessage()); + } + + +} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Sat Mar 21 00:00:14 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Sat Mar 21 02:09:05 2009 +0100 @@ -3,8 +3,13 @@ */ package com.beem.project.beem; -import java.util.List; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.RosterListener; +import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; @@ -15,11 +20,13 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.IBinder; +import android.os.Looper; import android.os.RemoteException; import android.widget.Toast; -import com.beem.project.beem.service.IXMPPFacade; - +import com.beem.project.beem.service.XMPPConnectionAdapter; +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; /** * @author darisk * @@ -28,27 +35,35 @@ private NotificationManager notificationManager; - private XMPPConnection connection; - + private IXMPPConnection connection; private SharedPreferences settings; - - private String login; - - private String password; - - private String host; + private String mLogin; + private String mPassword; + private String mHost; private IXMPPFacade.Stub bind = new IXMPPFacade.Stub() { - @Override - public List getContactList() throws RemoteException { - return null; - } + @Override + public IXMPPConnection getXMPPConnection() throws RemoteException { + return connection; + } + + @Override + public void disconnect() throws RemoteException { + connection.disconnect(); + } + - @Override - public List getGroupList() throws RemoteException { - return null; - } + @Override + public void connectAsync() throws RemoteException { + connection.connectAsync(mLogin, mPassword, "BEEM"); + } + + + @Override + public void connectSync() throws RemoteException { + connection.connectSync(mLogin, mPassword, "BEEM"); + } }; /* @@ -57,25 +72,26 @@ * @see android.app.Service#onBind(android.content.Intent) */ @Override - public IBinder onBind(Intent arg0) { - try { - connection = new XMPPConnection("10.0.2.2"); // address du pc host - // de l'emulateur - connection.connect(); - connection.login(login, password); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.BeemServiceCreated); - } catch (XMPPException e) { - // TODO Auto-generated catch block - Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(), - Toast.LENGTH_LONG); - toast.show(); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.PreferenceFileName); - } - return bind; + public IBinder onBind(Intent intent) { + showBasicNotification(R.string.BeemServiceCreated); + return bind; + // to forbid a client to bind + // return null; } + @Override + public void onCreate() { + super.onCreate(); + settings = getSharedPreferences(getString(R.string.PreferenceFileName), + MODE_PRIVATE); + mLogin = settings.getString(getString(R.string.PreferenceLoginKey), ""); + mPassword = settings.getString( + getString(R.string.PreferencePasswordKey), ""); + mHost = settings.getString(getString(R.string.PreferenceHostKey), ""); + notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); + connection = new XMPPConnectionAdapter("10.0.2.2"); // address + } + private void showBasicNotification(int stringResource) { String text = (String) getText(stringResource); Notification notif = new Notification(R.drawable.logo, text, System @@ -90,43 +106,29 @@ } @Override - public void onCreate() { - super.onCreate(); - settings = getSharedPreferences(getString(R.string.PreferenceFileName), - MODE_PRIVATE); - login = settings.getString(getString(R.string.PreferenceLoginKey), ""); - password = settings.getString( - getString(R.string.PreferencePasswordKey), ""); - host = settings.getString(getString(R.string.PreferenceHostKey), ""); - } - - @Override public void onStart(Intent intent, int startId) { - try { - connection = new XMPPConnection("10.0.2.2"); // address du pc host - // de l'emulateur - connection.connect(); - connection.login(login, password); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.BeemServiceCreated); - } catch (XMPPException e) { - // TODO Auto-generated catch block - Toast toast = Toast.makeText(this, "ERREUR " + e.getMessage(), - Toast.LENGTH_LONG); - toast.show(); - notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); - showBasicNotification(R.string.PreferenceFileName); - } - } - - private void closeConnection() { - if (connection != null) - connection.disconnect(); + try { + connection.connectSync(mLogin, mPassword, "BEEM"); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } @Override public void onDestroy() { - closeConnection(); - } + closeConnection(); + showBasicNotification(R.string.BeemServiceDestroyed); + } + + private void closeConnection() { + if (connection != null) + try { + connection.disconnect(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } } diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/IXMPPFacade.aidl --- a/src/com/beem/project/beem/service/IXMPPFacade.aidl Sat Mar 21 00:00:14 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -package com.beem.project.beem.service; - -// import org.jivesoftware.smack.XMPPConnection; - -interface IXMPPFacade { - - // org.jivesoftware.smack.XMPPConnection getXMPPConnection(); - - List getContactList(); - List getGroupList(); - -} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/RosterAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/RosterAdapter.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,61 @@ +/** + * + */ +package com.beem.project.beem.service; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.RosterEntry; +import org.jivesoftware.smack.XMPPException; + +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IRosterEntry; +import com.beem.project.beem.service.aidl.IRoster.Stub; + +/** + * @author darisk + * + */ +public class RosterAdapter extends com.beem.project.beem.service.aidl.IRoster.Stub { + + private Roster adaptee; + + public RosterAdapter(Roster roster) { + adaptee = roster; + } + + @Override + public IRosterEntry createEntry(String user, String name, String[] groups) + throws RemoteException { + try { + adaptee.createEntry(user, name, groups); + } catch (XMPPException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return null; + } + + @Override + public void createGroup(String groupname) throws RemoteException { + // TODO Auto-generated method stub + adaptee.createGroup(groupname); + } + + @Override + public List getEntries() throws RemoteException { + // TODO Auto-generated method stub + Collection col = adaptee.getEntries(); + ArrayList result = new ArrayList(col.size()); + for (RosterEntry rosterEntry : col ) { + result.add(new RosterEntryAdapter(rosterEntry)); + } + return result; + } + + +} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/RosterEntryAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/RosterEntryAdapter.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,42 @@ +/** + * + */ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.RosterEntry; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.packet.RosterPacket.ItemStatus; +import org.jivesoftware.smack.packet.RosterPacket.ItemType; + +import android.os.IBinder; +import android.os.RemoteException; + +import com.beem.project.beem.service.aidl.IRosterEntry; + +/** + * @author darisk + * + */ +public class RosterEntryAdapter extends IRosterEntry.Stub { + + private RosterEntry adaptee; + + public RosterEntryAdapter(RosterEntry entry) { + adaptee = entry; + } + + @Override + public String getName() throws RemoteException { + return adaptee.getName(); + } + + @Override + public String getUser() throws RemoteException { + return adaptee.getUser(); + } + + @Override + public void setName(String name) throws RemoteException { + adaptee.setName(name); + } +} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/XMPPConnectionAdapter.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/XMPPConnectionAdapter.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,204 @@ +/** + * + */ +package com.beem.project.beem.service; + +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.ConnectionListener; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; + +import android.os.RemoteCallbackList; +import android.os.RemoteException; + +import com.beem.project.beem.BeemException; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IXMPPConnection; + +/** + * @author darisk + * + */ +public class XMPPConnectionAdapter extends IXMPPConnection.Stub { + + private XMPPConnection adaptee; + private BeemException lastException; + + private RemoteCallbackList mRemoteConnListeners = new RemoteCallbackList(); + private ConnexionListenerAdapter mConListener = new ConnexionListenerAdapter(); + + public XMPPConnectionAdapter(XMPPConnection con) { + adaptee = con; + } + + public XMPPConnectionAdapter(String serviceName) { + this(new XMPPConnection(serviceName)); + } + + public XMPPConnectionAdapter(ConnectionConfiguration config) { + this(new XMPPConnection(config)); + } + + @Override + public boolean connectSync(String username, String password, String resource) + throws RemoteException { + try { + adaptee.connect(); + adaptee.addConnectionListener(mConListener); + adaptee.login(username, password, resource); + lastException = null; + triggerAsynchronousConnectEvent(); + return true; + } catch (XMPPException e) { + lastException = new BeemException(e); + } + return false; + } + + public boolean disconnect() { + adaptee.disconnect(); + lastException = null; + return true; + } + + @Override + public IRoster getRoster() throws RemoteException { + return new RosterAdapter(adaptee.getRoster()); + } + + @Override + public void connectAsync(final String username, final String password, final String resource) + throws RemoteException { + Thread t = new Thread(new Runnable() { + + @Override + public void run() { + try { + connectSync(username,password,resource); + } catch (RemoteException e) { + + } + } + }); + t.start(); + } + + @Override + public void addConnectionListener(IBeemConnectionListener listen) + throws RemoteException { + if (listen != null) + mRemoteConnListeners.register(listen); + } + + @Override + public void removeConnectionListener(IBeemConnectionListener listen) + throws RemoteException { + if (listen != null) + mRemoteConnListeners.unregister(listen); + } + + private void triggerAsynchronousConnectEvent() { + mConListener.onConnect(); + } + + private class ConnexionListenerAdapter implements ConnectionListener { + + public void onConnect() { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.onConnect(); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @Override + public void connectionClosed() { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.connectionClosed(); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @Override + public void connectionClosedOnError(Exception arg0) { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.connectionClosedOnError(); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @Override + public void reconnectingIn(int arg0) { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectingIn(arg0); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @Override + public void reconnectionFailed(Exception arg0) { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectionFailed(); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + + @Override + public void reconnectionSuccessful() { + final int N = mRemoteConnListeners.beginBroadcast(); + + for (int i = 0; i < N; i++) { + IBeemConnectionListener listener = mRemoteConnListeners.getBroadcastItem(i); + try { + listener.reconnectionSuccessful(); + } catch (RemoteException e) { + // The RemoteCallbackList will take care of removing the + // dead listeners. + } + } + mRemoteConnListeners.finishBroadcast(); + } + } + + +} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,17 @@ +package com.beem.project.beem.service.aidl; + +interface IBeemConnectionListener { + + void connectionClosed(); + + void onConnect(); + + //void connectionClosedOnError(in Exception e); + void connectionClosedOnError(); + + void reconnectingIn(in int seconds); + + void reconnectionFailed(); + + void reconnectionSuccessful(); +} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/aidl/IRoster.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IRoster.aidl Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,14 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IRosterEntry; + +interface IRoster { + + IRosterEntry createEntry(in String user, in String name, in String[] groups); + + void createGroup(in String groupname); + + // List + List getEntries(); + +} \ No newline at end of file diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/aidl/IRosterEntry.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IRosterEntry.aidl Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,12 @@ +package com.beem.project.beem.service.aidl; + +interface IRosterEntry { + + String getName(); + String getUser(); + void setName(in String name); + //TODO + // getStatus() + // getType + +} \ No newline at end of file diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IXMPPConnection.aidl Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,20 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IRoster; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; + +interface IXMPPConnection { + + boolean connectSync(in String username, in String password, in String resource); + + void connectAsync(in String username, in String password, in String resource); + + boolean disconnect(); + + // void login(String username, String password, String resource); + + IRoster getRoster(); + + void addConnectionListener(in IBeemConnectionListener listen); + void removeConnectionListener(in IBeemConnectionListener listen); +} \ No newline at end of file diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,15 @@ +package com.beem.project.beem.service.aidl; + +import com.beem.project.beem.service.aidl.IXMPPConnection; + +interface IXMPPFacade { + + IXMPPConnection getXMPPConnection(); + + void connectSync(); + + void connectAsync(); + + void disconnect(); + +} diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/ui/Beem.java --- a/src/com/beem/project/beem/ui/Beem.java Sat Mar 21 00:00:14 2009 +0100 +++ b/src/com/beem/project/beem/ui/Beem.java Sat Mar 21 02:09:05 2009 +0100 @@ -4,6 +4,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -13,62 +14,96 @@ import com.beem.project.beem.R; +/** + * La principale activite to be continuous. + */ public class Beem extends Activity { private SharedPreferences mSettings; private BeemDialogSettings mDialog; private Button mButton; + private Handler mHandler; + + /** + * Default constructor. + */ + public Beem() { + super(); + mHandler= new Handler(); + } /** * Called when the activity is first created. + * @param savedInstanceState + * previous state. */ @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.beem); - mSettings = getSharedPreferences( - getString(R.string.PreferenceFileName), MODE_PRIVATE); - mDialog = new BeemDialogSettings(this, mSettings); + public final void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.beem); + mSettings = getSharedPreferences( + getString(R.string.PreferenceFileName), MODE_PRIVATE); + mDialog = new BeemDialogSettings(this, mSettings); - mButton = (Button) findViewById(R.id.connection); - mButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - if (mButton.getText() == getString(R.string.BeemCreateAccount)) - mDialog.show(); - else - startActivity(new Intent(Beem.this, ContactList.class)); - } - }); - showJID(); + mButton = (Button) findViewById(R.id.connection); + mButton.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + if (mButton.getText() == getString(R.string.BeemCreateAccount)) + mDialog.show(); + else + startActivity(new Intent(Beem.this, ContactList.class)); + } + }); + showJID(); } + /** + * Callback for menu creation. + * @param menu + * the menu created + * @return true on success, false otherwise + */ @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.beemmenu, menu); - return true; + public final boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.beemmenu, menu); + return true; } + /** + * Callback for menu item selected. + * @param item + * the item selected + * @return true on success, false otherwise + */ @Override - public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case R.id.account_edit: - mDialog.show(); - return true; - case R.id.account_about: - return true; - } - return false; + public final boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.account_edit: + mDialog.show(); + return true; + case R.id.account_about: + return true; + default: + return false; + } } - public void showJID() { - String jid = mSettings.getString(getString(R.string.PreferenceLoginKey), "") + "@" - + mSettings.getString(getString(R.string.PreferenceHostKey), ""); - if (jid.length() == 1) - jid = getString(R.string.BeemCreateAccount); - mButton.setText(jid); + /** + * Show jabber id in button. + */ + public final void showJID() { + String jid = mSettings.getString( + getString(R.string.PreferenceLoginKey), "") + + "@" + + mSettings + .getString(getString(R.string.PreferenceHostKey), ""); + if (jid.length() == 1) + jid = getString(R.string.BeemCreateAccount); + mButton.setText(jid); } + } diff -r b915994d895e -r 0e65d5f55d2f src/com/beem/project/beem/ui/ContactList.java --- a/src/com/beem/project/beem/ui/ContactList.java Sat Mar 21 00:00:14 2009 +0100 +++ b/src/com/beem/project/beem/ui/ContactList.java Sat Mar 21 02:09:05 2009 +0100 @@ -11,12 +11,16 @@ import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; +import android.os.RemoteException; +import android.util.Log; import android.widget.ExpandableListAdapter; import android.widget.SimpleExpandableListAdapter; import com.beem.project.beem.BeemService; import com.beem.project.beem.R; -import com.beem.project.beem.service.IXMPPFacade; +import com.beem.project.beem.service.aidl.IBeemConnectionListener; +import com.beem.project.beem.service.aidl.IXMPPConnection; +import com.beem.project.beem.service.aidl.IXMPPFacade; public class ContactList extends ExpandableListActivity { @@ -27,7 +31,6 @@ super.onCreate(saveBundle); bindService(new Intent(this, BeemService.class), mConnection, BIND_AUTO_CREATE | BIND_DEBUG_UNBIND); - showContactList(); } private void showContactList() { @@ -44,7 +47,7 @@ for (int j = 0; j < 5; j++) { Map curChildMap = new HashMap(); children.add(curChildMap); - curChildMap.put("NAME CHILD", "Child " + j); + curChildMap.put("NAOME CHILD", "Child " + j); } childData.add(children); } @@ -61,10 +64,19 @@ @Override public void onServiceConnected(ComponentName name, IBinder service) { mService = IXMPPFacade.Stub.asInterface(service); + try { + IXMPPConnection con = mService.getXMPPConnection(); + con.addConnectionListener(new TestConnectionListener()); + mService.connectSync(); + Log.i("BEEM", "Connected !!!"); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + /* * mService.getGroupList(); mService.getContactList(); */ - showContactList(); } @Override @@ -79,4 +91,44 @@ unbindService(mConnection); } + private class TestConnectionListener extends IBeemConnectionListener.Stub { + + @Override + public void connectionClosed() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void connectionClosedOnError() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void onConnect() throws RemoteException { + // TODO Auto-generated method stub + showContactList(); + } + + @Override + public void reconnectingIn(int seconds) throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void reconnectionFailed() throws RemoteException { + // TODO Auto-generated method stub + + } + + @Override + public void reconnectionSuccessful() throws RemoteException { + // TODO Auto-generated method stub + + } + + } + }