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

Commit 0a04bb0d authored by Alan Viverette's avatar Alan Viverette
Browse files

Add first day of week API to date picker

BUG: 17377360
Change-Id: Id4c109ac68e083d488a4281655bf9411fea92163
parent b10e39e7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -37553,6 +37553,7 @@ package android.widget {
    method public android.widget.CalendarView getCalendarView();
    method public boolean getCalendarViewShown();
    method public int getDayOfMonth();
    method public int getFirstDayOfWeek();
    method public long getMaxDate();
    method public long getMinDate();
    method public int getMonth();
@@ -37560,6 +37561,7 @@ package android.widget {
    method public int getYear();
    method public void init(int, int, int, android.widget.DatePicker.OnDateChangedListener);
    method public void setCalendarViewShown(boolean);
    method public void setFirstDayOfWeek(int);
    method public void setMaxDate(long);
    method public void setMinDate(long);
    method public void setSpinnersShown(boolean);
+60 −1
Original line number Diff line number Diff line
@@ -125,6 +125,7 @@ public class DatePicker extends FrameLayout {
        final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePicker,
                defStyleAttr, defStyleRes);
        final int mode = a.getInt(R.styleable.DatePicker_datePickerMode, MODE_SPINNER);
        final int firstDayOfWeek = a.getInt(R.styleable.DatePicker_firstDayOfWeek, 0);
        a.recycle();

        switch (mode) {
@@ -136,6 +137,10 @@ public class DatePicker extends FrameLayout {
                mDelegate = createSpinnerUIDelegate(context, attrs, defStyleAttr, defStyleRes);
                break;
        }

        if (firstDayOfWeek != 0) {
            setFirstDayOfWeek(firstDayOfWeek);
        }
    }

    private DatePickerDelegate createSpinnerUIDelegate(Context context, AttributeSet attrs,
@@ -299,6 +304,47 @@ public class DatePicker extends FrameLayout {
        mDelegate.onConfigurationChanged(newConfig);
    }

    /**
     * Sets the first day of week.
     *
     * @param firstDayOfWeek The first day of the week conforming to the
     *            {@link CalendarView} APIs.
     * @see Calendar#SUNDAY
     * @see Calendar#MONDAY
     * @see Calendar#TUESDAY
     * @see Calendar#WEDNESDAY
     * @see Calendar#THURSDAY
     * @see Calendar#FRIDAY
     * @see Calendar#SATURDAY
     *
     * @attr ref android.R.styleable#DatePicker_firstDayOfWeek
     */
    public void setFirstDayOfWeek(int firstDayOfWeek) {
        if (firstDayOfWeek < Calendar.SUNDAY || firstDayOfWeek > Calendar.SATURDAY) {
            throw new IllegalArgumentException("firstDayOfWeek must be between 1 and 7");
        }
        mDelegate.setFirstDayOfWeek(firstDayOfWeek);
    }

    /**
     * Gets the first day of week.
     *
     * @return The first day of the week conforming to the {@link CalendarView}
     *         APIs.
     * @see Calendar#SUNDAY
     * @see Calendar#MONDAY
     * @see Calendar#TUESDAY
     * @see Calendar#WEDNESDAY
     * @see Calendar#THURSDAY
     * @see Calendar#FRIDAY
     * @see Calendar#SATURDAY
     *
     * @attr ref android.R.styleable#DatePicker_firstDayOfWeek
     */
    public int getFirstDayOfWeek() {
        return mDelegate.getFirstDayOfWeek();
    }

    /**
     * Gets whether the {@link CalendarView} is shown.
     *
@@ -382,6 +428,9 @@ public class DatePicker extends FrameLayout {
        int getMonth();
        int getDayOfMonth();

        void setFirstDayOfWeek(int firstDayOfWeek);
        int getFirstDayOfWeek();

        void setMinDate(long minDate);
        Calendar getMinDate();

@@ -698,6 +747,16 @@ public class DatePicker extends FrameLayout {
            return mCurrentDate.get(Calendar.DAY_OF_MONTH);
        }

        @Override
        public void setFirstDayOfWeek(int firstDayOfWeek) {
            mCalendarView.setFirstDayOfWeek(firstDayOfWeek);
        }

        @Override
        public int getFirstDayOfWeek() {
            return mCalendarView.getFirstDayOfWeek();
        }

        @Override
        public void setMinDate(long minDate) {
            mTempDate.setTimeInMillis(minDate);
+11 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import java.util.Locale;
 */
class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate implements
        View.OnClickListener, DatePickerController {
    private static final int USE_LOCALE = 0;

    private static final int UNINITIALIZED = -1;
    private static final int MONTH_AND_DAY_VIEW = 0;
@@ -99,6 +100,8 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i
    private Calendar mMinDate;
    private Calendar mMaxDate;

    private int mFirstDayOfWeek = USE_LOCALE;

    private HashSet<OnDateChangedListener> mListeners = new HashSet<OnDateChangedListener>();

    public DatePickerCalendarDelegate(DatePicker delegator, Context context, AttributeSet attrs,
@@ -441,8 +444,16 @@ class DatePickerCalendarDelegate extends DatePicker.AbstractDatePickerDelegate i
        return mMaxDate;
    }

    @Override
    public void setFirstDayOfWeek(int firstDayOfWeek) {
        mFirstDayOfWeek = firstDayOfWeek;
    }

    @Override
    public int getFirstDayOfWeek() {
        if (mFirstDayOfWeek != USE_LOCALE) {
            return mFirstDayOfWeek;
        }
        return mCurrentDate.getFirstDayOfWeek();
    }

+1 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ interface DatePickerController {

    Calendar getSelectedDay();

    void setFirstDayOfWeek(int firstDayOfWeek);
    int getFirstDayOfWeek();

    int getMinYear();
+2 −0
Original line number Diff line number Diff line
@@ -4339,6 +4339,8 @@
        <attr name="minDate" format="string" />
        <!-- The maximal date shown by this calendar view in mm/dd/yyyy format. -->
        <attr name="maxDate" format="string" />
        <!-- The first day of week according to {@link java.util.Calendar}. -->
        <attr name="firstDayOfWeek" />
        <!-- @hide The layout of the date picker. -->
        <attr name="internalLayout" format="reference"  />
        <!-- @hide The layout of the legacy DatePicker. -->