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

Commit 228137fa authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Refactor DatePickerDialog constructors to avoid early callback" into nyc-dev

parents 32e537c6 a9a75f50
Loading
Loading
Loading
Loading
+32 −25
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
     * @param context the parent context
     */
    public DatePickerDialog(@NonNull Context context) {
        this(context, 0);
        this(context, 0, null, Calendar.getInstance(), -1, -1, -1);
    }

    /**
@@ -70,24 +70,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
     *                   {@code context}'s default alert dialog theme
     */
    public DatePickerDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, resolveDialogTheme(context, themeResId));

        final Context themeContext = getContext();
        final LayoutInflater inflater = LayoutInflater.from(themeContext);
        final View view = inflater.inflate(R.layout.date_picker_dialog, null);
        setView(view);

        setButton(BUTTON_POSITIVE, themeContext.getString(R.string.ok), this);
        setButton(BUTTON_NEGATIVE, themeContext.getString(R.string.cancel), this);
        setButtonPanelLayoutHint(LAYOUT_HINT_SIDE);

        final Calendar calendar = Calendar.getInstance();
        final int year = calendar.get(Calendar.YEAR);
        final int monthOfYear = calendar.get(Calendar.MONTH);
        final int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        mDatePicker = (DatePicker) view.findViewById(R.id.datePicker);
        mDatePicker.init(year, monthOfYear, dayOfMonth, this);
        mDatePicker.setValidationCallback(mValidationCallback);
        this(context, themeResId, null, Calendar.getInstance(), -1, -1, -1);
    }

    /**
@@ -104,7 +87,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
     */
    public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener,
            int year, int month, int dayOfMonth) {
        this(context, 0, listener, year, month, dayOfMonth);
        this(context, 0, listener, null, year, month, dayOfMonth);
    }

    /**
@@ -116,16 +99,40 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener,
     *                   {@code context}'s default alert dialog theme
     * @param listener the listener to call when the user sets the date
     * @param year the initially selected year
     * @param month the initially selected month (0-11 for compatibility with
     *              {@link Calendar#MONTH})
     * @param monthOfYear the initially selected month of the year (0-11 for
     *                    compatibility with {@link Calendar#MONTH})
     * @param dayOfMonth the initially selected day of month (1-31, depending
     *                   on month)
     */
    public DatePickerDialog(@NonNull Context context, @StyleRes int themeResId,
            @Nullable OnDateSetListener listener, int year, int month, int dayOfMonth) {
        this(context, themeResId);
            @Nullable OnDateSetListener listener, int year, int monthOfYear, int dayOfMonth) {
        this(context, themeResId, listener, null, year, monthOfYear, dayOfMonth);
    }

    private DatePickerDialog(@NonNull Context context, @StyleRes int themeResId,
            @Nullable OnDateSetListener listener, @Nullable Calendar calendar, int year,
            int monthOfYear, int dayOfMonth) {
        super(context, resolveDialogTheme(context, themeResId));

        final Context themeContext = getContext();
        final LayoutInflater inflater = LayoutInflater.from(themeContext);
        final View view = inflater.inflate(R.layout.date_picker_dialog, null);
        setView(view);

        setButton(BUTTON_POSITIVE, themeContext.getString(R.string.ok), this);
        setButton(BUTTON_NEGATIVE, themeContext.getString(R.string.cancel), this);
        setButtonPanelLayoutHint(LAYOUT_HINT_SIDE);

        if (calendar != null) {
            year = calendar.get(Calendar.YEAR);
            monthOfYear = calendar.get(Calendar.MONTH);
            dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
        }

        mDatePicker = (DatePicker) view.findViewById(R.id.datePicker);
        mDatePicker.init(year, monthOfYear, dayOfMonth, this);
        mDatePicker.setValidationCallback(mValidationCallback);

        mDatePicker.updateDate(year, month, dayOfMonth);
        mDateSetListener = listener;
    }

+0 −2
Original line number Diff line number Diff line
@@ -75,8 +75,6 @@ import java.util.TimeZone;
 */
@Widget
public class DatePicker extends FrameLayout {
    private static final String LOG_TAG = DatePicker.class.getSimpleName();

    private static final int MODE_SPINNER = 1;
    private static final int MODE_CALENDAR = 2;

+2 −2
Original line number Diff line number Diff line
@@ -378,9 +378,9 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate {
        mCurrentDate.set(Calendar.MONTH, monthOfYear);
        mCurrentDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);

        mDateChangedListener = callBack;

        onDateChanged(false, false);

        mDateChangedListener = callBack;
    }

    @Override
+1 −0
Original line number Diff line number Diff line
@@ -244,6 +244,7 @@ class DatePickerSpinnerDelegate extends AbstractDatePickerDelegate {
        setDate(year, monthOfYear, dayOfMonth);
        updateSpinners();
        updateCalendarView();

        mOnDateChangedListener = onDateChangedListener;
    }