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

Commit 7f66c5ad authored by James Kung's avatar James Kung Committed by Android (Google) Code Review
Browse files

Merge "Integrating new date picker into app" into ics-ub-calendar-cream

parents c4fb86ef 56f42bfb
Loading
Loading
Loading
Loading
+37 −0
Original line number Diff line number Diff line
@@ -119,6 +119,9 @@ public class Utils {
    static int CONFLICT_COLOR = 0xFF000000;
    static boolean mMinutesLoaded = false;

    public static final int YEAR_MIN = 1970;
    public static final int YEAR_MAX = 2037;

    // The name of the shared preferences file. This name must be maintained for
    // historical
    // reasons, as it's what PreferenceManager assigned the first time the file
@@ -592,6 +595,40 @@ public class Utils {
        }
    }

    /**
     * Get first day of week as java.util.Calendar constant.
     *
     * @return the first day of week as a java.util.Calendar constant
     */
    public static int getFirstDayOfWeekAsCalendar(Context context) {
        return convertDayOfWeekFromTimeToCalendar(getFirstDayOfWeek(context));
    }

    /**
     * Converts the day of the week from android.text.format.Time to java.util.Calendar
     */
    public static int convertDayOfWeekFromTimeToCalendar(int timeDayOfWeek) {
        switch (timeDayOfWeek) {
            case Time.MONDAY:
                return Calendar.MONDAY;
            case Time.TUESDAY:
                return Calendar.TUESDAY;
            case Time.WEDNESDAY:
                return Calendar.WEDNESDAY;
            case Time.THURSDAY:
                return Calendar.THURSDAY;
            case Time.FRIDAY:
                return Calendar.FRIDAY;
            case Time.SATURDAY:
                return Calendar.SATURDAY;
            case Time.SUNDAY:
                return Calendar.SUNDAY;
            default:
                throw new IllegalArgumentException("Argument must be between Time.SUNDAY and " +
                        "Time.SATURDAY");
        }
    }

    /**
     * @return true when week number should be shown.
     */
+10 −1
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
    private static final String BUNDLE_KEY_READ_ONLY = "key_read_only";
    private static final String BUNDLE_KEY_EDIT_ON_LAUNCH = "key_edit_on_launch";

    private static final String BUNDLE_KEY_DATE_BUTTON_CLICKED = "date_button_clicked";

    private static final boolean DEBUG = false;

    private static final int TOKEN_EVENT = 1;
@@ -129,6 +131,7 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
    public boolean mShowModifyDialogOnLaunch = false;

    private boolean mTimeSelectedWasStartTime;
    private boolean mDateSelectedWasStartDate;

    private InputMethodManager mInputMethodManager;

@@ -527,7 +530,8 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
        } else {
            view = inflater.inflate(R.layout.edit_event, null);
        }
        mView = new EditEventView(mContext, view, mOnDone, mTimeSelectedWasStartTime);
        mView = new EditEventView(mContext, view, mOnDone, mTimeSelectedWasStartTime,
                mDateSelectedWasStartDate);
        startQuery();

        if (mUseCustomActionBar) {
@@ -578,6 +582,10 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
                mTimeSelectedWasStartTime = savedInstanceState.getBoolean(
                        "EditEventView_timebuttonclicked");
            }
            if (savedInstanceState.containsKey(BUNDLE_KEY_DATE_BUTTON_CLICKED)) {
                mDateSelectedWasStartDate = savedInstanceState.getBoolean(
                        BUNDLE_KEY_DATE_BUTTON_CLICKED);
            }

        }
    }
@@ -903,6 +911,7 @@ public class EditEventFragment extends Fragment implements EventHandler, OnColor
        outState.putBoolean(BUNDLE_KEY_READ_ONLY, mIsReadOnly);

        outState.putBoolean("EditEventView_timebuttonclicked", mView.mTimeSelectedWasStartTime);
        outState.putBoolean(BUNDLE_KEY_DATE_BUTTON_CLICKED, mView.mDateSelectedWasStartDate);
    }

    @Override
