Prevented server check due to orientation change in login view
authorDavid A. Velasco <dvelasco@solidgear.es>
Thu, 16 May 2013 10:30:37 +0000 (12:30 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Thu, 16 May 2013 10:30:37 +0000 (12:30 +0200)
src/com/owncloud/android/authentication/AuthenticatorActivity.java

index 141cd54..120fbde 100644 (file)
@@ -48,7 +48,9 @@ import android.net.Uri;
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.preference.PreferenceManager;\r
 import android.os.Bundle;\r
 import android.os.Handler;\r
 import android.preference.PreferenceManager;\r
+import android.text.Editable;\r
 import android.text.InputType;\r
 import android.text.InputType;\r
+import android.text.TextWatcher;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
@@ -87,12 +89,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
     private static final String KEY_OC_VERSION = "OC_VERSION";\r
     private static final String KEY_ACCOUNT = "ACCOUNT";\r
     private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
     private static final String KEY_OC_VERSION = "OC_VERSION";\r
     private static final String KEY_ACCOUNT = "ACCOUNT";\r
-    private static final String KEY_STATUS_TEXT = "STATUS_TEXT";\r
-    private static final String KEY_STATUS_ICON = "STATUS_ICON";\r
-    private static final String KEY_STATUS_CORRECT = "STATUS_CORRECT";\r
+    private static final String KEY_SERVER_CHECKED_AND_VALID = "SERVER_CHECKED_AND_VALID";\r
+    private static final String KEY_SERVER_CHECK_IN_PROGRESS = "SERVER_CHECK_IN_PROGRESS"; \r
+    private static final String KEY_SERVER_STATUS_TEXT = "SERVER_STATUS_TEXT";\r
+    private static final String KEY_SERVER_STATUS_ICON = "SERVER_STATUS_ICON";\r
     private static final String KEY_IS_SSL_CONN = "IS_SSL_CONN";\r
     private static final String KEY_IS_SSL_CONN = "IS_SSL_CONN";\r
-    private static final String KEY_OAUTH2_STATUS_TEXT = "OAUTH2_STATUS_TEXT";\r
-    private static final String KEY_OAUTH2_STATUS_ICON = "OAUTH2_STATUS_ICON";\r
+    private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
+    private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
     \r
     private static final String OAUTH_MODE_ON = "on";\r
     private static final String OAUTH_MODE_OFF = "off";\r
     \r
     private static final String OAUTH_MODE_ON = "on";\r
     private static final String OAUTH_MODE_OFF = "off";\r
@@ -110,9 +113,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
     \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
     \r
-    private int mStatusText, mStatusIcon;\r
-    private boolean mStatusCorrect, mIsSslConn;\r
-    private int mOAuth2StatusText, mOAuth2StatusIcon;    \r
+    private int mServerStatusText, mServerStatusIcon;\r
+    private boolean mServerCheckedAndValid, mIsSslConn;\r
+    private int mAuthStatusText, mAuthStatusIcon;    \r
     \r
     private final Handler mHandler = new Handler();\r
     private Thread mOperationThread;\r
     \r
     private final Handler mHandler = new Handler();\r
     private Thread mOperationThread;\r
@@ -138,6 +141,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     \r
     private TextView mOAuthAuthEndpointText;\r
     private TextView mOAuthTokenEndpointText;\r
     \r
     private TextView mOAuthAuthEndpointText;\r
     private TextView mOAuthTokenEndpointText;\r
+\r
+    private HostUrlWatcher mHostUrlChangedListener;\r
     \r
     \r
     /**\r
     \r
     \r
     /**\r
@@ -168,32 +173,19 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             b.setText(String.format(getString(R.string.auth_register), getString(R.string.app_name)));\r
         }\r
 \r
             b.setText(String.format(getString(R.string.auth_register), getString(R.string.app_name)));\r
         }\r
 \r
-        /// bind view elements to listeners\r
-        mHostUrlInput.setOnFocusChangeListener(this);\r
-        mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
-            @Override\r
-            public boolean onDrawableTouch(final MotionEvent event) {\r
-                AuthenticatorActivity.this.onRefreshClick(mHostUrlInput);\r
-                return true;\r
-            }\r
-        });\r
-        mPasswordInput.setOnFocusChangeListener(this);\r
-        mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
-        mPasswordInput.setOnEditorActionListener(this);\r
-        \r
         /// initialization\r
         mAccountMgr = AccountManager.get(this);\r
         mNewCapturedUriFromOAuth2Redirection = null;\r
         mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE); \r
         mAccount = null;\r
         /// initialization\r
         mAccountMgr = AccountManager.get(this);\r
         mNewCapturedUriFromOAuth2Redirection = null;\r
         mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE); \r
         mAccount = null;\r
+        mHostBaseUrl = "";\r
 \r
         if (savedInstanceState == null) {\r
             /// connection state and info\r
 \r
         if (savedInstanceState == null) {\r
             /// connection state and info\r
-            mStatusText = mStatusIcon = 0;\r
-            mStatusCorrect = false;\r
+            mServerStatusText = mServerStatusIcon = 0;\r
+            mServerCheckedAndValid = false;\r
             mIsSslConn = false;\r
             mIsSslConn = false;\r
-            updateConnStatus();\r
-            updateAuthStatus();\r
+            mAuthStatusText = mAuthStatusIcon = 0;\r
             \r
             /// retrieve extras from intent\r
             String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);\r
             \r
             /// retrieve extras from intent\r
             String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);\r
@@ -205,7 +197,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 if (ocVersion != null) {\r
                     mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
                 }\r
                 if (ocVersion != null) {\r
                     mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
                 }\r
-                mHostBaseUrl = mAccountMgr.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL);\r
+                mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, AccountAuthenticator.KEY_OC_BASE_URL));\r
                 mHostUrlInput.setText(mHostBaseUrl);\r
                 String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
                 mUsernameInput.setText(userName);\r
                 mHostUrlInput.setText(mHostBaseUrl);\r
                 String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
                 mUsernameInput.setText(userName);\r
@@ -216,9 +208,34 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             \r
 \r
         } else {\r
             \r
 \r
         } else {\r
-            loadSavedInstanceState(savedInstanceState);\r
+            /// connection state and info\r
+            mServerCheckedAndValid = savedInstanceState.getBoolean(KEY_SERVER_CHECKED_AND_VALID);\r
+            mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
+            mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);\r
+            mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);\r
+            mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT);\r
+            mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON);\r
+            \r
+            /// server data\r
+            String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
+            if (ocVersion != null) {\r
+                mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
+            }\r
+            mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);\r
+            \r
+            // account data, if updating\r
+            mAccount = savedInstanceState.getParcelable(KEY_ACCOUNT);\r
+            \r
+            // check if server check was interrupted by a configuration change\r
+            if (savedInstanceState.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS, false)) {\r
+                checkOcServer();\r
+            }\r
+            \r
         }\r
         \r
         }\r
         \r
+        showServerStatus();\r
+        showAuthStatus();\r
+        \r
         if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
             mOAuth2Check.setVisibility(View.GONE);\r
         }\r
         if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
             mOAuth2Check.setVisibility(View.GONE);\r
         }\r
@@ -228,13 +245,41 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mHostUrlInput.setEnabled(false);\r
             mUsernameInput.setEnabled(false);\r
             mOAuth2Check.setVisibility(View.GONE);\r
             mHostUrlInput.setEnabled(false);\r
             mUsernameInput.setEnabled(false);\r
             mOAuth2Check.setVisibility(View.GONE);\r
-            checkOcServer(); \r
+            if (!mServerCheckedAndValid && mOcServerChkOperation == null) {\r
+                checkOcServer(); \r
+            }\r
         }\r
         \r
         mPasswordInput.setText("");     // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)\r
         mJustCreated = true;\r
         }\r
         \r
         mPasswordInput.setText("");     // clean password to avoid social hacking (disadvantage: password in removed if the device is turned aside)\r
         mJustCreated = true;\r
+        \r
+        /// bind view elements to listeners\r
+        mHostUrlInput.setOnFocusChangeListener(this);\r
+        mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
+            @Override\r
+            public boolean onDrawableTouch(final MotionEvent event) {\r
+                AuthenticatorActivity.this.onRefreshClick(mHostUrlInput);\r
+                return true;\r
+            }\r
+        });\r
+        mPasswordInput.setOnFocusChangeListener(this);\r
+        mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
+        mPasswordInput.setOnEditorActionListener(this);\r
+    }\r
+    \r
+    @Override\r
+    protected void onStart() {\r
+        super.onStart();\r
+        //mHostUrlChangedListener = new  HostUrlWatcher();\r
+        //mHostUrlInput.addTextChangedListener(mHostUrlChangedListener);    \r
     }\r
 \r
     }\r
 \r
+    @Override\r
+    protected void onStop() {\r
+        super.onStop();\r
+        mHostUrlInput.removeTextChangedListener(mHostUrlChangedListener);\r
+    }\r
+    \r
 \r
     /**\r
      * Saves relevant state before {@link #onPause()}\r
 \r
     /**\r
      * Saves relevant state before {@link #onPause()}\r
@@ -249,66 +294,28 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         super.onSaveInstanceState(outState);\r
         \r
         /// connection state and info\r
         super.onSaveInstanceState(outState);\r
         \r
         /// connection state and info\r
-        outState.putInt(KEY_STATUS_TEXT, mStatusText);\r
-        outState.putInt(KEY_STATUS_ICON, mStatusIcon);\r
-        outState.putBoolean(KEY_STATUS_CORRECT, mStatusCorrect);\r
+        outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
+        outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon);\r
+        outState.putBoolean(KEY_SERVER_CHECKED_AND_VALID, mServerCheckedAndValid);\r
+        outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerCheckedAndValid && mOcServerChkOperation != null));\r
         outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn);\r
         outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn);\r
-\r
+        outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon);\r
+        outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
+        \r
         /// server data\r
         /// server data\r
-        if (mDiscoveredVersion != null) \r
+        if (mDiscoveredVersion != null) {\r
             outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());\r
             outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());\r
+        }\r
         outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);\r
         \r
         /// account data, if updating\r
         outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);\r
         \r
         /// account data, if updating\r
-        if (mAccount != null)\r
+        if (mAccount != null) {\r
             outState.putParcelable(KEY_ACCOUNT, mAccount);\r
             outState.putParcelable(KEY_ACCOUNT, mAccount);\r
-        \r
-        // Saving the state of oAuth2 components.\r
-        outState.putInt(KEY_OAUTH2_STATUS_ICON, mOAuth2StatusIcon);\r
-        outState.putInt(KEY_OAUTH2_STATUS_TEXT, mOAuth2StatusText);\r
-        \r
-    }\r
-\r
-\r
-    /**\r
-     * Loads saved state\r
-     * \r
-     * See {@link #onSaveInstanceState(Bundle)}.\r
-     * \r
-     * @param savedInstanceState    Saved state, as received in {@link #onCreate(Bundle)}.\r
-     */\r
-    private void loadSavedInstanceState(Bundle savedInstanceState) {\r
-        /// connection state and info\r
-        mStatusCorrect = savedInstanceState.getBoolean(KEY_STATUS_CORRECT);\r
-        mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);\r
-        mStatusText = savedInstanceState.getInt(KEY_STATUS_TEXT);\r
-        mStatusIcon = savedInstanceState.getInt(KEY_STATUS_ICON);\r
-        updateConnStatus();\r
-        \r
-        /// UI settings depending upon connection\r
-        mOkButton.setEnabled(mStatusCorrect);  \r
-        if (!mStatusCorrect) {\r
-            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
-        } else {\r
-            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
         }\r
         \r
         }\r
         \r
