X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/2e5b40e357a5ab18b3a04f823b7cd27d5c94dc90..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 cc1b6482..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(); @@ -167,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); @@ -179,6 +183,8 @@ 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); @@ -271,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 @@ -302,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; @@ -348,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()); @@ -477,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; } @@ -533,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); } @@ -722,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); @@ -731,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()); } } @@ -752,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(); @@ -766,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()); } } @@ -874,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); } } @@ -897,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(); @@ -916,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(); } }); @@ -942,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; } @@ -965,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); } } @@ -1083,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 + } + }