X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/fe1b334ce6b23d495f10ba0240ab3892793fa0bc..14a60a13e7a23e64098aecbc7fbc927706faf336:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index 07c9d537..375ef3b1 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -89,7 +89,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT"; private static final String KEY_OC_VERSION = "OC_VERSION"; private static final String KEY_ACCOUNT = "ACCOUNT"; - private static final String KEY_SERVER_CHECKED_AND_VALID = "SERVER_CHECKED_AND_VALID"; + private static final String KEY_SERVER_VALID = "SERVER_VALID"; + private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED"; private static final String KEY_SERVER_CHECK_IN_PROGRESS = "SERVER_CHECK_IN_PROGRESS"; private static final String KEY_SERVER_STATUS_TEXT = "SERVER_STATUS_TEXT"; private static final String KEY_SERVER_STATUS_ICON = "SERVER_STATUS_ICON"; @@ -114,7 +115,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private OwnCloudVersion mDiscoveredVersion; private int mServerStatusText, mServerStatusIcon; - private boolean mServerCheckedAndValid, mIsSslConn; + private boolean mServerIsChecked, mServerIsValid, mIsSslConn; private int mAuthStatusText, mAuthStatusIcon; private final Handler mHandler = new Handler(); @@ -142,8 +143,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private TextView mOAuthAuthEndpointText; private TextView mOAuthTokenEndpointText; - private HostUrlWatcher mHostUrlChangedListener; - /** * {@inheritDoc} @@ -183,7 +182,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (savedInstanceState == null) { /// connection state and info mServerStatusText = mServerStatusIcon = 0; - mServerCheckedAndValid = false; + mServerIsValid = false; + mServerIsChecked = false; mIsSslConn = false; mAuthStatusText = mAuthStatusIcon = 0; @@ -209,7 +209,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } else { /// connection state and info - mServerCheckedAndValid = savedInstanceState.getBoolean(KEY_SERVER_CHECKED_AND_VALID); + mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID); + mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED); mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT); mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON); mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN); @@ -235,6 +236,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity showServerStatus(); showAuthStatus(); + if (mServerIsChecked && !mServerIsValid) showRefreshButton(); + mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) { mOAuth2Check.setVisibility(View.GONE); @@ -245,7 +248,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mHostUrlInput.setEnabled(false); mUsernameInput.setEnabled(false); mOAuth2Check.setVisibility(View.GONE); - if (!mServerCheckedAndValid && mOcServerChkOperation == null) { + if (!mServerIsValid && mOcServerChkOperation == null) { checkOcServer(); } } @@ -262,25 +265,27 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity return true; } }); + mHostUrlInput.addTextChangedListener(new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) { + mOkButton.setEnabled(false); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + }); mPasswordInput.setOnFocusChangeListener(this); mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE); mPasswordInput.setOnEditorActionListener(this); } - @Override - protected void onStart() { - super.onStart(); - //mHostUrlChangedListener = new HostUrlWatcher(); - //mHostUrlInput.addTextChangedListener(mHostUrlChangedListener); - } - - @Override - protected void onStop() { - super.onStop(); - mHostUrlInput.removeTextChangedListener(mHostUrlChangedListener); - } - - /** * Saves relevant state before {@link #onPause()} * @@ -296,8 +301,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// connection state and info outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText); outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon); - outState.putBoolean(KEY_SERVER_CHECKED_AND_VALID, mServerCheckedAndValid); - outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerCheckedAndValid && mOcServerChkOperation != null)); + outState.putBoolean(KEY_SERVER_VALID, mServerIsValid); + outState.putBoolean(KEY_SERVER_CHECKED, mServerIsChecked); + outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerIsValid && mOcServerChkOperation != null)); outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn); outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon); outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText); @@ -408,15 +414,19 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void onUrlInputFocusLost(TextView hostInput) { if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) { checkOcServer(); + } else { + mOkButton.setEnabled(mServerIsValid); } } private void checkOcServer() { String uri = mHostUrlInput.getText().toString().trim(); - mServerCheckedAndValid = false; + mServerIsValid = false; + mServerIsChecked = false; mOkButton.setEnabled(false); mDiscoveredVersion = null; + hideRefreshButton(); if (uri.length() != 0) { mServerStatusText = R.string.auth_testing_connection; mServerStatusIcon = R.drawable.progress_small; @@ -425,7 +435,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(uri), this); mOperationThread = mOcServerChkOperation.execute(client, this, mHandler); } else { - mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); mServerStatusText = 0; mServerStatusIcon = 0; showServerStatus(); @@ -534,8 +543,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity */ private void startOauthorization() { // be gentle with the user - mServerStatusIcon = R.drawable.progress_small; - mServerStatusText = R.string.oauth_login_connection; + mAuthStatusIcon = R.drawable.progress_small; + mAuthStatusText = R.string.oauth_login_connection; showAuthStatus(); // GET AUTHORIZATION request @@ -585,12 +594,18 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) { if (operation.equals(mOcServerChkOperation)) { /// save result state - mServerCheckedAndValid = result.isSuccess(); + mServerIsChecked = true; + mServerIsValid = result.isSuccess(); mIsSslConn = (result.getCode() == ResultCode.OK_SSL); mOcServerChkOperation = null; /// update status icon and text - updateStatusIconAndText(result); + if (mServerIsValid) { + hideRefreshButton(); + } else { + showRefreshButton(); + } + updateServerStatusIconAndText(result); showServerStatus(); /// very special case (TODO: move to a common place for all the remote operations) @@ -599,19 +614,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity showDialog(DIALOG_SSL_VALIDATOR); } - /// update the visibility of the 'retry connection' button - if (!mServerCheckedAndValid) { - mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0); - } else { - mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); - } - /// retrieve discovered version and normalize server URL mDiscoveredVersion = operation.getDiscoveredVersion(); mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); /// allow or not the user try to access the server - mOkButton.setEnabled(mServerCheckedAndValid); + mOkButton.setEnabled(mServerIsValid); } // else nothing ; only the last check operation is considered; // multiple can be triggered if the user amends a URL before a previous check can be triggered @@ -634,7 +642,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity url = url.substring(0, url.length() - 1); } } - return url; + return (url != null ? url : ""); } /** @@ -642,8 +650,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * * @param result Result of a remote operation performed in this activity */ - private void updateStatusIconAndText(RemoteOperationResult result) { - mServerStatusText = mServerStatusIcon = 0; + private void updateServerStatusIconAndText(RemoteOperationResult result) { + mServerStatusIcon = R.drawable.common_error; // the most common case in the switch below switch (result.getCode()) { case OK_SSL: @@ -662,69 +670,131 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } break; + case NO_NETWORK_CONNECTION: + mServerStatusIcon = R.drawable.no_network; + mServerStatusText = R.string.auth_no_net_conn_title; + break; + case SSL_RECOVERABLE_PEER_UNVERIFIED: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_ssl_unverified_server_title; break; - case BAD_OC_VERSION: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_bad_oc_version_title; break; case WRONG_CONNECTION: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_wrong_connection_title; break; case TIMEOUT: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_timeout_title; break; case INCORRECT_ADDRESS: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_incorrect_address_title; break; - case SSL_ERROR: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_ssl_general_error_title; break; - case UNAUTHORIZED: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_unauthorized; break; case HOST_NOT_AVAILABLE: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_unknown_host_title; break; - case NO_NETWORK_CONNECTION: - mServerStatusIcon = R.drawable.no_network; - mServerStatusText = R.string.auth_no_net_conn_title; - break; case INSTANCE_NOT_CONFIGURED: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_not_configured_title; break; case FILE_NOT_FOUND: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_incorrect_path_title; break; case OAUTH2_ERROR: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_oauth_error; break; case OAUTH2_ERROR_ACCESS_DENIED: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_oauth_error_access_denied; break; case UNHANDLED_HTTP_CODE: case UNKNOWN_ERROR: - mServerStatusIcon = R.drawable.common_error; mServerStatusText = R.string.auth_unknown_error_title; break; - default: + mServerStatusText = 0; + mServerStatusIcon = 0; + } + } + + + /** + * Chooses the right icon and text to show to the user for the received operation result. + * + * @param result Result of a remote operation performed in this activity + */ + private void updateAuthStatusIconAndText(RemoteOperationResult result) { + mAuthStatusIcon = R.drawable.common_error; // the most common case in the switch below + + switch (result.getCode()) { + case OK_SSL: + mAuthStatusIcon = android.R.drawable.ic_secure; + mAuthStatusText = R.string.auth_secure_connection; + break; + + case OK_NO_SSL: + case OK: + if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://") ) { + mAuthStatusText = R.string.auth_connection_established; + mAuthStatusIcon = R.drawable.ic_ok; + } else { + mAuthStatusText = R.string.auth_nossl_plain_ok_title; + mAuthStatusIcon = android.R.drawable.ic_partial_secure; + } + break; + + case NO_NETWORK_CONNECTION: + mAuthStatusIcon = R.drawable.no_network; + mAuthStatusText = R.string.auth_no_net_conn_title; + break; + + case SSL_RECOVERABLE_PEER_UNVERIFIED: + mAuthStatusText = R.string.auth_ssl_unverified_server_title; + break; + case BAD_OC_VERSION: + mAuthStatusText = R.string.auth_bad_oc_version_title; + break; + case WRONG_CONNECTION: + mAuthStatusText = R.string.auth_wrong_connection_title; + break; + case TIMEOUT: + mAuthStatusText = R.string.auth_timeout_title; + break; + case INCORRECT_ADDRESS: + mAuthStatusText = R.string.auth_incorrect_address_title; + break; + case SSL_ERROR: + mAuthStatusText = R.string.auth_ssl_general_error_title; + break; + case UNAUTHORIZED: + mAuthStatusText = R.string.auth_unauthorized; + break; + case HOST_NOT_AVAILABLE: + mAuthStatusText = R.string.auth_unknown_host_title; + break; + case INSTANCE_NOT_CONFIGURED: + mAuthStatusText = R.string.auth_not_configured_title; break; + case FILE_NOT_FOUND: + mAuthStatusText = R.string.auth_incorrect_path_title; + break; + case OAUTH2_ERROR: + mAuthStatusText = R.string.auth_oauth_error; + break; + case OAUTH2_ERROR_ACCESS_DENIED: + mAuthStatusText = R.string.auth_oauth_error_access_denied; + break; + case UNHANDLED_HTTP_CODE: + case UNKNOWN_ERROR: + mAuthStatusText = R.string.auth_unknown_error_title; + break; + default: + mAuthStatusText = 0; + mAuthStatusIcon = 0; } } @@ -757,7 +827,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mAuthCheckOperation.execute(client, this, mHandler); } else { - updateStatusIconAndText(result); + updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); } @@ -792,7 +862,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity finish(); } else { - updateStatusIconAndText(result); + updateAuthStatusIconAndText(result); showAuthStatus(); Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); } @@ -997,11 +1067,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (mServerStatusIcon == 0 && mServerStatusText == 0) { tv.setVisibility(View.INVISIBLE); + } else { tv.setText(mServerStatusText); tv.setCompoundDrawablesWithIntrinsicBounds(mServerStatusIcon, 0, 0, 0); tv.setVisibility(View.VISIBLE); } + } @@ -1012,6 +1084,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void showAuthStatus() { if (mAuthStatusIcon == 0 && mAuthStatusText == 0) { mAuthStatusLayout.setVisibility(View.INVISIBLE); + } else { mAuthStatusLayout.setText(mAuthStatusText); mAuthStatusLayout.setCompoundDrawablesWithIntrinsicBounds(mAuthStatusIcon, 0, 0, 0); @@ -1020,6 +1093,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } + private void showRefreshButton() { + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0); + } + + private void hideRefreshButton() { + mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + /** * Called when the refresh button in the input field for ownCloud host is clicked. * @@ -1160,24 +1241,4 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity public abstract boolean onDrawableTouch(final MotionEvent event); } - - private class HostUrlWatcher implements TextWatcher { - - @Override - public void afterTextChanged(Editable s) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - if (mServerCheckedAndValid) { - mServerCheckedAndValid = false; - mOkButton.setEnabled(false); // avoids that the 'connect' button can be clicked if the test was previously passed - } - } - - } }