Skip to content

Commit 79a33ad

Browse files
fredquintanaAndroid (Google) Code Review
authored andcommitted
Merge "Continuation of the unified account chooser flow." into ics-factoryrom
2 parents b0a1f19 + b04fe4e commit 79a33ad

File tree

13 files changed

+245
-39
lines changed

13 files changed

+245
-39
lines changed

api/14.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ package android.accounts {
20722072
method public java.lang.String getUserData(android.accounts.Account, java.lang.String);
20732073
method public android.accounts.AccountManagerFuture<java.lang.Boolean> hasFeatures(android.accounts.Account, java.lang.String[], android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
20742074
method public void invalidateAuthToken(java.lang.String, java.lang.String);
2075-
method public static android.content.Intent newChooseAccountIntent(android.accounts.Account, java.util.ArrayList<android.accounts.Account>, java.lang.String[], android.os.Bundle);
2075+
method public static android.content.Intent newChooseAccountIntent(android.accounts.Account, java.util.ArrayList<android.accounts.Account>, java.lang.String[], boolean, java.lang.String, java.lang.String, java.lang.String[], android.os.Bundle);
20762076
method public java.lang.String peekAuthToken(android.accounts.Account, java.lang.String);
20772077
method public android.accounts.AccountManagerFuture<java.lang.Boolean> removeAccount(android.accounts.Account, android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
20782078
method public void removeOnAccountsUpdatedListener(android.accounts.OnAccountsUpdateListener);

api/current.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ package android.accounts {
20722072
method public java.lang.String getUserData(android.accounts.Account, java.lang.String);
20732073
method public android.accounts.AccountManagerFuture<java.lang.Boolean> hasFeatures(android.accounts.Account, java.lang.String[], android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
20742074
method public void invalidateAuthToken(java.lang.String, java.lang.String);
2075-
method public static android.content.Intent newChooseAccountIntent(android.accounts.Account, java.util.ArrayList<android.accounts.Account>, java.lang.String[], android.os.Bundle);
2075+
method public static android.content.Intent newChooseAccountIntent(android.accounts.Account, java.util.ArrayList<android.accounts.Account>, java.lang.String[], boolean, java.lang.String, java.lang.String, java.lang.String[], android.os.Bundle);
20762076
method public java.lang.String peekAuthToken(android.accounts.Account, java.lang.String);
20772077
method public android.accounts.AccountManagerFuture<java.lang.Boolean> removeAccount(android.accounts.Account, android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
20782078
method public void removeOnAccountsUpdatedListener(android.accounts.OnAccountsUpdateListener);

core/java/android/accounts/AccountManager.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,22 +1790,43 @@ public AccountManagerFuture<Bundle> getAuthTokenByFeatures(
17901790
* @param allowableAccountTypes an optional string array of account types. These are used
17911791
* both to filter the shown accounts and to filter the list of account types that are shown
17921792
* when adding an account.
1793-
* @param addAccountOptions This {@link Bundle} is passed as the addAccount options
1794-
* @return an {@link Intent} that can be used to launch the ChooseAccount activity flow.
1793+
* @param alwaysPromptForAccount if set the account chooser screen is always shown, otherwise
1794+
* it is only shown when there is more than one account from which to choose
1795+
* @param descriptionOverrideText if set, this string is used as the description in the
1796+
* accounts chooser screen rather than the default
1797+
* @param addAccountAuthTokenType This {@link Bundle} is passed as the {@link #addAccount}
1798+
* authTokenType
1799+
* @param addAccountRequiredFeatures This {@link Bundle} is passed as the {@link #addAccount}
1800+
* requiredFeatures
1801+
* @param addAccountOptions This {@link Bundle} is passed as the {@link #addAccount} options
1802+
* @return an {@link Intent} that can be used to launch the ChooseAccount activity flow.
17951803
*/
17961804
static public Intent newChooseAccountIntent(Account selectedAccount,
17971805
ArrayList<Account> allowableAccounts,
17981806
String[] allowableAccountTypes,
1807+
boolean alwaysPromptForAccount,
1808+
String descriptionOverrideText,
1809+
String addAccountAuthTokenType,
1810+
String[] addAccountRequiredFeatures,
17991811
Bundle addAccountOptions) {
18001812
Intent intent = new Intent();
18011813
intent.setClassName("android", "android.accounts.ChooseTypeAndAccountActivity");
18021814
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST,
18031815
allowableAccounts);
1804-
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST,
1805-
allowableAccountTypes != null ? Lists.newArrayList(allowableAccountTypes) : 0);
1816+
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY,
1817+
allowableAccountTypes);
18061818
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,
18071819
addAccountOptions);
18081820
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_SELECTED_ACCOUNT, selectedAccount);
1821+
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT,
1822+
alwaysPromptForAccount);
1823+
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_DESCRIPTION_TEXT_OVERRIDE,
1824+
descriptionOverrideText);
1825+
intent.putExtra(ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING,
1826+
addAccountAuthTokenType);
1827+
intent.putExtra(
1828+
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY,
1829+
addAccountRequiredFeatures);
18091830
return intent;
18101831
}
18111832

core/java/android/accounts/ChooseAccountTypeActivity.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage
5252
@Override
5353
public void onCreate(Bundle savedInstanceState) {
5454
super.onCreate(savedInstanceState);
55-
setContentView(R.layout.choose_account);
55+
setContentView(R.layout.choose_account_type);
5656

5757
// Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
5858
Set<String> setOfAllowableAccountTypes = null;
5959
ArrayList<String> validAccountTypes = getIntent().getStringArrayListExtra(
60-
ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST);
60+
ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
6161
if (validAccountTypes != null) {
6262
setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.size());
6363
for (String type : validAccountTypes) {
@@ -138,10 +138,14 @@ private void buildTypeToAuthDescriptionMap() {
138138

139139
protected void runAddAccountForAuthenticator(AuthInfo authInfo) {
140140
Log.d(TAG, "selected account type " + authInfo.name);
141-
Bundle options = getIntent().getBundleExtra(
141+
final Bundle options = getIntent().getBundleExtra(
142142
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE);
143-
AccountManager.get(this).addAccount(authInfo.desc.type, null, null, options,
144-
this, this, null);
143+
final String[] requiredFeatures = getIntent().getStringArrayExtra(
144+
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY);
145+
final String authTokenType = getIntent().getStringExtra(
146+
ChooseTypeAndAccountActivity.EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING);
147+
AccountManager.get(this).addAccount(authInfo.desc.type, authTokenType, requiredFeatures,
148+
options, this, this, null /* Handler */);
145149
}
146150

147151
public void run(final AccountManagerFuture<Bundle> accountManagerFuture) {

core/java/android/accounts/ChooseTypeAndAccountActivity.java

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import android.graphics.drawable.Drawable;
2424
import android.os.Bundle;
2525
import android.os.Parcelable;
26+
import android.text.TextUtils;
2627
import android.util.Log;
2728
import android.view.LayoutInflater;
2829
import android.view.View;
@@ -57,25 +58,68 @@ public class ChooseTypeAndAccountActivity extends Activity {
5758
* that match the types in this list, if this parameter is supplied. This list is also
5859
* used to filter the allowable account types if add account is selected.
5960
*/
60-
public static final String EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST = "allowableAccountTypes";
61+
public static final String EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY = "allowableAccountTypes";
6162

6263
/**
63-
* This is passed as the options bundle in AccountManager.addAccount() if it is called.
64+
* This is passed as the addAccountOptions parameter in AccountManager.addAccount()
65+
* if it is called.
6466
*/
6567
public static final String EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE = "addAccountOptions";
6668

69+
/**
70+
* This is passed as the requiredFeatures parameter in AccountManager.addAccount()
71+
* if it is called.
72+
*/
73+
public static final String EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY =
74+
"addAccountRequiredFeatures";
75+
76+
/**
77+
* This is passed as the authTokenType string in AccountManager.addAccount()
78+
* if it is called.
79+
*/
80+
public static final String EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING = "authTokenType";
81+
6782
/**
6883
* If set then the specified account is already "selected".
6984
*/
7085
public static final String EXTRA_SELECTED_ACCOUNT = "selectedAccount";
7186

87+
/**
88+
* If true then display the account selection list even if there is just
89+
* one account to choose from. boolean.
90+
*/
91+
public static final String EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT =
92+
"alwaysPromptForAccount";
93+
94+
/**
95+
* If set then this string willb e used as the description rather than
96+
* the default.
97+
*/
98+
public static final String EXTRA_DESCRIPTION_TEXT_OVERRIDE =
99+
"descriptionTextOverride";
100+
72101
private ArrayList<AccountInfo> mAccountInfos;
73102

74103
@Override
75104
public void onCreate(Bundle savedInstanceState) {
76105
super.onCreate(savedInstanceState);
77106
setContentView(R.layout.choose_type_and_account);
107+
108+
// save some items we use frequently
78109
final AccountManager accountManager = AccountManager.get(this);
110+
final Intent intent = getIntent();
111+
112+
// override the description text if supplied
113+
final String descriptionOverride =
114+
intent.getStringExtra(EXTRA_DESCRIPTION_TEXT_OVERRIDE);
115+
if (!TextUtils.isEmpty(descriptionOverride)) {
116+
((TextView)findViewById(R.id.description)).setText(descriptionOverride);
117+
}
118+
119+
// If the selected account matches one in the list we will place a
120+
// checkmark next to it.
121+
final Account selectedAccount =
122+
(Account)intent.getParcelableExtra(EXTRA_SELECTED_ACCOUNT);
79123

80124
// build an efficiently queryable map of account types to authenticator descriptions
81125
final HashMap<String, AuthenticatorDescription> typeToAuthDescription =
@@ -87,7 +131,7 @@ public void onCreate(Bundle savedInstanceState) {
87131
// Read the validAccounts, if present, and add them to the setOfAllowableAccounts
88132
Set<Account> setOfAllowableAccounts = null;
89133
final ArrayList<Parcelable> validAccounts =
90-
getIntent().getParcelableArrayListExtra(EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST);
134+
intent.getParcelableArrayListExtra(EXTRA_ALLOWABLE_ACCOUNTS_ARRAYLIST);
91135
if (validAccounts != null) {
92136
setOfAllowableAccounts = new HashSet<Account>(validAccounts.size());
93137
for (Parcelable parcelable : validAccounts) {
@@ -98,7 +142,7 @@ public void onCreate(Bundle savedInstanceState) {
98142
// Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
99143
Set<String> setOfAllowableAccountTypes = null;
100144
final ArrayList<String> validAccountTypes =
101-
getIntent().getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST);
145+
intent.getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
102146
if (validAccountTypes != null) {
103147
setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.size());
104148
for (String type : validAccountTypes) {
@@ -121,7 +165,8 @@ public void onCreate(Bundle savedInstanceState) {
121165
continue;
122166
}
123167
mAccountInfos.add(new AccountInfo(account,
124-
getDrawableForType(typeToAuthDescription, account.type)));
168+
getDrawableForType(typeToAuthDescription, account.type),
169+
account.equals(selectedAccount)));
125170
}
126171

127172
// If there are no allowable accounts go directly to add account
@@ -131,7 +176,8 @@ public void onCreate(Bundle savedInstanceState) {
131176
}
132177

133178
// if there is only one allowable account return it
134-
if (mAccountInfos.size() == 1) {
179+
if (!intent.getBooleanExtra(EXTRA_ALWAYS_PROMPT_FOR_ACCOUNT, false)
180+
&& mAccountInfos.size() == 1) {
135181
Account account = mAccountInfos.get(0).account;
136182
setResultAndFinish(account.name, account.type);
137183
return;
@@ -143,7 +189,6 @@ public void onCreate(Bundle savedInstanceState) {
143189
list.setAdapter(new AccountArrayAdapter(this,
144190
android.R.layout.simple_list_item_1, mAccountInfos));
145191
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
146-
list.setTextFilterEnabled(false);
147192
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
148193
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
149194
onListItemClick((ListView)parent, v, position, id);
@@ -173,10 +218,12 @@ protected void onActivityResult(final int requestCode, final int resultCode,
173218
return;
174219
}
175220
}
221+
Log.d(TAG, "ChooseTypeAndAccountActivity.onActivityResult: canceled");
176222
setResult(Activity.RESULT_CANCELED);
177223
finish();
178224
}
179225

226+
180227
private Drawable getDrawableForType(
181228
final HashMap<String, AuthenticatorDescription> typeToAuthDescription,
182229
String accountType) {
@@ -212,31 +259,40 @@ private void setResultAndFinish(final String accountName, final String accountTy
212259
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, accountName);
213260
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType);
214261
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
262+
Log.d(TAG, "ChooseTypeAndAccountActivity.setResultAndFinish: "
263+
+ "selected account " + accountName + ", " + accountType);
215264
finish();
216265
}
217266

218267
private void startChooseAccountTypeActivity() {
219268
final Intent intent = new Intent(this, ChooseAccountTypeActivity.class);
220-
intent.putStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST,
221-
getIntent().getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST));
269+
intent.putStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY,
270+
getIntent().getStringArrayListExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY));
222271
intent.putExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE,
223-
getIntent().getBundleExtra(EXTRA_ALLOWABLE_ACCOUNT_TYPES_ARRAYLIST));
272+
getIntent().getBundleExtra(EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE));
273+
intent.putExtra(EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY,
274+
getIntent().getStringArrayExtra(EXTRA_ADD_ACCOUNT_REQUIRED_FEATURES_STRING_ARRAY));
275+
intent.putExtra(EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING,
276+
getIntent().getStringArrayExtra(EXTRA_ADD_ACCOUNT_AUTH_TOKEN_TYPE_STRING));
224277
startActivityForResult(intent, 0);
225278
}
226279

227280
private static class AccountInfo {
228281
final Account account;
229282
final Drawable drawable;
283+
private final boolean checked;
230284

231-
AccountInfo(Account account, Drawable drawable) {
285+
AccountInfo(Account account, Drawable drawable, boolean checked) {
232286
this.account = account;
233287
this.drawable = drawable;
288+
this.checked = checked;
234289
}
235290
}
236291

237292
private static class ViewHolder {
238293
ImageView icon;
239294
TextView text;
295+
ImageView checkmark;
240296
}
241297

242298
private static class AccountArrayAdapter extends ArrayAdapter<AccountInfo> {
@@ -256,18 +312,21 @@ public View getView(int position, View convertView, ViewGroup parent) {
256312
ViewHolder holder;
257313

258314
if (convertView == null) {
259-
convertView = mLayoutInflater.inflate(R.layout.choose_account_row, null);
315+
convertView = mLayoutInflater.inflate(R.layout.choose_selected_account_row, null);
260316
holder = new ViewHolder();
261317
holder.text = (TextView) convertView.findViewById(R.id.account_row_text);
262318
holder.icon = (ImageView) convertView.findViewById(R.id.account_row_icon);
319+
holder.checkmark = (ImageView) convertView.findViewById(R.id.account_row_checkmark);
263320
convertView.setTag(holder);
264321
} else {
265322
holder = (ViewHolder) convertView.getTag();
266323
}
267324

268325
holder.text.setText(mInfos.get(position).account.name);
269326
holder.icon.setImageDrawable(mInfos.get(position).drawable);
270-
327+
final int displayCheckmark =
328+
mInfos.get(position).checked ? View.VISIBLE : View.INVISIBLE;
329+
holder.checkmark.setVisibility(displayCheckmark);
271330
return convertView;
272331
}
273332
}

core/res/AndroidManifest.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,19 +1533,14 @@
15331533
<activity android:name="android.accounts.ChooseTypeAndAccountActivity"
15341534
android:excludeFromRecents="true"
15351535
android:exported="true"
1536-
android:theme="@android:style/Theme.Holo.Dialog"
1536+
android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar"
15371537
android:label="@string/choose_account_label"
15381538
android:process=":ui">
1539-
<intent-filter>
1540-
<action android:name="android.intent.action.PICK" />
1541-
<category android:name="android.intent.category.ACCOUNT" />
1542-
</intent-filter>
15431539
</activity>
15441540

15451541
<activity android:name="android.accounts.ChooseAccountTypeActivity"
15461542
android:excludeFromRecents="true"
1547-
android:exported="true"
1548-
android:theme="@android:style/Theme.Holo.Dialog"
1543+
android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar"
15491544
android:label="@string/choose_account_label"
15501545
android:process=":ui">
15511546
</activity>
924 Bytes
Loading
658 Bytes
Loading
1.13 KB
Loading

0 commit comments

Comments
 (0)