Merge branch 'develop' into login_view_layout_improvements
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 120fbde..375ef3b 100644 (file)
@@ -89,7 +89,8 @@ 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_SERVER_CHECKED_AND_VALID = "SERVER_CHECKED_AND_VALID";\r
+    private static final String KEY_SERVER_VALID = "SERVER_VALID";\r
+    private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED";\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_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
@@ -114,7 +115,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private OwnCloudVersion mDiscoveredVersion;\r
     \r
     private int mServerStatusText, mServerStatusIcon;\r
     private OwnCloudVersion mDiscoveredVersion;\r
     \r
     private int mServerStatusText, mServerStatusIcon;\r
-    private boolean mServerCheckedAndValid, mIsSslConn;\r
+    private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
     private int mAuthStatusText, mAuthStatusIcon;    \r
     \r
     private final Handler mHandler = new Handler();\r
     private int mAuthStatusText, mAuthStatusIcon;    \r
     \r
     private final Handler mHandler = new Handler();\r
@@ -142,8 +143,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     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
      * {@inheritDoc}\r
     \r
     /**\r
      * {@inheritDoc}\r
@@ -183,7 +182,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         if (savedInstanceState == null) {\r
             /// connection state and info\r
             mServerStatusText = mServerStatusIcon = 0;\r
         if (savedInstanceState == null) {\r
             /// connection state and info\r
             mServerStatusText = mServerStatusIcon = 0;\r
-            mServerCheckedAndValid = false;\r
+            mServerIsValid = false;\r
+            mServerIsChecked = false;\r
             mIsSslConn = false;\r
             mAuthStatusText = mAuthStatusIcon = 0;\r
             \r
             mIsSslConn = false;\r
             mAuthStatusText = mAuthStatusIcon = 0;\r
             \r
@@ -209,7 +209,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
         } else {\r
             /// connection state and info\r
 \r
         } else {\r
             /// connection state and info\r
-            mServerCheckedAndValid = savedInstanceState.getBoolean(KEY_SERVER_CHECKED_AND_VALID);\r
+            mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID);\r
+            mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED);\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
             mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
             mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);\r
             mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN);\r
@@ -235,6 +236,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         \r
         showServerStatus();\r
         showAuthStatus();\r
         \r
         showServerStatus();\r
         showAuthStatus();\r
+        if (mServerIsChecked && !mServerIsValid) showRefreshButton();\r
+        mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\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
@@ -245,7 +248,7 @@ 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
-            if (!mServerCheckedAndValid && mOcServerChkOperation == null) {\r
+            if (!mServerIsValid && mOcServerChkOperation == null) {\r
                 checkOcServer(); \r
             }\r
         }\r
                 checkOcServer(); \r
             }\r
         }\r
@@ -262,25 +265,27 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 return true;\r
             }\r
         });\r
                 return true;\r
             }\r
         });\r
+        mHostUrlInput.addTextChangedListener(new TextWatcher() {\r
+\r
+            @Override\r
+            public void afterTextChanged(Editable s) {\r
+                if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) {\r
+                    mOkButton.setEnabled(false);\r
+                }\r
+            }\r
+\r
+            @Override\r
+            public void beforeTextChanged(CharSequence s, int start, int count, int after) {}\r
+\r
+            @Override\r
+            public void onTextChanged(CharSequence s, int start, int before, int count) {}\r
+            \r
+        });\r
         mPasswordInput.setOnFocusChangeListener(this);\r
         mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
         mPasswordInput.setOnEditorActionListener(this);\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
-    @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
      * \r
@@ -296,8 +301,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         /// connection state and info\r
         outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
         outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon);\r
         /// connection state and info\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_SERVER_VALID, mServerIsValid);\r
+        outState.putBoolean(KEY_SERVER_CHECKED, mServerIsChecked);\r
+        outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerIsValid && mOcServerChkOperation != null));\r
         outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn);\r
         outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon);\r
         outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
         outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn);\r
         outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon);\r
         outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
@@ -408,24 +414,27 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private void onUrlInputFocusLost(TextView hostInput) {\r
         if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) {\r
             checkOcServer();\r
     private void onUrlInputFocusLost(TextView hostInput) {\r
         if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) {\r
             checkOcServer();\r
+        } else {\r
+            mOkButton.setEnabled(mServerIsValid);\r
         }\r
     }\r
 \r
 \r
     private void checkOcServer() {\r
         String uri = mHostUrlInput.getText().toString().trim();\r
         }\r
     }\r
 \r
 \r
     private void checkOcServer() {\r
         String uri = mHostUrlInput.getText().toString().trim();\r
+        mServerIsValid = false;\r
+        mServerIsChecked = false;\r
+        mOkButton.setEnabled(false);\r
+        mDiscoveredVersion = null;\r
+        hideRefreshButton();\r
         if (uri.length() != 0) {\r
         if (uri.length() != 0) {\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
             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
-            mDiscoveredVersion = null;\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
-            mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
             mServerStatusText = 0;\r
             mServerStatusIcon = 0;\r
             showServerStatus();\r
             mServerStatusText = 0;\r
             mServerStatusIcon = 0;\r
             showServerStatus();\r
@@ -534,8 +543,8 @@ 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
-        mServerStatusIcon = R.drawable.progress_small;\r
-        mServerStatusText = R.string.oauth_login_connection;\r
+        mAuthStatusIcon = R.drawable.progress_small;\r
+        mAuthStatusText = R.string.oauth_login_connection;\r
         showAuthStatus();\r
         \r
         // GET AUTHORIZATION request\r
         showAuthStatus();\r
         \r
         // GET AUTHORIZATION request\r
@@ -585,12 +594,18 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) {\r
         if (operation.equals(mOcServerChkOperation)) {\r
             /// save result state\r
     private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) {\r
         if (operation.equals(mOcServerChkOperation)) {\r
             /// save result state\r
-            mServerCheckedAndValid = result.isSuccess();\r
+            mServerIsChecked = true;\r
+            mServerIsValid = result.isSuccess();\r
             mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
             mOcServerChkOperation = null;\r
             \r
             /// update status icon and text\r
             mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
             mOcServerChkOperation = null;\r
             \r
             /// update status icon and text\r
-            updateStatusIconAndText(result);\r
+            if (mServerIsValid) {\r
+                hideRefreshButton();\r
+            } else {\r
+                showRefreshButton();\r
+            }\r
+            updateServerStatusIconAndText(result);\r
             showServerStatus();\r
     \r
             /// very special case (TODO: move to a common place for all the remote operations)\r
             showServerStatus();\r
     \r
             /// very special case (TODO: move to a common place for all the remote operations)\r
@@ -599,19 +614,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 showDialog(DIALOG_SSL_VALIDATOR); \r
             }\r
             \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
-                mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
-            }\r
-            \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
             /// 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
+            mOkButton.setEnabled(mServerIsValid);\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
         }   // 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
@@ -634,7 +642,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 url = url.substring(0, url.length() - 1);\r
             }\r
         }\r
                 url = url.substring(0, url.length() - 1);\r
             }\r
         }\r
-        return url;\r
+        return (url != null ? url : "");\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
@@ -642,8 +650,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * \r
      * @param result    Result of a remote operation performed in this activity\r
      */\r
      * \r
      * @param result    Result of a remote operation performed in this activity\r
      */\r
