Prevented server check due to orientation change in login view

This commit is contained in:
David A. Velasco 2013-05-16 12:30:37 +02:00
parent b8fbf38c56
commit 17776812ee

View file

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