+35 −25
Original line number Diff line number Diff line
@@ -18,15 +18,10 @@ package com.android.calendar.event;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ProgressDialog;
import android.app.Service;
import com.android.datetimepicker.time.TimePickerDialog;
import com.android.datetimepicker.time.TimePickerDialog.OnTimeSetListener;
import com.android.datetimepicker.time.RadialPickerLayout;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@@ -61,10 +56,8 @@ import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.LinearLayout;
import android.widget.MultiAutoCompleteTextView;
import android.widget.RadioButton;
@@ -92,6 +85,11 @@ import com.android.calendar.recurrencepicker.RecurrencePickerDialog;
import com.android.calendarcommon2.EventRecurrence;
import com.android.common.Rfc822InputFilter;
import com.android.common.Rfc822Validator;
import com.android.datetimepicker.date.DatePickerDialog;
import com.android.datetimepicker.date.DatePickerDialog.OnDateSetListener;
import com.android.datetimepicker.time.RadialPickerLayout;
import com.android.datetimepicker.time.TimePickerDialog;
import com.android.datetimepicker.time.TimePickerDialog.OnTimeSetListener;
import com.android.ex.chips.AccountSpecifier;
import com.android.ex.chips.BaseRecipientAdapter;
import com.android.ex.chips.ChipsUtil;
@@ -99,7 +97,6 @@ import com.android.ex.chips.RecipientEditTextView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Formatter;
import java.util.HashMap;
import java.util.Locale;
@@ -112,6 +109,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
    private static final String GOOGLE_SECONDARY_CALENDAR = "calendar.google.com";
    private static final String PERIOD_SPACE = ". ";
    static final String FRAG_TAG_RECUR_PICKER = "recurrencePickerDialogFragment";
    private static final String FRAG_TAG_DATE_PICKER = "datePickerDialogFragment";
    private static final String FRAG_TAG_TIME_PICKER = "timePickerDialogFragment";

    ArrayList<View> mEditOnlyList = new ArrayList<View>();
