diff --git a/src/com/android/email/activity/setup/AccountSettingsFragment.java b/src/com/android/email/activity/setup/AccountSettingsFragment.java index 26327ad1e..adbf88970 100644 --- a/src/com/android/email/activity/setup/AccountSettingsFragment.java +++ b/src/com/android/email/activity/setup/AccountSettingsFragment.java @@ -68,7 +68,7 @@ public class AccountSettingsFragment extends PreferenceFragment { private static final String BUNDLE_KEY_ACCOUNT_ID = "AccountSettingsFragment.AccountId"; private static final String PREFERENCE_CATEGORY_TOP = "account_settings"; - private static final String PREFERENCE_DESCRIPTION = "account_description"; + public static final String PREFERENCE_DESCRIPTION = "account_description"; private static final String PREFERENCE_NAME = "account_name"; private static final String PREFERENCE_SIGNATURE = "account_signature"; private static final String PREFERENCE_FREQUENCY = "account_check_frequency"; @@ -122,6 +122,7 @@ public class AccountSettingsFragment extends PreferenceFragment { * Callback interface that owning activities must provide */ public interface Callback { + public void onSettingsChanged(Account account, String preference, Object value); public void onIncomingSettings(Account account); public void onOutgoingSettings(Account account); public void abandonEdit(); @@ -130,10 +131,11 @@ public class AccountSettingsFragment extends PreferenceFragment { private static class EmptyCallback implements Callback { public static final Callback INSTANCE = new EmptyCallback(); - @Override public void onIncomingSettings(Account account) { } - @Override public void onOutgoingSettings(Account account) { } - @Override public void abandonEdit() { } - @Override public void deleteAccount(Account account) { } + @Override public void onSettingsChanged(Account account, String preference, Object value) {} + @Override public void onIncomingSettings(Account account) {} + @Override public void onOutgoingSettings(Account account) {} + @Override public void abandonEdit() {} + @Override public void deleteAccount(Account account) {} } /** @@ -372,7 +374,7 @@ public class AccountSettingsFragment extends PreferenceFragment { } mAccountDescription.setSummary(summary); mAccountDescription.setText(summary); - onPreferenceChanged(); + onPreferenceChanged(PREFERENCE_DESCRIPTION, summary); return false; } } @@ -387,7 +389,7 @@ public class AccountSettingsFragment extends PreferenceFragment { if (!TextUtils.isEmpty(summary)) { mAccountName.setSummary(summary); mAccountName.setText(summary); - onPreferenceChanged(); + onPreferenceChanged(PREFERENCE_NAME, summary); } return false; } @@ -407,7 +409,7 @@ public class AccountSettingsFragment extends PreferenceFragment { signature = ""; } mAccountSignature.setText(signature); - onPreferenceChanged(); + onPreferenceChanged(PREFERENCE_SIGNATURE, signature); return false; } }); @@ -430,7 +432,7 @@ public class AccountSettingsFragment extends PreferenceFragment { int index = mCheckFrequency.findIndexOfValue(summary); mCheckFrequency.setSummary(mCheckFrequency.getEntries()[index]); mCheckFrequency.setValue(summary); - onPreferenceChanged(); + onPreferenceChanged(PREFERENCE_FREQUENCY, newValue); return false; } }); @@ -451,7 +453,7 @@ public class AccountSettingsFragment extends PreferenceFragment { int index = mSyncWindow.findIndexOfValue(summary); mSyncWindow.setSummary(mSyncWindow.getEntries()[index]); mSyncWindow.setValue(summary); - onPreferenceChanged(); + onPreferenceChanged(preference.getKey(), newValue); return false; } }); @@ -584,7 +586,7 @@ public class AccountSettingsFragment extends PreferenceFragment { private Preference.OnPreferenceChangeListener mPreferenceChangeListener = new Preference.OnPreferenceChangeListener() { public boolean onPreferenceChange(Preference preference, Object newValue) { - onPreferenceChanged(); + onPreferenceChanged(preference.getKey(), newValue); return true; } }; @@ -592,7 +594,8 @@ public class AccountSettingsFragment extends PreferenceFragment { /** * Called any time a preference is changed. */ - private void onPreferenceChanged() { + private void onPreferenceChanged(String preference, Object value) { + mCallback.onSettingsChanged(mAccount, preference, value); mSaveOnExit = true; } diff --git a/src/com/android/email/activity/setup/AccountSettingsXL.java b/src/com/android/email/activity/setup/AccountSettingsXL.java index 6ea1fb44e..1a450454a 100644 --- a/src/com/android/email/activity/setup/AccountSettingsXL.java +++ b/src/com/android/email/activity/setup/AccountSettingsXL.java @@ -94,7 +94,6 @@ public class AccountSettingsXL extends PreferenceActivity { private Header mRequestedAccountHeader; private Header[] mAccountListHeaders; private Header mAppPreferencesHeader; - private int mCurrentHeaderPosition; /* package */ Fragment mCurrentFragment; private long mDeletingAccountId = -1; private boolean mShowDebugMenu; @@ -474,7 +473,6 @@ public class AccountSettingsXL extends PreferenceActivity { } // Process header click normally - mCurrentHeaderPosition = position; super.onHeaderClick(header, position); } @@ -484,7 +482,6 @@ public class AccountSettingsXL extends PreferenceActivity { * with a dialog, and the user OK'd it. */ private void forceSwitchHeader(int position) { - mCurrentHeaderPosition = position; // Clear the current fragment; we're navigating away mCurrentFragment = null; // Ensure the UI visually shows the correct header selected @@ -526,6 +523,9 @@ public class AccountSettingsXL extends PreferenceActivity { * Callbacks for AccountSettingsFragment */ private class AccountSettingsFragmentCallback implements AccountSettingsFragment.Callback { + public void onSettingsChanged(Account account, String preference, Object value) { + AccountSettingsXL.this.onSettingsChanged(account, preference, value); + } public void onIncomingSettings(Account account) { AccountSettingsXL.this.onIncomingSettings(account); } @@ -570,6 +570,23 @@ public class AccountSettingsXL extends PreferenceActivity { } } + /** + * Some of the settings have changed. Update internal state as necessary. + */ + public void onSettingsChanged(Account account, String preference, Object value) { + if (AccountSettingsFragment.PREFERENCE_DESCRIPTION.equals(preference)) { + for (Header header : mAccountListHeaders) { + if (header.id == account.mId) { + // Manually tweak the header title. We cannot rebuild the header list from + // an account cursor as the account database has not been saved yet. + header.title = value.toString(); + invalidateHeaders(); + break; + } + } + } + } + /** * Dispatch to edit incoming settings. *