-        /// server data\r
-        String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
-        if (ocVersion != null)\r
-            mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
-        mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);\r
-        \r
-        // account data, if updating\r
-        mAccount = savedInstanceState.getParcelable(KEY_ACCOUNT);\r
-        \r
-        // state of oAuth2 components\r
-        mOAuth2StatusIcon = savedInstanceState.getInt(KEY_OAUTH2_STATUS_ICON);\r
-        mOAuth2StatusText = savedInstanceState.getInt(KEY_OAUTH2_STATUS_TEXT);\r
-        // END of getting the state of oAuth2 components.\r
     }\r
 \r
     }\r
 \r
-    \r
+\r
     /**\r
      * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request\r
      * is caught here.\r
     /**\r
      * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request\r
      * is caught here.\r
@@ -378,8 +385,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * Handles the change of focus on the text inputs for the server URL and the password\r
      */\r
     public void onFocusChange(View view, boolean hasFocus) {\r
      * Handles the change of focus on the text inputs for the server URL and the password\r
      */\r
     public void onFocusChange(View view, boolean hasFocus) {\r
-        if (view.getId() == R.id.hostUrlInput) {\r
-            onUrlInputFocusChanged((TextView) view, hasFocus);\r
+        if (view.getId() == R.id.hostUrlInput && !hasFocus) {\r
+            onUrlInputFocusLost((TextView) view);\r
             \r
         } else if (view.getId() == R.id.account_password) {\r
             onPasswordFocusChanged((TextView) view, hasFocus);\r
             \r
         } else if (view.getId() == R.id.account_password) {\r
             onPasswordFocusChanged((TextView) view, hasFocus);\r
@@ -397,15 +404,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * When hasFocus:    user 'comes back' to write again the server URL.\r
      * \r
      * @param hostInput     TextView with the URL input field receiving the change of focus.\r
      * When hasFocus:    user 'comes back' to write again the server URL.\r
      * \r
      * @param hostInput     TextView with the URL input field receiving the change of focus.\r
-     * @param hasFocus      'True' if focus is received, 'false' if is lost\r
      */\r
      */\r
-    private void onUrlInputFocusChanged(TextView hostInput, boolean hasFocus) {\r
-        if (!hasFocus) {\r
+    private void onUrlInputFocusLost(TextView hostInput) {\r
+        if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) {\r
             checkOcServer();\r
             checkOcServer();\r
-            \r
-        } else {\r
-            // avoids that the 'connect' button can be clicked if the test was previously passed\r
-            mOkButton.setEnabled(false); \r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -413,23 +415,20 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private void checkOcServer() {\r
         String uri = mHostUrlInput.getText().toString().trim();\r
         if (uri.length() != 0) {\r
     private void checkOcServer() {\r
         String uri = mHostUrlInput.getText().toString().trim();\r
         if (uri.length() != 0) {\r
-            mStatusText = R.string.auth_testing_connection;\r
-            mStatusIcon = R.drawable.progress_small;\r
-            updateConnStatus();\r
-            /** TODO cancel previous connection check if the user tries to ammend a wrong URL  \r
-            if(mConnChkOperation != null) {\r
-                mConnChkOperation.cancel();\r
-            } */\r
+            mServerCheckedAndValid = false;\r
+            mOkButton.setEnabled(false);\r
+            mServerStatusText = R.string.auth_testing_connection;\r
+            mServerStatusIcon = R.drawable.progress_small;\r
+            showServerStatus();\r
             mOcServerChkOperation = new  OwnCloudServerCheckOperation(uri, this);\r
             WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(uri), this);\r
             mOcServerChkOperation = new  OwnCloudServerCheckOperation(uri, this);\r
             WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(uri), this);\r
-            mHostBaseUrl = "";\r
             mDiscoveredVersion = null;\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
             mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
             mDiscoveredVersion = null;\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
             mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
-            mStatusText = 0;\r
-            mStatusIcon = 0;\r
-            updateConnStatus();\r
+            mServerStatusText = 0;\r
+            mServerStatusIcon = 0;\r
+            showServerStatus();\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -489,9 +488,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     public void onOkClick(View view) {\r
         // this check should be unnecessary\r
         if (mDiscoveredVersion == null || !mDiscoveredVersion.isVersionValid()  || mHostBaseUrl == null || mHostBaseUrl.length() == 0) {\r
     public void onOkClick(View view) {\r
         // this check should be unnecessary\r
         if (mDiscoveredVersion == null || !mDiscoveredVersion.isVersionValid()  || mHostBaseUrl == null || mHostBaseUrl.length() == 0) {\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_wtf_reenter_URL;\r
-            updateConnStatus();\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_wtf_reenter_URL;\r
+            showServerStatus();\r
             mOkButton.setEnabled(false);\r
             Log_OC.wtf(TAG,  "The user was allowed to click 'connect' to an unchecked server!!");\r
             return;\r
             mOkButton.setEnabled(false);\r
             Log_OC.wtf(TAG,  "The user was allowed to click 'connect' to an unchecked server!!");\r
             return;\r
@@ -535,9 +534,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      */\r
     private void startOauthorization() {\r
         // be gentle with the user\r
      */\r
     private void startOauthorization() {\r
         // be gentle with the user\r
-        mStatusIcon = R.drawable.progress_small;\r
-        mStatusText = R.string.oauth_login_connection;\r
-        updateAuthStatus();\r
+        mServerStatusIcon = R.drawable.progress_small;\r
+        mServerStatusText = R.string.oauth_login_connection;\r
+        showAuthStatus();\r
         \r
         // GET AUTHORIZATION request\r
         //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
         \r
         // GET AUTHORIZATION request\r
         //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
@@ -584,132 +583,144 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * @param result        Result of the check.\r
      */\r
     private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) {\r
      * @param result        Result of the check.\r
      */\r
     private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) {\r
-        /// update status icon and text\r
-        updateStatusIconAndText(result);\r
-        updateConnStatus();\r
-\r
-        /// save result state\r
-        mStatusCorrect = result.isSuccess();\r
-        mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
-        \r
-        /// very special case (TODO: move to a common place for all the remote operations)\r
-        if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
-            mLastSslUntrustedServerResult = result;\r
-            showDialog(DIALOG_SSL_VALIDATOR); \r
-        }\r
-        \r
-        /// update the visibility of the 'retry connection' button\r
-        if (!mStatusCorrect) {\r
-            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
-        } else {\r
-            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
-        }\r
-        \r
-        /// retrieve discovered version and normalize server URL\r
-        mDiscoveredVersion = operation.getDiscoveredVersion();\r
-        mHostBaseUrl = mHostUrlInput.getText().toString().trim();\r
-        if (!mHostBaseUrl.toLowerCase().startsWith("http://") &&\r
-            !mHostBaseUrl.toLowerCase().startsWith("https://")) {\r
+        if (operation.equals(mOcServerChkOperation)) {\r
+            /// save result state\r
+            mServerCheckedAndValid = result.isSuccess();\r
+            mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
+            mOcServerChkOperation = null;\r
             \r
             \r
-            if (mIsSslConn) {\r
-                mHostBaseUrl = "https://" + mHostBaseUrl;\r
+            /// update status icon and text\r
+            updateStatusIconAndText(result);\r
+            showServerStatus();\r
+    \r
+            /// very special case (TODO: move to a common place for all the remote operations)\r
+            if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
+                mLastSslUntrustedServerResult = result;\r
+                showDialog(DIALOG_SSL_VALIDATOR); \r
+            }\r
+            \r
+            /// update the visibility of the 'retry connection' button\r
+            if (!mServerCheckedAndValid) {\r
+                mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
             } else {\r
             } else {\r
-                mHostBaseUrl = "http://" + mHostBaseUrl;\r
+                mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
             }\r
             \r
             }\r
             \r
-        }\r
-        if (mHostBaseUrl.endsWith("/"))\r
-            mHostBaseUrl = mHostBaseUrl.substring(0, mHostBaseUrl.length() - 1);\r
-        \r
-        /// allow or not the user try to access the server\r
-        mOkButton.setEnabled(mStatusCorrect);\r
+            /// retrieve discovered version and normalize server URL\r
+            mDiscoveredVersion = operation.getDiscoveredVersion();\r
+            mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
+            \r
+            /// allow or not the user try to access the server\r
+            mOkButton.setEnabled(mServerCheckedAndValid);\r
+            \r
+        }   // else nothing ; only the last check operation is considered; \r
+            // multiple can be triggered if the user amends a URL before a previous check can be triggered\r
     }\r
 \r
 \r
     }\r
 \r
 \r
+    private String normalizeUrl(String url) {\r
+        if (url != null && url.length() > 0) {\r
+            url = url.trim();\r
+            if (!url.toLowerCase().startsWith("http://") &&\r
+                    !url.toLowerCase().startsWith("https://")) {\r
+                if (mIsSslConn) {\r
+                    url = "https://" + url;\r
+                } else {\r
+                    url = "http://" + url;\r
+                }\r
+                \r
+            }\r
+            if (url.endsWith("/")) {\r
+                url = url.substring(0, url.length() - 1);\r
+            }\r
+        }\r
+        return url;\r
+    }\r
+\r
     /**\r
      * Chooses the right icon and text to show to the user for the received operation result.\r
      * \r
      * @param result    Result of a remote operation performed in this activity\r
      */\r
     private void updateStatusIconAndText(RemoteOperationResult result) {\r
     /**\r
      * Chooses the right icon and text to show to the user for the received operation result.\r
      * \r
      * @param result    Result of a remote operation performed in this activity\r
      */\r
     private void updateStatusIconAndText(RemoteOperationResult result) {\r
-        mStatusText = mStatusIcon = 0;\r
+        mServerStatusText = mServerStatusIcon = 0;\r
 \r
         switch (result.getCode()) {\r
         case OK_SSL:\r
 \r
         switch (result.getCode()) {\r
         case OK_SSL:\r
-            mStatusIcon = android.R.drawable.ic_secure;\r
-            mStatusText = R.string.auth_secure_connection;\r
+            mServerStatusIcon = android.R.drawable.ic_secure;\r
+            mServerStatusText = R.string.auth_secure_connection;\r
             break;\r
             \r
         case OK_NO_SSL:\r
         case OK:\r
             if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://") ) {\r
             break;\r
             \r
         case OK_NO_SSL:\r
         case OK:\r
             if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://") ) {\r
-                mStatusText = R.string.auth_connection_established;\r
-                mStatusIcon = R.drawable.ic_ok;\r
+                mServerStatusText = R.string.auth_connection_established;\r
+                mServerStatusIcon = R.drawable.ic_ok;\r
             } else {\r
             } else {\r
-                mStatusText = R.string.auth_nossl_plain_ok_title;\r
-                mStatusIcon = android.R.drawable.ic_partial_secure;\r
+                mServerStatusText = R.string.auth_nossl_plain_ok_title;\r
+                mServerStatusIcon = android.R.drawable.ic_partial_secure;\r
             }\r
             break;\r
             \r
         case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
             }\r
             break;\r
             \r
         case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_ssl_unverified_server_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_ssl_unverified_server_title;\r
             break;\r
                 \r
         case BAD_OC_VERSION:\r
             break;\r
                 \r
         case BAD_OC_VERSION:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_bad_oc_version_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_bad_oc_version_title;\r
             break;\r
         case WRONG_CONNECTION:\r
             break;\r
         case WRONG_CONNECTION:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_wrong_connection_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_wrong_connection_title;\r
             break;\r
         case TIMEOUT:\r
             break;\r
         case TIMEOUT:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_timeout_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_timeout_title;\r
             break;\r
         case INCORRECT_ADDRESS:\r
             break;\r
         case INCORRECT_ADDRESS:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_incorrect_address_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_incorrect_address_title;\r
             break;\r
             \r
         case SSL_ERROR:\r
             break;\r
             \r
         case SSL_ERROR:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_ssl_general_error_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_ssl_general_error_title;\r
             break;\r
             \r
         case UNAUTHORIZED:\r
             break;\r
             \r
         case UNAUTHORIZED:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_unauthorized;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_unauthorized;\r
             break;\r
         case HOST_NOT_AVAILABLE:\r
             break;\r
         case HOST_NOT_AVAILABLE:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_unknown_host_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_unknown_host_title;\r
             break;\r
         case NO_NETWORK_CONNECTION:\r
             break;\r
         case NO_NETWORK_CONNECTION:\r
-            mStatusIcon = R.drawable.no_network;\r
-            mStatusText = R.string.auth_no_net_conn_title;\r
+            mServerStatusIcon = R.drawable.no_network;\r
+            mServerStatusText = R.string.auth_no_net_conn_title;\r
             break;\r
         case INSTANCE_NOT_CONFIGURED:\r
             break;\r
         case INSTANCE_NOT_CONFIGURED:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_not_configured_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_not_configured_title;\r
             break;\r
         case FILE_NOT_FOUND:\r
             break;\r
         case FILE_NOT_FOUND:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_incorrect_path_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_incorrect_path_title;\r
             break;\r
         case OAUTH2_ERROR:\r
             break;\r
         case OAUTH2_ERROR:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_oauth_error;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_oauth_error;\r
             break;\r
         case OAUTH2_ERROR_ACCESS_DENIED:\r
             break;\r
         case OAUTH2_ERROR_ACCESS_DENIED:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_oauth_error_access_denied;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_oauth_error_access_denied;\r
             break;\r
         case UNHANDLED_HTTP_CODE:\r
         case UNKNOWN_ERROR:\r
             break;\r
         case UNHANDLED_HTTP_CODE:\r
         case UNKNOWN_ERROR:\r
-            mStatusIcon = R.drawable.common_error;\r
-            mStatusText = R.string.auth_unknown_error_title;\r
+            mServerStatusIcon = R.drawable.common_error;\r
+            mServerStatusText = R.string.auth_unknown_error_title;\r
             break;\r
             \r
         default:\r
             break;\r
             \r
         default:\r
@@ -747,7 +758,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             \r
         } else {\r
             updateStatusIconAndText(result);\r
             \r
         } else {\r
             updateStatusIconAndText(result);\r
-            updateAuthStatus();\r
+            showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
     }\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
     }\r
@@ -782,7 +793,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             \r
         } else {\r
             updateStatusIconAndText(result);\r
             \r
         } else {\r
             updateStatusIconAndText(result);\r
-            updateAuthStatus();\r
+            showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
     }\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
     }\r
@@ -981,14 +992,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * Updates the content and visibility state of the icon and text associated\r
      * to the last check on the ownCloud server.\r
      */\r
      * Updates the content and visibility state of the icon and text associated\r
      * to the last check on the ownCloud server.\r
      */\r
-    private void updateConnStatus() {\r
+    private void showServerStatus() {\r
         TextView tv = (TextView) findViewById(R.id.server_status_text);\r
 \r
         TextView tv = (TextView) findViewById(R.id.server_status_text);\r
 \r
-        if (mStatusIcon == 0 && mStatusText == 0) {\r
+        if (mServerStatusIcon == 0 && mServerStatusText == 0) {\r
             tv.setVisibility(View.INVISIBLE);\r
         } else {\r
             tv.setVisibility(View.INVISIBLE);\r
         } else {\r
-            tv.setText(mStatusText);\r
-            tv.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0);\r
+            tv.setText(mServerStatusText);\r
+            tv.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);\r
             tv.setVisibility(View.VISIBLE);\r
         }\r
     }\r
             tv.setVisibility(View.VISIBLE);\r
         }\r
     }\r
@@ -998,12 +1009,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * Updates the content and visibility state of the icon and text associated\r
      * to the interactions with the OAuth authorization server.\r
      */\r
      * Updates the content and visibility state of the icon and text associated\r
      * to the interactions with the OAuth authorization server.\r
      */\r
-    private void updateAuthStatus() {\r
-        if (mStatusIcon == 0 && mStatusText == 0) {\r
+    private void showAuthStatus() {\r
+        if (mServerStatusIcon == 0 && mServerStatusText == 0) {\r
             mAuthStatusLayout.setVisibility(View.INVISIBLE);\r
         } else {\r
             mAuthStatusLayout.setVisibility(View.INVISIBLE);\r
         } else {\r
-            mAuthStatusLayout.setText(mStatusText);\r
-            mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0);\r
+            mAuthStatusLayout.setText(mServerStatusText);\r
+            mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);\r
             mAuthStatusLayout.setVisibility(View.VISIBLE);\r
         }\r
     }     \r
             mAuthStatusLayout.setVisibility(View.VISIBLE);\r
         }\r
     }     \r
@@ -1149,4 +1160,24 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         public abstract boolean onDrawableTouch(final MotionEvent event);\r
     }\r
     \r
         public abstract boolean onDrawableTouch(final MotionEvent event);\r
     }\r
     \r
+    \r
+    private class HostUrlWatcher implements TextWatcher {\r
+\r
+        @Override\r
+        public void afterTextChanged(Editable s) {\r
+        }\r
+\r
+        @Override\r
+        public void beforeTextChanged(CharSequence s, int start, int count, int after) {\r
+        }\r
+\r
+        @Override\r
+        public void onTextChanged(CharSequence s, int start, int before, int count) {\r
+            if (mServerCheckedAndValid) {\r
+                mServerCheckedAndValid = false;\r
+                mOkButton.setEnabled(false);    // avoids that the 'connect' button can be clicked if the test was previously passed\r
+            }\r
+        }\r
+        \r
+    }\r
 }\r
 }\r