import android.content.DialogInterface;\r
import android.content.Intent;\r
import android.content.SharedPreferences;\r
+import android.graphics.Rect;\r
+import android.graphics.drawable.Drawable;\r
import android.net.Uri;\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.TextWatcher;\r
import android.view.KeyEvent;\r
+import android.view.MotionEvent;\r
import android.view.View;\r
import android.view.View.OnFocusChangeListener;\r
+import android.view.View.OnTouchListener;\r
import android.view.Window;\r
import android.view.inputmethod.EditorInfo;\r
import android.widget.CheckBox;\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_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
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
private byte mAction;\r
private Account mAccount;\r
\r
- private ImageView mRefreshButton;\r
private ImageView mViewPasswordButton;\r
private EditText mHostUrlInput;\r
private EditText mUsernameInput;\r
\r
private TextView mOAuthAuthEndpointText;\r
private TextView mOAuthTokenEndpointText;\r
+\r
+ private HostUrlWatcher mHostUrlChangedListener;\r
\r
\r
/**\r
\r
/// set view and get references to view elements\r
setContentView(R.layout.account_setup);\r
- mRefreshButton = (ImageView) findViewById(R.id.refreshButton);\r
mViewPasswordButton = (ImageView) findViewById(R.id.viewPasswordButton);\r
mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput);\r
mUsernameInput = (EditText) findViewById(R.id.account_username);\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
- 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
+ mHostBaseUrl = "";\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
- 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
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
\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
+ showServerStatus();\r
+ showAuthStatus();\r
+ \r
if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
mOAuth2Check.setVisibility(View.GONE);\r
}\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
+ /// 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
+ @Override\r
+ protected void onStop() {\r
+ super.onStop();\r
+ mHostUrlInput.removeTextChangedListener(mHostUrlChangedListener);\r
+ }\r
+ \r
\r
/**\r
* Saves relevant state before {@link #onPause()}\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
-\r
+ outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon);\r
+ outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
+ \r
/// server data\r
- if (mDiscoveredVersion != null) \r
+ if (mDiscoveredVersion != null) {\r
outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());\r
+ }\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
- \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
/**\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
- mRefreshButton.setVisibility(View.VISIBLE); // seems that setting visibility is necessary\r
- else\r
- mRefreshButton.setVisibility(View.INVISIBLE);\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
* The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION request\r
* is caught here.\r
* \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
* 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
- 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
- \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
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
- mHostBaseUrl = "";\r
mDiscoveredVersion = null;\r
mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
} else {\r
- mRefreshButton.setVisibility(View.INVISIBLE);\r
- mStatusText = 0;\r
- mStatusIcon = 0;\r
- updateConnStatus();\r
+ mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+ mServerStatusText = 0;\r
+ mServerStatusIcon = 0;\r
+ showServerStatus();\r
}\r
}\r
\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
*/\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
* @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
- mRefreshButton.setVisibility(View.VISIBLE);\r
- else\r
- mRefreshButton.setVisibility(View.INVISIBLE);\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
- 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
- mHostBaseUrl = "http://" + mHostBaseUrl;\r
+ mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\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
+ 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
- mStatusText = mStatusIcon = 0;\r
+ mServerStatusText = mServerStatusIcon = 0;\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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
\r
} else {\r
updateStatusIconAndText(result);\r
- updateAuthStatus();\r
+ showAuthStatus();\r
Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
}\r
}\r
\r
} else {\r
updateStatusIconAndText(result);\r
- updateAuthStatus();\r
+ showAuthStatus();\r
Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
}\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
- if (mStatusIcon == 0 && mStatusText == 0) {\r
+ if (mServerStatusIcon == 0 && mServerStatusText == 0) {\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
* 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.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
* @param view Refresh 'button'\r
*/\r
public void onRefreshClick(View view) {\r
- onFocusChange(mRefreshButton, false);\r
+ onFocusChange(mHostUrlInput, false);\r
}\r
\r
\r
return false; // always return false to grant that the software keyboard is hidden anyway\r
}\r
\r
+ \r
+ private abstract static class RightDrawableOnTouchListener implements OnTouchListener {\r
+\r
+ private int fuzz = 10;\r
+ \r
+ /**\r
+ * {@inheritDoc}\r
+ */\r
+ @Override\r
+ public boolean onTouch(View view, MotionEvent event) {\r
+ if (event.getAction() == MotionEvent.ACTION_DOWN) {\r
+ Drawable rightDrawable = null;\r
+ if (view instanceof TextView) {\r
+ Drawable[] drawables = ((TextView)view).getCompoundDrawables();\r
+ if (drawables.length > 2) {\r
+ rightDrawable = drawables[2];\r
+ }\r
+ }\r
+ if (rightDrawable != null) {\r
+ final int x = (int) event.getX();\r
+ final int y = (int) event.getY();\r
+ final Rect bounds = rightDrawable.getBounds();\r
+ if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz)\r
+ && y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) {\r
+ \r
+ return onDrawableTouch(event);\r
+ }\r
+ }\r
+ }\r
+ return false;\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