--- a/.classpath Thu Dec 03 00:36:12 2009 +0100
+++ b/.classpath Thu Dec 03 10:49:44 2009 +0100
@@ -1,24 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
- <classpathentry kind="lib" path="libs/smackx-debug.jar"/>
- <classpathentry kind="lib" path="libs/smackx-jingle.jar" sourcepath="/home/nikita/devel/smack">
+ <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry exported="true" kind="lib" path="libs/smackx-debug.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/smackx-jingle.jar" sourcepath="/home/nikita/devel/smack">
<attributes>
<attribute name="javadoc_location" value="file:/home/nikita/devel/smack_src_3_1_0/javadoc/"/>
</attributes>
</classpathentry>
- <classpathentry kind="lib" path="libs/security.jar"/>
- <classpathentry kind="lib" path="libs/smack.jar" sourcepath="/home/marseille/smack_src_3_1_0/source">
+ <classpathentry exported="true" kind="lib" path="libs/security.jar"/>
+ <classpathentry exported="true" kind="lib" path="libs/smack.jar" sourcepath="/home/marseille/smack_src_3_1_0/source">
<attributes>
<attribute name="javadoc_location" value="file:/home/nikita/devel/smack_src_3_1_0/javadoc/org/"/>
</attributes>
</classpathentry>
- <classpathentry kind="lib" path="libs/smackx.jar" sourcepath="/home/nikita/devel/smack">
+ <classpathentry exported="true" kind="lib" path="libs/smackx.jar" sourcepath="/home/nikita/devel/smack">
<attributes>
<attribute name="javadoc_location" value="file:/home/nikita/devel/smack_src_3_1_0/javadoc/"/>
</attributes>
</classpathentry>
- <classpathentry kind="lib" path="libs/jlibrtp.jar">
+ <classpathentry exported="true" kind="lib" path="libs/jlibrtp.jar">
<attributes>
<attribute name="javadoc_location" value="file:/home/nikita/android/docs/reference/"/>
</attributes>
--- a/.hgignore Thu Dec 03 00:36:12 2009 +0100
+++ b/.hgignore Thu Dec 03 10:49:44 2009 +0100
@@ -5,3 +5,6 @@
src/com/beem/project/beem/service/aidl/*.java
gen/*
local.properties
+**~
+**/.*.sw?
+
--- a/AndroidManifest.xml Thu Dec 03 00:36:12 2009 +0100
+++ b/AndroidManifest.xml Thu Dec 03 10:49:44 2009 +0100
@@ -11,6 +11,9 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ </activity>
+ <activity android:name=".ui.LoginAnim" android:label="ANIM"
+ android:launchMode="singleTop">
<intent-filter android:label="Beem Connection">
<action
android:name="com.beem.project.beem.service.XmppConnectionAdapter.CONNECTION_CLOSED" />
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/res/anim/rotate_and_scale.xml Thu Dec 03 10:49:44 2009 +0100
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<set xmlns:android="http://schemas.android.com/apk/res/android">
+ <scale android:fromXScale="0.5" android:toXScale="1.0"
+ android:fromYScale="0.5" android:toYScale="1.0"
+ android:pivotX="50%" android:pivotY="50%"
+ android:repeatMode="reverse" android:duration="8000"
+ android:repeatCount="infinite" />
+ <rotate android:fromDegrees="0" android:toDegrees="360"
+ android:pivotX="50%" android:pivotY="50%"
+ android:duration="5000"
+ android:repeatMode="restart"
+ android:repeatCount="infinite" />
+</set>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/res/layout/login_anim.xml Thu Dec 03 10:49:44 2009 +0100
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_height="fill_parent" android:layout_width="fill_parent"
+ android:orientation="vertical">
+ <ImageView android:id="@+id/loginanim_logo_anim" android:src="@drawable/beem_launcher_icon_color"
+ android:layout_height="fill_parent" android:layout_width="fill_parent"
+ android:layout_weight="1" />
+ <ProgressBar android:id="@+id/loginanim_progressbar"
+ android:layout_width="fill_parent" android:layout_height="fill_parent"
+ android:layout_weight="1" />
+ <Button android:id="@+id/loginanim_cancel_button"
+ android:layout_height="wrap_content" android:layout_width="fill_parent"
+ android:layout_gravity="bottom" android:text="@string/CancelButton" />
+</LinearLayout>
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/res/menu/contactlist_context.xml Thu Dec 03 10:49:44 2009 +0100
@@ -0,0 +1,5 @@
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/contact_list_context_menu_chat_item" android:title="@string/CDChat" />
+ <item android:id="@+id/contact_list_context_menu_call_item" android:title="@string/CDCall" android:visible="false" />
+ <item android:id="@+id/contact_list_context_menu_manage_user_item" android:title="@string/CDInfos" />
+</menu>
--- a/res/menu/edit_settings.xml Thu Dec 03 00:36:12 2009 +0100
+++ b/res/menu/edit_settings.xml Thu Dec 03 10:49:44 2009 +0100
@@ -3,10 +3,6 @@
android:visible="true"
android:icon="@drawable/ic_menu_invite"
android:title="@string/settings_menu_create_account" />
- <item android:id="@+id/settings_menu_login"
- android:visible="true"
- android:title="@string/settings_menu_login"
- android:icon="@drawable/ic_menu_login" />
<item android:id="@+id/settings_menu_privacy_lists"
android:visible="true"
android:title="@string/settings_menu_privacy_lists"
--- a/res/menu/login.xml Thu Dec 03 00:36:12 2009 +0100
+++ b/res/menu/login.xml Thu Dec 03 10:49:44 2009 +0100
@@ -1,4 +1,8 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
+ <item android:id="@+id/login_menu_login"
+ android:visible="true"
+ android:title="@string/login_menu_login"
+ android:icon="@drawable/ic_menu_login" />
<item android:id="@+id/login_menu_settings"
android:visible="true"
android:title="@string/login_menu_settings"
--- a/res/values-fr/strings.xml Thu Dec 03 00:36:12 2009 +0100
+++ b/res/values-fr/strings.xml Thu Dec 03 10:49:44 2009 +0100
@@ -170,12 +170,12 @@
<string name="login_login_progress">Connexion en cours. Veuillez patienter...</string>
<string name="login_error_msg">Malheureusement, une erreur est survenu.\n\nDétail
de l\'erreur :\n%s</string>
+ <string name="login_menu_login">Se connecter</string>
<!--
EditSettings Activity
-->
<string name="settings_menu_create_account">Créer un compte</string>
- <string name="settings_menu_login">Se connecter</string>
<string name="settings_menu_privacy_lists">Gérer mes listes privées</string>
<string name="settings_saved_ok">Les paramètres ont été enregistrés avec succès.</string>
--- a/res/values/strings.xml Thu Dec 03 00:36:12 2009 +0100
+++ b/res/values/strings.xml Thu Dec 03 10:49:44 2009 +0100
@@ -160,10 +160,10 @@
<string name="login_max_retry">Max retry</string>
<string name="login_error_msg">Unfortunately, an error occured.\n\nError
detail:\n%s</string>
+ <string name="login_menu_login">Login</string>
<!-- EditSettings Activity -->
<string name="settings_menu_create_account">Create an account</string>
- <string name="settings_menu_login">Login</string>
<string name="settings_menu_privacy_lists">Manage my privacy lists</string>
<string name="settings_saved_ok">The settings have been saved successfully.</string>
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java Thu Dec 03 10:49:44 2009 +0100
@@ -28,9 +28,9 @@
import com.beem.project.beem.service.aidl.IChatManager;
import com.beem.project.beem.service.aidl.IRoster;
import com.beem.project.beem.service.aidl.IXmppConnection;
+import com.beem.project.beem.ui.ChangeStatus;
import com.beem.project.beem.ui.Subscription;
import com.beem.project.beem.utils.BeemBroadcastReceiver;
-import com.beem.project.beem.ui.ChangeStatus;
import com.beem.project.beem.utils.Status;
/**
@@ -51,6 +51,7 @@
private final String mLogin;
private final String mPassword;
private String mResource;
+ private String mErrorMsg;
private RosterAdapter mRoster;
private int mPreviousPriority;
private PrivacyListManagerAdapter mPrivacyListManager;
@@ -120,6 +121,8 @@
*/
@Override
public final void connectAsync() throws RemoteException {
+ if (mAdaptee.isConnected() || mAdaptee.isAuthenticated())
+ return;
Thread t = new Thread(new Runnable() {
@Override
@@ -156,12 +159,22 @@
return true;
} catch (XMPPException e) {
Log.d(TAG, "Error while connecting", e);
- if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null)
- mConListener.connectionFailed(e.getXMPPError().getMessage());
- else if (e.getMessage() != null)
- mConListener.connectionFailed(e.getMessage());
+ if (e.getXMPPError() != null && e.getXMPPError().getMessage() != null) {
+ mErrorMsg = e.getXMPPError().getMessage();
+ Log.d(TAG, "XMPP Error "+ e.getXMPPError().getCode() + "message :" +e.getXMPPError().getMessage());
+ }
+ else if (e.getStreamError() != null ) {
+ mErrorMsg = e.getStreamError().toString();
+ Log.d(TAG, "Stream Error "+ e.getStreamError().getCode() + "message :" +e.getStreamError());
+ }
+ else if (e.getMessage() != null) {
+ // SASL !!
+ mErrorMsg = e.getMessage();
+ Log.d(TAG, "Error " + e.getMessage());
+ }
else
- mConListener.connectionFailed("Error On Connection");
+ mErrorMsg = "Error On Connection";
+ mConListener.connectionFailed(mErrorMsg);
} catch (IllegalStateException e) {
mConListener.connectionFailed(e.getMessage());
}
@@ -331,6 +344,14 @@
}
/**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getErrorMessage() {
+ return mErrorMsg;
+ }
+
+ /**
* Listener for XMPP connection events. It will calls the remote listeners for connection events.
* @author darisk
*/
--- a/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/service/aidl/IBeemConnectionListener.aidl Thu Dec 03 10:49:44 2009 +0100
@@ -10,35 +10,35 @@
* Callback to call when the connection is closed
*/
void connectionClosed();
-
+
/**
* Callback to call when the connection occurs
*/
void onConnect();
-
+
//void connectionClosedOnError(in Exception e);
/**
* Callback to call when the connection is closed on error
*/
void connectionClosedOnError();
-
+
/**
* Callback to call when trying to reconnecting
*/
void reconnectingIn(in int seconds);
-
+
/**
* Callback to call when the reconnection has failed
*/
void reconnectionFailed();
-
+
/**
* Callback to call when the reconnection is successfull
- */
+ */
void reconnectionSuccessful();
-
+
/**
* Callback to call when the connection Failed
- */
+ */
void connectionFailed(in String errorMsg);
}
--- a/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/service/aidl/IXmppConnection.aidl Thu Dec 03 10:49:44 2009 +0100
@@ -27,4 +27,6 @@
void changeStatus(in int status, in String msg);
IPrivacyListManager getPrivacyListManager();
+
+ String getErrorMessage();
}
--- a/src/com/beem/project/beem/ui/AddContact.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/ui/AddContact.java Thu Dec 03 10:49:44 2009 +0100
@@ -129,6 +129,7 @@
private final OnClickListener mOkListener = new OnClickListener() {
+ @Override
public void onClick(View v) {
String login;
login = getWidgetText(R.id.addc_login);
--- a/src/com/beem/project/beem/ui/Chat.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/ui/Chat.java Thu Dec 03 10:49:44 2009 +0100
@@ -740,7 +740,6 @@
* JID attribute mutator.
* @param bareJid A String containing the author's bare JID of the message.
*/
- @SuppressWarnings("unused")
public void setBareJid(String bareJid) {
mBareJid = bareJid;
}
@@ -749,7 +748,6 @@
* Name attribute mutator.
* @param name A String containing the author's name of the message.
*/
- @SuppressWarnings("unused")
public void setName(String name) {
mName = name;
}
--- a/src/com/beem/project/beem/ui/ContactList.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/ui/ContactList.java Thu Dec 03 10:49:44 2009 +0100
@@ -23,6 +23,7 @@
import android.os.IBinder;
import android.os.RemoteException;
import android.preference.PreferenceManager;
+import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@@ -36,7 +37,6 @@
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
-import android.widget.AdapterView.OnItemLongClickListener;
import com.beem.project.beem.R;
import com.beem.project.beem.service.Contact;
@@ -131,6 +131,55 @@
}
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ // TODO gere les info du context menu pour afficher que pour le bon long click
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.contactlist_context, menu);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean onContextItemSelected(MenuItem item) {
+ ContextMenu.ContextMenuInfo i = item.getMenuInfo();
+ if (i != null && i instanceof AdapterView.AdapterContextMenuInfo) {
+ AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) i;
+ Contact c = mListContact.get(info.position);
+ Intent in;
+ if (c != null) {
+ switch (item.getItemId()) {
+ case R.id.contact_list_context_menu_chat_item:
+ in = new Intent(this, Chat.class);
+ in.setData(c.toUri());
+ startActivity(in);
+ return true;
+ case R.id.contact_list_context_menu_call_item:
+ try {
+ mXmppFacade.call(c.getJID() + "/psi");
+ return true;
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ case R.id.contact_list_context_menu_manage_user_item:
+ in = new Intent(this, UserInfo.class);
+ //TODO use in.setData(c.toUri()); a la place
+ in.putExtra("contact_contactdialog", c.getJID());
+ startActivity(in);
+ return true;
+ default:
+ return super.onContextItemSelected(item);
+ }
+ }
+ }
+ return super.onContextItemSelected(item);
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -139,7 +188,7 @@
mListContact.clear();
stopService(SERVICE_INTENT);
finish();
- startActivity(new Intent(this, Login.class));
+ // startActivity(new Intent(this, Login.class));
}
}
}
@@ -161,8 +210,10 @@
super.onStop();
if (mContactDialog != null)
mContactDialog.dismiss();
- if (mReceiver.isBinded())
+ if (mReceiver.isBinded()) {
unbindService(mServConn);
+ mReceiver.setBinded(false);
+ }
}
@Override
@@ -174,7 +225,8 @@
/**
* Comparator Contact by Name.
*/
- class ComparatorContactListByName<T> implements Comparator<T> {
+ @SuppressWarnings("unused")
+ private class ComparatorContactListByName<T> implements Comparator<T> {
/**
* Constructor.
*/
@@ -194,7 +246,7 @@
/**
* Comparator Contact by status and name.
*/
- class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
+ private class ComparatorContactListByStatusAndName<T> implements Comparator<T> {
/**
* Constructor.
*/
@@ -226,7 +278,7 @@
sortBeemContactList();
ListView listView = (ListView) findViewById(R.id.contactlist);
listView.setOnItemClickListener(new BeemContactListOnClick());
- listView.setOnItemLongClickListener(new BeemContactListOnLongClick());
+ registerForContextMenu(listView);
listView.setAdapter(mAdapterContactList);
}
@@ -242,7 +294,7 @@
/**
* Event simple click on item of the contact list.
*/
- public class BeemContactListOnClick implements OnItemClickListener {
+ private class BeemContactListOnClick implements OnItemClickListener {
/**
* Constructor.
*/
@@ -263,30 +315,6 @@
}
/**
- * Event long click on item of the contact list.
- */
- public class BeemContactListOnLongClick implements OnItemLongClickListener {
- /**
- * Constructor.
- */
- public BeemContactListOnLongClick() {
-
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onItemLongClick(AdapterView<?> arg0, View v, int pos, long lpos) {
- Contact c = mListContact.get(pos);
- mContactDialog = new ContactDialog(ContactList.this, c);
- mContactDialog.setOwnerActivity(ContactList.this);
- mContactDialog.show();
- return true;
- }
- }
-
- /**
* Event simple click on middle groupe name.
*/
private class OnItemClickGroupName implements OnItemClickListener {
@@ -512,7 +540,20 @@
*/
@Override
public Object getItem(int position) {
- return position;
+ Contact c = null;
+ if (mSettings.getBoolean("settings_key_hidden_contact", false)) {
+ int res = 0;
+ for (Contact cur : mListContact) {
+ if (res == position) {
+ c = cur;
+ break;
+ }
+ if (Status.statusOnline(cur.getStatus()))
+ res++;
+ }
+ } else
+ c = mListContact.get(position);
+ return c;
}
/**
@@ -523,6 +564,7 @@
return position;
}
+
/**
* {@inheritDoc}
*/
@@ -581,7 +623,7 @@
/**
* Adapter banner list.
*/
- public class BeemBanner extends BaseAdapter {
+ private class BeemBanner extends BaseAdapter {
/**
* Constructor.
* @param c context activity.
--- a/src/com/beem/project/beem/ui/Login.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/ui/Login.java Thu Dec 03 10:49:44 2009 +0100
@@ -2,19 +2,11 @@
import android.app.Activity;
import android.app.AlertDialog;
-import android.app.ProgressDialog;
-import android.content.ComponentName;
import android.content.DialogInterface;
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.RemoteException;
-import android.os.SystemClock;
import android.preference.PreferenceManager;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -22,36 +14,17 @@
import android.widget.Toast;
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;
-import com.beem.project.beem.utils.Status;
/**
- * This class represents an activity which allows the user to connect to an XMPP server with his username/password.
- * @author Jean-Manuel Da Silva <dasilvj at beem-project dot com>
+ * This class is the main Activity for the Beem project.
+ * @author Da Risk <darisk972@gmai.com>
*/
public class Login extends Activity {
- private static final String TAG = "Login";
- private static final int REQUEST_CODE = 1;
- private static final Intent SERVICE_INTENT = new Intent();
- static {
- SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
- }
-
- private final Handler mConnectionHandler = new Handler();
- private final ConnectionRunnable mConnectionRunnable = new ConnectionRunnable();
- private ProgressDialog mProgressDialog;
-
- private boolean mIsConnectedService;
- private final ServiceConnection mServConn = new BeemServiceConnection();
- private IXmppFacade mXmppFacade;
-
private SharedPreferences mSettings;
+ private TextView mTextView;
private boolean mIsConfigured;
- private int mRetry;
- private IXmppConnection mXmppConnection;
+ private boolean mIsResult;
/**
* Constructor.
@@ -59,10 +32,75 @@
public Login() {
}
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.login);
+ mTextView = (TextView) findViewById(R.id.log_as_msg);
+ mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
+ // TODO utiliser une options des preference plutot.
+ if (mIsConfigured && !mIsResult) {
+ mTextView.setText("");
+ Intent i = new Intent(this, LoginAnim.class);
+ startActivityForResult(i, 42);
+ mIsResult = false;
+ }
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == 42) {
+ mIsResult = true;
+ if (resultCode == Activity.RESULT_OK) {
+ startActivity(new Intent(this, ContactList.class));
+ finish();
+ } else if (resultCode == Activity.RESULT_CANCELED) {
+ if (data != null) {
+ String tmp = data.getExtras().getString("message");
+ Toast.makeText(Login.this, tmp, Toast.LENGTH_SHORT).show();
+ mTextView.setText(tmp);
+ }
+ }
+ }
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.login, menu);
+ return true;
+ }
+
+ @Override
+ public final boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.login_menu_settings:
+ mTextView.setText("");
+ startActivity(new Intent(Login.this, Settings.class));
+ return true;
+ case R.id.login_menu_about:
+ createAboutDialog();
+ return true;
+ case R.id.login_menu_login:
+ Intent i = new Intent(this, LoginAnim.class);
+ startActivityForResult(i, 42);
+ return true;
+ default:
+ return false;
+ }
+ }
+
/**
* Create an about "BEEM" dialog.
*/
- public void createAboutDialog() {
+ private void createAboutDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.login_about_title).setMessage(R.string.login_about_msg).setCancelable(false);
builder.setNeutralButton(R.string.login_about_button, new DialogInterface.OnClickListener() {
@@ -74,320 +112,4 @@
AlertDialog aboutDialog = builder.create();
aboutDialog.show();
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Log.d(TAG, "BEGIN onCreate.");
- mSettings = PreferenceManager.getDefaultSharedPreferences(this);
- setContentView(R.layout.login);
- mProgressDialog = new ProgressDialog(this);
- Log.d(TAG, "END onCreate.");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onStop() {
- super.onStop();
- Log.d(TAG, "BEGIN onStop.");
- if (mIsConfigured && (mIsConnectedService || mXmppFacade != null)) {
- boolean isConnected = false;
- if (mXmppConnection != null) {
- try {
- isConnected = mXmppConnection.isAuthentificated();
- } catch (RemoteException e) {
- e.printStackTrace();
- }
- }
- unbindService(mServConn);
- if (!isConnected) {
- stopService(SERVICE_INTENT);
- }
- mXmppFacade = null;
- }
- Log.d(TAG, "END onStop.");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onPause() {
- super.onPause();
- Log.d(TAG, "BEGIN onPause.");
- mConnectionHandler.removeCallbacks(mConnectionRunnable);
- mProgressDialog.dismiss();
- Log.d(TAG, "END onPause.");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onResume() {
- super.onResume();
- Log.d(TAG, "BEGIN onResume.");
- Log.d(TAG, "END onResume.");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void onStart() {
- super.onStart();
- Log.d(TAG, "BEGIN onStart.");
- mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
- if (mIsConfigured && !mIsConnectedService) {
- try {
- Thread.sleep(1000); // HACK: Pour éviter de rebinder un service
- // pas encore arreter.
- } catch (InterruptedException e) {
- Log.e(TAG, e.getMessage());
- }
- bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
- mIsConnectedService = true;
- }
- Log.d(TAG, "END onStart.");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_CODE) {
- if (resultCode == RESULT_OK) {
- stopService(SERVICE_INTENT);
- }
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- super.onCreateOptionsMenu(menu);
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.login, 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.login_menu_settings:
- startActivity(new Intent(Login.this, Settings.class));
- return true;
- case R.id.login_menu_about:
- createAboutDialog();
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Connection runnable.
- * @author nikita
- */
- private class ConnectionRunnable implements Runnable {
-
- /**
- * Constructor.
- */
- public ConnectionRunnable() {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void run() {
- if (mRetry++ > 3) {
- Toast.makeText(Login.this, R.string.login_max_retry, Toast.LENGTH_LONG).show();
- mConnectionHandler.removeCallbacks(mConnectionRunnable);
- } else {
- mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
- if (mIsConfigured) {
- bindService(Login.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
- }
- }
-
- }
- }
-
- /**
- * Listener use to check the state of the connection with the server.
- */
- private class BeemConnectionListener extends IBeemConnectionListener.Stub {
-
- /**
- * Constructor.
- */
- public BeemConnectionListener() {
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void connectionClosed() throws RemoteException {
- Log.d(TAG, "BEGIN connectionClosed.");
- if (mXmppFacade != null) {
- launchReconnectionHandler();
- mXmppFacade = null;
- }
- Log.d(TAG, "END connectionClosed.");
- }
-
- @Override
- public void connectionClosedOnError() throws RemoteException {
- Log.d(TAG, "BEGIN connectionClosedOnError.");
- if (mXmppFacade != null) {
- launchReconnectionHandler();
- mXmppFacade = null;
- }
- Log.d(TAG, "END connectionClosedOnError.");
- }
-
- @Override
- public void connectionFailed(String errorMsg) throws RemoteException {
- Log.d(TAG, "BEGIN connectionFailed.");
- if (mXmppFacade != null) {
- Login.this.unbindService(mServConn);
- Login.this.stopService(SERVICE_INTENT);
- mIsConnectedService = false;
- mXmppFacade = null;
- }
- dismissProgressDialog();
- showToast(errorMsg);
- launchReconnectionHandler();
- Log.d(TAG, "END connectionFailed.");
- }
-
- /**
- * launch reconnection handler.
- */
- private void launchReconnectionHandler() {
- mConnectionHandler.postAtTime(mConnectionRunnable, Integer.parseInt(mSettings.getString(
- "settings_key_reco_delay", "10"))
- * 1000 + SystemClock.uptimeMillis());
- }
-
- /**
- * Show an error message with a toast.
- * @param errorMsg The message to display.
- */
- private void showToast(final String errorMsg) {
- mConnectionHandler.post(new Runnable() {
- /**
- * @{inheritDoc
- */
- @Override
- public void run() {
- Toast.makeText(Login.this, errorMsg, Toast.LENGTH_LONG).show();
- TextView labelError = (TextView) findViewById(R.id.log_as_msg);
- labelError.setText(getString(R.string.login_error_msg, errorMsg));
- }
- });
- }
-
- /**
- * Dismiss the progress dialog.
- */
- private void dismissProgressDialog() {
- mConnectionHandler.post(new Runnable() {
-
- /**
- * @{inheritDoc
- */
- @Override
- public void run() {
- mProgressDialog.dismiss();
- }
- });
- }
-
- @Override
- public void onConnect() throws RemoteException {
- Log.d(TAG, "BEGIN onConnect.");
- dismissProgressDialog();
- mXmppFacade.changeStatus(Status.CONTACT_STATUS_AVAILABLE, null);
- mRetry = 0;
- startActivity(new Intent(Login.this, ContactList.class));
- finish();
- Log.d(TAG, "END onConnect.");
- }
-
- @Override
- public void reconnectingIn(int seconds) throws RemoteException {
- }
-
- @Override
- public void reconnectionFailed() throws RemoteException {
- }
-
- @Override
- public void reconnectionSuccessful() throws RemoteException {
- }
- }
-
- /**
- * ServiceConnection use to connect to the Beem Service.
- */
- private class BeemServiceConnection implements ServiceConnection {
- /**
- * Constructor.
- */
- public BeemServiceConnection() {
- }
-
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- Log.d(TAG, "BEGIN onServiceConnected.");
- mXmppFacade = IXmppFacade.Stub.asInterface(service);
- mIsConnectedService = true;
- try {
- mXmppConnection = mXmppFacade.createConnection();
- mXmppConnection.addConnectionListener(new BeemConnectionListener());
- if (!mXmppConnection.isAuthentificated()) {
- mConnectionHandler.post(new Runnable() {
- @Override
- public void run() {
- mProgressDialog.setMessage(getString(R.string.login_login_progress));
- mProgressDialog.show();
- }
- });
- Login.this.startService(Login.SERVICE_INTENT);
- } else {
- startActivity(new Intent(Login.this, ContactList.class));
- finish();
- }
- } catch (RemoteException e) {
- Log.e(TAG, e.getMessage());
- }
- Log.d(TAG, "END onServiceConnected.");
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- Log.d(TAG, "BEGIN onServiceDisconnected.");
- mIsConnectedService = false;
- mXmppFacade = null;
- Log.d(TAG, "END onServiceDisconnected.");
- }
- }
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/com/beem/project/beem/ui/LoginAnim.java Thu Dec 03 10:49:44 2009 +0100
@@ -0,0 +1,209 @@
+package com.beem.project.beem.ui;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.ServiceConnection;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.util.Log;
+import android.view.KeyEvent;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.animation.Animation;
+import android.view.animation.AnimationUtils;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.ProgressBar;
+
+import com.beem.project.beem.R;
+import com.beem.project.beem.service.aidl.IXmppConnection;
+import com.beem.project.beem.service.aidl.IXmppFacade;
+
+/**
+ * This class is an activity which display an animation during the connection with the server.
+ * @author Da Risk <darisk972@gmail.com>
+ */
+public class LoginAnim extends Activity {
+
+ private static final String TAG = "LoginAnim";
+ private static final Intent SERVICE_INTENT = new Intent();
+ static {
+ SERVICE_INTENT.setComponent(new ComponentName("com.beem.project.beem", "com.beem.project.beem.BeemService"));
+ }
+ private ImageView mLogo;
+ private Animation mRotateAnim;
+ private final ServiceConnection mServConn = new LoginServiceConnection();
+ private IXmppFacade mXmppFacade;
+ private AsyncTask<IXmppFacade, Void, Boolean> mTask;
+ private Button mCancelBt;
+ private ProgressBar mProgressBar;
+
+ /**
+ * Constructor.
+ */
+ public LoginAnim() {
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.login_anim);
+ mLogo = (ImageView) findViewById(R.id.loginanim_logo_anim);
+ mRotateAnim = AnimationUtils.loadAnimation(this, R.anim.rotate_and_scale);
+ mCancelBt = (Button) findViewById(R.id.loginanim_cancel_button);
+ mCancelBt.setOnClickListener(new ClickListener());
+ mProgressBar = (ProgressBar) findViewById(R.id.loginanim_progressbar);
+ mProgressBar.setIndeterminate(true);
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ mLogo.startAnimation(mRotateAnim);
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (mTask == null)
+ mTask = new LoginTask();
+ if (mXmppFacade == null)
+ bindService(LoginAnim.SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
+ }
+
+ @Override
+ protected void onPause() {
+ super.onPause();
+ if (mXmppFacade != null) { // and async task not en cours
+ unbindService(mServConn);
+ mXmppFacade = null;
+ }
+ }
+
+ @Override
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
+ // TODO use onBackPressed on Eclair (2.0)
+ if (keyCode == KeyEvent.KEYCODE_BACK && mTask.getStatus() != AsyncTask.Status.FINISHED) {
+ if (!mTask.cancel(true)) {
+ Log.d(TAG, "Can't interrupt the connection");
+ }
+ setResult(Activity.RESULT_CANCELED);
+ }
+ return super.onKeyDown(keyCode, event);
+ }
+
+ /**
+ * Click event listener on cancel button.
+ */
+ private class ClickListener implements OnClickListener {
+
+ /**
+ * Constructor.
+ */
+ ClickListener() {
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mCancelBt) {
+ if (!mTask.cancel(true)) {
+ Log.d(TAG, "Can't interrupt the connection");
+ }
+ setResult(Activity.RESULT_CANCELED);
+ finish();
+ }
+ }
+ }
+
+ /**
+ * Asynchronous class for connection.
+ */
+ class LoginTask extends AsyncTask<IXmppFacade, Void, Boolean> {
+
+ private IXmppConnection mConnection;
+ private String mMsg;
+
+ /**
+ * Constructor.
+ */
+ LoginTask() {
+ }
+
+ @Override
+ protected Boolean doInBackground(IXmppFacade... params) {
+ boolean result = true;
+ IXmppFacade facade = params[0];
+ try {
+ mConnection = facade.createConnection();
+ if (!mConnection.isAuthentificated()) {
+ result = mConnection.connectSync();
+ if (!result)
+ mMsg = mConnection.getErrorMessage();
+ }
+ } catch (RemoteException e) {
+ mMsg = "Exception during connection";
+ result = false;
+ }
+ return result;
+ }
+
+ @Override
+ protected void onPostExecute(Boolean result) {
+
+ if (result == null || !result) { // Task cancelled or exception
+ if (!result) {
+ Intent i = new Intent();
+ i.putExtra("message", mMsg);
+ LoginAnim.this.setResult(Activity.RESULT_CANCELED, i);
+ } else
+ LoginAnim.this.setResult(Activity.RESULT_CANCELED);
+ LoginAnim.this.finish();
+ } else {
+ mCancelBt.setEnabled(false);
+ LoginAnim.this.startService(LoginAnim.SERVICE_INTENT);
+ LoginAnim.this.setResult(Activity.RESULT_OK);
+ LoginAnim.this.finish();
+ }
+ }
+
+ @Override
+ protected void onCancelled() {
+ try {
+ if (mConnection != null && mConnection.isAuthentificated()) {
+ mConnection.disconnect();
+ }
+ } catch (RemoteException e) {
+ Log.d(TAG, "Remote exception", e);
+ }
+ LoginAnim.this.stopService(LoginAnim.SERVICE_INTENT);
+ }
+
+ }
+
+ /**
+ * The service connection used to connect to the Beem service.
+ */
+ private class LoginServiceConnection implements ServiceConnection {
+
+ /**
+ * Constructor.
+ */
+ public LoginServiceConnection() {
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ mXmppFacade = IXmppFacade.Stub.asInterface(service);
+ if (mTask.getStatus() == AsyncTask.Status.PENDING)
+ mTask = mTask.execute(mXmppFacade);
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName name) {
+ mXmppFacade = null;
+ }
+ }
+}
--- a/src/com/beem/project/beem/ui/Settings.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/ui/Settings.java Thu Dec 03 10:49:44 2009 +0100
@@ -92,16 +92,6 @@
i = new Intent(this, CreateAccount.class);
startActivity(i);
return true;
- case R.id.settings_menu_login:
- setResult(RESULT_OK);
- SharedPreferences settings = getPreferenceManager().getSharedPreferences();
- settings.edit().putBoolean(
- "PreferenceIsConfigured",
- !"".equals(settings.getString("settings_key_account_username", ""))
- || !"".equals(settings.getString("settings_key_account_password", ""))).commit();
- this.stopService(SERVICE_INTENT);
- finish();
- return true;
case R.id.settings_menu_privacy_lists:
/*
* i = new Intent(this, PrivacyList.class); startActivity(i);
--- a/src/com/beem/project/beem/ui/UserInfo.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/ui/UserInfo.java Thu Dec 03 10:49:44 2009 +0100
@@ -252,7 +252,7 @@
/**
* Event simple click on layout resend suscription.
*/
- class ResendListener implements View.OnClickListener {
+ private class ResendListener implements View.OnClickListener {
/**
* Constructor.
@@ -293,12 +293,13 @@
/**
* Event simple click on layout delete.
*/
- class DeleteListener implements View.OnClickListener {
+ private class DeleteListener implements View.OnClickListener {
/**
* Constructor.
*/
public DeleteListener() {
+
}
@Override
--- a/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Thu Dec 03 00:36:12 2009 +0100
+++ b/src/com/beem/project/beem/utils/BeemBroadcastReceiver.java Thu Dec 03 10:49:44 2009 +0100
@@ -8,8 +8,6 @@
import android.util.Log;
import android.widget.Toast;
-import com.beem.project.beem.ui.Login;
-
/**
* Manage broadcast disconnect intent.
* @author nikita
@@ -41,9 +39,10 @@
if (mIsBinded)
context.unbindService(mService);
setBinded(false);
+ // TODO ce code est comment car il empeche de gerer un cancel sur une connexion
// start activity if unexpected disconnection
- if (!intent.getBooleanExtra("normally", false))
- context.startActivity(new Intent(context, Login.class));
+// if (!intent.getBooleanExtra("normally", false))
+// context.startActivity(new Intent(context, Login.class));
CharSequence message = intent.getCharSequenceExtra("message");
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
if (context instanceof Activity) {