Update headers when accounts are changed.

Also pass an account to authenticator settings to avoid Email settings crash.

Bug: 6610990
Change-Id: I42884619728dd97446de65cc77e1729f3e143efa
This commit is contained in:
Amith Yamasani
2012-06-05 13:20:45 -07:00
parent 9050451649
commit 56821dbeaa
2 changed files with 21 additions and 1 deletions

View File

@@ -26,6 +26,9 @@ import com.android.settings.deviceinfo.Memory;
import com.android.settings.fuelgauge.PowerUsageSummary;
import com.android.settings.wifi.WifiEnabler;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -64,7 +67,8 @@ import java.util.List;
/**
* Top-level settings activity to handle single pane and double pane UI layout.
*/
public class Settings extends PreferenceActivity implements ButtonBarHandler {
public class Settings extends PreferenceActivity
implements ButtonBarHandler, OnAccountsUpdateListener {
private static final String LOG_TAG = "Settings";
private static final String META_DATA_KEY_HEADER_ID =
@@ -183,6 +187,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
ListAdapter listAdapter = getListAdapter();
if (listAdapter instanceof HeaderAdapter) {
((HeaderAdapter) listAdapter).resume();
AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
}
}
@@ -193,6 +198,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
ListAdapter listAdapter = getListAdapter();
if (listAdapter instanceof HeaderAdapter) {
((HeaderAdapter) listAdapter).pause();
AccountManager.get(this).removeOnAccountsUpdatedListener(this);
}
}
@@ -711,6 +717,12 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
super.setListAdapter(new HeaderAdapter(this, mHeaders, mAuthenticatorHelper));
}
@Override
public void onAccountsUpdated(Account[] accounts) {
mAuthenticatorHelper.onAccountsUpdated(this, accounts);
invalidateHeaders();
}
/*
* Settings subclasses for launching independently.
*/

View File

@@ -60,6 +60,7 @@ import java.util.HashSet;
public class ManageAccountsSettings extends AccountPreferenceBase
implements OnAccountsUpdateListener {
private static final String ACCOUNT_KEY = "account"; // to pass to auth settings
public static final String KEY_ACCOUNT_TYPE = "account_type";
public static final String KEY_ACCOUNT_LABEL = "account_label";
@@ -74,6 +75,8 @@ public class ManageAccountsSettings extends AccountPreferenceBase
private SettingsDialogFragment mDialogFragment;
// If an account type is set, then show only accounts of that type
private String mAccountType;
// Temporary hack, to deal with backward compatibility
private Account mFirstAccount;
@Override
public void onCreate(Bundle icicle) {
@@ -299,6 +302,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase
public void onAccountsUpdated(Account[] accounts) {
if (getActivity() == null) return;
getPreferenceScreen().removeAll();
mFirstAccount = null;
addPreferencesFromResource(R.xml.manage_accounts_settings);
for (int i = 0, n = accounts.length; i < n; i++) {
final Account account = accounts[i];
@@ -322,6 +326,9 @@ public class ManageAccountsSettings extends AccountPreferenceBase
final AccountPreference preference =
new AccountPreference(getActivity(), account, icon, auths);
getPreferenceScreen().addPreference(preference);
if (mFirstAccount == null) {
mFirstAccount = account;
}
}
}
if (mAccountType != null) {
@@ -347,6 +354,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase
prefs.removePreference(prefs.getPreference(i));
continue;
} else {
intent.putExtra(ACCOUNT_KEY, mFirstAccount);
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
}
}