3333import android .widget .TextView ;
3434import com .android .internal .R ;
3535
36- import java .io .IOException ;
3736import java .util .ArrayList ;
3837import java .util .HashMap ;
3938import java .util .HashSet ;
4342/**
4443 * @hide
4544 */
46- public class ChooseAccountTypeActivity extends Activity implements AccountManagerCallback < Bundle > {
45+ public class ChooseAccountTypeActivity extends Activity {
4746 private static final String TAG = "AccountManager" ;
4847
4948 private HashMap <String , AuthInfo > mTypeToAuthenticatorInfo = new HashMap <String , AuthInfo >();
@@ -52,7 +51,6 @@ public class ChooseAccountTypeActivity extends Activity implements AccountManage
5251 @ Override
5352 public void onCreate (Bundle savedInstanceState ) {
5453 super .onCreate (savedInstanceState );
55- setContentView (R .layout .choose_account_type );
5654
5755 // Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
5856 Set <String > setOfAllowableAccountTypes = null ;
@@ -90,10 +88,11 @@ public void onCreate(Bundle savedInstanceState) {
9088 }
9189
9290 if (mAuthenticatorInfosToDisplay .size () == 1 ) {
93- runAddAccountForAuthenticator (mAuthenticatorInfosToDisplay .get (0 ));
91+ setResultAndFinish (mAuthenticatorInfosToDisplay .get (0 ). desc . type );
9492 return ;
9593 }
9694
95+ setContentView (R .layout .choose_account_type );
9796 // Setup the list
9897 ListView list = (ListView ) findViewById (android .R .id .list );
9998 // Use an existing ListAdapter that will map an array of strings to TextViews
@@ -103,11 +102,20 @@ public void onCreate(Bundle savedInstanceState) {
103102 list .setTextFilterEnabled (false );
104103 list .setOnItemClickListener (new AdapterView .OnItemClickListener () {
105104 public void onItemClick (AdapterView <?> parent , View v , int position , long id ) {
106- runAddAccountForAuthenticator (mAuthenticatorInfosToDisplay .get (position ));
105+ setResultAndFinish (mAuthenticatorInfosToDisplay .get (position ). desc . type );
107106 }
108107 });
109108 }
110109
110+ private void setResultAndFinish (final String type ) {
111+ Bundle bundle = new Bundle ();
112+ bundle .putString (AccountManager .KEY_ACCOUNT_TYPE , type );
113+ setResult (Activity .RESULT_OK , new Intent ().putExtras (bundle ));
114+ Log .d (TAG , "ChooseAccountTypeActivity.setResultAndFinish: "
115+ + "selected account type " + type );
116+ finish ();
117+ }
118+
111119 private void buildTypeToAuthDescriptionMap () {
112120 for (AuthenticatorDescription desc : AccountManager .get (this ).getAuthenticatorTypes ()) {
113121 String name = null ;
@@ -136,42 +144,6 @@ private void buildTypeToAuthDescriptionMap() {
136144 }
137145 }
138146
139- protected void runAddAccountForAuthenticator (AuthInfo authInfo ) {
140- Log .d (TAG , "selected account type " + authInfo .name );
141- final Bundle options = getIntent ().getBundleExtra (
142- ChooseTypeAndAccountActivity .EXTRA_ADD_ACCOUNT_OPTIONS_BUNDLE );
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 */ );
149- }
150-
151- public void run (final AccountManagerFuture <Bundle > accountManagerFuture ) {
152- try {
153- Bundle accountManagerResult = accountManagerFuture .getResult ();
154- Bundle bundle = new Bundle ();
155- bundle .putString (AccountManager .KEY_ACCOUNT_NAME ,
156- accountManagerResult .getString (AccountManager .KEY_ACCOUNT_NAME ));
157- bundle .putString (AccountManager .KEY_ACCOUNT_TYPE ,
158- accountManagerResult .getString (AccountManager .KEY_ACCOUNT_TYPE ));
159- setResult (Activity .RESULT_OK , new Intent ().putExtras (bundle ));
160- finish ();
161- return ;
162- } catch (OperationCanceledException e ) {
163- setResult (Activity .RESULT_CANCELED );
164- finish ();
165- return ;
166- } catch (IOException e ) {
167- } catch (AuthenticatorException e ) {
168- }
169- Bundle bundle = new Bundle ();
170- bundle .putString (AccountManager .KEY_ERROR_MESSAGE , "error communicating with server" );
171- setResult (Activity .RESULT_OK , new Intent ().putExtras (bundle ));
172- finish ();
173- }
174-
175147 private static class AuthInfo {
176148 final AuthenticatorDescription desc ;
177149 final String name ;
0 commit comments