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:
@@ -26,6 +26,9 @@ import com.android.settings.deviceinfo.Memory;
|
|||||||
import com.android.settings.fuelgauge.PowerUsageSummary;
|
import com.android.settings.fuelgauge.PowerUsageSummary;
|
||||||
import com.android.settings.wifi.WifiEnabler;
|
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.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
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.
|
* 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 LOG_TAG = "Settings";
|
||||||
private static final String META_DATA_KEY_HEADER_ID =
|
private static final String META_DATA_KEY_HEADER_ID =
|
||||||
@@ -183,6 +187,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
|
|||||||
ListAdapter listAdapter = getListAdapter();
|
ListAdapter listAdapter = getListAdapter();
|
||||||
if (listAdapter instanceof HeaderAdapter) {
|
if (listAdapter instanceof HeaderAdapter) {
|
||||||
((HeaderAdapter) listAdapter).resume();
|
((HeaderAdapter) listAdapter).resume();
|
||||||
|
AccountManager.get(this).addOnAccountsUpdatedListener(this, null, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +198,7 @@ public class Settings extends PreferenceActivity implements ButtonBarHandler {
|
|||||||
ListAdapter listAdapter = getListAdapter();
|
ListAdapter listAdapter = getListAdapter();
|
||||||
if (listAdapter instanceof HeaderAdapter) {
|
if (listAdapter instanceof HeaderAdapter) {
|
||||||
((HeaderAdapter) listAdapter).pause();
|
((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));
|
super.setListAdapter(new HeaderAdapter(this, mHeaders, mAuthenticatorHelper));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAccountsUpdated(Account[] accounts) {
|
||||||
|
mAuthenticatorHelper.onAccountsUpdated(this, accounts);
|
||||||
|
invalidateHeaders();
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Settings subclasses for launching independently.
|
* Settings subclasses for launching independently.
|
||||||
*/
|
*/
|
||||||
|
@@ -60,6 +60,7 @@ import java.util.HashSet;
|
|||||||
public class ManageAccountsSettings extends AccountPreferenceBase
|
public class ManageAccountsSettings extends AccountPreferenceBase
|
||||||
implements OnAccountsUpdateListener {
|
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_TYPE = "account_type";
|
||||||
public static final String KEY_ACCOUNT_LABEL = "account_label";
|
public static final String KEY_ACCOUNT_LABEL = "account_label";
|
||||||
|
|
||||||
@@ -74,6 +75,8 @@ public class ManageAccountsSettings extends AccountPreferenceBase
|
|||||||
private SettingsDialogFragment mDialogFragment;
|
private SettingsDialogFragment mDialogFragment;
|
||||||
// If an account type is set, then show only accounts of that type
|
// If an account type is set, then show only accounts of that type
|
||||||
private String mAccountType;
|
private String mAccountType;
|
||||||
|
// Temporary hack, to deal with backward compatibility
|
||||||
|
private Account mFirstAccount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -299,6 +302,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase
|
|||||||
public void onAccountsUpdated(Account[] accounts) {
|
public void onAccountsUpdated(Account[] accounts) {
|
||||||
if (getActivity() == null) return;
|
if (getActivity() == null) return;
|
||||||
getPreferenceScreen().removeAll();
|
getPreferenceScreen().removeAll();
|
||||||
|
mFirstAccount = null;
|
||||||
addPreferencesFromResource(R.xml.manage_accounts_settings);
|
addPreferencesFromResource(R.xml.manage_accounts_settings);
|
||||||
for (int i = 0, n = accounts.length; i < n; i++) {
|
for (int i = 0, n = accounts.length; i < n; i++) {
|
||||||
final Account account = accounts[i];
|
final Account account = accounts[i];
|
||||||
@@ -322,6 +326,9 @@ public class ManageAccountsSettings extends AccountPreferenceBase
|
|||||||
final AccountPreference preference =
|
final AccountPreference preference =
|
||||||
new AccountPreference(getActivity(), account, icon, auths);
|
new AccountPreference(getActivity(), account, icon, auths);
|
||||||
getPreferenceScreen().addPreference(preference);
|
getPreferenceScreen().addPreference(preference);
|
||||||
|
if (mFirstAccount == null) {
|
||||||
|
mFirstAccount = account;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mAccountType != null) {
|
if (mAccountType != null) {
|
||||||
@@ -347,6 +354,7 @@ public class ManageAccountsSettings extends AccountPreferenceBase
|
|||||||
prefs.removePreference(prefs.getPreference(i));
|
prefs.removePreference(prefs.getPreference(i));
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
|
intent.putExtra(ACCOUNT_KEY, mFirstAccount);
|
||||||
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user