-    private void updateStatusIconAndText(RemoteOperationResult result) {\r
-        mServerStatusText = mServerStatusIcon = 0;\r
+    private void updateServerStatusIconAndText(RemoteOperationResult result) {\r
+        mServerStatusIcon = R.drawable.common_error;    // the most common case in the switch below\r
 \r
         switch (result.getCode()) {\r
         case OK_SSL:\r
 \r
         switch (result.getCode()) {\r
         case OK_SSL:\r
@@ -662,69 +670,131 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             }\r
             break;\r
             \r
             }\r
             break;\r
             \r
+        case NO_NETWORK_CONNECTION:\r
+            mServerStatusIcon = R.drawable.no_network;\r
+            mServerStatusText = R.string.auth_no_net_conn_title;\r
+            break;\r
+            \r
         case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
         case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_ssl_unverified_server_title;\r
             break;\r
             mServerStatusText = R.string.auth_ssl_unverified_server_title;\r
             break;\r
-                \r
         case BAD_OC_VERSION:\r
         case BAD_OC_VERSION:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_bad_oc_version_title;\r
             break;\r
         case WRONG_CONNECTION:\r
             mServerStatusText = R.string.auth_bad_oc_version_title;\r
             break;\r
         case WRONG_CONNECTION:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_wrong_connection_title;\r
             break;\r
         case TIMEOUT:\r
             mServerStatusText = R.string.auth_wrong_connection_title;\r
             break;\r
         case TIMEOUT:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_timeout_title;\r
             break;\r
         case INCORRECT_ADDRESS:\r
             mServerStatusText = R.string.auth_timeout_title;\r
             break;\r
         case INCORRECT_ADDRESS:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_incorrect_address_title;\r
             break;\r
             mServerStatusText = R.string.auth_incorrect_address_title;\r
             break;\r
-            \r
         case SSL_ERROR:\r
         case SSL_ERROR:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_ssl_general_error_title;\r
             break;\r
             mServerStatusText = R.string.auth_ssl_general_error_title;\r
             break;\r
-            \r
         case UNAUTHORIZED:\r
         case UNAUTHORIZED:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_unauthorized;\r
             break;\r
         case HOST_NOT_AVAILABLE:\r
             mServerStatusText = R.string.auth_unauthorized;\r
             break;\r
         case HOST_NOT_AVAILABLE:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_unknown_host_title;\r
             break;\r
             mServerStatusText = R.string.auth_unknown_host_title;\r
             break;\r
-        case NO_NETWORK_CONNECTION:\r
-            mServerStatusIcon = R.drawable.no_network;\r
-            mServerStatusText = R.string.auth_no_net_conn_title;\r
-            break;\r
         case INSTANCE_NOT_CONFIGURED:\r
         case INSTANCE_NOT_CONFIGURED:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_not_configured_title;\r
             break;\r
         case FILE_NOT_FOUND:\r
             mServerStatusText = R.string.auth_not_configured_title;\r
             break;\r
         case FILE_NOT_FOUND:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_incorrect_path_title;\r
             break;\r
         case OAUTH2_ERROR:\r
             mServerStatusText = R.string.auth_incorrect_path_title;\r
             break;\r
         case OAUTH2_ERROR:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_oauth_error;\r
             break;\r
         case OAUTH2_ERROR_ACCESS_DENIED:\r
             mServerStatusText = R.string.auth_oauth_error;\r
             break;\r
         case OAUTH2_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
             mServerStatusText = R.string.auth_oauth_error_access_denied;\r
             break;\r
         case UNHANDLED_HTTP_CODE:\r
         case UNKNOWN_ERROR:\r
-            mServerStatusIcon = R.drawable.common_error;\r
             mServerStatusText = R.string.auth_unknown_error_title;\r
             break;\r
             mServerStatusText = R.string.auth_unknown_error_title;\r
             break;\r
-            \r
         default:\r
         default:\r
+            mServerStatusText = 0;\r
+            mServerStatusIcon = 0;\r
+        }\r
+    }\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 updateAuthStatusIconAndText(RemoteOperationResult result) {\r
+        mAuthStatusIcon = R.drawable.common_error;    // the most common case in the switch below\r
+\r
+        switch (result.getCode()) {\r
+        case OK_SSL:\r
+            mAuthStatusIcon = android.R.drawable.ic_secure;\r
+            mAuthStatusText = 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
+                mAuthStatusText = R.string.auth_connection_established;\r
+                mAuthStatusIcon = R.drawable.ic_ok;\r
+            } else {\r
+                mAuthStatusText = R.string.auth_nossl_plain_ok_title;\r
+                mAuthStatusIcon = android.R.drawable.ic_partial_secure;\r
+            }\r
+            break;\r
+            \r
+        case NO_NETWORK_CONNECTION:\r
+            mAuthStatusIcon = R.drawable.no_network;\r
+            mAuthStatusText = R.string.auth_no_net_conn_title;\r
+            break;\r
+            \r
+        case SSL_RECOVERABLE_PEER_UNVERIFIED:\r
+            mAuthStatusText = R.string.auth_ssl_unverified_server_title;\r
+            break;\r
+        case BAD_OC_VERSION:\r
+            mAuthStatusText = R.string.auth_bad_oc_version_title;\r
+            break;\r
+        case WRONG_CONNECTION:\r
+            mAuthStatusText = R.string.auth_wrong_connection_title;\r
+            break;\r
+        case TIMEOUT:\r
+            mAuthStatusText = R.string.auth_timeout_title;\r
+            break;\r
+        case INCORRECT_ADDRESS:\r
+            mAuthStatusText = R.string.auth_incorrect_address_title;\r
+            break;\r
+        case SSL_ERROR:\r
+            mAuthStatusText = R.string.auth_ssl_general_error_title;\r
+            break;\r
+        case UNAUTHORIZED:\r
+            mAuthStatusText = R.string.auth_unauthorized;\r
+            break;\r
+        case HOST_NOT_AVAILABLE:\r
+            mAuthStatusText = R.string.auth_unknown_host_title;\r
+            break;\r
+        case INSTANCE_NOT_CONFIGURED:\r
+            mAuthStatusText = R.string.auth_not_configured_title;\r
             break;\r
             break;\r
+        case FILE_NOT_FOUND:\r
+            mAuthStatusText = R.string.auth_incorrect_path_title;\r
+            break;\r
+        case OAUTH2_ERROR:\r
+            mAuthStatusText = R.string.auth_oauth_error;\r
+            break;\r
+        case OAUTH2_ERROR_ACCESS_DENIED:\r
+            mAuthStatusText = R.string.auth_oauth_error_access_denied;\r
+            break;\r
+        case UNHANDLED_HTTP_CODE:\r
+        case UNKNOWN_ERROR:\r
+            mAuthStatusText = R.string.auth_unknown_error_title;\r
+            break;\r
+        default:\r
+            mAuthStatusText = 0;\r
+            mAuthStatusIcon = 0;\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r
@@ -757,7 +827,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mAuthCheckOperation.execute(client, this, mHandler);\r
             \r
         } else {\r
             mAuthCheckOperation.execute(client, this, mHandler);\r
             \r
         } else {\r
-            updateStatusIconAndText(result);\r
+            updateAuthStatusIconAndText(result);\r
             showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
             showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
@@ -792,7 +862,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             finish();\r
             \r
         } else {\r
             finish();\r
             \r
         } else {\r
-            updateStatusIconAndText(result);\r
+            updateAuthStatusIconAndText(result);\r
             showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
             showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
         }\r
