import android.view.Window;\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 com.owncloud.android.R;\r
private boolean mStatusCorrect, mIsSslConn;\r
private RemoteOperationResult mLastSslUntrustedServerResult;\r
\r
+ public static final String PARAM_ACCOUNTNAME = "param_Accountname";\r
+ \r
public static final String PARAM_USERNAME = "param_Username";\r
public static final String PARAM_HOSTNAME = "param_Hostname";\r
\r
mStatusText = mStatusIcon = 0;\r
mStatusCorrect = false;\r
mIsSslConn = false;\r
+ \r
+ String accountName = getIntent().getExtras().getString(PARAM_ACCOUNTNAME);\r
+ String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);\r
+ if (AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(tokenType)) {\r
+ CheckBox oAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);\r
+ oAuth2Check.setChecked(true);\r
+ changeViewByOAuth2Check(true);\r
+ } \r
+ \r
+ if (accountName != null) {\r
+ ((TextView) findViewById(R.id.account_username)).setText(accountName.substring(0, accountName.lastIndexOf('@')));\r
+ tv.setText(accountName.substring(accountName.lastIndexOf('@') + 1));\r
+ }\r
}\r
iv.setOnClickListener(this);\r
iv2.setOnClickListener(this);\r
tv.setOnFocusChangeListener(this);\r
tv2.setOnFocusChangeListener(this);\r
\r
+ Button b = (Button) findViewById(R.id.account_register);\r
+ if (b != null) {\r
+ b.setText(String.format(getString(R.string.auth_register), getString(R.string.app_name)));\r
+ }\r
+\r
mNewCapturedUriFromOAuth2Redirection = null;\r
- \r
- Log.d(TAG, "onCreate");\r
}\r
\r
\r
// NOTHING TO DO ; can't find out what situation that leads to the exception in this code, but user logs signal that it happens\r
}\r
TextView tv = (TextView) findViewById(R.id.account_username);\r
- tv.setError(message);\r
+ tv.setError(message + " "); // the extra spaces are a workaround for an ugly bug: \r
+ // 1. insert wrong credentials and connect\r
+ // 2. put the focus on the user name field with using hardware controls (don't touch the screen); the error is shown UNDER the field\r
+ // 3. touch the user name field; the software keyboard appears; the error popup is moved OVER the field and SHRINKED in width, losing the last word\r
+ // Seen, at least, in Android 2.x devices\r
}\r
}\r
public void onCancelClick(View view) {\r
}\r
\r
public void onRegisterClick(View view) {\r
- Intent register = new Intent(Intent.ACTION_VIEW, Uri.parse("https://owncloud.com/mobile/new"));\r
+ Intent register = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.url_account_register)));\r
setResult(RESULT_CANCELED);\r
startActivity(register);\r
}\r
\r
URL uri = null;\r
mDiscoveredVersion = mConnChkRunnable.getDiscoveredVersion();\r
- String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion);\r
+ String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, false);\r
\r
if (webdav_path == null) {\r
onAuthenticationResult(false, getString(R.string.auth_bad_oc_version_title));\r
findViewById(R.id.buttonOK).setEnabled(mStatusCorrect);\r
}\r
\r
- @Override\r
public void onFocusChange(View view, boolean hasFocus) {\r
if (view.getId() == R.id.host_URL) {\r
if (!hasFocus) {\r
onFocusChange(findViewById(R.id.host_URL), false);\r
} else if (v.getId() == R.id.viewPassword) {\r
TextView view = (TextView) findViewById(R.id.account_password);\r
- int input_type = InputType.TYPE_CLASS_TEXT\r
- | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;\r
+ int input_type = view.getInputType();\r
+ if ((input_type & InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) {\r
+ input_type = InputType.TYPE_CLASS_TEXT\r
+ | InputType.TYPE_TEXT_VARIATION_PASSWORD;\r
+ } else {\r
+ input_type = InputType.TYPE_CLASS_TEXT\r
+ | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;\r
+ }\r
view.setInputType(input_type);\r
}\r
}\r
\r
showDialog(DIALOG_LOGIN_PROGRESS);\r
String accessToken = ((GetOAuth2AccessToken)operation).getResultTokenMap().get(OAuth2Context.KEY_ACCESS_TOKEN);\r
- Log.d(TAG, "ACCESS TOKEN: " + accessToken);\r
+ Log.d(TAG, "Got ACCESS TOKEN: " + accessToken);\r
mAuthChkOperation = new ExistenceCheckOperation("", this, accessToken);\r
WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(uri, getApplicationContext());\r
mAuthChkOperation.execute(client, this, mHandler);\r
\r
if (result.isSuccess()) {\r
TextView tv = (TextView) findViewById(R.id.oAuth_URL);\r
- tv.setError("OOOOOKKKKKK");\r
- Log.d(TAG, "OOOOK!!!!");\r
- /**\r
+ Log.d(TAG, "Checked access - time to save the account");\r
+ \r
Uri uri = Uri.parse(mBaseUrl);\r
String username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong(); \r
String accountName = username + "@" + uri.getHost();\r
// TODO - check that accountName does not exist\r
Account account = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE);\r
AccountManager accManager = AccountManager.get(this);\r
- /// TODO SAVE THE ACCESS TOKEN, HERE OR IN SOME BETTER PLACE\r
- //accManager.addAccountExplicitly(account, mAccesToken, null); //// IS THIS REALLY NEEDED? IS NOT REDUNDANT WITH SETACCOUNTAUTHENTICATORRESULT?\r
+ accManager.addAccountExplicitly(account, "", null); // with our implementation, the password is never input in the app\r
\r
// Add this account as default in the preferences, if there is none\r
Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
final Intent intent = new Intent();\r
intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);\r
intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);\r
- intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);\r
intent.putExtra(AccountManager.KEY_USERDATA, username);\r
- intent.putExtra(AccountManager.KEY_AUTHTOKEN, mAccessToken)\r
\r
+ accManager.setAuthToken(account, AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN, ((ExistenceCheckOperation) operation).getAccessToken());\r
+ \r
accManager.setUserData(account, AccountAuthenticator.KEY_OC_VERSION, mConnChkRunnable.getDiscoveredVersion().toString());\r
accManager.setUserData(account, AccountAuthenticator.KEY_OC_BASE_URL, mBaseUrl);\r
+ accManager.setUserData(account, AccountAuthenticator.KEY_SUPPORTS_OAUTH2, "TRUE");\r
\r
setAccountAuthenticatorResult(intent.getExtras());\r
setResult(RESULT_OK, intent);\r
ContentResolver.requestSync(account, "org.owncloud", bundle);\r
\r
finish();\r
- */\r
\r
} else { \r
TextView tv = (TextView) findViewById(R.id.oAuth_URL);\r
tv.setError(result.getLogMessage());\r
- Log.d(TAG, "NOOOOO " + result.getLogMessage());\r
+ Log.d(TAG, "Access failed: " + result.getLogMessage());\r
}\r
}\r
}\r