X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/4d67655bbedbc250ccd796cebab09aed52ecccb0..9dc5a62e44952bdfb972bd46ff4b92ed2cba3d74:/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 bf888378..cc1adcf3 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -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; @@ -59,7 +61,6 @@ import android.view.inputmethod.EditorInfo; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Button; -import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import android.widget.TextView.OnEditorActionListener; @@ -87,11 +88,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_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"; private static final String KEY_IS_SSL_CONN = "IS_SSL_CONN"; + private static final String KEY_PASSWORD_VISIBLE = "PASSWORD_VISIBLE"; private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; @@ -112,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(); @@ -128,7 +131,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private byte mAction; private Account mAccount; - private ImageView mViewPasswordButton; private EditText mHostUrlInput; private EditText mUsernameInput; private EditText mPasswordInput; @@ -153,7 +155,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// set view and get references to view elements setContentView(R.layout.account_setup); - mViewPasswordButton = (ImageView) findViewById(R.id.viewPasswordButton); mHostUrlInput = (EditText) findViewById(R.id.hostUrlInput); mUsernameInput = (EditText) findViewById(R.id.account_username); mPasswordInput = (EditText) findViewById(R.id.account_password); @@ -179,7 +180,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; @@ -205,12 +207,16 @@ 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); mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT); mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON); + if (savedInstanceState.getBoolean(KEY_PASSWORD_VISIBLE, false)) { + showPassword(); + } /// server data String ocVersion = savedInstanceState.getString(KEY_OC_VERSION); @@ -231,6 +237,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); @@ -241,7 +249,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(); } } @@ -254,13 +262,40 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mHostUrlInput.setOnTouchListener(new RightDrawableOnTouchListener() { @Override public boolean onDrawableTouch(final MotionEvent event) { - AuthenticatorActivity.this.onRefreshClick(mHostUrlInput); + if (event.getAction() == MotionEvent.ACTION_UP) { + AuthenticatorActivity.this.onRefreshClick(); + } 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); + mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() { + @Override + public boolean onDrawableTouch(final MotionEvent event) { + if (event.getAction() == MotionEvent.ACTION_UP) { + AuthenticatorActivity.this.onViewPasswordClick(); + } + return true; + } + }); } /** @@ -278,9 +313,11 @@ 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.putBoolean(KEY_PASSWORD_VISIBLE, isPasswordVisible()); outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon); outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText); @@ -390,13 +427,16 @@ 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(); @@ -427,15 +467,42 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity */ private void onPasswordFocusChanged(TextView passwordInput, boolean hasFocus) { if (hasFocus) { - mViewPasswordButton.setVisibility(View.VISIBLE); + showViewPasswordButton(); } else { - int input_type = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD; - passwordInput.setInputType(input_type); - mViewPasswordButton.setVisibility(View.INVISIBLE); + hidePassword(); + hidePasswordButton(); } } + private void showViewPasswordButton() { + //int drawable = android.R.drawable.ic_menu_view; + int drawable = R.drawable.ic_view; + if (isPasswordVisible()) { + //drawable = android.R.drawable.ic_secure; + drawable = R.drawable.ic_hide; + } + mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0); + } + + private boolean isPasswordVisible() { + return ((mPasswordInput.getInputType() & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); + } + + private void hidePasswordButton() { + mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + } + + private void showPassword() { + mPasswordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); + showViewPasswordButton(); + } + + private void hidePassword() { + mPasswordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); + showViewPasswordButton(); + } + /** * Cancels the authenticator activity @@ -567,12 +634,13 @@ 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 - if (mServerCheckedAndValid) { + if (mServerIsValid) { hideRefreshButton(); } else { showRefreshButton(); @@ -591,7 +659,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity 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 @@ -614,7 +682,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity url = url.substring(0, url.length() - 1); } } - return url; + return (url != null ? url : ""); } /** @@ -1080,30 +1148,25 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * * @param view Refresh 'button' */ - public void onRefreshClick(View view) { + public void onRefreshClick() { checkOcServer(); } + /** * Called when the eye icon in the password field is clicked. * * Toggles the visibility of the password in the field. - * - * @param view 'View password' 'button' */ - public void onViewPasswordClick(View view) { + public void onViewPasswordClick() { int selectionStart = mPasswordInput.getSelectionStart(); int selectionEnd = mPasswordInput.getSelectionEnd(); - int input_type = mPasswordInput.getInputType(); - if ((input_type & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { - input_type = InputType.TYPE_CLASS_TEXT - | InputType.TYPE_TEXT_VARIATION_PASSWORD; + if (isPasswordVisible()) { + hidePassword(); } else { - input_type = InputType.TYPE_CLASS_TEXT - | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; + showPassword(); } - mPasswordInput.setInputType(input_type); mPasswordInput.setSelection(selectionStart, selectionEnd); } @@ -1134,13 +1197,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mOAuthTokenEndpointText.setVisibility(View.VISIBLE); mUsernameInput.setVisibility(View.GONE); mPasswordInput.setVisibility(View.GONE); - mViewPasswordButton.setVisibility(View.GONE); } else { mOAuthAuthEndpointText.setVisibility(View.GONE); mOAuthTokenEndpointText.setVisibility(View.GONE); mUsernameInput.setVisibility(View.VISIBLE); mPasswordInput.setVisibility(View.VISIBLE); - mViewPasswordButton.setVisibility(View.INVISIBLE); } } @@ -1181,30 +1242,28 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private abstract static class RightDrawableOnTouchListener implements OnTouchListener { - private int fuzz = 10; + private int fuzz = 75; /** * {@inheritDoc} */ @Override public boolean onTouch(View view, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { - Drawable rightDrawable = null; - if (view instanceof TextView) { - Drawable[] drawables = ((TextView)view).getCompoundDrawables(); - if (drawables.length > 2) { - rightDrawable = drawables[2]; - } + Drawable rightDrawable = null; + if (view instanceof TextView) { + Drawable[] drawables = ((TextView)view).getCompoundDrawables(); + if (drawables.length > 2) { + rightDrawable = drawables[2]; } - if (rightDrawable != null) { - final int x = (int) event.getX(); - final int y = (int) event.getY(); - final Rect bounds = rightDrawable.getBounds(); - if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz) - && y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) { - - return onDrawableTouch(event); - } + } + if (rightDrawable != null) { + final int x = (int) event.getX(); + final int y = (int) event.getY(); + final Rect bounds = rightDrawable.getBounds(); + if (x >= (view.getRight() - bounds.width() - fuzz) && x <= (view.getRight() - view.getPaddingRight() + fuzz) + && y >= (view.getPaddingTop() - fuzz) && y <= (view.getHeight() - view.getPaddingBottom()) + fuzz) { + + return onDrawableTouch(event); } } return false;