Merge "Continuation of the unified account chooser flow." into ics-factoryrom

This commit is contained in:
Fred Quintana
2011-09-19 10:43:59 -07:00
committed by Android (Google) Code Review
13 changed files with 245 additions and 39 deletions

View File

@@ -2072,7 +2072,7 @@ package android.accounts {
method public java.lang.String getUserData(android.accounts.Account, java.lang.String);
method public android.accounts.AccountManagerFuture<java.lang.Boolean> hasFeatures(android.accounts.Account, java.lang.String[], android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
method public void invalidateAuthToken(java.lang.String, java.lang.String);
method public static android.content.Intent newChooseAccountIntent(android.accounts.Account, java.util.ArrayList<android.accounts.Account>, java.lang.String[], android.os.Bundle);
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);
method public java.lang.String peekAuthToken(android.accounts.Account, java.lang.String);
method public android.accounts.AccountManagerFuture<java.lang.Boolean> removeAccount(android.accounts.Account, android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
method public void removeOnAccountsUpdatedListener(android.accounts.OnAccountsUpdateListener);

View File

@@ -2072,7 +2072,7 @@ package android.accounts {
method public java.lang.String getUserData(android.accounts.Account, java.lang.String);
method public android.accounts.AccountManagerFuture<java.lang.Boolean> hasFeatures(android.accounts.Account, java.lang.String[], android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
method public void invalidateAuthToken(java.lang.String, java.lang.String);
method public static android.content.Intent newChooseAccountIntent(android.accounts.Account, java.util.ArrayList<android.accounts.Account>, java.lang.String[], android.os.Bundle);
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);
method public java.lang.String peekAuthToken(android.accounts.Account, java.lang.String);
method public android.accounts.AccountManagerFuture<java.lang.Boolean> removeAccount(android.accounts.Account, android.accounts.AccountManagerCallback<java.lang.Boolean>, android.os.Handler);
method public void removeOnAccountsUpdatedListener(android.accounts.OnAccountsUpdateListener);

View File

@@ -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;
}

View File

@@ -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) {

View File

@@ -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;
}
}

View File

@@ -1533,19 +1533,14 @@
<activity android:name="android.accounts.ChooseTypeAndAccountActivity"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@android:style/Theme.Holo.Dialog"
android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar"
android:label="@string/choose_account_label"
android:process=":ui">
<intent-filter>
<action android:name="android.intent.action.PICK" />
<category android:name="android.intent.category.ACCOUNT" />
</intent-filter>
</activity>
<activity android:name="android.accounts.ChooseAccountTypeActivity"
android:excludeFromRecents="true"
android:exported="true"
android:theme="@android:style/Theme.Holo.Dialog"
android:theme="@android:style/Theme.Holo.DialogWhenLarge.NoActionBar"
android:label="@string/choose_account_label"
android:process=":ui">
</activity>

Binary file not shown.

After

Width:  |  Height:  |  Size: 924 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 658 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/layout/list_content.xml
**
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="16dip"
android:paddingRight="16dip">
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="left"
android:text="@string/add_account_label"
android:paddingTop="16dip"
android:paddingBottom="16dip"
android:textColor="@android:color/holo_blue_light"
/>
<View android:layout_height="3dip"
android:layout_width="match_parent"
android:background="#323232"/>
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:scrollbarAlwaysDrawVerticalTrack="true" />
</LinearLayout>

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingLeft="0dip"
android:paddingRight="0dip"
android:orientation="horizontal" >
<ImageView android:id="@+id/account_row_icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingRight="8dip" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/account_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight" />
<ImageView android:id="@+id/account_row_checkmark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_weight="2"
android:paddingRight="8dip"
android:src="@drawable/ic_checkmark_holo_light" />
</LinearLayout>

View File

@@ -24,21 +24,44 @@
android:paddingLeft="16dip"
android:paddingRight="16dip">
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="left"
android:text="@string/choose_account_label"
android:paddingTop="16dip"
android:paddingBottom="16dip"
android:textColor="@android:color/holo_blue_light"
/>
<View android:layout_height="3dip"
android:layout_width="match_parent"
android:background="#323232"/>
<TextView android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_gravity="left|center_vertical"
android:text="@string/choose_account_text"
android:paddingTop="16dip"
android:paddingBottom="16dip"
/>
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawSelectorOnTop="false"
android:layout_weight="1"
android:scrollbarAlwaysDrawVerticalTrack="true" />
<Button android:id="@+id/addAccount"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/add_account_button_label"
/>
</LinearLayout>

View File

@@ -3094,6 +3094,12 @@
<!-- Choose Account Activity label -->
<string name="choose_account_label">Select an account</string>
<string name="add_account_label">"Add an account"</string>
<string name="choose_account_text">"Which account would you like to use?"</string>
<!-- Button label to add an account [CHAR LIMIT=20] -->
<string name="add_account_button_label">Add account</string>
<!-- NumberPicker - accessibility support -->
<!-- Description of the button to increment the NumberPicker value. [CHAR LIMIT=NONE] -->
<string name="number_picker_increment_button">Increment</string>
@@ -3174,6 +3180,9 @@
<!-- Slide lock screen -->
<!-- Description of the sliding handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
<string name="content_description_sliding_handle">"Sliding handle. Tap and hold."</string>
<!-- Description of the up direction in which one can to slide the handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
<string name="description_direction_up">Up for <xliff:g id="target_description" example="Unlock">%s</xliff:g>.</string>
<!-- Description of the down direction in which one can to slide the handle in the Slide unlock screen. [CHAR LIMIT=NONE] -->
@@ -3293,4 +3302,4 @@
<!-- Delimeter used between each item in a textual list; for example "Alpha, Beta". [CHAR LIMIT=3] -->
<string name="list_delimeter">", "</string>
</resources>
</resources>