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

Commit 0b9fe092 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio Committed by Android Git Automerger
Browse files

am d009491e: am 09370607: Fix bug #16245852 Clean...

am d009491e: am 09370607: Fix bug #16245852 Clean SimpleMonthView.setMonthParams() in the new DatePicker

* commit 'd009491e8811b712de0e620c53f0417dcffa575c':
  Fix bug #16245852 Clean SimpleMonthView.setMonthParams() in the new DatePicker
parents 97da26c4 16b7e2e8
Loading
Loading
Loading
Loading
+3 −7
Original line number Original line Diff line number Diff line
@@ -142,14 +142,10 @@ class SimpleMonthAdapter extends BaseAdapter implements SimpleMonthView.OnDayCli
            enabledDayRangeEnd = 31;
            enabledDayRangeEnd = 31;
        }
        }


        drawingParams.put(SimpleMonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
        v.setMonthParams(selectedDay, month, year, mController.getFirstDayOfWeek(),
        drawingParams.put(SimpleMonthView.VIEW_PARAMS_YEAR, year);
                enabledDayRangeStart, enabledDayRangeEnd);
        drawingParams.put(SimpleMonthView.VIEW_PARAMS_MONTH, month);
        drawingParams.put(SimpleMonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek());
        drawingParams.put(SimpleMonthView.VIEW_PARAMS_ENABLEDDAYRANGE_START, enabledDayRangeStart);
        drawingParams.put(SimpleMonthView.VIEW_PARAMS_ENABLEDDAYRANGE_END, enabledDayRangeEnd);
        v.setMonthParams(drawingParams);
        v.invalidate();
        v.invalidate();

        return v;
        return v;
    }
    }


+32 −68
Original line number Original line Diff line number Diff line
@@ -52,44 +52,6 @@ import java.util.Locale;
class SimpleMonthView extends View {
class SimpleMonthView extends View {
    private static final String TAG = "SimpleMonthView";
    private static final String TAG = "SimpleMonthView";


    /**
     * These params can be passed into the view to control how it appears.
     * {@link #VIEW_PARAMS_WEEK} is the only required field, though the default
     * values are unlikely to fit most layouts correctly.
     */
    /**
     * This sets the height of this week in pixels
     */
    static final String VIEW_PARAMS_HEIGHT = "height";
    /**
     * This specifies the position (or weeks since the epoch) of this week,
     * calculated using
     */
    static final String VIEW_PARAMS_MONTH = "month";
    /**
     * This specifies the position (or weeks since the epoch) of this week,
     * calculated using
     */
    static final String VIEW_PARAMS_YEAR = "year";
    /**
     * This sets one of the days in this view as selected {@link Time#SUNDAY}
     * through {@link Time#SATURDAY}.
     */
    static final String VIEW_PARAMS_SELECTED_DAY = "selected_day";
    /**
     * Which day the week should start on. {@link Time#SUNDAY} through
     * {@link Time#SATURDAY}.
     */
    static final String VIEW_PARAMS_WEEK_START = "week_start";
    /**
     * First enabled day.
     */
    static final String VIEW_PARAMS_ENABLEDDAYRANGE_START = "enabled_day_range_start";
    /**
     * Last enabled day.
     */
    static final String VIEW_PARAMS_ENABLEDDAYRANGE_END = "enabled_day_range_end";

    private static int DEFAULT_HEIGHT = 32;
    private static int DEFAULT_HEIGHT = 32;
    private static int MIN_HEIGHT = 10;
    private static int MIN_HEIGHT = 10;


@@ -327,36 +289,38 @@ class SimpleMonthView extends View {
        drawDays(canvas);
        drawDays(canvas);
    }
    }


    private static boolean isValidDay(int day) {
        return (day >= Time.SUNDAY && day <= Time.SATURDAY);
    }

    /**
    /**
     * Sets all the parameters for displaying this week. The only required
     * Sets all the parameters for displaying this week. Parameters have a default value and
     * parameter is the week number. Other parameters have a default value and
     * will only update if a new value is included, except for focus month, which will always
     * will only update if a new value is included, except for focus month,
     * default to no focus month if no value is passed in. The only required parameter is the
     * which will always default to no focus month if no value is passed in. See
     * week start.
     * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
     *
     *
     * @param params A map of the new parameters, see
     * @param selectedDay the selected day.
     *            {@link #VIEW_PARAMS_HEIGHT}
     * @param month the month.
     * @param year the year.
     * @param weekStart which day the week should start on. {@link Time#SUNDAY} through
     *        {@link Time#SATURDAY}.
     * @param enabledDayStart the first enabled day.
     * @param enabledDayEnd the last enabled day.
     */
     */
    void setMonthParams(HashMap<String, Integer> params) {
    void setMonthParams(int selectedDay, int month, int year, int weekStart, int enabledDayStart,
        if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
            int enabledDayEnd) {
            throw new InvalidParameterException(
                    "You must specify the month and year for this view");
        }
        setTag(params);
        // We keep the current value for any params not present
        if (params.containsKey(VIEW_PARAMS_HEIGHT)) {
            mRowHeight = params.get(VIEW_PARAMS_HEIGHT);
        if (mRowHeight < MIN_HEIGHT) {
        if (mRowHeight < MIN_HEIGHT) {
            mRowHeight = MIN_HEIGHT;
            mRowHeight = MIN_HEIGHT;
        }
        }
        }

        if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
        if (isValidDay(selectedDay)) {
            mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
            mSelectedDay = selectedDay;
        }
        }


        // Allocate space for caching the day numbers and focus values
        if (month >= Calendar.JANUARY && month <= Calendar.DECEMBER) {
        mMonth = params.get(VIEW_PARAMS_MONTH);
            mMonth = month;
        mYear = params.get(VIEW_PARAMS_YEAR);
        }
        mYear = year;


        // Figure out what day today is
        // Figure out what day today is
        final Time today = new Time(Time.getCurrentTimezone());
        final Time today = new Time(Time.getCurrentTimezone());
@@ -369,17 +333,17 @@ class SimpleMonthView extends View {
        mCalendar.set(Calendar.DAY_OF_MONTH, 1);
        mCalendar.set(Calendar.DAY_OF_MONTH, 1);
        mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);
        mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);


        if (params.containsKey(VIEW_PARAMS_WEEK_START)) {
        if (isValidDay(weekStart)) {
            mWeekStart = params.get(VIEW_PARAMS_WEEK_START);
            mWeekStart = weekStart;
        } else {
        } else {
            mWeekStart = mCalendar.getFirstDayOfWeek();
            mWeekStart = mCalendar.getFirstDayOfWeek();
        }
        }


        if (params.containsKey(VIEW_PARAMS_ENABLEDDAYRANGE_START)) {
        if (enabledDayStart > 0 && enabledDayEnd < 32) {
            mEnabledDayStart = params.get(VIEW_PARAMS_ENABLEDDAYRANGE_START);
            mEnabledDayStart = enabledDayStart;
        }
        }
        if (params.containsKey(VIEW_PARAMS_ENABLEDDAYRANGE_END)) {
        if (enabledDayEnd > 0 && enabledDayEnd < 32 && enabledDayEnd >= enabledDayStart) {
            mEnabledDayEnd = params.get(VIEW_PARAMS_ENABLEDDAYRANGE_END);
            mEnabledDayEnd = enabledDayEnd;
        }
        }


        mNumCells = getDaysInMonth(mMonth, mYear);
        mNumCells = getDaysInMonth(mMonth, mYear);