* Copyright (C) 2012-2013 ownCloud Inc.\r
*\r
* This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 2 of the License, or\r
- * (at your option) any later version.\r
+ * it under the terms of the GNU General Public License version 2,\r
+ * as published by the Free Software Foundation.\r
*\r
* This program is distributed in the hope that it will be useful,\r
* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
package com.owncloud.android.authentication;\r
\r
import com.owncloud.android.AccountUtils;\r
+import com.owncloud.android.Log_OC;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
import com.owncloud.android.utils.OwnCloudVersion;\r
import android.os.Handler;\r
import android.preference.PreferenceManager;\r
import android.text.InputType;\r
-import android.util.Log;\r
+import android.view.KeyEvent;\r
import android.view.View;\r
import android.view.View.OnFocusChangeListener;\r
import android.view.Window;\r
+import android.view.inputmethod.EditorInfo;\r
import android.widget.CheckBox;\r
import android.widget.EditText;\r
import android.widget.Button;\r
import android.widget.ImageView;\r
import android.widget.TextView;\r
import android.widget.Toast;\r
+import android.widget.TextView.OnEditorActionListener;\r
\r
import com.owncloud.android.R;\r
\r
* @author David A. Velasco\r
*/\r
public class AuthenticatorActivity extends AccountAuthenticatorActivity\r
- implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener {\r
+ implements OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeListener, OnEditorActionListener {\r
\r
private static final String TAG = AuthenticatorActivity.class.getSimpleName();\r
\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
+ \r
+ private static final String OAUTH_MODE_ON = "on";\r
+ private static final String OAUTH_MODE_OFF = "off";\r
+ private static final String OAUTH_MODE_OPTIONAL = "optional";\r
\r
private static final int DIALOG_LOGIN_PROGRESS = 0;\r
private static final int DIALOG_SSL_VALIDATOR = 1;\r
mOkButton = findViewById(R.id.buttonOK);\r
mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); \r
\r
-\r
/// complete label for 'register account' button\r
Button b = (Button) findViewById(R.id.account_register);\r
if (b != null) {\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
mStatusText = mStatusIcon = 0;\r
mStatusCorrect = false;\r
mIsSslConn = false;\r
+ updateConnStatus();\r
+ updateAuthStatus();\r
\r
/// retrieve extras from intent\r
String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);\r
- boolean oAuthRequired = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(tokenType);\r
+ boolean oAuthRequired = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(tokenType) || OAUTH_MODE_ON.equals(getString(R.string.oauth2_mode));\r
\r
mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);\r
if (mAccount != null) {\r
loadSavedInstanceState(savedInstanceState);\r
}\r
\r
+ if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
+ mOAuth2Check.setVisibility(View.GONE);\r
+ }\r
+ \r
if (mAction == ACTION_UPDATE_TOKEN) {\r
/// lock things that should not change\r
mHostUrlInput.setEnabled(false);\r
updateConnStatus();\r
\r
/// UI settings depending upon connection\r
- mOkButton.setEnabled(mStatusCorrect); // TODO really necessary?\r
+ mOkButton.setEnabled(mStatusCorrect); \r
if (!mStatusCorrect)\r
mRefreshButton.setVisibility(View.VISIBLE); // seems that setting visibility is necessary\r
else\r
*/\r
@Override\r
protected void onNewIntent (Intent intent) {\r
- Log.d(TAG, "onNewIntent()");\r
+ Log_OC.d(TAG, "onNewIntent()");\r
Uri data = intent.getData();\r
if (data != null && data.toString().startsWith(getString(R.string.oauth2_redirect_uri))) {\r
mNewCapturedUriFromOAuth2Redirection = data;\r
\r
/// GET ACCESS TOKEN to the oAuth server \r
RemoteOperation operation = new OAuth2GetAccessToken( getString(R.string.oauth2_client_id), \r
- getString(R.string.oauth2_redirect_uri), // TODO check - necessary here? \r
+ getString(R.string.oauth2_redirect_uri), \r
getString(R.string.oauth2_grant_type),\r
queryParameters);\r
- WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
+ //WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
+ WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext());\r
operation.execute(client, this, mHandler);\r
}\r
\r
mStatusText = R.string.auth_wtf_reenter_URL;\r
updateConnStatus();\r
mOkButton.setEnabled(false);\r
- Log.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!");\r
+ Log_OC.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!");\r
return;\r
}\r
\r
updateAuthStatus();\r
\r
// GET AUTHORIZATION request\r
- Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
+ //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
+ Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
Uri.Builder uriBuilder = uri.buildUpon();\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type));\r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)); \r
uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope));\r
//uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant);\r
uri = uriBuilder.build();\r
- Log.d(TAG, "Starting browser to view " + uri.toString());\r
+ Log_OC.d(TAG, "Starting browser to view " + uri.toString());\r
Intent i = new Intent(Intent.ACTION_VIEW, uri);\r
startActivity(i);\r
}\r
\r
/// time to test the retrieved access token on the ownCloud server\r
mOAuthAccessToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
- Log.d(TAG, "Got ACCESS TOKEN: " + mOAuthAccessToken);\r
+ Log_OC.d(TAG, "Got ACCESS TOKEN: " + mOAuthAccessToken);\r
mAuthCheckOperation = new ExistenceCheckOperation("", this, false);\r
WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this);\r
client.setBearerCredentials(mOAuthAccessToken);\r
} else {\r
updateStatusIconAndText(result);\r
updateAuthStatus();\r
- Log.d(TAG, "Access failed: " + result.getLogMessage());\r
+ Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
}\r
}\r
\r
}\r
\r
if (result.isSuccess()) {\r
- Log.d(TAG, "Successful access - time to save the account");\r
+ Log_OC.d(TAG, "Successful access - time to save the account");\r
\r
if (mAction == ACTION_CREATE) {\r
createAccount();\r
} else {\r
updateStatusIconAndText(result);\r
updateAuthStatus();\r
- Log.d(TAG, "Access failed: " + result.getLogMessage());\r
+ Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
}\r
}\r
\r
break;\r
}\r
default:\r
- Log.e(TAG, "Incorrect dialog called with id = " + id);\r
+ Log_OC.e(TAG, "Incorrect dialog called with id = " + id);\r
}\r
}\r
\r
@Override\r
public void onCancel(DialogInterface dialog) {\r
/// TODO study if this is enough\r
- Log.i(TAG, "Login canceled");\r
+ Log_OC.i(TAG, "Login canceled");\r
if (mOperationThread != null) {\r
mOperationThread.interrupt();\r
finish();\r
.setOnCancelListener(new DialogInterface.OnCancelListener() {\r
@Override\r
public void onCancel(DialogInterface dialog) {\r
- Log.i(TAG, "Login canceled");\r
+ Log_OC.i(TAG, "Login canceled");\r
finish();\r
}\r
});\r
break;\r
}\r
default:\r
- Log.e(TAG, "Incorrect dialog called with id = " + id);\r
+ Log_OC.e(TAG, "Incorrect dialog called with id = " + id);\r
}\r
return dialog;\r
}\r
* to the last check on the ownCloud server.\r
*/\r
private void updateConnStatus() {\r
- ImageView iv = (ImageView) findViewById(R.id.action_indicator);\r
- TextView tv = (TextView) findViewById(R.id.status_text);\r
+ TextView tv = (TextView) findViewById(R.id.server_status_text);\r
\r
if (mStatusIcon == 0 && mStatusText == 0) {\r
- iv.setVisibility(View.INVISIBLE);\r
tv.setVisibility(View.INVISIBLE);\r
} else {\r
- iv.setImageResource(mStatusIcon);\r
tv.setText(mStatusText);\r
- iv.setVisibility(View.VISIBLE);\r
+ tv.setCompoundDrawablesWithIntrinsicBounds(mStatusIcon, 0, 0, 0);\r
tv.setVisibility(View.VISIBLE);\r
}\r
}\r
showDialog(DIALOG_CERT_NOT_SAVED);\r
}\r
\r
+\r
+ /**\r
+ * Called when the 'action' button in an IME is pressed ('enter' in software keyboard).\r
+ * \r
+ * Used to trigger the authorization check when the user presses 'enter' after writing the password.\r
+ */\r
+ @Override\r
+ public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event) {\r
+ if (inputField != null && inputField.equals(mPasswordInput) && \r
+ actionId == EditorInfo.IME_ACTION_DONE) {\r
+ if (mOkButton.isEnabled()) {\r
+ mOkButton.performClick();\r
+ }\r
+ }\r
+ return false; // always return false to grant that the software keyboard is hidden anyway\r
+ }\r
+\r
}\r