# 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 4d26854143e2 -r 0e65d5f55d2f AndroidManifest.xml --- a/AndroidManifest.xml Fri Mar 20 23:21:05 2009 +0100 +++ b/AndroidManifest.xml Sat Mar 21 02:09:05 2009 +0100 @@ -3,12 +3,13 @@ package="com.beem.project.beem" android:versionCode="1" android:versionName="1.0"> - + + diff -r 4d26854143e2 -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 4d26854143e2 -r 0e65d5f55d2f checkstyle.xml --- a/checkstyle.xml Fri Mar 20 23:21:05 2009 +0100 +++ b/checkstyle.xml Sat Mar 21 02:09:05 2009 +0100 @@ -7,17 +7,17 @@ Checkstyle configuration that checks the sun coding conventions from: - - the Java Language Specification at - http://java.sun.com/docs/books/jls/second_edition/html/index.html + - the Java Language Specification at + http://java.sun.com/docs/books/jls/second_edition/html/index.html - - the Sun Code Conventions at http://java.sun.com/docs/codeconv/ + - the Sun Code Conventions at http://java.sun.com/docs/codeconv/ - - the Javadoc guidelines at - http://java.sun.com/j2se/javadoc/writingdoccomments/index.html + - the Javadoc guidelines at + http://java.sun.com/j2se/javadoc/writingdoccomments/index.html - - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html + - the JDK Api documentation http://java.sun.com/j2se/docs/api/index.html - - some best practices + - some best practices Checkstyle is very configurable. Be sure to read the documentation at http://checkstyle.sf.net (or in your downloaded distribution). @@ -47,127 +47,129 @@ - - - + + + - - - + + + + + - - - - - + + + + + - - - - - + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - - - - - + + + + + + - - - + + + - - + + - - - - - - - - - + + + + + + + + + - - + --> + + - - - - + + + + - - - - - + + + + + - + - - + + - + - - - + + + - - + + - - - - + + + + @@ -185,43 +187,39 @@ - - - - - - - + + + + + + + - + - - - + + + - - - - - - - - + + + + + + + - - - - - + + diff -r 4d26854143e2 -r 0e65d5f55d2f res/drawable/avatar.png Binary file res/drawable/avatar.png has changed diff -r 4d26854143e2 -r 0e65d5f55d2f res/drawable/bart.jpg Binary file res/drawable/bart.jpg has changed diff -r 4d26854143e2 -r 0e65d5f55d2f res/layout/beem.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/beem.xml Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,35 @@ + + + + + + + + + + + \ No newline at end of file diff -r 4d26854143e2 -r 0e65d5f55d2f res/layout/contactlist.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlist.xml Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,19 @@ + + + + + + + + diff -r 4d26854143e2 -r 0e65d5f55d2f res/layout/contactlistgroup.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/layout/contactlistgroup.xml Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,16 @@ + + + + + + diff -r 4d26854143e2 -r 0e65d5f55d2f res/layout/main.xml --- a/res/layout/main.xml Fri Mar 20 23:21:05 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - diff -r 4d26854143e2 -r 0e65d5f55d2f res/menu/account.xml --- a/res/menu/account.xml Fri Mar 20 23:21:05 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff -r 4d26854143e2 -r 0e65d5f55d2f res/menu/beemmenu.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/res/menu/beemmenu.xml Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,4 @@ + + + + diff -r 4d26854143e2 -r 0e65d5f55d2f res/values/strings.xml --- a/res/values/strings.xml Fri Mar 20 23:21:05 2009 +0100 +++ b/res/values/strings.xml Sat Mar 21 02:09:05 2009 +0100 @@ -1,15 +1,20 @@ - Beem - -Use the Beem Service -BeemService Created -BeemService destroyed + Beem - -Beem -login -host -password -port + + Creer un compte + Jabber ID + + + Use the Beem Service + BeemService Created + BeemService destroyed + + + Beem + login + host + password + port diff -r 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/Beem.java --- a/src/com/beem/project/beem/Beem.java Fri Mar 20 23:21:05 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -package com.beem.project.beem; - -import com.beem.project.beem.service.aidl.IBeemConnectionListener; -import com.beem.project.beem.service.aidl.IXMPPConnection; -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.content.SharedPreferences; -import android.os.Bundle; -import android.os.Handler; -import android.os.IBinder; -import android.os.Message; -import android.os.RemoteException; -import android.util.Log; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.View; -import android.view.View.OnClickListener; -import android.widget.Button; -import android.widget.EditText; -import android.widget.Toast; - -public class Beem extends Activity { - - private SharedPreferences mSettings; - - private IXMPPFacade facade; - - private Handler mHandler; - - /** - * Called when the activity is first created. - */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - mHandler = new Handler(); - setContentView(R.layout.main); - mSettings = getSharedPreferences(getString(R.string.PreferenceFileName), MODE_PRIVATE); - showJID(); - Button btConnection = (Button) findViewById(R.id.connection); - btConnection.setOnClickListener(new OnClickListener() { - - @Override - public void onClick(View v) { - // TODO Auto-generated method stub - // startService(new Intent(Beem.this,BeemService.class)); - boolean ok = bindService(new Intent(Beem.this,BeemService.class), new ServiceConnection() { - - @Override - public void onServiceDisconnected(ComponentName name) { - // TODO Auto-generated method stub - - } - - @Override - public void onServiceConnected(ComponentName name, IBinder service) { - // TODO Auto-generated method stub - try { - facade = (IXMPPFacade) service; - IXMPPConnection con = facade.getXMPPConnection(); - con.addConnectionListener(new IBeemConnectionListener.Stub() { - - @Override - public void reconnectionSuccessful() throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void reconnectionFailed() throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void reconnectingIn(int seconds) throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void onConnect() throws RemoteException { - // TODO Auto-generated method stub - mHandler.post(new Runnable() { - - @Override - public void run() { - // TODO Auto-generated method stub - Log.w("BEEM", "ON s'est COnnecter !!!"); - Toast toast = Toast.makeText(Beem.this, "Connection estabished", Toast.LENGTH_LONG); - toast.show(); - } - }); - - } - - @Override - public void connectionClosedOnError() throws RemoteException { - // TODO Auto-generated method stub - - } - - @Override - public void connectionClosed() throws RemoteException { - // TODO Auto-generated method stub - - } - }); - facade.connectAsync(); - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - }, BIND_AUTO_CREATE); - if (! ok) - Log.w("BEEM", "Connection au service echoue"); - } - }); - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - super.onCreateOptionsMenu(menu); - MenuInflater inflater = getMenuInflater(); - inflater.inflate(R.menu.account, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(MenuItem item) { - SettingsDialog Dialog = new SettingsDialog(this, mSettings); - switch (item.getItemId()) { - case R.id.account_edit: - Dialog.show(); - return true; - case R.id.account_about: - return true; - } - return false; - } - - public void showJID() { - EditText ejid = (EditText) findViewById(R.id.jid); - String jid = mSettings.getString("login", "") + - "@" + mSettings.getString("host", "") ; - if (jid.length() == 1) - jid = "Enter Jabber ID / Create New Account"; - ejid.setText(jid); - } - - - private class TestHandler extends Handler{ - - @Override - public void handleMessage(Message msg) { - // TODO Auto-generated method stub - super.handleMessage(msg); - } - - } -} diff -r 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/BeemService.java --- a/src/com/beem/project/beem/BeemService.java Fri Mar 20 23:21:05 2009 +0100 +++ b/src/com/beem/project/beem/BeemService.java Sat Mar 21 02:09:05 2009 +0100 @@ -10,6 +10,8 @@ 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; import android.app.Notification; import android.app.NotificationManager; @@ -25,10 +27,9 @@ 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 - * + * */ public class BeemService extends Service { @@ -39,6 +40,7 @@ private String mLogin; private String mPassword; private String mHost; + private IXMPPFacade.Stub bind = new IXMPPFacade.Stub() { @Override @@ -46,7 +48,6 @@ return connection; } - @Override public void disconnect() throws RemoteException { connection.disconnect(); @@ -90,6 +91,19 @@ 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 + .currentTimeMillis()); + notif.defaults = Notification.DEFAULT_ALL; + notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity( + this, 0, new Intent(), 0)); + notificationManager.notify(stringResource, notif); + Toast toast = Toast.makeText(this, R.string.BeemServiceCreated, + Toast.LENGTH_LONG); + toast.show(); + } @Override public void onStart(Intent intent, int startId) { @@ -107,16 +121,6 @@ showBasicNotification(R.string.BeemServiceDestroyed); } - private void showBasicNotification(int stringResource) { - String text = (String) getText(stringResource); - Notification notif = new Notification(R.drawable.logo, text, System - .currentTimeMillis()); - notif.defaults = Notification.DEFAULT_ALL; - notif.setLatestEventInfo(this, text, text, PendingIntent.getActivity( - this, 0, new Intent(), 0)); - notificationManager.notify(stringResource, notif); - } - private void closeConnection() { if (connection != null) try { diff -r 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/SettingsDialog.java --- a/src/com/beem/project/beem/SettingsDialog.java Fri Mar 20 23:21:05 2009 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -package com.beem.project.beem; - -import android.app.Dialog; -import android.content.Context; -import android.content.SharedPreferences; -import android.view.View; -import android.widget.Button; -import android.widget.EditText; - -/** - * - */ -public class SettingsDialog extends Dialog implements android.view.View.OnClickListener { - - private Beem mbeem; - private SharedPreferences mSettings; - public SettingsDialog(Beem beem, SharedPreferences settings) { - super(beem); - this.mbeem = beem; - this.mSettings = settings; - } - - @Override - protected void onStart() { - super.onStart(); - setContentView(R.layout.settings); - getWindow().setFlags(4, 4); - setTitle("Jabber Account Settings"); - showSettings(); - Button ok = (Button) findViewById(R.id.ok); - ok.setOnClickListener(this); - } - - @Override - public void onClick(View v) { - SharedPreferences.Editor editor = mSettings.edit(); - Context ctx = getContext(); - editor.putString(ctx.getString(R.string.PreferenceHostKey), getWidgetText(R.id.host)); - editor.putString(ctx.getString(R.string.PreferencePortKey), getWidgetText(R.id.port)); - editor.putString(ctx.getString(R.string.PreferenceLoginKey), getWidgetText(R.id.userid)); - editor.putString(ctx.getString(R.string.PreferencePasswordKey), getWidgetText(R.id.password)); - editor.commit(); - this.mbeem.showJID(); - dismiss(); - } - - private void showSettings() { - String tmp; - EditText eHost = (EditText) findViewById(R.id.host); - if ((tmp = mSettings.getString("host","")) != "") - eHost.setText(tmp); - EditText ePort = (EditText) findViewById(R.id.port); - if ((tmp = mSettings.getString("port","")) != "") - ePort.setText(tmp); - EditText eLogin = (EditText) findViewById(R.id.userid); - if ((tmp = mSettings.getString("login","")) != "") - eLogin.setText(tmp); - EditText ePwd = (EditText) findViewById(R.id.password); - if ((tmp = mSettings.getString("password","")) != "") - ePwd.setText(tmp); - } - - private String getWidgetText(int id) { - EditText widget = (EditText) this.findViewById(id); - return widget.getText().toString(); - } -} diff -r 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/service/aidl/IXMPPFacade.aidl diff -r 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/ui/Beem.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/Beem.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,109 @@ +package com.beem.project.beem.ui; + +import android.app.Activity; +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; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.Button; + +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 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(); + } + + /** + * Callback for menu creation. + * @param menu + * the menu created + * @return true on success, false otherwise + */ + @Override + 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 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; + } + } + + /** + * 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 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/ui/BeemDialogSettings.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/BeemDialogSettings.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,76 @@ +package com.beem.project.beem.ui; + +import android.app.Dialog; +import android.content.Context; +import android.content.SharedPreferences; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.beem.project.beem.R; + +/** + * + */ +public class BeemDialogSettings extends Dialog implements + android.view.View.OnClickListener { + + private Beem mbeem; + + private SharedPreferences mSettings; + + public BeemDialogSettings(Beem beem, SharedPreferences settings) { + super(beem); + this.mbeem = beem; + this.mSettings = settings; + } + + @Override + protected void onStart() { + super.onStart(); + setContentView(R.layout.beemdialogsettings); + getWindow().setFlags(4, 4); + setTitle("Jabber Account Settings"); + showSettings(); + Button ok = (Button) findViewById(R.id.ok); + ok.setOnClickListener(this); + } + + @Override + public void onClick(View v) { + SharedPreferences.Editor editor = mSettings.edit(); + Context ctx = getContext(); + editor.putString(ctx.getString(R.string.PreferenceHostKey), + getWidgetText(R.id.host)); + editor.putString(ctx.getString(R.string.PreferencePortKey), + getWidgetText(R.id.port)); + editor.putString(ctx.getString(R.string.PreferenceLoginKey), + getWidgetText(R.id.userid)); + editor.putString(ctx.getString(R.string.PreferencePasswordKey), + getWidgetText(R.id.password)); + editor.commit(); + this.mbeem.showJID(); + dismiss(); + } + + private void showSettings() { + String tmp; + EditText eHost = (EditText) findViewById(R.id.host); + if ((tmp = mSettings.getString("host", "")) != "") + eHost.setText(tmp); + EditText ePort = (EditText) findViewById(R.id.port); + if ((tmp = mSettings.getString("port", "")) != "") + ePort.setText(tmp); + EditText eLogin = (EditText) findViewById(R.id.userid); + if ((tmp = mSettings.getString("login", "")) != "") + eLogin.setText(tmp); + EditText ePwd = (EditText) findViewById(R.id.password); + if ((tmp = mSettings.getString("password", "")) != "") + ePwd.setText(tmp); + } + + private String getWidgetText(int id) { + EditText widget = (EditText) this.findViewById(id); + return widget.getText().toString(); + } +} diff -r 4d26854143e2 -r 0e65d5f55d2f src/com/beem/project/beem/ui/ContactList.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/com/beem/project/beem/ui/ContactList.java Sat Mar 21 02:09:05 2009 +0100 @@ -0,0 +1,134 @@ +package com.beem.project.beem.ui; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import android.app.ExpandableListActivity; +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.widget.ExpandableListAdapter; +import android.widget.SimpleExpandableListAdapter; + +import com.beem.project.beem.BeemService; +import com.beem.project.beem.R; +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 { + + private IXMPPFacade mService = null; + + @Override + public void onCreate(Bundle saveBundle) { + super.onCreate(saveBundle); + bindService(new Intent(this, BeemService.class), mConnection, + BIND_AUTO_CREATE | BIND_DEBUG_UNBIND); + } + + private void showContactList() { + ExpandableListAdapter Adapter; + List> groupData = new ArrayList>(); + List>> childData = new ArrayList>>(); + + for (int i = 0; i < 2; i++) { + Map curGroupMap = new HashMap(); + groupData.add(curGroupMap); + curGroupMap.put("NAME", "Group " + i); + + List> children = new ArrayList>(); + for (int j = 0; j < 5; j++) { + Map curChildMap = new HashMap(); + children.add(curChildMap); + curChildMap.put("NAOME CHILD", "Child " + j); + } + childData.add(children); + } + + Adapter = new SimpleExpandableListAdapter(this, + groupData, R.layout.contactlistgroup, + new String[] {"NAME"}, new int[] {R.id.textgroup}, + childData, R.layout.contactlist, + new String[] {"NAME CHILD"}, new int[] {R.id.textchild}); + setListAdapter(Adapter); + } + + private ServiceConnection mConnection = new ServiceConnection() { + @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(); + */ + } + + @Override + public void onServiceDisconnected(ComponentName name) { + } + + }; + + @Override + public void onDestroy() { + super.onDestroy(); + 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 + + } + + } + +}