Gestion de la touche BACK lors d'un login. et connection automatique si on est
congifuré
--- a/src/com/beem/project/beem/ui/Login2.java Sat Nov 28 01:55:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/Login2.java Sat Nov 28 02:45:10 2009 +0100
@@ -4,7 +4,9 @@
import android.app.AlertDialog;
import android.content.Intent;
import android.content.DialogInterface;
+import android.content.SharedPreferences;
import android.os.Bundle;
+import android.preference.PreferenceManager;
import android.util.Log;
import com.beem.project.beem.R;
import android.view.Menu;
@@ -18,6 +20,8 @@
public class Login2 extends Activity {
private static final String TAG = "Login2";
+ private SharedPreferences mSettings;
+ private boolean mIsConfigured;
/**
* Constructor.
@@ -30,13 +34,18 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
+ mSettings = PreferenceManager.getDefaultSharedPreferences(this);
}
@Override
protected void onStart() {
super.onStart();
- Intent i = new Intent (this, LoginAnim.class);
- startActivityForResult(i, 42);
+ mIsConfigured = mSettings.getBoolean("PreferenceIsConfigured", false);
+ //TODO utiliser une options des preference plutot.
+ if (mIsConfigured) {
+ Intent i = new Intent (this, LoginAnim.class);
+ startActivityForResult(i, 42);
+ }
}
@Override
--- a/src/com/beem/project/beem/ui/LoginAnim.java Sat Nov 28 01:55:26 2009 +0100
+++ b/src/com/beem/project/beem/ui/LoginAnim.java Sat Nov 28 02:45:10 2009 +0100
@@ -16,6 +16,7 @@
import android.widget.TextView;
import android.widget.ProgressBar;
import android.view.animation.AnimationUtils;
+import android.view.KeyEvent;
import com.beem.project.beem.R;
import android.util.Log;
import com.beem.project.beem.service.aidl.IXmppFacade;
@@ -49,6 +50,18 @@
public LoginAnim() {
}
+ @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);
+ }
+
/**
* {@inheritDoc}
*/
@@ -152,7 +165,7 @@
protected void onCancelled() {
mCancelBt.setText("Cancelled. Retry");
try {
- if (mConnection.isAuthentificated()) {
+ if (mConnection != null && mConnection.isAuthentificated()) {
mConnection.disconnect();
}
} catch (RemoteException e) {