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

Commit 446687ad authored by Steve Kondik's avatar Steve Kondik Committed by Gerrit Code Review
Browse files

Merge "Allow editing of contact birthdays also for Exchange contacts." into gingerbread

parents 7f0f4f28 b7ae5c9c
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -84,6 +84,7 @@
    <string name="label_sip_address" msgid="124073911714324974">"Internetanruf"</string>
    <string name="label_sip_address" msgid="124073911714324974">"Internetanruf"</string>
    <string name="label_ringtone" msgid="8833166825330686244">"Klingelton"</string>
    <string name="label_ringtone" msgid="8833166825330686244">"Klingelton"</string>
    <string name="label_date">Datum</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_name" msgid="6490954238641157585">"Vor- und Nachname"</string>
    <string name="ghostData_phonetic_name" msgid="7852749081984070902">"Phonetischer Name"</string>
    <string name="ghostData_phonetic_name" msgid="7852749081984070902">"Phonetischer Name"</string>
    <string name="ghostData_company" msgid="5414421120553765775">"Unternehmen"</string>
    <string name="ghostData_company" msgid="5414421120553765775">"Unternehmen"</string>
+3 −0
Original line number Original line Diff line number Diff line
@@ -1119,6 +1119,9 @@
    <!-- Field title for the date for an event -->
    <!-- Field title for the date for an event -->
    <string name="label_date">Date</string>
    <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 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>
    <string name="account_type_format"><xliff:g id="source" example="Gmail">%1$s</xliff:g> contact</string>


+26 −0
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import com.google.android.collect.Lists;
import android.content.ContentValues;
import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Event;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.provider.ContactsContract.CommonDataKinds.Im;
import android.provider.ContactsContract.CommonDataKinds.Nickname;
import android.provider.ContactsContract.CommonDataKinds.Nickname;
import android.provider.ContactsContract.CommonDataKinds.Note;
import android.provider.ContactsContract.CommonDataKinds.Note;
@@ -57,6 +58,7 @@ public class ExchangeSource extends FallbackSource {
        inflatePhoto(context, inflateLevel);
        inflatePhoto(context, inflateLevel);
        inflateNote(context, inflateLevel);
        inflateNote(context, inflateLevel);
        inflateWebsite(context, inflateLevel);
        inflateWebsite(context, inflateLevel);
        inflateEvent(context, inflateLevel);


        setInflatedLevel(inflateLevel);
        setInflatedLevel(inflateLevel);
    }
    }
@@ -304,6 +306,30 @@ public class ExchangeSource extends FallbackSource {
        return kind;
        return kind;
    }
    }


    @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
    @Override
    public int getHeaderColor(Context context) {
    public int getHeaderColor(Context context) {
        return 0xffd5ba96;
        return 0xffd5ba96;
+49 −11
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import com.google.android.collect.Lists;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog;
import android.content.ContentValues;
import android.content.ContentValues;
import android.content.Context;
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds.BaseTypes;
import android.provider.ContactsContract.CommonDataKinds.BaseTypes;
@@ -48,6 +49,7 @@ import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Calendar;
import java.util.Date;
import java.util.Date;
import java.util.Locale;
import java.util.Locale;
import java.util.TimeZone;


public class FallbackSource extends ContactsSource {
public class FallbackSource extends ContactsSource {
    protected static final int FLAGS_PHONE = EditorInfo.TYPE_CLASS_PHONE;
    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.typeList.add(buildEventType(Event.TYPE_OTHER));


            kind.fieldList = Lists.newArrayList();
            kind.fieldList = Lists.newArrayList();
            kind.fieldList.add(new EventDateEditField());
            kind.fieldList.add(new EventDateEditField(false));
        }
        }


        return kind;
        return kind;
@@ -733,8 +735,6 @@ public class FallbackSource extends ContactsSource {
    }
    }


    public static class EventDateInflater extends SimpleInflater {
    public static class EventDateInflater extends SimpleInflater {
        private static SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");

        public EventDateInflater() {
        public EventDateInflater() {
            super(Event.START_DATE);
            super(Event.START_DATE);
        }
        }
@@ -763,15 +763,40 @@ public class FallbackSource extends ContactsSource {
    }
    }


    private static class EventDateConverter {
    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) {
        public static Date parseDateFromDb(CharSequence value) {
            if (value != null) {
            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 {
            try {
                    return sDateFormat.parse(value.toString());
                return format.parse(value);
            } catch (ParseException e) {
            } catch (ParseException e) {
            }
            }
            }
            return null;
            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 View.OnClickListener mListener;
        private boolean mAllowClear;


        public EventDateEditField() {
        public EventDateEditField(boolean allowClear) {
            super(Event.START_DATE, R.string.label_date, FLAGS_DATE);
            super(Event.START_DATE, R.string.label_date, FLAGS_DATE);


            mAllowClear = allowClear;
            mListener = new View.OnClickListener() {
            mListener = new View.OnClickListener() {
                @Override
                @Override
                public void onClick(View v) {
                public void onClick(View v) {
@@ -821,6 +848,17 @@ public class FallbackSource extends ContactsSource {
                                                       cal.get(Calendar.YEAR),
                                                       cal.get(Calendar.YEAR),
                                                       cal.get(Calendar.MONTH),
                                                       cal.get(Calendar.MONTH),
                                                       cal.get(Calendar.DAY_OF_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();
            dp.show();
        }
        }