/**
  * Attempts to restore accessibility focus to the specified date.
  *
  * @param day The date which should receive focus
  * @return {@code false} if the date is not valid for this month view, or {@code true} if the date
  *     received focus
  */
 public boolean restoreAccessibilityFocus(CalendarDay day) {
   if ((day.year != mYear) || (day.month != mMonth) || (day.day > mNumCells)) {
     return false;
   }
   mTouchHelper.setFocusedVirtualView(day.day);
   return true;
 }
 /** @return The date that has accessibility focus, or {@code null} if no date has focus */
 public CalendarDay getAccessibilityFocus() {
   final int day = mTouchHelper.getFocusedVirtualView();
   if (day >= 0) {
     return new CalendarDay(mYear, mMonth, day);
   }
   return null;
 }
  @Override
  protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    mWidth = w;

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
  }
  /**
   * Sets the selected day.
   *
   * @param dayOfMonth the selected day of the month, or {@code -1} to clear the selection
   */
  public void setSelectedDay(int dayOfMonth) {
    mActivatedDay = dayOfMonth;

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
    invalidate();
  }
 @Override
 public boolean dispatchHoverEvent(MotionEvent event) {
   // First right-of-refusal goes the touch exploration helper.
   if (mTouchHelper.dispatchHoverEvent(event)) {
     return true;
   }
   return super.dispatchHoverEvent(event);
 }
  /**
   * Sets the first day of the week.
   *
   * @param weekStart which day the week should start on, valid values are {@link Calendar#SUNDAY}
   *     through {@link Calendar#SATURDAY}
   */
  public void setFirstDayOfWeek(int weekStart) {
    if (isValidDayOfWeek(weekStart)) {
      mWeekStart = weekStart;
    } else {
      mWeekStart = mCalendar.getFirstDayOfWeek();
    }

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
    invalidate();
  }
  /**
   * Called when the user clicks on a day. Handles callbacks to the {@link OnDayClickListener} if
   * one is set.
   *
   * <p>If the day is out of the range set by minDate and/or maxDate, this is a no-op.
   *
   * @param day The day that was clicked
   */
  private void onDayClick(int day) {
    // If the min / max date are set, only process the click if it's a valid selection.
    if (isOutOfRange(mYear, mMonth, day)) {
      return;
    }

    if (mOnDayClickListener != null) {
      mOnDayClickListener.onDayClick(this, new CalendarDay(mYear, mMonth, day));
    }

    // This is a no-op if accessibility is turned off.
    mTouchHelper.sendEventForVirtualView(day, AccessibilityEvent.TYPE_VIEW_CLICKED);
  }
示例#8
0
  /**
   * 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();
    final Calendar today = Calendar.getInstance();
    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 = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    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();
  }
  /**
   * Called when the user clicks on a day. Handles callbacks to the {@link OnDayClickListener} if
   * one is set.
   *
   * @param day the day that was clicked
   */
  private boolean onDayClicked(int day) {
    if (!isValidDayOfMonth(day) || !isDayEnabled(day)) {
      return false;
    }

    if (mOnDayClickListener != null) {
      final Calendar date = Calendar.getInstance();
      date.set(mYear, mMonth, day);
      mOnDayClickListener.onDayClick(this, date);
    }

    // This is a no-op if accessibility is turned off.
    mTouchHelper.sendEventForVirtualView(day, AccessibilityEvent.TYPE_VIEW_CLICKED);
    return true;
  }
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (!changed) {
      return;
    }

    // Let's initialize a completely reasonable number of variables.
    final int w = right - left;
    final int h = bottom - top;
    final int paddingLeft = getPaddingLeft();
    final int paddingTop = getPaddingTop();
    final int paddingRight = getPaddingRight();
    final int paddingBottom = getPaddingBottom();
    final int paddedRight = w - paddingRight;
    final int paddedBottom = h - paddingBottom;
    final int paddedWidth = paddedRight - paddingLeft;
    final int paddedHeight = paddedBottom - paddingTop;
    if (paddedWidth == mPaddedWidth || paddedHeight == mPaddedHeight) {
      return;
    }

    mPaddedWidth = paddedWidth;
    mPaddedHeight = paddedHeight;

    // We may have been laid out smaller than our preferred size. If so,
    // scale all dimensions to fit.
    final int measuredPaddedHeight = getMeasuredHeight() - paddingTop - paddingBottom;
    final float scaleH = paddedHeight / (float) measuredPaddedHeight;
    final int monthHeight = (int) (mDesiredMonthHeight * scaleH);
    final int cellWidth = mPaddedWidth / DAYS_IN_WEEK;
    mMonthHeight = monthHeight;
    mDayOfWeekHeight = (int) (mDesiredDayOfWeekHeight * scaleH);
    mDayHeight = (int) (mDesiredDayHeight * scaleH);
    mCellWidth = cellWidth;

    // Compute the largest day selector radius that's still within the clip
    // bounds and desired selector radius.
    final int maxSelectorWidth = cellWidth / 2 + Math.min(paddingLeft, paddingRight);
    final int maxSelectorHeight = mDayHeight / 2 + paddingBottom;
    mDaySelectorRadius =
        Math.min(mDesiredDaySelectorRadius, Math.min(maxSelectorWidth, maxSelectorHeight));

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
  }
  /**
   * Sets all the parameters for displaying this week.
   *
   * <p>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. The only
   * required parameter is the week start.
   *
   * @param selectedDay the selected day of the month, or -1 for no selection
   * @param month the month
   * @param year the year
   * @param weekStart which day the week should start on, valid values are {@link Calendar#SUNDAY}
   *     through {@link Calendar#SATURDAY}
   * @param enabledDayStart the first enabled day
   * @param enabledDayEnd the last enabled day
   */
  void setMonthParams(
      int selectedDay, int month, int year, int weekStart, int enabledDayStart, int enabledDayEnd) {
    mActivatedDay = selectedDay;

    if (isValidMonth(month)) {
      mMonth = month;
    }
    mYear = year;

    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 (isValidDayOfWeek(weekStart)) {
      mWeekStart = weekStart;
    } else {
      mWeekStart = mCalendar.getFirstDayOfWeek();
    }

    // Figure out what day today is.
    final Calendar today = Calendar.getInstance();
    mToday = -1;
    mDaysInMonth = getDaysInMonth(mMonth, mYear);
    for (int i = 0; i < mDaysInMonth; i++) {
      final int day = i + 1;
      if (sameDay(day, today)) {
        mToday = day;
      }
    }

    mEnabledDayStart = MathUtils.constrain(enabledDayStart, 1, mDaysInMonth);
    mEnabledDayEnd = MathUtils.constrain(enabledDayEnd, mEnabledDayStart, mDaysInMonth);

    // Invalidate the old title.
    mTitle = null;

    // Invalidate cached accessibility information.
    mTouchHelper.invalidateRoot();
  }
 /**
  * Clears accessibility focus within the view. No-op if the view does not contain accessibility
  * focus.
  */
 public void clearAccessibilityFocus() {
   mTouchHelper.clearFocusedVirtualView();
 }