@@ -175,8 +173,9 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
    private TimezoneAdapter mTimezoneAdapter;

    public boolean mTimeSelectedWasStartTime;
    public boolean mDateSelectedWasStartDate;

    private ArrayList<Integer> mRecurrenceIndexes = new ArrayList<Integer>(0);
    private DatePickerDialog mDatePickerDialog;

    /**
     * Contents of the "minutes" spinner.  This has default values from the XML file, augmented
@@ -314,7 +313,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
        }

        @Override
        public void onDateSet(DatePicker view, int year, int month, int monthDay) {
        public void onDateSet(DatePickerDialog view, int year, int month, int monthDay) {
            Log.d(TAG, "onDateSet: " + year +  " " + month +  " " + monthDay);
            // Cache the member variables locally to avoid inner class overhead.
            Time startTime = mStartTime;
@@ -488,22 +487,22 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa

        @Override
        public void onClick(View v) {
            DatePickerDialog dpd = new DatePickerDialog(
                    mActivity, new DateListener(v), mTime.year, mTime.month, mTime.monthDay);
            CalendarView cv = dpd.getDatePicker().getCalendarView();
            cv.setShowWeekNumber(Utils.getShowWeekNumber(mActivity));
            int startOfWeek = Utils.getFirstDayOfWeek(mActivity);
            // Utils returns Time days while CalendarView wants Calendar days
            if (startOfWeek == Time.SATURDAY) {
                startOfWeek = Calendar.SATURDAY;
            } else if (startOfWeek == Time.SUNDAY) {
                startOfWeek = Calendar.SUNDAY;

            if (v == mStartDateButton) {
                mDateSelectedWasStartDate = true;
            } else {
                startOfWeek = Calendar.MONDAY;
                mDateSelectedWasStartDate = false;
            }
            cv.setFirstDayOfWeek(startOfWeek);
            dpd.setCanceledOnTouchOutside(true);
            dpd.show();

            final DateListener listener = new DateListener(v);
            if (mDatePickerDialog != null) {
                mDatePickerDialog.dismiss();
            }
            mDatePickerDialog = DatePickerDialog.newInstance(listener,
                    mTime.year, mTime.month, mTime.monthDay);
            mDatePickerDialog.setFirstDayOfWeek(Utils.getFirstDayOfWeekAsCalendar(mActivity));
            mDatePickerDialog.setYearRange(Utils.YEAR_MIN, Utils.YEAR_MAX);
            mDatePickerDialog.show(mActivity.getFragmentManager(), FRAG_TAG_DATE_PICKER);
        }
    }

@@ -758,7 +757,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
    }

    public EditEventView(Activity activity, View view, EditDoneRunnable done,
            boolean timeSelectedWasStartTime) {
            boolean timeSelectedWasStartTime, boolean dateSelectedWasStartDate) {

        mActivity = activity;
        mView = view;
@@ -906,6 +905,17 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
            }
            tpd.setOnTimeSetListener(new TimeListener(v));
        }
        mDatePickerDialog = (DatePickerDialog) fm.findFragmentByTag(FRAG_TAG_DATE_PICKER);
        if (mDatePickerDialog != null) {
            View v;
            mDateSelectedWasStartDate = dateSelectedWasStartDate;
            if (dateSelectedWasStartDate) {
                v = mStartDateButton;
            } else {
                v = mEndDateButton;
            }
            mDatePickerDialog.setOnDateSetListener(new DateListener(v));
        }
    }


+14 −114
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@

package com.android.calendar.recurrencepicker;

import android.app.DatePickerDialog;
import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.res.Resources;
import android.os.Bundle;
@@ -41,7 +38,6 @@ import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
@@ -55,6 +51,7 @@ import android.widget.ToggleButton;
import com.android.calendar.R;
import com.android.calendar.Utils;
import com.android.calendarcommon2.EventRecurrence;
import com.android.datetimepicker.date.DatePickerDialog;

import java.text.DateFormatSymbols;
import java.util.ArrayList;
@@ -80,6 +77,8 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele
    private static final int DAY_OF_WEEK_CHECKED_TEXT_COLOR = 0xFFFFFFFF;
    private static final int DAY_OF_WEEK_UNCHECKED_TEXT_COLOR = 0xFF000000;

    private DatePickerDialog mDatePickerDialog;

    private class Model implements Parcelable {

        // Not repeating
@@ -952,19 +951,7 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele
        // TODO Update title with pretty rrule
        if (getDialog() != null) {
            getDialog().setTitle(R.string.recurrence_dialog_title);

            // copyModelToEventRecurrence(mModel, mRecurrence);
            // String title =
            // EventRecurrenceFormatter.getRepeatString(getActivity(),
            // mResources,
            // mRecurrence, false);
            // if (title != null) {
            // getDialog().setTitle(title);
            // } else {
            // getDialog().setTitle(R.string.recurrence_dialog_title);
            // }
        }
        // doToast();
    }

    /**
@@ -1058,64 +1045,8 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele
    public void onNothingSelected(AdapterView<?> arg0) {
    }

    static public class DatePickerDialogFragment extends DialogFragment
            implements DatePickerDialog.OnDateSetListener {
        private OnDateSetListener mOnDateSetListener;
        private DatePickerDialog mDialog;

        public DatePickerDialogFragment() {
            super();
        }

        public void setOnDateSetListener(DatePickerDialog.OnDateSetListener l) {
            mOnDateSetListener = l;
        }

    @Override
        public Dialog onCreateDialog(Bundle b) {
            int year, month, day;

            if (b == null) {
                b = getArguments();
            }

            if (b == null) {
                Time t = new Time(); // TODO timezone?
                t.setToNow();
                t.month += 3;
                t.normalize(false);

                year = t.year;
                month = t.month;
                day = t.monthDay;
            } else {
                year = b.getInt(BUNDLE_END_YEAR);
                month = b.getInt(BUNDLE_END_MONTH);
                day = b.getInt(BUNDLE_END_DAY);
            }

            mDialog = new DatePickerDialog(getActivity(), this, year,
                    month, day);

            return mDialog;
        }

        @Override
        public void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
        }

        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {

            if (mOnDateSetListener != null) {
                mOnDateSetListener.onDateSet(null, year, month, dayOfMonth);
            }
        }
    }

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
        if (mModel.endDate == null) {
            mModel.endDate = new Time(mTime.timezone);
            mModel.endDate.hour = mModel.endDate.minute = mModel.endDate.second = 0;
@@ -1174,20 +1105,14 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele
    @Override
    public void onClick(View v) {
        if (mEndDateTextView == v) {
            Bundle b = new Bundle();
            b.putInt(BUNDLE_END_YEAR, mModel.endDate.year);
            b.putInt(BUNDLE_END_MONTH, mModel.endDate.month);
            b.putInt(BUNDLE_END_DAY, mModel.endDate.monthDay);

            DatePickerDialogFragment dpdf = (DatePickerDialogFragment) getFragmentManager()
                    .findFragmentByTag(FRAG_TAG_DATE_PICKER);
            if (dpdf != null) {
                dpdf.dismiss();
            }
            dpdf = new DatePickerDialogFragment();
            dpdf.setArguments(b);
            dpdf.setOnDateSetListener(this);
            dpdf.show(getFragmentManager(), FRAG_TAG_DATE_PICKER);
            if (mDatePickerDialog != null) {
                mDatePickerDialog.dismiss();
            }
            mDatePickerDialog = DatePickerDialog.newInstance(this, mModel.endDate.year,
                    mModel.endDate.month, mModel.endDate.monthDay);
            mDatePickerDialog.setFirstDayOfWeek(Utils.getFirstDayOfWeekAsCalendar(getActivity()));
            mDatePickerDialog.setYearRange(Utils.YEAR_MIN, Utils.YEAR_MAX);
            mDatePickerDialog.show(getFragmentManager(), FRAG_TAG_DATE_PICKER);
        } else if (mDone == v) {
            String rrule;
            if (mModel.freq == Model.FREQ_NONE) {
@@ -1205,10 +1130,10 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        DatePickerDialogFragment dialogFrag = (DatePickerDialogFragment) getFragmentManager()
        mDatePickerDialog = (DatePickerDialog) getFragmentManager()
                .findFragmentByTag(FRAG_TAG_DATE_PICKER);
        if (dialogFrag != null) {
            dialogFrag.setOnDateSetListener(this);
        if (mDatePickerDialog != null) {
            mDatePickerDialog.setOnDateSetListener(this);
        }
    }

@@ -1219,29 +1144,4 @@ public class RecurrencePickerDialog extends DialogFragment implements OnItemSele
    public void setOnRecurrenceSetListener(OnRecurrenceSetListener l) {
        mRecurrenceSetListener = l;
    }

    // TODO handle the case where user deletes all the text.

    // @Override
    // public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    // if (v == mInterval) {
    // int interval;
    // try {
    // interval = Integer.parseInt(mInterval.getText().toString());
    // } catch (NumberFormatException e) {
    // interval = INTERVAL_DEFAULT;
    // }
    // mModel.interval = interval;
    // } else if (v == mEndCount) {
    // int count;
    // try {
    // count = Integer.parseInt(mEndCount.getText().toString());
    // } catch (NumberFormatException e) {
    // count = COUNT_DEFAULT;
    // }
    // mModel.endCount = count;
    // }
    // doToast();
    // return false;
    // }
}