From: David A. Velasco Date: Mon, 17 Jun 2013 10:07:32 +0000 (-0700) Subject: Merge pull request #178 from owncloud/login_smart_clip_of_URL_suffix X-Git-Tag: oc-android-1.4.3~20 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/a65b73a97282291605f27f6082f362d9b02a2a6a?hp=-c Merge pull request #178 from owncloud/login_smart_clip_of_URL_suffix OC-208: suffix remote.php/webdav. OC-34 --- a65b73a97282291605f27f6082f362d9b02a2a6a diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index b4b1c6b6,1287a9cf..e4839707 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@@ -61,6 -61,7 +61,6 @@@ import android.view.inputmethod.EditorI 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; @@@ -94,10 -95,8 +94,10 @@@ implements OnRemoteOperationListener, 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"; + private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED"; private static final String OAUTH_MODE_ON = "on"; private static final String OAUTH_MODE_OFF = "off"; @@@ -110,8 -109,7 +110,7 @@@ public static final byte ACTION_CREATE = 0; public static final byte ACTION_UPDATE_TOKEN = 1; - - + private String mHostBaseUrl; private OwnCloudVersion mDiscoveredVersion; @@@ -132,6 -130,7 +131,6 @@@ private byte mAction; private Account mAccount; - private ImageView mViewPasswordButton; private EditText mHostUrlInput; private EditText mUsernameInput; private EditText mPasswordInput; @@@ -142,8 -141,6 +141,8 @@@ private TextView mOAuthAuthEndpointText; private TextView mOAuthTokenEndpointText; + + private boolean mRefreshButtonEnabled; /** @@@ -158,6 -155,7 +157,6 @@@ /// 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); @@@ -217,10 -215,7 +216,10 @@@ 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); if (ocVersion != null) { @@@ -234,16 -229,13 +233,16 @@@ // check if server check was interrupted by a configuration change if (savedInstanceState.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS, false)) { checkOcServer(); - } + } + + // refresh button enabled + mRefreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED); } showServerStatus(); showAuthStatus(); - if (mServerIsChecked && !mServerIsValid) showRefreshButton(); + if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton(); mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) { @@@ -268,9 -260,7 +267,9 @@@ 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; } }); @@@ -292,16 -282,7 +291,16 @@@ }); mPasswordInput.setOnFocusChangeListener(this); mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE); - mPasswordInput.setOnEditorActionListener(this); + 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; + } + }); } /** @@@ -323,7 -304,6 +322,7 @@@ 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); @@@ -337,9 -317,6 +336,9 @@@ if (mAccount != null) { outState.putParcelable(KEY_ACCOUNT, mAccount); } + + // refresh button enabled + outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, mRefreshButtonEnabled); } @@@ -416,9 -393,6 +415,9 @@@ if (view.getId() == R.id.hostUrlInput) { if (!hasFocus) { onUrlInputFocusLost((TextView) view); + if (!mServerIsValid) { + showRefreshButton(); + } } else { hideRefreshButton(); @@@ -451,7 -425,7 +450,7 @@@ private void checkOcServer() { - String uri = mHostUrlInput.getText().toString().trim(); + String uri = trimUrlWebdav(mHostUrlInput.getText().toString().trim()); mServerIsValid = false; mServerIsChecked = false; mOkButton.setEnabled(false); @@@ -484,43 -458,16 +483,43 @@@ */ 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 * @@@ -693,15 -640,33 +692,33 @@@ } else { url = "http://" + url; } - } + + // OC-208: Add suffix remote.php/webdav to normalize (OC-34) + url = trimUrlWebdav(url); + if (url.endsWith("/")) { url = url.substring(0, url.length() - 1); } + } + Log_OC.d(TAG, "URL Normalize " + url); return (url != null ? url : ""); } + + private String trimUrlWebdav(String url){ + if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){ + url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length()); + } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){ + url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length()); + } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){ + url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length()); + } + return (url != null ? url : ""); + } + + /** * Chooses the right icon and text to show to the user for the received operation result. * @@@ -1152,12 -1117,10 +1169,12 @@@ private void showRefreshButton() { mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0); + mRefreshButtonEnabled = true; } private void hideRefreshButton() { mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); + mRefreshButtonEnabled = false; } /** @@@ -1167,24 -1130,30 +1184,24 @@@ * * @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); } @@@ -1215,11 -1184,13 +1232,11 @@@ 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); } } @@@ -1260,28 -1231,30 +1277,28 @@@ 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;