summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorCarlos Valdivia <carlosvaldivia@google.com>2012-05-16 17:44:34 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-05-16 17:44:34 -0700
commit864019503c20350393fa1fbaecc36f0577ca45bb (patch)
tree872955ed5da7a35d06b00705191027806d40a6cc /core/java
parent7fde8e2ba27942ed61a1d57f63f3b4eea3e0bbc8 (diff)
parentcf0a881f1c27718f686a307e6c94213815ee9dc1 (diff)
Merge "Streamline the logic to add account." into jb-dev
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/accounts/ChooseTypeAndAccountActivity.java86
1 files changed, 50 insertions, 36 deletions
diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java
index 136c68c13466..291e75ee4de0 100644
--- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java
+++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java
@@ -119,8 +119,6 @@ public class ChooseTypeAndAccountActivity extends Activity
+ savedInstanceState + ")");
}
- setContentView(R.layout.choose_type_and_account);
-
if (savedInstanceState != null) {
mPendingRequest = savedInstanceState.getInt(KEY_INSTANCE_STATE_PENDING_REQUEST);
mExistingAccounts =
@@ -164,14 +162,29 @@ public class ChooseTypeAndAccountActivity extends Activity
}
}
- // Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
- Set<String> setOfAllowableAccountTypes = null;
- final String[] validAccountTypes =
+ // An account type is relevant iff it is allowed by the caller and supported by the account
+ // manager.
+ Set<String> setOfRelevantAccountTypes = null;
+ final String[] allowedAccountTypes =
intent.getStringArrayExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
- if (validAccountTypes != null) {
- setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.length);
- for (String type : validAccountTypes) {
- setOfAllowableAccountTypes.add(type);
+ if (allowedAccountTypes != null) {
+
+ setOfRelevantAccountTypes = new HashSet<String>(allowedAccountTypes.length);
+ Set<String> setOfAllowedAccountTypes = new HashSet<String>(allowedAccountTypes.length);
+ for (String type : allowedAccountTypes) {
+ setOfAllowedAccountTypes.add(type);
+ }
+
+ AuthenticatorDescription[] descs = AccountManager.get(this).getAuthenticatorTypes();
+ Set<String> supportedAccountTypes = new HashSet<String>(descs.length);
+ for (AuthenticatorDescription desc : descs) {
+ supportedAccountTypes.add(desc.type);
+ }
+
+ for (String acctType : setOfAllowedAccountTypes) {
+ if (supportedAccountTypes.contains(acctType)) {
+ setOfRelevantAccountTypes.add(acctType);
+ }
}
}
@@ -185,8 +198,8 @@ public class ChooseTypeAndAccountActivity extends Activity
&& !setOfAllowableAccounts.contains(account)) {
continue;
}
- if (setOfAllowableAccountTypes != null
- && !setOfAllowableAccountTypes.contains(account.type)) {
+ if (setOfRelevantAccountTypes != null
+ && !setOfRelevantAccountTypes.contains(account.type)) {
continue;
}
mAccountInfos.add(new AccountInfo(account,
@@ -194,6 +207,29 @@ public class ChooseTypeAndAccountActivity extends Activity
account.equals(selectedAccount)));
}
+ if (mPendingRequest == REQUEST_NULL) {
+ // If there are no relevant accounts and only one relevant account typoe go directly to
+ // add account. Otherwise let the user choose.
+ if (mAccountInfos.isEmpty()) {
+ if (setOfRelevantAccountTypes.size() == 1) {
+ runAddAccountForAuthenticator(setOfRelevantAccountTypes.iterator().next());
+ } else {
+ startChooseAccountTypeActivity();
+ }
+ return;
+ }
+
+ // if there is only one allowable account return it
+ if (!intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false)
+ && mAccountInfos.size() == 1) {
+ Account account = mAccountInfos.get(0).account;
+ setResultAndFinish(account.name, account.type);
+ return;
+ }
+ }
+
+ setContentView(R.layout.choose_type_and_account);
+
// there is more than one allowable account. initialize the list adapter to allow
// the user to select an account.
ListView list = (ListView) findViewById(android.R.id.list);
@@ -201,6 +237,7 @@ public class ChooseTypeAndAccountActivity extends Activity
android.R.layout.simple_list_item_1, mAccountInfos));
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+ @Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
onListItemClick((ListView)parent, v, position, id);
}
@@ -209,26 +246,11 @@ public class ChooseTypeAndAccountActivity extends Activity
// set the listener for the addAccount button
Button addAccountButton = (Button) findViewById(R.id.addAccount);
addAccountButton.setOnClickListener(new View.OnClickListener() {
+ @Override
public void onClick(final View v) {
startChooseAccountTypeActivity();
}
});
-
- if (mPendingRequest == REQUEST_NULL) {
- // If there are no allowable accounts go directly to add account
- if (shouldSkipToChooseAccountTypeFlow()) {
- startChooseAccountTypeActivity();
- return;
- }
-
- // if there is only one allowable account return it
- if (!intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false)
- && mAccountInfos.size() == 1) {
- Account account = mAccountInfos.get(0).account;
- setResultAndFinish(account.name, account.type);
- return;
- }
- }
}
@Override
@@ -267,7 +289,7 @@ public class ChooseTypeAndAccountActivity extends Activity
if (resultCode == RESULT_CANCELED) {
// if cancelling out of addAccount and the original state caused us to skip this,
// finish this activity
- if (shouldSkipToChooseAccountTypeFlow()) {
+ if (mAccountInfos.isEmpty()) {
setResult(Activity.RESULT_CANCELED);
finish();
}
@@ -324,14 +346,6 @@ public class ChooseTypeAndAccountActivity extends Activity
finish();
}
- /**
- * convenience method to check if we should skip the accounts list display and immediately
- * jump to the flow that asks the user to select from the account type list
- */
- private boolean shouldSkipToChooseAccountTypeFlow() {
- return mAccountInfos.isEmpty();
- }
-
protected void runAddAccountForAuthenticator(String type) {
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "runAddAccountForAuthenticator: " + type);