feature #221:
authorNikita Kozlov <nikita@beem-project.com>
Fri, 04 Dec 2009 14:25:30 +0100
changeset 559 99c587773311
parent 554 eaf76f5b1f65
child 560 261c4895bf84
feature #221: Ajout d'une classe pour verifier la connection. On verifie si on a le net au moment d'appuyer sur login.
AndroidManifest.xml
res/values-fr/strings.xml
res/values/strings.xml
src/com/beem/project/beem/BeemService.java
src/com/beem/project/beem/service/RosterAdapter.java
src/com/beem/project/beem/service/XmppConnectionAdapter.java
src/com/beem/project/beem/ui/Login.java
src/com/beem/project/beem/utils/BeemConnectivity.java
--- a/AndroidManifest.xml	Thu Dec 03 12:15:54 2009 +0100
+++ b/AndroidManifest.xml	Fri Dec 04 14:25:30 2009 +0100
@@ -92,6 +92,7 @@
 	<uses-permission android:name="android.permission.VIBRATE"></uses-permission>
 	<uses-permission android:name="com.beem.project.beem.BEEM_SERVICE"></uses-permission>
 	<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"></uses-permission>
+	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
 	<uses-sdk android:minSdkVersion="3"></uses-sdk>
 
 </manifest> 
--- a/res/values-fr/strings.xml	Thu Dec 03 12:15:54 2009 +0100
+++ b/res/values-fr/strings.xml	Fri Dec 04 14:25:30 2009 +0100
@@ -171,6 +171,7 @@
 	<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>
+	<string name="login_no_connectivity">Pas de connexion internet disponible</string>
 
 	<!--
 		EditSettings Activity
--- a/res/values/strings.xml	Thu Dec 03 12:15:54 2009 +0100
+++ b/res/values/strings.xml	Fri Dec 04 14:25:30 2009 +0100
@@ -161,6 +161,7 @@
 	<string name="login_error_msg">Unfortunately, an error occured.\n\nError
 		detail:\n%s</string>
 	<string name="login_menu_login">Login</string>
+	<string name="login_no_connectivity">No internet connection found</string>
 
 	<!-- EditSettings Activity -->
 	<string name="settings_menu_create_account">Create an account</string>
--- a/src/com/beem/project/beem/BeemService.java	Thu Dec 03 12:15:54 2009 +0100
+++ b/src/com/beem/project/beem/BeemService.java	Fri Dec 04 14:25:30 2009 +0100
@@ -221,7 +221,7 @@
      */
     public void resetStatus() {
 	Editor edit = mSettings.edit();
-	edit.putInt(getString(R.string.PreferenceStatus), 1);
+	edit.putInt("PreferenceStatus", 1);
 	edit.commit();
     }
 
--- a/src/com/beem/project/beem/service/RosterAdapter.java	Thu Dec 03 12:15:54 2009 +0100
+++ b/src/com/beem/project/beem/service/RosterAdapter.java	Fri Dec 04 14:25:30 2009 +0100
@@ -254,7 +254,6 @@
 	 * @param group the group the entry was.
 	 * @param jid the jid of the entry which is deleted.
 	 */
-	@SuppressWarnings("unused")
 	public void onEntryDeleteFromGroup(final String group, final String jid) {
 	    // Log.i(TAG, "entry delete listener");
 	    final int n = mRemoteRosListeners.beginBroadcast();
--- a/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Thu Dec 03 12:15:54 2009 +0100
+++ b/src/com/beem/project/beem/service/XmppConnectionAdapter.java	Fri Dec 04 14:25:30 2009 +0100
@@ -44,8 +44,6 @@
      */
 
     private static final String TAG = "XMPPConnectionAdapter";
-    private static final int PRESENCE_PRIORITY = 128;
-
     private final XMPPConnection mAdaptee;
     private IChatManager mChatManager;
     private final String mLogin;
--- a/src/com/beem/project/beem/ui/Login.java	Thu Dec 03 12:15:54 2009 +0100
+++ b/src/com/beem/project/beem/ui/Login.java	Fri Dec 04 14:25:30 2009 +0100
@@ -14,6 +14,7 @@
 import android.widget.Toast;
 
 import com.beem.project.beem.R;
+import com.beem.project.beem.utils.BeemConnectivity;
 
 /**
  * This class is the main Activity for the Beem project.
@@ -89,14 +90,24 @@
 		createAboutDialog();
 		return true;
 	    case R.id.login_menu_login:
-		Intent i = new Intent(this, LoginAnim.class);
-		startActivityForResult(i, 42);
+		if (testConnectivity()) {
+		    Intent i = new Intent(this, LoginAnim.class);
+		    startActivityForResult(i, 42);
+		}
 		return true;
 	    default:
 		return false;
 	}
     }
 
+    private boolean testConnectivity() {
+	if (!BeemConnectivity.isConnected(getApplicationContext())) {
+	    Toast.makeText(Login.this, R.string.login_no_connectivity, Toast.LENGTH_SHORT).show();
+	    return false;
+	}
+	return true;
+    }
+
     /**
      * Create an about "BEEM" dialog.
      */
--- a/src/com/beem/project/beem/utils/BeemConnectivity.java	Thu Dec 03 12:15:54 2009 +0100
+++ b/src/com/beem/project/beem/utils/BeemConnectivity.java	Fri Dec 04 14:25:30 2009 +0100
@@ -12,7 +12,7 @@
     static public boolean isConnected(Context ctx) {
 	ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
 	NetworkInfo ni = cm.getActiveNetworkInfo();
-	return ni.isConnected();
+	return ni != null && ni.isConnected();
     }
     
     public static boolean isWifi(Context ctx) {