am 767ea863: Merge change 25344 into eclair

Merge commit '767ea863986c1d03332ca43591106510de0c8725' into eclair-plus-aosp

* commit '767ea863986c1d03332ca43591106510de0c8725':
  Add "Sync Contacts" to Account preferences screen (part of #2106733)
This commit is contained in:
Marc Blank 2009-09-17 08:42:01 -07:00 committed by Android Git Automerger
commit a380b1a2e8
3 changed files with 72 additions and 21 deletions

View File

@ -399,7 +399,7 @@
<string name="account_setup_options_default_label">Send email from this account by default.</string>
<!-- In Account setup options & Account Settings screens, check box for new-mail notification -->
<string name="account_setup_options_notify_label">Notify me when email arrives.</string>
<!-- In Account setup options & Account Settings screens, optional check box to also sync contacts -->
<!-- In Account setup options screen, optional check box to also sync contacts -->
<string name="account_setup_options_sync_contacts_label">Sync contacts from this account.</string>
<!-- Dialog title when "setup" could not finish -->
<string name="account_setup_failed_dlg_title">Setup could not finish</string>
@ -469,6 +469,12 @@
<string name="account_settings_name_label">Your name</string>
<!-- On Settings screen, section heading -->
<string name="account_settings_notifications">Notification settings</string>
<!-- On settings screen, sync contacts check box label -->
<string name="account_settings_sync_contacts_enable">Sync contacts</string>
<!-- On settings screen, sync contacts summary text -->
<string name="account_settings_sync_contacts_summary">Also sync contacts from this account</string>
<!-- On Settings screen, setting check box label -->
<string name="account_settings_vibrate_enable">Vibrate</string>
<!-- On Settings screen, setting summary text -->

View File

@ -89,6 +89,13 @@
android:key="outgoing"
android:title="@string/account_settings_outgoing_label" />
<CheckBoxPreference
android:layout="?android:attr/preferenceLayoutChild"
android:key="account_sync_contacts"
android:defaultValue="true"
android:title="@string/account_settings_sync_contacts_enable"
android:summary="@string/account_settings_sync_contacts_summary" />
<PreferenceScreen
android:key="add_account"
android:title="@string/account_settings_add_account_label" />

View File

@ -23,8 +23,10 @@ import com.android.email.mail.Sender;
import com.android.email.mail.Store;
import com.android.email.provider.EmailContent.Account;
import com.android.email.provider.EmailContent.HostAuth;
import com.android.exchange.Eas;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -35,6 +37,7 @@ import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.RingtonePreference;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.KeyEvent;
@ -53,6 +56,7 @@ public class AccountSettings extends PreferenceActivity {
private static final String PREFERENCE_INCOMING = "incoming";
private static final String PREFERENCE_OUTGOING = "outgoing";
private static final String PREFERENCE_ADD_ACCOUNT = "add_account";
private static final String PREFERENCE_SYNC_CONTACTS = "account_sync_contacts";
private long mAccountId;
private Account mAccount;
@ -66,6 +70,7 @@ public class AccountSettings extends PreferenceActivity {
private CheckBoxPreference mAccountNotify;
private CheckBoxPreference mAccountVibrate;
private RingtonePreference mAccountRingtone;
private CheckBoxPreference mSyncContacts;
/**
* Display (and edit) settings for a specific account
@ -81,8 +86,18 @@ public class AccountSettings extends PreferenceActivity {
super.onCreate(savedInstanceState);
Intent i = getIntent();
mAccountId = getIntent().getLongExtra(EXTRA_ACCOUNT_ID, -1);
mAccountId = i.getLongExtra(EXTRA_ACCOUNT_ID, -1);
mAccount = Account.restoreAccountWithId(this, mAccountId);
if (mAccount == null) {
finish();
return;
}
mAccount.mHostAuthRecv = HostAuth.restoreHostAuthWithId(this, mAccount.mHostAuthKeyRecv);
mAccount.mHostAuthSend = HostAuth.restoreHostAuthWithId(this, mAccount.mHostAuthKeySend);
if (mAccount.mHostAuthRecv == null || mAccount.mHostAuthSend == null) {
finish();
return;
}
mAccountDirty = false;
addPreferencesFromResource(R.xml.account_settings_preferences);
@ -113,9 +128,9 @@ public class AccountSettings extends PreferenceActivity {
return false;
}
});
mCheckFrequency = (ListPreference) findPreference(PREFERENCE_FREQUENCY);
// Before setting value, we may need to adjust the lists
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(mAccount.getStoreUri(this), this);
if (info.mPushSupported) {
@ -134,7 +149,7 @@ public class AccountSettings extends PreferenceActivity {
return false;
}
});
// Add check window preference
mSyncWindow = null;
if (info.mVisibleLimitDefault == -1) {
@ -171,7 +186,7 @@ public class AccountSettings extends PreferenceActivity {
prefs.edit().putString(PREFERENCE_RINGTONE, mAccount.getRingtone()).commit();
mAccountVibrate = (CheckBoxPreference) findPreference(PREFERENCE_VIBRATE);
mAccountVibrate.setChecked(0 !=
mAccountVibrate.setChecked(0 !=
(mAccount.getFlags() & Account.FLAGS_VIBRATE));
findPreference(PREFERENCE_INCOMING).setOnPreferenceClickListener(
@ -207,7 +222,20 @@ public class AccountSettings extends PreferenceActivity {
PREFERENCE_SERVER_CATERGORY);
serverCategory.removePreference(prefOutgoing);
}
mSyncContacts = (CheckBoxPreference) findPreference(PREFERENCE_SYNC_CONTACTS);
if (mAccount.mHostAuthRecv.mProtocol.equals("eas")) {
String login = mAccount.mHostAuthRecv.mLogin;
android.accounts.Account acct =
new android.accounts.Account(login, Eas.ACCOUNT_MANAGER_TYPE);
mSyncContacts.setChecked(ContentResolver
.getSyncAutomatically(acct, ContactsContract.AUTHORITY));
} else {
PreferenceCategory serverCategory = (PreferenceCategory) findPreference(
PREFERENCE_SERVER_CATERGORY);
serverCategory.removePreference(mSyncContacts);
}
findPreference(PREFERENCE_ADD_ACCOUNT).setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
public boolean onPreferenceClick(Preference preference) {
@ -216,39 +244,41 @@ public class AccountSettings extends PreferenceActivity {
}
});
}
@Override
public void onResume() {
super.onResume();
if (mAccountDirty) {
// if we are coming back from editing incoming or outgoing settings,
// if we are coming back from editing incoming or outgoing settings,
// we need to refresh them here so we don't accidentally overwrite the
// old values we're still holding here
mAccount.mHostAuthRecv = HostAuth.restoreHostAuthWithId(
this, mAccount.mHostAuthKeyRecv);
mAccount.mHostAuthSend = HostAuth.restoreHostAuthWithId(
this, mAccount.mHostAuthKeySend);
mAccount.mHostAuthRecv =
HostAuth.restoreHostAuthWithId(this, mAccount.mHostAuthKeyRecv);
mAccount.mHostAuthSend =
HostAuth.restoreHostAuthWithId(this, mAccount.mHostAuthKeySend);
// Because "delete policy" UI is on edit incoming settings, we have
// to refresh that as well.
Account refreshedAccount = Account.restoreAccountWithId(this, mAccount.mId);
if (refreshedAccount == null || mAccount.mHostAuthRecv == null
|| mAccount.mHostAuthSend == null) {
finish();
return;
}
mAccount.setDeletePolicy(refreshedAccount.getDeletePolicy());
mAccountDirty = false;
}
}
private void saveSettings() {
int newFlags = mAccount.getFlags() &
int newFlags = mAccount.getFlags() &
~(Account.FLAGS_NOTIFY_NEW_MAIL | Account.FLAGS_VIBRATE);
mAccount.setDefaultAccount(mAccountDefault.isChecked());
mAccount.setDisplayName(mAccountDescription.getText());
mAccount.setSenderName(mAccountName.getText());
newFlags |= mAccountNotify.isChecked() ? Account.FLAGS_NOTIFY_NEW_MAIL : 0;
mAccount.setSyncInterval(Integer.parseInt(mCheckFrequency.getValue()));
if (mSyncWindow != null)
{
if (mSyncWindow != null) {
mAccount.setSyncLookback(Integer.parseInt(mSyncWindow.getValue()));
}
newFlags |= mAccountVibrate.isChecked() ? Account.FLAGS_VIBRATE : 0;
@ -256,8 +286,16 @@ public class AccountSettings extends PreferenceActivity {
mAccount.setRingtone(prefs.getString(PREFERENCE_RINGTONE, null));
mAccount.setFlags(newFlags);
AccountSettingsUtils.commitSettings(this, mAccount);
Email.setServicesEnabled(this);
if (mAccount.mHostAuthRecv.mProtocol.equals("eas")) {
String login = mAccount.mHostAuthRecv.mLogin;
android.accounts.Account acct =
new android.accounts.Account(login, Eas.ACCOUNT_MANAGER_TYPE);
ContentResolver.setSyncAutomatically(acct, ContactsContract.AUTHORITY,
mSyncContacts.isChecked());
AccountSettingsUtils.commitSettings(this, mAccount);
Email.setServicesEnabled(this);
}
}
@Override