@@ -997,11 +1067,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
         if (mServerStatusIcon == 0 && mServerStatusText == 0) {\r
             tv.setVisibility(View.INVISIBLE);\r
 \r
         if (mServerStatusIcon == 0 && mServerStatusText == 0) {\r
             tv.setVisibility(View.INVISIBLE);\r
+            \r
         } else {\r
             tv.setText(mServerStatusText);\r
             tv.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);\r
             tv.setVisibility(View.VISIBLE);\r
         }\r
         } else {\r
             tv.setText(mServerStatusText);\r
             tv.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);\r
             tv.setVisibility(View.VISIBLE);\r
         }\r
+        \r
     }\r
     \r
     \r
     }\r
     \r
     \r
@@ -1010,16 +1082,25 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * to the interactions with the OAuth authorization server.\r
      */\r
     private void showAuthStatus() {\r
      * to the interactions with the OAuth authorization server.\r
      */\r
     private void showAuthStatus() {\r
-        if (mServerStatusIcon == 0 && mServerStatusText == 0) {\r
+        if (mAuthStatusIcon == 0 && mAuthStatusText == 0) {\r
             mAuthStatusLayout.setVisibility(View.INVISIBLE);\r
             mAuthStatusLayout.setVisibility(View.INVISIBLE);\r
+            \r
         } else {\r
         } else {\r
-            mAuthStatusLayout.setText(mServerStatusText);\r
-            mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0);\r
+            mAuthStatusLayout.setText(mAuthStatusText);\r
+            mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon, 0, 0, 0);\r
             mAuthStatusLayout.setVisibility(View.VISIBLE);\r
         }\r
     }     \r
 \r
     \r
             mAuthStatusLayout.setVisibility(View.VISIBLE);\r
         }\r
     }     \r
 \r
     \r
+    private void showRefreshButton() {\r
+        mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
+    }\r
+    \r
+    private void hideRefreshButton() {\r
+        mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+    }\r
+    \r
     /**\r
      * Called when the refresh button in the input field for ownCloud host is clicked.\r
      * \r
     /**\r
      * Called when the refresh button in the input field for ownCloud host is clicked.\r
      * \r
@@ -1028,7 +1109,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * @param view      Refresh 'button'\r
      */\r
     public void onRefreshClick(View view) {\r
      * @param view      Refresh 'button'\r
      */\r
     public void onRefreshClick(View view) {\r
-        onFocusChange(mHostUrlInput, false);\r
+        checkOcServer();\r
     }\r
     \r
     \r
     }\r
     \r
     \r
@@ -1160,24 +1241,4 @@ 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