Update account tester

- update Theme to use default one
- AccountManager.getAuthTokenByFeatures() can be called thru a button
- code refactoring and cleaning

Change-Id: I1b4cfb340d9ed1506541fb9faf349f50d05df472
This commit is contained in:
Fabrice Di Meglio
2011-01-17 17:37:55 -08:00
parent e8afb7e327
commit ac3b18ffe1
6 changed files with 240 additions and 124 deletions

View File

@@ -78,7 +78,6 @@
</activity> </activity>
<activity android:name="AccountsTester" android:label="AccountsTester" <activity android:name="AccountsTester" android:label="AccountsTester"
android:theme="@android:style/Theme.Light"
android:windowSoftInputMode="stateHidden"> android:windowSoftInputMode="stateHidden">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

View File

@@ -14,18 +14,17 @@
limitations under the License. limitations under the License.
--> -->
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@@ -40,11 +39,12 @@
android:layout_height="wrap_content"/> android:layout_height="wrap_content"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:orientation="vertical"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@@ -59,6 +59,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/accounts_tester_get_all_accounts"/> android:text="@string/accounts_tester_get_all_accounts"/>
<Button android:id="@+id/accounts_tester_add_account" <Button android:id="@+id/accounts_tester_add_account"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -68,12 +69,19 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/accounts_tester_edit_properties"/> android:text="@string/accounts_tester_edit_properties"/>
<Button android:id="@+id/accounts_tester_get_auth_token_by_type_and_feature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/accounts_tester_get_auth_token_by_type_and_feature"/>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView android:id="@+id/accounts_tester_desiredFeatures" <TextView android:id="@+id/accounts_tester_desiredFeatures"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -84,10 +92,12 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minEms="15"/> android:minEms="15"/>
</LinearLayout> </LinearLayout>
<LinearLayout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<TextView android:id="@+id/accounts_tester_desiredFeatures" <TextView android:id="@+id/accounts_tester_desiredFeatures"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@@ -101,7 +111,7 @@
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">

View File

@@ -21,7 +21,8 @@
android:layout_height="match_parent"> android:layout_height="match_parent">
<TextView android:id="@+id/accounts_tester_get_auth_token_dialog_message" <TextView android:id="@+id/accounts_tester_get_auth_token_dialog_message"
android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/accounts_tester_enter_auth_token_type" /> android:text="@string/accounts_tester_enter_auth_token_type" />
<EditText android:id="@+id/accounts_tester_auth_token_type" <EditText android:id="@+id/accounts_tester_auth_token_type"

View File

@@ -0,0 +1,51 @@
<?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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:id="@+id/accounts_tester_get_auth_token_dialog_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/accounts_tester_enter_auth_token_type" />
<EditText android:id="@+id/accounts_tester_auth_token_type"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="250dip"
android:scrollHorizontally="true"
android:capitalize="none"
android:autoText="false"/>
<TextView android:id="@+id/accounts_tester_get_features_dialog_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/accounts_tester_enter_features" />
<EditText android:id="@+id/accounts_tester_features"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="250dip"
android:scrollHorizontally="true"
android:capitalize="none"
android:autoText="false"/>
</LinearLayout>

View File

@@ -171,11 +171,13 @@
<string name="accounts_tester_process_name_header">Process Name:</string> <string name="accounts_tester_process_name_header">Process Name:</string>
<string name="accounts_tester_remove_account">Remove Account</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_get_auth_token">Get Auth Token</string>
<string name="accounts_tester_get_auth_token_by_type_and_feature">Get Auth Token By Type/Feature</string>
<string name="accounts_tester_test_has_features">Has Features</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_invalidate_auth_token">Invalidate Token</string>
<string name="accounts_tester_account_context_menu_title">account operations</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_ok_button">Ok</string>
<string name="accounts_tester_enter_auth_token_type">Enter the authtoken type:</string> <string name="accounts_tester_enter_auth_token_type">Enter the authtoken type:</string>
<string name="accounts_tester_enter_features">Enter the features separated by a space:</string>
<string name="accounts_tester_update_credentials">Update Credentials</string> <string name="accounts_tester_update_credentials">Update Credentials</string>
<string name="accounts_tester_confirm_credentials">Confirm Credentials</string> <string name="accounts_tester_confirm_credentials">Confirm Credentials</string>
<string name="accounts_tester_clear_password">Clear Password</string> <string name="accounts_tester_clear_password">Clear Password</string>

