Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f4e1681d authored by Justin Ho's avatar Justin Ho Committed by Android (Google) Code Review
Browse files

Merge "Update headers when accounts are changed." into jb-dev

parents ab049a19 56821dbe
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -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.
     */
+8 −0
Original line number Diff line number Diff line
@@ -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);
                }
            }