am 75e508a7: Merge "Cleanup account name, user name, and summary" into honeycomb

* commit '75e508a794a61a1f96ff30f8833f00c0e05bd379':
  Cleanup account name, user name, and summary
This commit is contained in:
Andy Stadler 2011-01-20 11:42:08 -08:00 committed by Android Git Automerger
commit eb7913fa28
4 changed files with 44 additions and 20 deletions

View File

@ -515,6 +515,8 @@ save attachment.</string>
<!-- On "Set up email" screen, label of text field --> <!-- On "Set up email" screen, label of text field -->
<string name="account_setup_names_user_name_label"> <string name="account_setup_names_user_name_label">
Your name (displayed on outgoing messages)</string> Your name (displayed on outgoing messages)</string>
<!-- On "Set up email" screen, error pop-up when user_name field is empty [CHAR LIMIT=none] -->
<string name="account_setup_names_user_name_empty_error">This field cannot be blank</string>
<!-- Activity Title for the account type selector (IMAP or POP3 or EAS) [CHAR LIMIT=45] --> <!-- Activity Title for the account type selector (IMAP or POP3 or EAS) [CHAR LIMIT=45] -->
<string name="account_setup_account_type_title">Account setup</string> <string name="account_setup_account_type_title">Account setup</string>

View File

@ -24,21 +24,24 @@
android:order="1" android:order="1"
android:title="@string/account_settings_description_label" android:title="@string/account_settings_description_label"
android:summary="" android:summary=""
android:dialogTitle="@string/account_settings_description_label" /> android:dialogTitle="@string/account_settings_description_label"
android:inputType="textCapWords" />
<EditTextPreference <EditTextPreference
android:key="account_name" android:key="account_name"
android:order="2" android:order="2"
android:title="@string/account_settings_name_label" android:title="@string/account_settings_name_label"
android:summary="" android:summary=""
android:dialogTitle="@string/account_settings_name_label" /> android:dialogTitle="@string/account_settings_name_label"
android:inputType="textPersonName|textCapWords" />
<EditTextPreference <EditTextPreference
android:key="account_signature" android:key="account_signature"
android:order="3" android:order="3"
android:title="@string/account_settings_signature_label" android:title="@string/account_settings_signature_label"
android:summary="" android:summary="@string/account_settings_signature_hint"
android:dialogTitle="@string/account_settings_signature_label" /> android:dialogTitle="@string/account_settings_signature_label"
android:inputType="textCapSentences" />
<ListPreference <ListPreference
android:key="account_check_frequency" android:key="account_check_frequency"

View File

