com.prolificinteractive.materialcalendarview.CalendarDay Java Examples

The following examples show how to use com.prolificinteractive.materialcalendarview.CalendarDay. 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: BasicActivityDecorated.java    From material-calendarview with MIT License 6 votes vote down vote up
@Override
protected List<CalendarDay> doInBackground(@NonNull Void... voids) {
  try {
    Thread.sleep(2000);
  } catch (InterruptedException e) {
    e.printStackTrace();
  }
  LocalDate temp = LocalDate.now().minusMonths(2);
  final ArrayList<CalendarDay> dates = new ArrayList<>();
  for (int i = 0; i < 30; i++) {
    final CalendarDay day = CalendarDay.from(temp);
    dates.add(day);
    temp = temp.plusDays(5);
  }

  return dates;
}
 
Example #2
Source File: GettersActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@OnClick(R.id.get_selected_dates) public void getSelectedDateClick(final View v) {
  final List<CalendarDay> selectedDates = widget.getSelectedDates();
  if (!selectedDates.isEmpty()) {
    Toast.makeText(this, selectedDates.toString(), Toast.LENGTH_SHORT).show();
    Log.e("GettersActivity", selectedDates.toString());
  } else {
    Toast.makeText(this, "No Selection", Toast.LENGTH_SHORT).show();
  }
}
 
Example #3
Source File: SelectionModesActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override public void onDateSelected(
    @NonNull final MaterialCalendarView widget,
    @NonNull final CalendarDay date,
    final boolean selected) {
  final String text = selected ? FORMATTER.format(date.getDate()) : "No Selection";
  Toast.makeText(SelectionModesActivity.this, text, Toast.LENGTH_SHORT).show();
}
 
Example #4
Source File: MonthWeekMaterialCalendarView.java    From monthweekmaterialcalendarview with Apache License 2.0 5 votes vote down vote up
/**
 * 选中日期
 * @param date
 */
public void setSelectedDate(@Nullable CalendarDay date) {
    mCalendarViewWeek.setSelectedDate(date);
    mCalendarViewMonth.setSelectedDate(date);
    selectDate = date;
    int position = getCurrentItemPosition(date);
    setStopItemPosition(position);
    if (currentMode == Mode.WEEK) {
        setTransYObjectAnimator(mCalendarViewMonth, mCalendarViewMonth.getTranslationY(), singleItemHight - defaultStopHeight, 250, null);
    }
}
 
Example #5
Source File: CalendarActivity.java    From monthweekmaterialcalendarview with Apache License 2.0 5 votes vote down vote up
private void AddDecorator() {
    //150天
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -2);
    ArrayList<CalendarDay> dates = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        CalendarDay day = CalendarDay.from(calendar);
        dates.add(day);
        calendar.add(Calendar.DATE, 5);
    }
    //增加有红点标志
    monthWeekMaterialCalendarView.addDecorator(new EventDecorator(Color.RED, dates));
}
 
Example #6
Source File: CalendarSmoothActivity.java    From monthweekmaterialcalendarview with Apache License 2.0 5 votes vote down vote up
private void AddDecorator() {
    //150天
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.MONTH, -2);
    ArrayList<CalendarDay> dates = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        CalendarDay day = CalendarDay.from(calendar);
        dates.add(day);
        calendar.add(Calendar.DATE, 5);
    }
    //增加有红点标志
    monthWeekMaterialCalendarView.addDecorator(new EventDecorator(Color.RED, dates));
}
 
Example #7
Source File: SelectionModesActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override public void onRangeSelected(
    @NonNull final MaterialCalendarView widget,
    @NonNull final List<CalendarDay> dates) {
  if (dates.size() > 0) {
    decorator.addFirstAndLast(dates.get(0), dates.get(dates.size() - 1));
    range.invalidateDecorators();
  }
}
 
Example #8
Source File: MonthWeekMaterialCalendarView.java    From monthweekmaterialcalendarview with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    setSingleItemHeight(mCalendarViewMonth.getItemHeight());
    if (defaultStopHeight == 0) {
        // 设置停止滑动的位置
        setStopItemPosition(getCurrentItemPosition(CalendarDay.today()));
    }
    calendarMonthHight = mCalendarViewMonth.getMeasuredHeight();
    weekViewHight = mTopWeekView.getMeasuredHeight();
    finalMonthModeHeight = weekViewHight + calendarMonthHight;
    finalWeekModeHeight = singleItemHight + weekViewHight;
    setMaxOffset(calendarMonthHight - singleItemHight);
}
 
