private void init(Context context) {
   ArrayList<String> years = new ArrayList<String>();
   for (int year = mController.getMinYear(); year <= mController.getMaxYear(); year++) {
     years.add(String.format("%d", year));
   }
   mAdapter = new YearAdapter(context, R.layout.year_label_text_view, years);
   setAdapter(mAdapter);
 }
 @Override
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   mController.tryVibrate();
   if (position != mSelectedPosition) {
     mSelectedPosition = position;
     mAdapter.notifyDataSetChanged();
   }
   mController.onYearSelected(mAdapter.getItem(position));
 }
Exemple #3
0
  public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if (darkTheme) {
      mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal_dark_theme);
      mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day_dark_theme);
      mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
      mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted_dark_theme);
    } else {
      mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal);
      mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day);
      mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled);
      mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted);
    }
    mSelectedDayTextColor = res.getColor(R.color.mdtp_white);
    mTodayNumberColor = mController.getAccentColor();
    mMonthTitleColor = res.getColor(R.color.mdtp_white);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE =
        res.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);

    mRowHeight =
        (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
                - getMonthHeaderSize())
            / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
  }
 @Override
 public void onDateChanged() {
   updateAdapterData();
   mAdapter.notifyDataSetChanged();
   postSetSelectionCentered(
       mController.getSelectedDay().get(Calendar.YEAR) - mMinDate.get(Calendar.YEAR));
 }
  private boolean isBeforeMin(int year, int month, int day) {
    if (mController == null) {
      return false;
    }
    Calendar minDate = mController.getMinDate();
    if (minDate == null) {
      return false;
    }

    if (year < minDate.get(Calendar.YEAR)) {
      return true;
    } else if (year > minDate.get(Calendar.YEAR)) {
      return false;
    }

    if (month < minDate.get(Calendar.MONTH)) {
      return true;
    } else if (month > minDate.get(Calendar.MONTH)) {
      return false;
    }

    if (day < minDate.get(Calendar.DAY_OF_MONTH)) {
      return true;
    } else {
      return false;
    }
  }
  private boolean isAfterMax(int year, int month, int day) {
    if (mController == null) {
      return false;
    }
    Calendar maxDate = mController.getMaxDate();
    if (maxDate == null) {
      return false;
    }

    if (year > maxDate.get(Calendar.YEAR)) {
      return true;
    } else if (year < maxDate.get(Calendar.YEAR)) {
      return false;
    }

    if (month > maxDate.get(Calendar.MONTH)) {
      return true;
    } else if (month < maxDate.get(Calendar.MONTH)) {
      return false;
    }

    if (day > maxDate.get(Calendar.DAY_OF_MONTH)) {
      return true;
    } else {
      return false;
    }
  }
  public void init(DatePickerController controller) {
    mController = controller;
    mController.registerOnDateChangedListener(this);

    updateAdapterData();

    onDateChanged();
  }
 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
   mController.tryVibrate();
   TextViewWithCircularIndicator clickedView = (TextViewWithCircularIndicator) view;
   if (clickedView != null) {
     if (clickedView != mSelectedView) {
       if (mSelectedView != null) {
         mSelectedView.drawIndicator(false);
         mSelectedView.requestLayout();
       }
       clickedView.drawIndicator(true);
       clickedView.requestLayout();
       mSelectedView = clickedView;
     }
     mController.onYearSelected(getYearFromTextView(clickedView));
     mAdapter.notifyDataSetChanged();
   }
 }
  @SuppressLint("NewApi")
  @SuppressWarnings("unchecked")
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    MonthView v;
    HashMap<String, Integer> drawingParams = null;
    if (convertView != null) {
      v = (MonthView) convertView;
      // We store the drawing parameters in the view so it can be recycled
      drawingParams = (HashMap<String, Integer>) v.getTag();
    } else {
      v = createMonthView(mContext);
      // Set up the new view
      LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      v.setLayoutParams(params);
      v.setClickable(true);
      v.setOnDayClickListener(this);
    }
    if (drawingParams == null) {
      drawingParams = new HashMap<String, Integer>();
    }
    drawingParams.clear();

    final int month = position % MONTHS_IN_YEAR;
    final int year = position / MONTHS_IN_YEAR + mController.getMinYear();

    int selectedDay = -1;
    if (isSelectedDayInMonth(year, month)) {
      selectedDay = mSelectedDay.day;
    }

    // Invokes requestLayout() to ensure that the recycled view is set with the appropriate
    // height/number of weeks before being displayed.
    v.reuse();

    drawingParams.put(MonthView.VIEW_PARAMS_SELECTED_DAY, selectedDay);
    drawingParams.put(MonthView.VIEW_PARAMS_YEAR, year);
    drawingParams.put(MonthView.VIEW_PARAMS_MONTH, month);
    drawingParams.put(MonthView.VIEW_PARAMS_WEEK_START, mController.getFirstDayOfWeek());
    v.setMonthParams(drawingParams);
    v.invalidate();
    return v;
  }
