Java Code Examples for com.android.datetimepicker.Utils#getDaysInMonth()

The following examples show how to use com.android.datetimepicker.Utils#getDaysInMonth() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatePickerDialog.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
private void adjustDayInMonthIfNeeded(int month, int year) {
    int day = mCalendar.get(Calendar.DAY_OF_MONTH);
    int daysInMonth = Utils.getDaysInMonth(month, year);
    if (day > daysInMonth) {
        mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
    }
}
 
Example 2
Source File: CalendarFragment.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
private void adjustDayInMonthIfNeeded(int month, int year) {
    int day = mCalendar.get(Calendar.DAY_OF_MONTH);
    int daysInMonth = Utils.getDaysInMonth(month, year);
    if (day > daysInMonth) {
        mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
    }
}
 
Example 3
Source File: DatePickerDialog.java    From StyleableDateTimePicker with MIT License 5 votes vote down vote up
private void adjustDayInMonthIfNeeded(int month, int year) {
    int day = mCalendar.get(Calendar.DAY_OF_MONTH);
    int daysInMonth = Utils.getDaysInMonth(month, year);
    if (day > daysInMonth) {
        mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
    }
}
 
Example 4
Source File: DatePickerDialog.java    From cathode with Apache License 2.0 5 votes vote down vote up
private void adjustDayInMonthIfNeeded(int month, int year) {
  int day = mCalendar.get(Calendar.DAY_OF_MONTH);
  int daysInMonth = Utils.getDaysInMonth(month, year);
  if (day > daysInMonth) {
    mCalendar.set(Calendar.DAY_OF_MONTH, daysInMonth);
  }
}
 
Example 5
Source File: MonthView.java    From narrate-android with Apache License 2.0 4 votes vote down vote up
/**
 * Sets all the parameters for displaying this week. The only required
 * 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 default to no focus month if no value is passed in. See
 * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
 *
 * @param params A map of the new parameters, see
 *               {@link #VIEW_PARAMS_HEIGHT}
 */
public void setMonthParams(HashMap<String, Integer> params) {
    if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
        throw new InvalidParameterException("You must specify 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) {
            mRowHeight = MIN_HEIGHT;
        }
    }
    if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
        mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
    }

    // Allocate space for caching the day numbers and focus values
    mMonth = params.get(VIEW_PARAMS_MONTH);
    mYear = params.get(VIEW_PARAMS_YEAR);

    // Figure out what day today is
    final Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();
    mHasToday = false;
    mToday = -1;

    mCalendar.set(Calendar.MONTH, mMonth);
    mCalendar.set(Calendar.YEAR, mYear);
    mCalendar.set(Calendar.DAY_OF_MONTH, 1);
    mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);

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

    mNumCells = Utils.getDaysInMonth(mMonth, mYear);
    for (int i = 0; i < mNumCells; i++) {
        final int day = i + 1;
        if (sameDay(day, today)) {
            mHasToday = true;
            mToday = day;
        }
    }
    mNumRows = calculateNumRows();

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
}
 
Example 6
Source File: MonthView.java    From StyleableDateTimePicker with MIT License 4 votes vote down vote up
/**
 * Sets all the parameters for displaying this week. The only required
 * 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 default to no focus month if no value is passed in. See
 * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
 *
 * @param params A map of the new parameters, see
 *            {@link #VIEW_PARAMS_HEIGHT}
 */
public void setMonthParams(HashMap<String, Integer> params) {
    if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
        throw new InvalidParameterException("You must specify 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) {
            mRowHeight = MIN_HEIGHT;
        }
    }
    if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
        mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
    }

    // Allocate space for caching the day numbers and focus values
    mMonth = params.get(VIEW_PARAMS_MONTH);
    mYear = params.get(VIEW_PARAMS_YEAR);

    // Figure out what day today is
    final Time today = new Time(Time.getCurrentTimezone());
    today.setToNow();
    mHasToday = false;
    mToday = -1;

    mCalendar.set(Calendar.MONTH, mMonth);
    mCalendar.set(Calendar.YEAR, mYear);
    mCalendar.set(Calendar.DAY_OF_MONTH, 1);
    mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);

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

    mNumCells = Utils.getDaysInMonth(mMonth, mYear);
    for (int i = 0; i < mNumCells; i++) {
        final int day = i + 1;
        if (sameDay(day, today)) {
            mHasToday = true;
            mToday = day;
        }
    }
    mNumRows = calculateNumRows();

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
}
 
Example 7
Source File: MonthView.java    From cathode with Apache License 2.0 4 votes vote down vote up
/**
 * Sets all the parameters for displaying this week. The only required
 * 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 default to no focus month if no value is passed in. See
 * {@link #VIEW_PARAMS_HEIGHT} for more info on parameters.
 *
 * @param params A map of the new parameters, see
 * {@link #VIEW_PARAMS_HEIGHT}
 */
public void setMonthParams(HashMap<String, Integer> params) {
  if (!params.containsKey(VIEW_PARAMS_MONTH) && !params.containsKey(VIEW_PARAMS_YEAR)) {
    throw new InvalidParameterException("You must specify 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) {
      mRowHeight = MIN_HEIGHT;
    }
  }
  if (params.containsKey(VIEW_PARAMS_SELECTED_DAY)) {
    mSelectedDay = params.get(VIEW_PARAMS_SELECTED_DAY);
  }

  // Allocate space for caching the day numbers and focus values
  mMonth = params.get(VIEW_PARAMS_MONTH);
  mYear = params.get(VIEW_PARAMS_YEAR);

  // Figure out what day today is
  final Time today = new Time(Time.getCurrentTimezone());
  today.setToNow();
  mHasToday = false;
  mToday = -1;

  mCalendar.set(Calendar.MONTH, mMonth);
  mCalendar.set(Calendar.YEAR, mYear);
  mCalendar.set(Calendar.DAY_OF_MONTH, 1);
  mDayOfWeekStart = mCalendar.get(Calendar.DAY_OF_WEEK);

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

  mNumCells = Utils.getDaysInMonth(mMonth, mYear);
  for (int i = 0; i < mNumCells; i++) {
    final int day = i + 1;
    if (sameDay(day, today)) {
      mHasToday = true;
      mToday = day;
    }
  }
  mNumRows = calculateNumRows();

  // Invalidate cached accessibility information.
  mTouchHelper.invalidateRoot();
}