diff options
author | Steve Kondik <shade@chemlab.org> | 2011-08-23 07:43:33 +0400 |
---|---|---|
committer | Gerrit Code Review <gerrit@review.cyanogenmod.com> | 2011-08-23 07:43:33 +0400 |
commit | 446687ad02d00e00e578deff6c2ca97a0595daeb (patch) | |
tree | 3aaa9cd1b55c5a0cfeaefc195ec8da2a583a4ea4 | |
parent | 7f0f4f287b5a78b662ee7bb2d5f2763def0ad38a (diff) | |
parent | b7ae5c9cd36890255200950b446721ba672dfaea (diff) | |
download | packages_apps_Contacts-446687ad02d00e00e578deff6c2ca97a0595daeb.tar.gz packages_apps_Contacts-446687ad02d00e00e578deff6c2ca97a0595daeb.tar.bz2 packages_apps_Contacts-446687ad02d00e00e578deff6c2ca97a0595daeb.zip |
Merge "Allow editing of contact birthdays also for Exchange contacts." into gingerbread
-rw-r--r-- | res/values-de/strings.xml | 1 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | src/com/android/contacts/model/ExchangeSource.java | 26 | ||||
-rw-r--r-- | src/com/android/contacts/model/FallbackSource.java | 60 |
4 files changed, 79 insertions, 11 deletions
diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 44112f810..511125b01 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -84,6 +84,7 @@ <string name="label_sip_address" msgid="124073911714324974">"Internetanruf"</string> <string name="label_ringtone" msgid="8833166825330686244">"Klingelton"</string> <string name="label_date">Datum</string> + <string name="button_clear_date">Entfernen</string> <string name="ghostData_name" msgid="6490954238641157585">"Vor- und Nachname"</string> <string name="ghostData_phonetic_name" msgid="7852749081984070902">"Phonetischer Name"</string> <string name="ghostData_company" msgid="5414421120553765775">"Unternehmen"</string> diff --git a/res/values/strings.xml b/res/values/strings.xml index 76bd9803f..c3a8deaa8 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1119,6 +1119,9 @@ <!-- Field title for the date for an event --> <string name="label_date">Date</string> + <!-- Title of clear button in date picker --> + <string name="button_clear_date">Clear</string> + <!-- String describing which account type a contact came from when editing it --> <string name="account_type_format"><xliff:g id="source" example="Gmail">%1$s</xliff:g> contact</string> diff --git a/src/com/android/contacts/model/ExchangeSource.java b/src/com/android/contacts/model/ExchangeSource.java index 3f2ab6c34..579b7e0f1 100644 --- a/src/com/android/contacts/model/ExchangeSource.java +++ b/src/com/android/contacts/model/ExchangeSource.java @@ -22,6 +22,7 @@ import com.google.android.collect.Lists; import android.content.ContentValues; import android.content.Context; import android.provider.ContactsContract.CommonDataKinds.Email; +import android.provider.ContactsContract.CommonDataKinds.Event; import android.provider.ContactsContract.CommonDataKinds.Im; import android.provider.ContactsContract.CommonDataKinds.Nickname; import android.provider.ContactsContract.CommonDataKinds.Note; @@ -57,6 +58,7 @@ public class ExchangeSource extends FallbackSource { inflatePhoto(context, inflateLevel); inflateNote(context, inflateLevel); inflateWebsite(context, inflateLevel); + inflateEvent(context, inflateLevel); setInflatedLevel(inflateLevel); } @@ -305,6 +307,30 @@ public class ExchangeSource extends FallbackSource { } @Override + protected DataKind inflateEvent(Context context, int inflateLevel) { + final DataKind kind = super.inflateEvent(context, ContactsSource.LEVEL_MIMETYPES); + + if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) { + kind.isList = false; + + kind.defaultValues = new ContentValues(); + kind.defaultValues.put(Event.TYPE, Event.TYPE_BIRTHDAY); + + /* + * The normal title is 'Event', but the Exchange sync adapter + * only supports birthdays, so make that clear from the + * title. + */ + kind.titleRes = com.android.internal.R.string.eventTypeBirthday; + + kind.fieldList = Lists.newArrayList(); + kind.fieldList.add(new EventDateEditField(true)); + } + + return kind; + } + + @Override public int getHeaderColor(Context context) { return 0xffd5ba96; } diff --git a/src/com/android/contacts/model/FallbackSource.java b/src/com/android/contacts/model/FallbackSource.java index cb604e80b..4751f8279 100644 --- a/src/com/android/contacts/model/FallbackSource.java +++ b/src/com/android/contacts/model/FallbackSource.java @@ -22,6 +22,7 @@ import com.google.android.collect.Lists; import android.app.DatePickerDialog; import android.content.ContentValues; import android.content.Context; +import android.content.DialogInterface; import android.content.res.Resources; import android.database.Cursor; import android.provider.ContactsContract.CommonDataKinds.BaseTypes; @@ -48,6 +49,7 @@ import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Locale; +import java.util.TimeZone; public class FallbackSource extends ContactsSource { protected static final int FLAGS_PHONE = EditorInfo.TYPE_CLASS_PHONE; @@ -465,7 +467,7 @@ public class FallbackSource extends ContactsSource { kind.typeList.add(buildEventType(Event.TYPE_OTHER)); kind.fieldList = Lists.newArrayList(); - kind.fieldList.add(new EventDateEditField()); + kind.fieldList.add(new EventDateEditField(false)); } return kind; @@ -733,8 +735,6 @@ public class FallbackSource extends ContactsSource { } public static class EventDateInflater extends SimpleInflater { - private static SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd"); - public EventDateInflater() { super(Event.START_DATE); } @@ -763,14 +763,39 @@ public class FallbackSource extends ContactsSource { } private static class EventDateConverter { - private static SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd"); + private static SimpleDateFormat sDateFormat = + new SimpleDateFormat("yyyy-MM-dd", Locale.US); + private static SimpleDateFormat sFullDateFormat = + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US); public static Date parseDateFromDb(CharSequence value) { - if (value != null) { - try { - return sDateFormat.parse(value.toString()); - } catch (ParseException e) { - } + if (value == null) { + return null; + } + + String valueString = value.toString(); + + /* + * Try the most comprehensive format first. + * Some servers (e.g. Exchange) use 'Z' as timezone, indicating + * that the time is in UTC. The SimpleDateFormat routines don't + * support that format, so replace 'Z' by 'GMT'. + * Also make sure to reset the format time zone back to default + * in case it was changed by a previous run. + */ + sFullDateFormat.setTimeZone(TimeZone.getDefault()); + Date date = parseDate(valueString.replace("Z", "GMT"), sFullDateFormat); + if (date != null) { + return date; + } + + return parseDate(valueString, sDateFormat); + } + + private static Date parseDate(String value, SimpleDateFormat format) { + try { + return format.parse(value); + } catch (ParseException e) { } return null; } @@ -780,12 +805,14 @@ public class FallbackSource extends ContactsSource { } } - private static class EventDateEditField extends EditField { + protected static class EventDateEditField extends EditField { private View.OnClickListener mListener; + private boolean mAllowClear; - public EventDateEditField() { + public EventDateEditField(boolean allowClear) { super(Event.START_DATE, R.string.label_date, FLAGS_DATE); + mAllowClear = allowClear; mListener = new View.OnClickListener() { @Override public void onClick(View v) { @@ -821,6 +848,17 @@ public class FallbackSource extends ContactsSource { cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); + + if (mAllowClear) { + dp.setButton3(context.getString(R.string.button_clear_date), + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + edit.setText(null); + } + }); + } + dp.show(); } |