2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.settings.accounts;
19 import android.accounts.AccountManager;
20 import android.accounts.AccountManagerCallback;
21 import android.accounts.AccountManagerFuture;
22 import android.accounts.AuthenticatorException;
23 import android.accounts.OperationCanceledException;
24 import android.app.Activity;
25 import android.content.Intent;
26 import android.os.Bundle;
27 import android.util.Log;
29 import java.io.IOException;
32 * Entry point Actiivty for account setup. Works as follows
34 * 1) When the other Activities launch this Activity, it launches {@link ChooseAccountActivity}
35 * without showing anything.
36 * 2) After receiving an account type from ChooseAccountActivity, this Activity launches the
37 * account setup specified by AccountManager.
38 * 3) After the account setup, this Activity finishes without showing anything.
41 * Previously this Activity did what {@link ChooseAccountActivity} does right now, but we
42 * currently delegate the work to the other Activity. When we let this Activity do that work, users
43 * would see the list of account types when leaving this Activity, since the UI is already ready
44 * when returning from each account setup, which doesn't look good.
46 public class AddAccountSettings extends Activity {
47 private static final String TAG = "AccountSettings";
49 /* package */ static final String EXTRA_SELECTED_ACCOUNT = "selected_account";
51 private static final int CHOOSE_ACCOUNT_REQUEST = 1;
53 private AccountManagerCallback<Bundle> mCallback = new AccountManagerCallback<Bundle>() {
54 public void run(AccountManagerFuture<Bundle> future) {
56 Bundle bundle = future.getResult();
59 if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "account added: " + bundle);
60 } catch (OperationCanceledException e) {
61 if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "addAccount was canceled");
62 } catch (IOException e) {
63 if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "addAccount failed: " + e);
64 } catch (AuthenticatorException e) {
65 if (Log.isLoggable(TAG, Log.VERBOSE)) Log.v(TAG, "addAccount failed: " + e);
73 public void onCreate(Bundle savedInstanceState) {
74 super.onCreate(savedInstanceState);
76 final String[] authorities =
77 getIntent().getStringArrayExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY);
78 final String[] accountTypes =
79 getIntent().getStringArrayExtra(AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY);
80 final Intent intent = new Intent(this, ChooseAccountActivity.class);
81 if (authorities != null) {
82 intent.putExtra(AccountPreferenceBase.AUTHORITIES_FILTER_KEY, authorities);
84 if (accountTypes != null) {
85 intent.putExtra(AccountPreferenceBase.ACCOUNT_TYPES_FILTER_KEY, accountTypes);
87 startActivityForResult(intent, CHOOSE_ACCOUNT_REQUEST);
91 public void onActivityResult(int requestCode, int resultCode, Intent data) {
92 switch (requestCode) {
93 case CHOOSE_ACCOUNT_REQUEST:
94 if (resultCode == RESULT_CANCELED) {
95 setResult(resultCode);
99 // Go to account setup screen. finish() is called inside mCallback.
100 addAccount(data.getStringExtra(EXTRA_SELECTED_ACCOUNT));
105 private void addAccount(String accountType) {
106 AccountManager.get(this).addAccount(
108 null, /* authTokenType */
109 null, /* requiredFeatures */
110 null, /* addAccountOptions */