diff options
author | Fred Quintana <fredq@google.com> | 2010-03-08 13:13:53 -0800 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2010-03-16 12:49:29 -0700 |
commit | 5edd3d7a39b915b657f56fb0d9acc32388b70a37 (patch) | |
tree | f3858a45d8839b22ba9a2b768f7978d6ab08f084 | |
parent | 33638a7cd24068387621b143f71227ea542993b0 (diff) | |
download | android_development-5edd3d7a39b915b657f56fb0d9acc32388b70a37.tar.gz android_development-5edd3d7a39b915b657f56fb0d9acc32388b70a37.tar.bz2 android_development-5edd3d7a39b915b657f56fb0d9acc32388b70a37.zip |
- change the accounts list to include the account type
- removed the list of account types from the top
- changed the context menu to use the actual account type, not
the one selected in the spinner
- add the clear password option to the context menu
Change-Id: Icd509ed3f3da889f48b064cf524345e0121899fc
-rw-r--r-- | apps/Development/AndroidManifest.xml | 3 | ||||
-rw-r--r-- | apps/Development/res/layout/account_list_context_menu.xml | 3 | ||||
-rw-r--r-- | apps/Development/res/layout/account_list_item.xml (renamed from apps/Development/res/layout/authenticators_list_item.xml) | 4 | ||||
-rw-r--r-- | apps/Development/res/layout/accounts_tester.xml | 3 | ||||
-rw-r--r-- | apps/Development/res/values/strings.xml | 9 | ||||
-rw-r--r-- | apps/Development/src/com/android/development/AccountsTester.java | 233 |
6 files changed, 117 insertions, 138 deletions
diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml index 1b33226fc..c4774c27a 100644 --- a/apps/Development/AndroidManifest.xml +++ b/apps/Development/AndroidManifest.xml @@ -77,7 +77,8 @@ </activity> <activity android:name="AccountsTester" android:label="AccountsTester" - android:theme="@android:style/Theme.Light"> + android:theme="@android:style/Theme.Light" + android:windowSoftInputMode="stateHidden"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.TEST" /> diff --git a/apps/Development/res/layout/account_list_context_menu.xml b/apps/Development/res/layout/account_list_context_menu.xml index 89f8241aa..ad20b28e1 100644 --- a/apps/Development/res/layout/account_list_context_menu.xml +++ b/apps/Development/res/layout/account_list_context_menu.xml @@ -25,6 +25,9 @@ <item android:id="@+id/accounts_tester_test_has_features" android:title="@string/accounts_tester_test_has_features" /> + <item android:id="@+id/accounts_tester_clear_password" + android:title="@string/accounts_tester_clear_password" /> + <item android:id="@+id/accounts_tester_invalidate_auth_token" android:title="@string/accounts_tester_invalidate_auth_token" /> diff --git a/apps/Development/res/layout/authenticators_list_item.xml b/apps/Development/res/layout/account_list_item.xml index 25e1daefe..e79690da9 100644 --- a/apps/Development/res/layout/authenticators_list_item.xml +++ b/apps/Development/res/layout/account_list_item.xml @@ -27,13 +27,13 @@ android:paddingLeft="9dip" android:paddingRight="9dip"> - <ImageView android:id="@+id/accounts_tester_authenticator_icon" + <ImageView android:id="@+id/accounts_tester_account_type_icon" android:paddingRight="9dip" android:layout_gravity="center_vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"/> - <TextView android:id="@+id/accounts_tester_authenticator_label" + <TextView android:id="@+id/accounts_tester_account_name" android:layout_width="wrap_content" android:layout_height="match_parent" android:gravity="center_vertical" diff --git a/apps/Development/res/layout/accounts_tester.xml b/apps/Development/res/layout/accounts_tester.xml index e3dee5314..df7c73fe4 100644 --- a/apps/Development/res/layout/accounts_tester.xml +++ b/apps/Development/res/layout/accounts_tester.xml @@ -25,9 +25,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - <ListView android:id="@+id/accounts_tester_authenticators_list" - android:layout_width="match_parent" android:layout_height="match_parent"/> - <LinearLayout android:orientation="horizontal" android:layout_width="match_parent" diff --git a/apps/Development/res/values/strings.xml b/apps/Development/res/values/strings.xml index c28ae6de5..1bb65cfde 100644 --- a/apps/Development/res/values/strings.xml +++ b/apps/Development/res/values/strings.xml @@ -161,15 +161,16 @@ <string name="accounts_tester_add_account">Add</string> <string name="accounts_tester_select_account_type">Select Account Type</string> <string name="accounts_tester_process_name_header">Process Name:</string> - <string name="accounts_tester_remove_account">remove</string> - <string name="accounts_tester_get_auth_token">get authtoken</string> - <string name="accounts_tester_test_has_features">test has features</string> - <string name="accounts_tester_invalidate_auth_token">invalidate token</string> + <string name="accounts_tester_remove_account">Remove Account</string> + <string name="accounts_tester_get_auth_token">Get Auth Token</string> + <string name="accounts_tester_test_has_features">Has Features</string> + <string name="accounts_tester_invalidate_auth_token">Invalidate Token</string> <string name="accounts_tester_account_context_menu_title">account operations</string> <string name="accounts_tester_do_get_auth_token">Ok</string> <string name="accounts_tester_enter_auth_token_type">Enter the authtoken type:</string> <string name="accounts_tester_update_credentials">Update Credentials</string> <string name="accounts_tester_confirm_credentials">Confirm Credentials</string> + <string name="accounts_tester_clear_password">Clear Password</string> <string name="accounts_tester_edit_properties">Properties</string> <string name="accounts_tester_desired_authtokentype_label">authtoken type:</string> <string name="accounts_tester_desired_features_label">features:</string> diff --git a/apps/Development/src/com/android/development/AccountsTester.java b/apps/Development/src/com/android/development/AccountsTester.java index 8e087e3a6..ba0622df4 100644 --- a/apps/Development/src/com/android/development/AccountsTester.java +++ b/apps/Development/src/com/android/development/AccountsTester.java @@ -37,10 +37,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener private static final String TAG = "AccountsTester"; private Spinner mAccountTypesSpinner; private ListView mAccountsListView; - private ListView mAuthenticatorsListView; private AccountManager mAccountManager; - private String mLongPressedAccount = null; - private static final String COM_GOOGLE = "com.google"; + private Account mLongPressedAccount = null; private AuthenticatorDescription[] mAuthenticatorDescs; private static final int GET_AUTH_TOKEN_DIALOG_ID = 1; @@ -61,9 +59,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener mAccountTypesSpinner = (Spinner) findViewById(R.id.accounts_tester_account_types_spinner); mAccountsListView = (ListView) findViewById(R.id.accounts_tester_accounts_list); - mAuthenticatorsListView = (ListView) findViewById(R.id.accounts_tester_authenticators_list); registerForContextMenu(mAccountsListView); - getAuthenticatorTypes(); + initializeAuthenticatorsSpinner(); findViewById(R.id.accounts_tester_get_all_accounts).setOnClickListener(buttonClickListener); findViewById(R.id.accounts_tester_get_accounts_by_type).setOnClickListener( buttonClickListener); @@ -74,18 +71,18 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener mDesiredFeaturesEditText = (EditText) findViewById(R.id.accounts_tester_desired_features); } - private static class AuthenticatorsArrayAdapter extends ArrayAdapter<AuthenticatorDescription> { + private class AccountArrayAdapter extends ArrayAdapter<Account> { protected LayoutInflater mInflater; - private static final int mResource = R.layout.authenticators_list_item; - public AuthenticatorsArrayAdapter(Context context, AuthenticatorDescription[] items) { - super(context, mResource, items); + public AccountArrayAdapter(Context context, Account[] accounts) { + super(context, R.layout.account_list_item, accounts); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); } - static class ViewHolder { - TextView label; + class ViewHolder { + TextView name; ImageView icon; + Account account; } @Override @@ -98,15 +95,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener // to reinflate it. We only inflate a new View when the convertView supplied // by ListView is null. if (convertView == null) { - convertView = mInflater.inflate(R.layout.authenticators_list_item, null); + convertView = mInflater.inflate(R.layout.account_list_item, null); // Creates a ViewHolder and store references to the two children views // we want to bind data to. holder = new ViewHolder(); - holder.label = (TextView) convertView.findViewById( - R.id.accounts_tester_authenticator_label); + holder.name = (TextView) convertView.findViewById( + R.id.accounts_tester_account_name); holder.icon = (ImageView) convertView.findViewById( - R.id.accounts_tester_authenticator_icon); + R.id.accounts_tester_account_type_icon); convertView.setTag(holder); } else { @@ -115,25 +112,29 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener holder = (ViewHolder) convertView.getTag(); } - final AuthenticatorDescription desc = getItem(position); - final String packageName = desc.packageName; - try { - final Context authContext = getContext().createPackageContext(packageName, 0); - - // Set text field - holder.label.setText(authContext.getString(desc.labelId)); - - // Set resource icon - holder.icon.setImageDrawable(authContext.getResources().getDrawable(desc.iconId)); - } catch (PackageManager.NameNotFoundException e) { - Log.d(TAG, "error getting the Package Context for " + packageName, e); + final Account account = getItem(position); + holder.account = account; + holder.icon.setVisibility(View.INVISIBLE); + for (AuthenticatorDescription desc : mAuthenticatorDescs) { + if (desc.type.equals(account.type)) { + final String packageName = desc.packageName; + try { + final Context authContext = getContext().createPackageContext(packageName, 0); + holder.icon.setImageDrawable(authContext.getResources().getDrawable(desc.iconId)); + holder.icon.setVisibility(View.VISIBLE); + } catch (PackageManager.NameNotFoundException e) { + Log.d(TAG, "error getting the Package Context for " + packageName, e); + } + } } + // Set text field + holder.name.setText(account.name); return convertView; } } - private void getAuthenticatorTypes() { + private void initializeAuthenticatorsSpinner() { mAuthenticatorDescs = mAccountManager.getAuthenticatorTypes(); String[] names = new String[mAuthenticatorDescs.length]; for (int i = 0; i < mAuthenticatorDescs.length; i++) { @@ -150,21 +151,11 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener new ArrayAdapter<String>(AccountsTester.this, android.R.layout.simple_spinner_item, names); mAccountTypesSpinner.setAdapter(adapter); - - mAuthenticatorsListView.setAdapter(new AuthenticatorsArrayAdapter( - AccountsTester.this, mAuthenticatorDescs)); } public void onAccountsUpdated(Account[] accounts) { Log.d(TAG, "onAccountsUpdated: \n " + TextUtils.join("\n ", accounts)); - String[] accountNames = new String[accounts.length]; - for (int i = 0; i < accounts.length; i++) { - accountNames[i] = accounts[i].name; - } - ArrayAdapter<String> adapter = - new ArrayAdapter<String>(AccountsTester.this, - android.R.layout.simple_list_item_1, accountNames); - mAccountsListView.setAdapter(adapter); + mAccountsListView.setAdapter(new AccountArrayAdapter(this, accounts)); } protected void onStart() { @@ -187,21 +178,6 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener String type = getSelectedAuthenticator().type; onAccountsUpdated(mAccountManager.getAccountsByType(type)); } else if (R.id.accounts_tester_add_account == v.getId()) { - AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() { - public void run(AccountManagerFuture<Bundle> future) { - try { - Bundle bundle = future.getResult(); - bundle.keySet(); - Log.d(TAG, "account added: " + bundle); - } catch (OperationCanceledException e) { - Log.d(TAG, "addAccount was canceled"); - } catch (IOException e) { - Log.d(TAG, "addAccount failed: " + e); - } catch (AuthenticatorException e) { - Log.d(TAG, "addAccount failed: " + e); - } - } - }; String authTokenType = mDesiredAuthTokenTypeEditText.getText().toString(); if (TextUtils.isEmpty(authTokenType)) { authTokenType = null; @@ -213,30 +189,18 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener } mAccountManager.addAccount(getSelectedAuthenticator().type, authTokenType, requiredFeatures, null /* options */, - AccountsTester.this, callback, null /* handler */); + AccountsTester.this, + new CallbackToDialog(AccountsTester.this, "add account"), + null /* handler */); } else if (R.id.accounts_tester_edit_properties == v.getId()) { mAccountManager.editProperties(getSelectedAuthenticator().type, - AccountsTester.this, new EditPropertiesCallback(), null /* handler */); + AccountsTester.this, + new CallbackToDialog(AccountsTester.this, "edit properties"), + null /* handler */); } else { // unknown button } } - - private class EditPropertiesCallback implements AccountManagerCallback<Bundle> { - public void run(AccountManagerFuture<Bundle> future) { - try { - Bundle bundle = future.getResult(); - bundle.keySet(); - Log.d(TAG, "editProperties succeeded: " + bundle); - } catch (OperationCanceledException e) { - Log.d(TAG, "editProperties was canceled"); - } catch (IOException e) { - Log.d(TAG, "editProperties failed: ", e); - } catch (AuthenticatorException e) { - Log.d(TAG, "editProperties failed: ", e); - } - } - } } private AuthenticatorDescription getSelectedAuthenticator() { @@ -252,13 +216,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener MenuInflater inflater = getMenuInflater(); inflater.inflate(R.layout.account_list_context_menu, menu); - mLongPressedAccount = ((TextView)info.targetView).getText().toString(); + AccountArrayAdapter.ViewHolder holder = + (AccountArrayAdapter.ViewHolder)info.targetView.getTag(); + mLongPressedAccount = holder.account; } @Override public boolean onContextItemSelected(MenuItem item) { if (item.getItemId() == R.id.accounts_tester_remove_account) { - final Account account = new Account(mLongPressedAccount, COM_GOOGLE); + final Account account = mLongPressedAccount; mAccountManager.removeAccount(account, new AccountManagerCallback<Boolean>() { public void run(AccountManagerFuture<Boolean> future) { try { @@ -269,6 +235,10 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener } } }, null /* handler */); + } else if (item.getItemId() == R.id.accounts_tester_clear_password) { + final Account account = mLongPressedAccount; + mAccountManager.clearPassword(account); + showMessageDialog("cleared"); } else if (item.getItemId() == R.id.accounts_tester_get_auth_token) { showDialog(GET_AUTH_TOKEN_DIALOG_ID); } else if (item.getItemId() == R.id.accounts_tester_test_has_features) { @@ -278,8 +248,9 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener } else if (item.getItemId() == R.id.accounts_tester_update_credentials) { showDialog(UPDATE_CREDENTIALS_DIALOG_ID); } else if (item.getItemId() == R.id.accounts_tester_confirm_credentials) { - mAccountManager.confirmCredentials(new Account(mLongPressedAccount, COM_GOOGLE), null, - AccountsTester.this, new ConfirmCredentialsCallback(), null /* handler */); + mAccountManager.confirmCredentials(mLongPressedAccount, null, + AccountsTester.this, new CallbackToDialog(this, "confirm credentials"), + null /* handler */); } return true; } @@ -297,30 +268,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener R.id.accounts_tester_auth_token_type); String authTokenType = value.getText().toString(); - AccountManagerCallback<Bundle> callback = new AccountManagerCallback<Bundle>() { - public void run(AccountManagerFuture<Bundle> future) { - try { - Bundle bundle = future.getResult(); - bundle.keySet(); - Log.d(TAG, "dialog " + id + " success: " + bundle); - } catch (OperationCanceledException e) { - Log.d(TAG, "dialog " + id + " canceled"); - } catch (IOException e) { - Log.d(TAG, "dialog " + id + " failed: " + e); - } catch (AuthenticatorException e) { - Log.d(TAG, "dialog " + id + " failed: " + e); - } - } - }; - final Account account = new Account(mLongPressedAccount, - COM_GOOGLE); + final Account account = mLongPressedAccount; if (id == GET_AUTH_TOKEN_DIALOG_ID) { mAccountManager.getAuthToken(account, authTokenType, null /* loginOptions */, AccountsTester.this, - callback, null /* handler */); + new CallbackToDialog(AccountsTester.this, "get auth token"), + null /* handler */); } else if (id == INVALIDATE_AUTH_TOKEN_DIALOG_ID) { mAccountManager.getAuthToken(account, authTokenType, false, - new GetAndInvalidateAuthTokenCallback(), null); + new GetAndInvalidateAuthTokenCallback(account), null); } else if (id == TEST_HAS_FEATURES_DIALOG_ID) { String[] features = TextUtils.split(authTokenType, ","); mAccountManager.hasFeatures(account, features, @@ -329,7 +285,9 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener mAccountManager.updateCredentials( account, authTokenType, null /* loginOptions */, - AccountsTester.this, callback, null /* handler */); + AccountsTester.this, + new CallbackToDialog(AccountsTester.this, "update"), + null /* handler */); } } }); @@ -397,32 +355,22 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener Log.d(TAG, "GetAuthTokenCallback: type " + mAccountType + ", features " + (mFeatures == null ? "none" : TextUtils.join(",", mFeatures))); - try { - Bundle result = future.getResult(); - result.keySet(); - Log.d(TAG, " result: " + result); - } catch (OperationCanceledException e) { - Log.d(TAG, "failure", e); - } catch (IOException e) { - Log.d(TAG, "failure", e); - } catch (AuthenticatorException e) { - Log.d(TAG, "failure", e); - } + getAndLogResult(future, "get auth token"); } } private class GetAndInvalidateAuthTokenCallback implements AccountManagerCallback<Bundle> { + private final Account mAccount; + + private GetAndInvalidateAuthTokenCallback(Account account) { + mAccount = account; + } + public void run(AccountManagerFuture<Bundle> future) { - try { - Bundle bundle = future.getResult(); - String authToken = bundle.getString(AccountManager.KEY_AUTHTOKEN); - mAccountManager.invalidateAuthToken(COM_GOOGLE, authToken); - } catch (OperationCanceledException e) { - Log.d(TAG, "invalidate: interrupted while getting authToken"); - } catch (IOException e) { - Log.d(TAG, "invalidate: error getting authToken", e); - } catch (AuthenticatorException e) { - Log.d(TAG, "invalidate: error getting authToken", e); + Bundle result = getAndLogResult(future, "get and invalidate"); + if (result != null) { + String authToken = result.getString(AccountManager.KEY_AUTHTOKEN); + mAccountManager.invalidateAuthToken(mAccount.type, authToken); } } } @@ -452,19 +400,48 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener } } - private static class ConfirmCredentialsCallback implements AccountManagerCallback<Bundle> { + private static class CallbackToDialog implements AccountManagerCallback<Bundle> { + private final AccountsTester mActivity; + private final String mLabel; + + private CallbackToDialog(AccountsTester activity, String label) { + mActivity = activity; + mLabel = label; + } + public void run(AccountManagerFuture<Bundle> future) { - try { - Bundle bundle = future.getResult(); - bundle.keySet(); - Log.d(TAG, "confirmCredentials success: " + bundle); - } catch (OperationCanceledException e) { - Log.d(TAG, "confirmCredentials canceled"); - } catch (AuthenticatorException e) { - Log.d(TAG, "confirmCredentials failed: " + e); - } catch (IOException e) { - Log.d(TAG, "confirmCredentials failed: " + e); + mActivity.getAndLogResult(future, mLabel); + } + } + + private Bundle getAndLogResult(AccountManagerFuture<Bundle> future, String label) { + try { + Bundle result = future.getResult(); + result.keySet(); + Log.d(TAG, label + ": " + result); + StringBuffer sb = new StringBuffer(); + sb.append(label).append(" result:"); + for (String key : result.keySet()) { + Object value = result.get(key); + if (AccountManager.KEY_AUTHTOKEN.equals(key)) { + value = "<redacted>"; + } + sb.append("\n ").append(key).append(" -> ").append(value); } + showMessageDialog(sb.toString()); + return result; + } catch (OperationCanceledException e) { + Log.d(TAG, label + " failed", e); + showMessageDialog(label + " was canceled"); + return null; + } catch (IOException e) { + Log.d(TAG, label + " failed", e); + showMessageDialog(label + " failed with IOException: " + e.getMessage()); + return null; + } catch (AuthenticatorException e) { + Log.d(TAG, label + " failed", e); + showMessageDialog(label + " failed with an AuthenticatorException: " + e.getMessage()); + return null; } } } |