Example #9
Source File: SwappableBasicActivityDecorated.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override
public void onDateSelected(
    @NonNull MaterialCalendarView widget,
    @NonNull CalendarDay date,
    boolean selected) {
  //If you change a decorate, you need to invalidate decorators
  oneDayDecorator.setDate(date.getDate());
  widget.invalidateDecorators();
}
 
Example #10
Source File: MonthArrayTitleFormatter.java    From material-calendarview with MIT License 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public CharSequence format(CalendarDay day) {
  return new SpannableStringBuilder()
      .append(monthLabels[day.getMonth() - 1])
      .append(" ")
      .append(String.valueOf(day.getYear()));
}
 
Example #11
Source File: CalendarManager.java    From ReactNativeCalendarAndroid with MIT License 5 votes vote down vote up
@Override
protected void addEventEmitters(final ThemedReactContext reactContext, final Calendar view) {
    view.setOnDateChangedListener(new OnDateSelectedListener() {
        @Override
        public void onDateSelected(MaterialCalendarView widget, CalendarDay date, boolean selected) {
            reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
                    .dispatchEvent(new CalendarEvent(
                            view.getId(),
                            date,
                            selected));
        }
    });
}
 
Example #12
Source File: CalendarManager.java    From ReactNativeCalendarAndroid with MIT License 5 votes vote down vote up
/**
 * Should update new value of minimum or maximum date
 *
 * Check if the new min or max date is different from the previous one, if yes we update otherwise we don't.
 *
 * @param minMaxDate
 * @param newDate
 * @return boolean
 */
private boolean shouldUpdateMinMaxDate(CalendarDay minMaxDate, Date newDate) {
    if (minMaxDate == null) {
        return true;
    }

    java.util.Calendar newDateCalendar = java.util.Calendar.getInstance();
    newDateCalendar.setTimeInMillis(newDate.getTime());

    return (minMaxDate.getYear() != newDateCalendar.get(java.util.Calendar.YEAR) &&
            minMaxDate.getMonth() != newDateCalendar.get(java.util.Calendar.MONTH) &&
            minMaxDate.getDay() != newDateCalendar.get(java.util.Calendar.DAY_OF_MONTH));
}
 
Example #13
Source File: DialogsActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override
public void onDateSelected(
    @NonNull MaterialCalendarView widget,
    @NonNull CalendarDay date,
    boolean selected) {
  textView.setText(FORMATTER.format(date.getDate()));
}
 
Example #14
Source File: BasicActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override
public void onDateSelected(
    @NonNull MaterialCalendarView widget,
    @NonNull CalendarDay date,
    boolean selected) {
  textView.setText(selected ? FORMATTER.format(date.getDate()) : "No Selection");
}
 
Example #15
Source File: BasicActivityDecorated.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override
public void onDateSelected(
    @NonNull MaterialCalendarView widget,
    @NonNull CalendarDay date,
    boolean selected) {
  //If you change a decorate, you need to invalidate decorators
  oneDayDecorator.setDate(date.getDate());
  widget.invalidateDecorators();
}
 
Example #16
Source File: BasicActivityDecorated.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override
protected void onPostExecute(@NonNull List<CalendarDay> calendarDays) {
  super.onPostExecute(calendarDays);

  if (isFinishing()) {
    return;
  }

  widget.addDecorator(new EventDecorator(Color.RED, calendarDays));
}
 
Example #17
Source File: DynamicSettersActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@OnClick(R.id.button_min_date)
void onMinClicked() {
  showDatePickerDialog(this, widget.getMinimumDate(),
      (view, year, monthOfYear, dayOfMonth) ->
          widget.state().edit()
              .setMinimumDate(CalendarDay.from(year, monthOfYear + 1, dayOfMonth))
              .commit()
  );
}
 
Example #18
Source File: DynamicSettersActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@OnClick(R.id.button_max_date)
void onMaxClicked() {
  showDatePickerDialog(this, widget.getMaximumDate(),
      (view, year, monthOfYear, dayOfMonth) ->
          widget.state().edit()
              .setMaximumDate(CalendarDay.from(year, monthOfYear + 1, dayOfMonth))
              .commit()
  );
}
 
Example #19
Source File: DynamicSettersActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@OnClick(R.id.button_selected_date)
void onSelectedClicked() {
  showDatePickerDialog(this, widget.getSelectedDate(),
      (view, year, monthOfYear, dayOfMonth) ->
          widget.setSelectedDate(CalendarDay.from(year, monthOfYear + 1, dayOfMonth))
  );
}
 