Exemple #10
0
  /**
   * @return true if the specified year/month/day are within the selectable days or the range set by
   *     minDate and maxDate. If one or either have not been set, they are considered as
   *     Integer.MIN_VALUE and Integer.MAX_VALUE.
   */
  protected boolean isOutOfRange(int year, int month, int day) {
    if (mController.getSelectableDays() != null) {
      return !isSelectable(year, month, day);
    }

    if (isBeforeMin(year, month, day)) {
      return true;
    } else if (isAfterMax(year, month, day)) {
      return true;
    }

    return false;
  }
Exemple #11
0
 private boolean isSelectable(int year, int month, int day) {
   Calendar[] selectableDays = mController.getSelectableDays();
   for (Calendar c : selectableDays) {
     if (year < c.get(Calendar.YEAR)) break;
     if (year > c.get(Calendar.YEAR)) continue;
     if (month < c.get(Calendar.MONTH)) break;
     if (month > c.get(Calendar.MONTH)) continue;
     if (day < c.get(Calendar.DAY_OF_MONTH)) break;
     if (day > c.get(Calendar.DAY_OF_MONTH)) continue;
     return true;
   }
   return false;
 }
Exemple #12
0
 /**
  * @param year
  * @param month
  * @param day
  * @return true if the given date should be highlighted
  */
 protected boolean isHighlighted(int year, int month, int day) {
   Calendar[] highlightedDays = mController.getHighlightedDays();
   if (highlightedDays == null) return false;
   for (Calendar c : highlightedDays) {
     if (year < c.get(Calendar.YEAR)) break;
     if (year > c.get(Calendar.YEAR)) continue;
     if (month < c.get(Calendar.MONTH)) break;
     if (month > c.get(Calendar.MONTH)) continue;
     if (day < c.get(Calendar.DAY_OF_MONTH)) break;
     if (day > c.get(Calendar.DAY_OF_MONTH)) continue;
     return true;
   }
   return false;
 }
  public YearPickerView(Context context, DatePickerController datePickerController) {
    super(context);
    mController = datePickerController;
    mController.registerOnDateChangedListener(this);

    setLayoutParams(
        new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    Resources resources = context.getResources();
    mViewSize = resources.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height);
    mChildSize = resources.getDimensionPixelOffset(R.dimen.year_label_height);

    setVerticalFadingEdgeEnabled(true);
    setFadingEdgeLength(mChildSize / 3);
    init(context);
    setOnItemClickListener(this);
    setSelector(new StateListDrawable());
    setDividerHeight(0);
    onDateChanged();
  }
 /**
  * Maintains the same hour/min/sec but moves the day to the tapped day.
  *
  * @param day The day that was tapped
  */
 protected void onDayTapped(CalendarDay day) {
   mController.tryVibrate();
   mController.onDayOfMonthSelected(day.year, day.month, day.day);
   setSelectedDay(day);
 }
 @Override
 public int getCount() {
   return ((mController.getMaxYear() - mController.getMinYear()) + 1) * MONTHS_IN_YEAR;
 }
 public MonthAdapter(Context context, DatePickerController controller) {
   mContext = context;
   mController = controller;
   init();
   setSelectedDay(mController.getSelectedDay());
 }
 public void onDateChanged() {
   mAdapter.notifyDataSetChanged();
   postSetSelectionCentered(mController.getSelectedDay().year - mController.getMinYear());
 }