summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
authorFred Quintana <fredq@google.com>2011-09-19 10:43:59 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2011-09-19 10:43:59 -0700
commit79a33ad49e8dd54f36ea7ea5f1a275bf38daf5e8 (patch)
tree7bac26d271aa7b6c8289e87a0fc5c24e8a3d4dd2 /core/java
parentb0a1f197303d520d788ba11fcb0ac56f3a3c8604 (diff)
parentb04fe4e82abb073b4e5d82563b0882cea0dcc139 (diff)
downloadframeworks_base-79a33ad49e8dd54f36ea7ea5f1a275bf38daf5e8.zip
frameworks_base-79a33ad49e8dd54f36ea7ea5f1a275bf38daf5e8.tar.gz
frameworks_base-79a33ad49e8dd54f36ea7ea5f1a275bf38daf5e8.tar.bz2
Merge "Continuation of the unified account chooser flow." into ics-factoryrom
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/accounts/AccountManager.java29
-rw-r--r--core/java/android/accounts/ChooseAccountTypeActivity.java14
-rw-r--r--core/java/android/accounts/ChooseTypeAndAccountActivity.java85
3 files changed, 106 insertions, 22 deletions
diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java
index 530ecf1..3d3a373 100644
--- a/core/java/android/accounts/AccountManager.java
+++ b/core/java/android/accounts/AccountManager.java
@@ -1790,22 +1790,43 @@ public class AccountManager {
* @param allowableAccountTypes an optional string array of account types. These are used
* both to filter the shown accounts and to filter the list of account types that are shown
* when adding an account.
- * @param addAccountOptions This {@link Bundle} is passed as the addAccount options
- * @return an {@link Intent} that can be used to launch the ChooseAccount activity flow.
+ * @param alwaysPromptForAccount if set the account chooser screen is always shown, otherwise
+ * it is only shown when there is more than one account from which to choose
+ * @param descriptionOverrideText if set, this string is used as the description in the
+ * accounts chooser screen rather than the default
+ * @param addAccountAuthTokenType This {@link Bundle} is passed as the {@link #addAccount}
+ * authTokenType
+ * @param addAccountRequiredFeatures This {@link Bundle} is passed as the {@link #addAccount}
+ * requiredFeatures
+ * @param addAccountOptions This {@link Bundle} is passed as the {@link #addAccount} options
+ * @return an {@link Intent} that can be used to launch the ChooseAccount activity flow.
*/
static public Intent newChooseAccountIntent(Account selectedAccount,
ArrayList<Account> allowableAccounts,
String[] allowableAccountTypes,
+ boolean alwaysPromptForAccount,
+ String descriptionOverrideText,
+ String addAccountAuthTokenType,
+ String[] addAccountRequiredFeatures,
Bundle addAccountOptions) {
Intent intent = new Intent();
intent.setClassName("android", "android.accounts.ChooseTypeAndAccountActivity");
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST,
allowableAccounts);
- intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST,
- allowableAccountTypes != null ? Lists.newArrayList(allowableAccountTypes) : 0);
+ intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY,
+ allowableAccountTypes);
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,
addAccountOptions);
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_SELECTED_ACCOUNT, selectedAccount);
+ intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT,
+ alwaysPromptForAccount);
+ intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_DESCRIPTION_TEXT_OVERRIDE,
+ descriptionOverrideText);
+ intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING,
+ addAccountAuthTokenType);
+ intent.putExtra(
+ ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY,
+ addAccountRequiredFeatures);
return intent;
}
diff --git a/core/java/android/accounts/ChooseAccountTypeActivity.java b/core/java/android/accounts/ChooseAccountTypeActivity.java
index 836164c..f53e6f3 100644
--- a/core/java/android/accounts/ChooseAccountTypeActivity.java
+++ b/core/java/android/accounts/ChooseAccountTypeActivity.java
@@ -52,12 +52,12 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.choose_account);
+ setContentView(R.layout.choose_account_type);
// Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
Set<String> setOfAllowableAccountTypes = null;
ArrayList<String> validAccountTypes = getIntent().getStringArrayListExtra(
- ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST);
+ ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
if (validAccountTypes != null) {
setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.size());
for (String type : validAccountTypes) {
@@ -138,10 +138,14 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage
protected void runAddAccountForAuthenticator(AuthInfo authInfo) {
Log.d(TAG, "selected account type " + authInfo.name);
- Bundle options = getIntent().getBundleExtra(
+ final Bundle options = getIntent().getBundleExtra(
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE);
- AccountManager.get(this).addAccount(authInfo.desc.type, null, null, options,
- this, this, null);
+ final String[] requiredFeatures = getIntent().getStringArrayExtra(
+ ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY);
+ final String authTokenType = getIntent().getStringExtra(
+ ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING);
+ AccountManager.get(this).addAccount(authInfo.desc.type, authTokenType, requiredFeatures,
+ options, this, this, null /* Handler */);
}
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {
diff --git a/core/java/android/accounts/ChooseTypeAndAccountActivity.java b/core/java/android/accounts/ChooseTypeAndAccountActivity.java
index a903399..b4030b9 100644
--- a/core/java/android/accounts/ChooseTypeAndAccountActivity.java
+++ b/core/java/android/accounts/ChooseTypeAndAccountActivity.java
@@ -23,6 +23,7 @@ import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
+import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@@ -57,25 +58,68 @@ public class ChooseTypeAndAccountActivity extends Activity {
* that match the types in this list, if this parameter is supplied. This list is also
* used to filter the allowable account types if add account is selected.
*/
- public static final String EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST = "allowableAccountTypes";
+ public static final String EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY = "allowableAccountTypes";
/**
- * This is passed as the options bundle in AccountManager.addAccount() if it is called.
+ * This is passed as the addAccountOptions parameter in AccountManager.addAccount()
+ * if it is called.
*/
public static final String EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE = "addAccountOptions";
/**
+ * This is passed as the requiredFeatures parameter in AccountManager.addAccount()
+ * if it is called.
+ */
+ public static final String EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY =
+ "addAccountRequiredFeatures";
+
+ /**
+ * This is passed as the authTokenType string in AccountManager.addAccount()
+ * if it is called.
+ */
+ public static final String EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING = "authTokenType";
+
+ /**
* If set then the specified account is already "selected".
*/
public static final String EXTRA_SELECTED_ACCOUNT = "selectedAccount";
+ /**
+ * If true then display the account selection list even if there is just
+ * one account to choose from. boolean.
+ */
+ public static final String EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT =
+ "alwaysPromptForAccount";
+
+ /**
+ * If set then this string willb e used as the description rather than
+ * the default.
+ */
+ public static final String EXTRA_DESCRIPTION_TEXT_OVERRIDE =
+ "descriptionTextOverride";
+
private ArrayList<AccountInfo> mAccountInfos;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.choose_type_and_account);
+
+ // save some items we use frequently
final AccountManager accountManager = AccountManager.get(this);
+ final Intent intent = getIntent();
+
+ // override the description text if supplied
+ final String descriptionOverride =
+ intent.getStringExtra(EXTRA_DESCRIPTION_TEXT_OVERRIDE);
+ if (!TextUtils.isEmpty(descriptionOverride)) {
+ ((TextView)findViewById(R.id.description)).setText(descriptionOverride);
+ }
+
+ // If the selected account matches one in the list we will place a
+ // checkmark next to it.
+ final Account selectedAccount =
+ (Account)intent.getParcelableExtra(EXTRA_SELECTED_ACCOUNT);
// build an efficiently queryable map of account types to authenticator descriptions
final HashMap<String, AuthenticatorDescription> typeToAuthDescription =
@@ -87,7 +131,7 @@ public class ChooseTypeAndAccountActivity extends Activity {
// Read the validAccounts, if present, and add them to the setOfAllowableAccounts
Set<Account> setOfAllowableAccounts = null;
final ArrayList<Parcelable> validAccounts =
- getIntent().getParcelableArrayListExtra(EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST);
+ intent.getParcelableArrayListExtra(EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST);
if (validAccounts != null) {
setOfAllowableAccounts = new HashSet<Account>(validAccounts.size());
for (Parcelable parcelable : validAccounts) {
@@ -98,7 +142,7 @@ public class ChooseTypeAndAccountActivity extends Activity {
// Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
Set<String> setOfAllowableAccountTypes = null;
final ArrayList<String> validAccountTypes =
- getIntent().getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST);
+ intent.getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
if (validAccountTypes != null) {
setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.size());
for (String type : validAccountTypes) {
@@ -121,7 +165,8 @@ public class ChooseTypeAndAccountActivity extends Activity {
continue;
}
mAccountInfos.add(new AccountInfo(account,
- getDrawableForType(typeToAuthDescription, account.type)));
+ getDrawableForType(typeToAuthDescription, account.type),
+ account.equals(selectedAccount)));
}
// If there are no allowable accounts go directly to add account
@@ -131,7 +176,8 @@ public class ChooseTypeAndAccountActivity extends Activity {
}
// if there is only one allowable account return it
- if (mAccountInfos.size() == 1) {
+ if (!intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false)
+ && mAccountInfos.size() == 1) {
Account account = mAccountInfos.get(0).account;
setResultAndFinish(account.name, account.type);
return;
@@ -143,7 +189,6 @@ public class ChooseTypeAndAccountActivity extends Activity {
list.setAdapter(new AccountArrayAdapter(this,
android.R.layout.simple_list_item_1, mAccountInfos));
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
- list.setTextFilterEnabled(false);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
onListItemClick((ListView)parent, v, position, id);
@@ -173,10 +218,12 @@ public class ChooseTypeAndAccountActivity extends Activity {
return;
}
}
+ Log.d(TAG, "ChooseTypeAndAccountActivity.onActivityResult: canceled");
setResult(Activity.RESULT_CANCELED);
finish();
}
+
private Drawable getDrawableForType(
final HashMap<String, AuthenticatorDescription> typeToAuthDescription,
String accountType) {
@@ -212,31 +259,40 @@ public class ChooseTypeAndAccountActivity extends Activity {
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
+ Log.d(TAG, "ChooseTypeAndAccountActivity.setResultAndFinish: "
+ + "selected account " + accountName + ", " + accountType);
finish();
}
private void startChooseAccountTypeActivity() {
final Intent intent = new Intent(this, ChooseAccountTypeActivity.class);
- intent.putStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST,
- getIntent().getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST));
+ intent.putStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY,
+ getIntent().getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY));
intent.putExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,
- getIntent().getBundleExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST));
+ getIntent().getBundleExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE));
+ intent.putExtra(EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY,
+ getIntent().getStringArrayExtra(EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY));
+ intent.putExtra(EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING,
+ getIntent().getStringArrayExtra(EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING));
startActivityForResult(intent, 0);
}
private static class AccountInfo {
final Account account;
final Drawable drawable;
+ private final boolean checked;
- AccountInfo(Account account, Drawable drawable) {
+ AccountInfo(Account account, Drawable drawable, boolean checked) {
this.account = account;
this.drawable = drawable;
+ this.checked = checked;
}
}
private static class ViewHolder {
ImageView icon;
TextView text;
+ ImageView checkmark;
}
private static class AccountArrayAdapter extends ArrayAdapter<AccountInfo> {
@@ -256,10 +312,11 @@ public class ChooseTypeAndAccountActivity extends Activity {
ViewHolder holder;
if (convertView == null) {
- convertView = mLayoutInflater.inflate(R.layout.choose_account_row, null);
+ convertView = mLayoutInflater.inflate(R.layout.choose_selected_account_row, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.account_row_text);
holder.icon = (ImageView) convertView.findViewById(R.id.account_row_icon);
+ holder.checkmark = (ImageView) convertView.findViewById(R.id.account_row_checkmark);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
@@ -267,7 +324,9 @@ public class ChooseTypeAndAccountActivity extends Activity {
holder.text.setText(mInfos.get(position).account.name);
holder.icon.setImageDrawable(mInfos.get(position).drawable);
-
+ final int displayCheckmark =
+ mInfos.get(position).checked ? View.VISIBLE : View.INVISIBLE;
+ holder.checkmark.setVisibility(displayCheckmark);
return convertView;
}
}