View File

@@ -46,6 +46,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
private static final int INVALIDATE_AUTH_TOKEN_DIALOG_ID = 3; private static final int INVALIDATE_AUTH_TOKEN_DIALOG_ID = 3;
private static final int TEST_HAS_FEATURES_DIALOG_ID = 4; private static final int TEST_HAS_FEATURES_DIALOG_ID = 4;
private static final int MESSAGE_DIALOG_ID = 5; private static final int MESSAGE_DIALOG_ID = 5;
private static final int GET_AUTH_TOKEN_BY_TYPE_AND_FEATURE_DIALOG_ID = 6;
private EditText mDesiredAuthTokenTypeEditText; private EditText mDesiredAuthTokenTypeEditText;
private EditText mDesiredFeaturesEditText; private EditText mDesiredFeaturesEditText;
private volatile CharSequence mDialogMessage; private volatile CharSequence mDialogMessage;
@@ -66,6 +68,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
buttonClickListener); buttonClickListener);
findViewById(R.id.accounts_tester_add_account).setOnClickListener(buttonClickListener); findViewById(R.id.accounts_tester_add_account).setOnClickListener(buttonClickListener);
findViewById(R.id.accounts_tester_edit_properties).setOnClickListener(buttonClickListener); findViewById(R.id.accounts_tester_edit_properties).setOnClickListener(buttonClickListener);
findViewById(R.id.accounts_tester_get_auth_token_by_type_and_feature).setOnClickListener(
buttonClickListener);
mDesiredAuthTokenTypeEditText = mDesiredAuthTokenTypeEditText =
(EditText) findViewById(R.id.accounts_tester_desired_authtokentype); (EditText) findViewById(R.id.accounts_tester_desired_authtokentype);
mDesiredFeaturesEditText = (EditText) findViewById(R.id.accounts_tester_desired_features); mDesiredFeaturesEditText = (EditText) findViewById(R.id.accounts_tester_desired_features);
@@ -119,8 +123,10 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
if (desc.type.equals(account.type)) { if (desc.type.equals(account.type)) {
final String packageName = desc.packageName; final String packageName = desc.packageName;
try { try {
final Context authContext = getContext().createPackageContext(packageName, 0); final Context authContext = getContext().createPackageContext(packageName,
holder.icon.setImageDrawable(authContext.getResources().getDrawable(desc.iconId)); 0);
holder.icon.setImageDrawable(authContext.getResources().getDrawable(
desc.iconId));
holder.icon.setVisibility(View.VISIBLE); holder.icon.setVisibility(View.VISIBLE);
} catch (PackageManager.NameNotFoundException e) { } catch (PackageManager.NameNotFoundException e) {
Log.d(TAG, "error getting the Package Context for " + packageName, e); Log.d(TAG, "error getting the Package Context for " + packageName, e);
@@ -197,6 +203,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
AccountsTester.this, AccountsTester.this,
new CallbackToDialog(AccountsTester.this, "edit properties"), new CallbackToDialog(AccountsTester.this, "edit properties"),
null /* handler */); null /* handler */);
} else if (R.id.accounts_tester_get_auth_token_by_type_and_feature == v.getId()) {
showDialog(GET_AUTH_TOKEN_BY_TYPE_AND_FEATURE_DIALOG_ID);
} else { } else {
// unknown button // unknown button
} }
@@ -265,11 +273,15 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
@Override @Override
protected Dialog onCreateDialog(final int id) { protected Dialog onCreateDialog(final int id) {
if (id == GET_AUTH_TOKEN_DIALOG_ID || id == INVALIDATE_AUTH_TOKEN_DIALOG_ID switch (id) {
|| id == UPDATE_CREDENTIALS_DIALOG_ID || id == TEST_HAS_FEATURES_DIALOG_ID) { case GET_AUTH_TOKEN_DIALOG_ID:
final View view = LayoutInflater.from(this).inflate(R.layout.get_auth_token_view, null); case INVALIDATE_AUTH_TOKEN_DIALOG_ID:
case UPDATE_CREDENTIALS_DIALOG_ID:
case TEST_HAS_FEATURES_DIALOG_ID: {
final View view = LayoutInflater.from(this).inflate(R.layout.get_auth_token_view,
null);
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton(R.string.accounts_tester_do_get_auth_token, builder.setPositiveButton(R.string.accounts_tester_ok_button,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
EditText value = (EditText) view.findViewById( EditText value = (EditText) view.findViewById(
@@ -278,9 +290,12 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
String authTokenType = value.getText().toString(); String authTokenType = value.getText().toString();
final Account account = mLongPressedAccount; final Account account = mLongPressedAccount;
if (id == GET_AUTH_TOKEN_DIALOG_ID) { if (id == GET_AUTH_TOKEN_DIALOG_ID) {
mAccountManager.getAuthToken(account, authTokenType, mAccountManager.getAuthToken(account,
null /* loginOptions */, AccountsTester.this, authTokenType,
new CallbackToDialog(AccountsTester.this, "get auth token"), null /* loginOptions */,
AccountsTester.this,
new CallbackToDialog(AccountsTester.this,
"get auth token"),
null /* handler */); null /* handler */);
} else if (id == INVALIDATE_AUTH_TOKEN_DIALOG_ID) { } else if (id == INVALIDATE_AUTH_TOKEN_DIALOG_ID) {
mAccountManager.getAuthToken(account, authTokenType, false, mAccountManager.getAuthToken(account, authTokenType, false,
@@ -302,11 +317,48 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
builder.setView(view); builder.setView(view);
return builder.create(); return builder.create();
} }
if (id == MESSAGE_DIALOG_ID) {
case GET_AUTH_TOKEN_BY_TYPE_AND_FEATURE_DIALOG_ID: {
final View view = LayoutInflater.from(this).inflate(R.layout.get_features_view,
null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setPositiveButton(R.string.accounts_tester_ok_button,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
EditText value = (EditText) view.findViewById(
R.id.accounts_tester_auth_token_type);
String authTokenType = value.getText().toString();
value = (EditText) view.findViewById(
R.id.accounts_tester_features);
String features = value.getText().toString();
final Account account = mLongPressedAccount;
mAccountManager.getAuthTokenByFeatures(
getSelectedAuthenticator().type,
authTokenType,
TextUtils.isEmpty(features) ? null : features.split(" "),
AccountsTester.this,
null /* addAccountOptions */,
null /* getAuthTokenOptions */,
new CallbackToDialog(AccountsTester.this,
"get auth token by features"),
null /* handler */);
}
});
builder.setView(view);
return builder.create();
}
case MESSAGE_DIALOG_ID: {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(mDialogMessage); builder.setMessage(mDialogMessage);
return builder.create(); return builder.create();
} }
}
return super.onCreateDialog(id); return super.onCreateDialog(id);
} }
@@ -344,7 +396,8 @@ public class AccountsTester extends Activity implements OnAccountsUpdateListener
} }
} }
AccountManagerCallback<Bundle> newAuthTokensCallback(String type, String authTokenType, String[] features) { AccountManagerCallback<Bundle> newAuthTokensCallback(String type, String authTokenType,
String[] features) {
return new GetAuthTokenCallback(type, authTokenType, features); return new GetAuthTokenCallback(type, authTokenType, features);
} }