Example #20
Source File: DynamicSettersActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
public static void showDatePickerDialog(
    Context context, CalendarDay day,
    DatePickerDialog.OnDateSetListener callback) {
  if (day == null) {
    day = CalendarDay.today();
  }
  DatePickerDialog dialog = new DatePickerDialog(
      context, 0, callback, day.getYear(), day.getMonth() - 1, day.getDay()
  );
  dialog.show();
}
 
Example #21
Source File: CustomizeCodeActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_basic);
  ButterKnife.bind(this);

  widget.setShowOtherDates(MaterialCalendarView.SHOW_ALL);
  widget.setLeftArrow(R.drawable.ic_arrow_back);
  widget.setRightArrow(R.drawable.ic_arrow_forward);
  widget.setSelectionColor(getResources().getColor(R.color.sample_primary));
  widget.setWeekDayTextAppearance(R.style.CustomTextAppearance);
  widget.setHeaderTextAppearance(R.style.CustomTextAppearance);
  widget.setDateTextAppearance(R.style.CustomTextAppearance);
  widget.setTitleFormatter(new MonthArrayTitleFormatter(getResources().getTextArray(R.array.custom_months)));
  widget.setWeekDayFormatter(new ArrayWeekDayFormatter(getResources().getTextArray(R.array.custom_weekdays)));
  widget.setTileSize((int) TypedValue.applyDimension(
      TypedValue.COMPLEX_UNIT_DIP,
      36,
      getResources().getDisplayMetrics()
  ));
  widget.setTitleAnimationOrientation(MaterialCalendarView.VERTICAL);

  CalendarDay today = CalendarDay.from(2016, 5, 2);
  widget.setCurrentDate(today);
  widget.setSelectedDate(today);

  widget.state().edit()
      .setFirstDayOfWeek(DayOfWeek.WEDNESDAY)
      .setMinimumDate(CalendarDay.from(2016, 4, 3))
      .setMaximumDate(CalendarDay.from(2016, 5, 12))
      .setCalendarDisplayMode(CalendarMode.WEEKS)
      .commit();
}
 
Example #22
Source File: GettersActivity.java    From material-calendarview with MIT License 5 votes vote down vote up
@OnClick(R.id.get_selected_date) public void getSelectedDatesClick(final View v) {
  final CalendarDay selectedDate = widget.getSelectedDate();
  if (selectedDate != null) {
    Toast.makeText(this, selectedDate.toString(), Toast.LENGTH_SHORT).show();
    Log.e("GettersActivity", selectedDate.toString());
  } else {
    Toast.makeText(this, "No Selection", Toast.LENGTH_SHORT).show();
  }
}
 
Example #23
Source File: HoraireFragment.java    From ETSMobile-Android2 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDateSelected(MaterialCalendarView widget, CalendarDay date, boolean selected) {
    widget.setSelectedDate(date);
    fillSeancesList(date.getDate());

    openCourseListDialog();
}
 
Example #24
Source File: CalendarEvent.java    From ReactNativeCalendarAndroid with MIT License 4 votes vote down vote up
public CalendarEvent(int viewId, CalendarDay date, boolean selected) {
    super(viewId);
    this.date = date;
    this.selected = selected;
}
 
Example #25
Source File: DateFormatDayFormatter.java    From monthweekmaterialcalendarview with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
@NonNull
public String format(@NonNull CalendarDay day) {
    return dateFormat.format(day.getDate());
}
 
Example #26
Source File: OneDayDecorator.java    From material-calendarview with MIT License 4 votes vote down vote up
public OneDayDecorator() {
  date = CalendarDay.today();
}
 
Example #27
Source File: OneDayDecorator.java    From material-calendarview with MIT License 4 votes vote down vote up
@Override
public boolean shouldDecorate(CalendarDay day) {
  return date != null && day.equals(date);
}
 
Example #28
Source File: OneDayDecorator.java    From material-calendarview with MIT License 4 votes vote down vote up
/**
 * We're changing the internals, so make sure to call {@linkplain MaterialCalendarView#invalidateDecorators()}
 */
public void setDate(LocalDate date) {
  this.date = CalendarDay.from(date);
}
 
Example #29
Source File: EventDecorator.java    From ETSMobile-Android2 with Apache License 2.0 4 votes vote down vote up
public EventDecorator(ArrayList<CalendarDay> dates, int color) {
    this.dates = new HashSet<>(dates);
    this.color = color;
}
 
Example #30
Source File: EventDecorator.java    From material-calendarview with MIT License 4 votes vote down vote up
public EventDecorator(int color, Collection<CalendarDay> dates) {
  this.color = color;
  this.dates = new HashSet<>(dates);
}