X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/980b31de2e11487480422378df244ebf23602ef5..842f46d7caed7de94c5e230321a5ea675857f320:/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 44ebf6a9..dd3b4a0e 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -3,9 +3,8 @@ * Copyright (C) 2012-2013 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,6 +19,7 @@ package com.owncloud.android.authentication; import com.owncloud.android.AccountUtils; +import com.owncloud.android.Log_OC; import com.owncloud.android.ui.dialog.SslValidatorDialog; import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener; import com.owncloud.android.utils.OwnCloudVersion; @@ -47,16 +47,18 @@ import android.os.Bundle; import android.os.Handler; import android.preference.PreferenceManager; import android.text.InputType; -import android.util.Log; +import android.view.KeyEvent; import android.view.View; import android.view.View.OnFocusChangeListener; import android.view.Window; +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; import com.owncloud.android.R; @@ -69,7 +71,7 @@ import eu.alefzero.webdav.WebdavClient; * @author David A. Velasco */ public class AuthenticatorActivity extends AccountAuthenticatorActivity - implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener { + implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener { private static final String TAG = AuthenticatorActivity.class.getSimpleName(); @@ -87,6 +89,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity 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 OAUTH_MODE_ON = "on"; + private static final String OAUTH_MODE_OFF = "off"; + private static final String OAUTH_MODE_OPTIONAL = "optional"; private static final int DIALOG_LOGIN_PROGRESS = 0; private static final int DIALOG_SSL_VALIDATOR = 1; @@ -154,7 +160,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mOkButton = findViewById(R.id.buttonOK); mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); - /// complete label for 'register account' button Button b = (Button) findViewById(R.id.account_register); if (b != null) { @@ -164,6 +169,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// bind view elements to listeners mHostUrlInput.setOnFocusChangeListener(this); mPasswordInput.setOnFocusChangeListener(this); + mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE); + mPasswordInput.setOnEditorActionListener(this); /// initialization mAccountMgr = AccountManager.get(this); @@ -176,10 +183,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity 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); + 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) { @@ -201,6 +210,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity 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); @@ -264,7 +277,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity updateConnStatus(); /// UI settings depending upon connection - mOkButton.setEnabled(mStatusCorrect); // TODO really necessary? + mOkButton.setEnabled(mStatusCorrect); if (!mStatusCorrect) mRefreshButton.setVisibility(View.VISIBLE); // seems that setting visibility is necessary else @@ -295,7 +308,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity */ @Override protected void onNewIntent (Intent intent) { - Log.d(TAG, "onNewIntent()"); + Log_OC.d(TAG, "onNewIntent()"); Uri data = intent.getData(); if (data != null && data.toString().startsWith(getString(R.string.oauth2_redirect_uri))) { mNewCapturedUriFromOAuth2Redirection = data; @@ -341,7 +354,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// GET ACCESS TOKEN to the oAuth server RemoteOperation operation = new OAuth2GetAccessToken( getString(R.string.oauth2_client_id), - getString(R.string.oauth2_redirect_uri), // TODO check - necessary here? + getString(R.string.oauth2_redirect_uri), getString(R.string.oauth2_grant_type), queryParameters); //WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext()); @@ -470,7 +483,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mStatusText = R.string.auth_wtf_reenter_URL; updateConnStatus(); mOkButton.setEnabled(false); - Log.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!"); + Log_OC.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!"); return; } @@ -526,7 +539,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope)); //uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant); uri = uriBuilder.build(); - Log.d(TAG, "Starting browser to view " + uri.toString()); + Log_OC.d(TAG, "Starting browser to view " + uri.toString()); Intent i = new Intent(Intent.ACTION_VIEW, uri); startActivity(i); } @@ -715,7 +728,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// time to test the retrieved access token on the ownCloud server mOAuthAccessToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN); - Log.d(TAG, "Got ACCESS TOKEN: " + mOAuthAccessToken); + Log_OC.d(TAG, "Got ACCESS TOKEN: " + mOAuthAccessToken); mAuthCheckOperation = new ExistenceCheckOperation("", this, false); WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this); client.setBearerCredentials(mOAuthAccessToken); @@ -724,7 +737,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } else { updateStatusIconAndText(result); updateAuthStatus(); - Log.d(TAG, "Access failed: " + result.getLogMessage()); + Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); } } @@ -745,7 +758,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } if (result.isSuccess()) { - Log.d(TAG, "Successful access - time to save the account"); + Log_OC.d(TAG, "Successful access - time to save the account"); if (mAction == ACTION_CREATE) { createAccount(); @@ -759,7 +772,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } else { updateStatusIconAndText(result); updateAuthStatus(); - Log.d(TAG, "Access failed: " + result.getLogMessage()); + Log_OC.d(TAG, "Access failed: " + result.getLogMessage()); } } @@ -867,7 +880,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity break; } default: - Log.e(TAG, "Incorrect dialog called with id = " + id); + Log_OC.e(TAG, "Incorrect dialog called with id = " + id); } } @@ -890,7 +903,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity @Override public void onCancel(DialogInterface dialog) { /// TODO study if this is enough - Log.i(TAG, "Login canceled"); + Log_OC.i(TAG, "Login canceled"); if (mOperationThread != null) { mOperationThread.interrupt(); finish(); @@ -909,7 +922,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { - Log.i(TAG, "Login canceled"); + Log_OC.i(TAG, "Login canceled"); finish(); } }); @@ -935,7 +948,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity break; } default: - Log.e(TAG, "Incorrect dialog called with id = " + id); + Log_OC.e(TAG, "Incorrect dialog called with id = " + id); } return dialog; } @@ -958,16 +971,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * to the last check on the ownCloud server. */ private void updateConnStatus() { - ImageView iv = (ImageView) findViewById(R.id.action_indicator); - TextView tv = (TextView) findViewById(R.id.status_text); + TextView tv = (TextView) findViewById(R.id.server_status_text); if (mStatusIcon == 0 && mStatusText == 0) { - iv.setVisibility(View.INVISIBLE); tv.setVisibility(View.INVISIBLE); } else { - iv.setImageResource(mStatusIcon); tv.setText(mStatusText); - iv.setVisibility(View.VISIBLE); + tv.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0); tv.setVisibility(View.VISIBLE); } } @@ -1076,4 +1086,21 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity showDialog(DIALOG_CERT_NOT_SAVED); } + + /** + * Called when the 'action' button in an IME is pressed ('enter' in software keyboard). + * + * Used to trigger the authorization check when the user presses 'enter' after writing the password. + */ + @Override + public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event) { + if (inputField != null && inputField.equals(mPasswordInput) && + actionId == EditorInfo.IME_ACTION_DONE) { + if (mOkButton.isEnabled()) { + mOkButton.performClick(); + } + } + return false; // always return false to grant that the software keyboard is hidden anyway + } + }