@ -49,6 +49,7 @@ import android.preference.PreferenceFragment;
import android.preference.RingtonePreference; import android.preference.RingtonePreference;
import android.provider.Calendar; import android.provider.Calendar;
import android.provider.ContactsContract; import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.Log; import android.util.Log;
/** /**
@ -363,7 +364,10 @@ public class AccountSettingsFragment extends PreferenceFragment {
mAccountDescription.setOnPreferenceChangeListener( mAccountDescription.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() { new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString(); String summary = newValue.toString().trim();
if (TextUtils.isEmpty(summary)) {
summary = mAccount.mEmailAddress;
}
mAccountDescription.setSummary(summary); mAccountDescription.setSummary(summary);
mAccountDescription.setText(summary); mAccountDescription.setText(summary);
onPreferenceChanged(); onPreferenceChanged();
@ -377,22 +381,27 @@ public class AccountSettingsFragment extends PreferenceFragment {
mAccountName.setText(mAccount.getSenderName()); mAccountName.setText(mAccount.getSenderName());
mAccountName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { mAccountName.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
final String summary = newValue.toString(); final String summary = newValue.toString().trim();
mAccountName.setSummary(summary); if (!TextUtils.isEmpty(summary)) {
mAccountName.setText(summary); mAccountName.setSummary(summary);
onPreferenceChanged(); mAccountName.setText(summary);
onPreferenceChanged();
}
return false; return false;
} }
}); });
mAccountSignature = (EditTextPreference) findPreference(PREFERENCE_SIGNATURE); mAccountSignature = (EditTextPreference) findPreference(PREFERENCE_SIGNATURE);
mAccountSignature.setSummary(mAccount.getSignature()); String signature = mAccount.getSignature();
if (!TextUtils.isEmpty(signature)) {
mAccountSignature.setSummary(mAccount.getSignature());
}
mAccountSignature.setText(mAccount.getSignature()); mAccountSignature.setText(mAccount.getSignature());
mAccountSignature.setOnPreferenceChangeListener( mAccountSignature.setOnPreferenceChangeListener(
new Preference.OnPreferenceChangeListener() { new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
String summary = newValue.toString(); String summary = newValue.toString().trim();
if (summary == null || summary.length() == 0) { if (TextUtils.isEmpty(summary)) {
mAccountSignature.setSummary(R.string.account_settings_signature_hint); mAccountSignature.setSummary(R.string.account_settings_signature_hint);
} else { } else {
mAccountSignature.setSummary(summary); mAccountSignature.setSummary(summary);
@ -601,8 +610,10 @@ public class AccountSettingsFragment extends PreferenceFragment {
newFlags |= mAccountBackgroundAttachments.isChecked() ? newFlags |= mAccountBackgroundAttachments.isChecked() ?
Account.FLAGS_BACKGROUND_ATTACHMENTS : 0; Account.FLAGS_BACKGROUND_ATTACHMENTS : 0;
mAccount.setDefaultAccount(mAccountDefault.isChecked()); mAccount.setDefaultAccount(mAccountDefault.isChecked());
mAccount.setDisplayName(mAccountDescription.getText()); // If the display name has been cleared, we'll reset it to the default value (email addr)
mAccount.setSenderName(mAccountName.getText()); mAccount.setDisplayName(mAccountDescription.getText().trim());
// The sender name must never be empty (this is enforced by the preference editor)
mAccount.setSenderName(mAccountName.getText().trim());
mAccount.setSignature(mAccountSignature.getText()); mAccount.setSignature(mAccountSignature.getText());
newFlags |= mAccountNotify.isChecked() ? Account.FLAGS_NOTIFY_NEW_MAIL : 0; newFlags |= mAccountNotify.isChecked() ? Account.FLAGS_NOTIFY_NEW_MAIL : 0;
mAccount.setSyncInterval(Integer.parseInt(mCheckFrequency.getValue())); mAccount.setSyncInterval(Integer.parseInt(mCheckFrequency.getValue()));

View File

@ -31,6 +31,7 @@ import android.content.Intent;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.TextKeyListener; import android.text.method.TextKeyListener;
import android.text.method.TextKeyListener.Capitalize; import android.text.method.TextKeyListener.Capitalize;
@ -41,8 +42,6 @@ import android.widget.EditText;
/** /**
* Final screen of setup process. Collect account nickname and/or username. * Final screen of setup process. Collect account nickname and/or username.
*
* TODO: Better processing of account nickname including trimming and prevention of empty string.
*/ */
public class AccountSetupNames extends AccountSetupActivity implements OnClickListener { public class AccountSetupNames extends AccountSetupActivity implements OnClickListener {
private static final int REQUEST_SECURITY = 0; private static final int REQUEST_SECURITY = 0;
@ -136,7 +135,15 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
* Check input fields for legal values and enable/disable next button * Check input fields for legal values and enable/disable next button
*/ */
private void validateFields() { private void validateFields() {
boolean newEnabled = mEasAccount || Utility.isTextViewNotEmpty(mName); boolean newEnabled = true;
// Validation is based only on the "user name" field, not shown for EAS accounts
if (!mEasAccount) {
String userName = mName.getText().toString().trim();
newEnabled = !TextUtils.isEmpty(userName);
if (!newEnabled) {
mName.setError(getString(R.string.account_setup_names_user_name_empty_error));
}
}
mNextButton.setEnabled(newEnabled); mNextButton.setEnabled(newEnabled);
} }
@ -173,10 +180,11 @@ public class AccountSetupNames extends AccountSetupActivity implements OnClickLi
private void onNext() { private void onNext() {
// Update account object from UI // Update account object from UI
Account account = SetupData.getAccount(); Account account = SetupData.getAccount();
if (Utility.isTextViewNotEmpty(mDescription)) { String description = mDescription.getText().toString().trim();
account.setDisplayName(mDescription.getText().toString()); if (!TextUtils.isEmpty(description)) {
account.setDisplayName(description);
} }
account.setSenderName(mName.getText().toString()); account.setSenderName(mName.getText().toString().trim());
// Launch async task for final commit work // Launch async task for final commit work
new FinalSetupTask(account).execute(); new FinalSetupTask(account).execute();