346 lines
12 KiB
Java
346 lines
12 KiB
Java
package com.prolificinteractive.materialcalendarview;
|
|
|
|
import android.util.AttributeSet;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
|
|
import com.prolificinteractive.materialcalendarview.format.DayFormatter;
|
|
import com.prolificinteractive.materialcalendarview.format.WeekDayFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.Calendar;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes3.dex */
|
|
public abstract class CalendarPagerView extends ViewGroup implements View.OnClickListener {
|
|
protected static final int DAY_NAMES_ROW = 1;
|
|
protected static final int DEFAULT_DAYS_IN_WEEK = 7;
|
|
protected static final int DEFAULT_MAX_WEEKS = 6;
|
|
private static final Calendar tempWorkingCalendar = CalendarUtils.getInstance();
|
|
private final Collection<DayView> dayViews;
|
|
private final ArrayList<DecoratorResult> decoratorResults;
|
|
private int dividerColor;
|
|
private int dividerSize;
|
|
private boolean enableWeekDivider;
|
|
private boolean enableWeekOfMonthDivider;
|
|
private int firstDayOfWeek;
|
|
private CalendarDay firstViewDay;
|
|
private CalendarDay maxDate;
|
|
private MaterialCalendarView mcv;
|
|
private CalendarDay minDate;
|
|
|
|
@MaterialCalendarView.ShowOtherDates
|
|
protected int showOtherDates;
|
|
private final ArrayList<WeekDayView> weekDayViews;
|
|
|
|
protected abstract void buildDayViews(Collection<DayView> collection, Calendar calendar);
|
|
|
|
protected abstract int getRows();
|
|
|
|
protected abstract boolean isDayEnabled(CalendarDay calendarDay);
|
|
|
|
@Override // android.view.ViewGroup
|
|
public boolean shouldDelayChildPressedState() {
|
|
return false;
|
|
}
|
|
|
|
public CalendarPagerView(MaterialCalendarView materialCalendarView, CalendarDay calendarDay, int i) {
|
|
super(materialCalendarView.getContext());
|
|
this.weekDayViews = new ArrayList<>();
|
|
this.decoratorResults = new ArrayList<>();
|
|
this.showOtherDates = 4;
|
|
this.minDate = null;
|
|
this.maxDate = null;
|
|
this.dividerColor = 0;
|
|
this.dividerSize = 0;
|
|
ArrayList arrayList = new ArrayList();
|
|
this.dayViews = arrayList;
|
|
this.mcv = materialCalendarView;
|
|
this.firstViewDay = calendarDay;
|
|
this.firstDayOfWeek = i;
|
|
setClipChildren(false);
|
|
setClipToPadding(false);
|
|
buildWeekDays(resetAndGetWorkingCalendar());
|
|
buildDayViews(arrayList, resetAndGetWorkingCalendar());
|
|
}
|
|
|
|
private void buildWeekDays(Calendar calendar) {
|
|
for (int i = 0; i < 7; i++) {
|
|
WeekDayView weekDayView = new WeekDayView(getContext(), CalendarUtils.getDayOfWeek(calendar));
|
|
this.weekDayViews.add(weekDayView);
|
|
addView(weekDayView);
|
|
calendar.add(5, 1);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public void addDayView(Collection<DayView> collection, Calendar calendar) {
|
|
DayView dayView = new DayView(getContext(), CalendarDay.from(calendar));
|
|
dayView.setOnClickListener(this);
|
|
collection.add(dayView);
|
|
addView(dayView, new LayoutParams());
|
|
calendar.add(5, 1);
|
|
}
|
|
|
|
protected Calendar resetAndGetWorkingCalendar() {
|
|
CalendarDay firstViewDay = getFirstViewDay();
|
|
Calendar calendar = tempWorkingCalendar;
|
|
firstViewDay.copyTo(calendar);
|
|
calendar.setFirstDayOfWeek(getFirstDayOfWeek());
|
|
int firstDayOfWeek = getFirstDayOfWeek() - CalendarUtils.getDayOfWeek(calendar);
|
|
if (!MaterialCalendarView.showOtherMonths(this.showOtherDates) ? firstDayOfWeek > 0 : firstDayOfWeek >= 0) {
|
|
firstDayOfWeek -= 7;
|
|
}
|
|
calendar.add(5, firstDayOfWeek);
|
|
return calendar;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public void setDayViewDecorators(List<DecoratorResult> list) {
|
|
this.decoratorResults.clear();
|
|
if (list != null) {
|
|
this.decoratorResults.addAll(list);
|
|
}
|
|
invalidateDecorators();
|
|
}
|
|
|
|
public void setWeekDayTextAppearance(int i) {
|
|
Iterator<WeekDayView> it = this.weekDayViews.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().setTextAppearance(getContext(), i);
|
|
}
|
|
}
|
|
|
|
public void setDateTextAppearance(int i) {
|
|
Iterator<DayView> it = this.dayViews.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().setTextAppearance(getContext(), i);
|
|
}
|
|
}
|
|
|
|
public void setShowOtherDates(@MaterialCalendarView.ShowOtherDates int i) {
|
|
this.showOtherDates = i;
|
|
updateUi();
|
|
}
|
|
|
|
public void setSelectionEnabled(boolean z) {
|
|
for (DayView dayView : this.dayViews) {
|
|
dayView.setOnClickListener(z ? this : null);
|
|
dayView.setClickable(z);
|
|
}
|
|
}
|
|
|
|
public void setSelectionColor(int i) {
|
|
Iterator<DayView> it = this.dayViews.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().setSelectionColor(i);
|
|
}
|
|
}
|
|
|
|
public void setWeekDayFormatter(WeekDayFormatter weekDayFormatter) {
|
|
Iterator<WeekDayView> it = this.weekDayViews.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().setWeekDayFormatter(weekDayFormatter);
|
|
}
|
|
}
|
|
|
|
public void setDayFormatter(DayFormatter dayFormatter) {
|
|
Iterator<DayView> it = this.dayViews.iterator();
|
|
while (it.hasNext()) {
|
|
it.next().setDayFormatter(dayFormatter);
|
|
}
|
|
}
|
|
|
|
public void setMinimumDate(CalendarDay calendarDay) {
|
|
this.minDate = calendarDay;
|
|
updateUi();
|
|
}
|
|
|
|
public void setMaximumDate(CalendarDay calendarDay) {
|
|
this.maxDate = calendarDay;
|
|
updateUi();
|
|
}
|
|
|
|
public void setEnableWeekDivider(boolean z) {
|
|
this.enableWeekDivider = z;
|
|
updateUi();
|
|
}
|
|
|
|
public void setEnableWeekOfMonthDivider(boolean z) {
|
|
this.enableWeekOfMonthDivider = z;
|
|
updateUi();
|
|
}
|
|
|
|
public void setDividerColor(int i) {
|
|
this.dividerColor = i;
|
|
updateUi();
|
|
}
|
|
|
|
public void setDividerSize(int i) {
|
|
this.dividerSize = i;
|
|
updateUi();
|
|
}
|
|
|
|
public void setSelectedDates(Collection<CalendarDay> collection) {
|
|
for (DayView dayView : this.dayViews) {
|
|
dayView.setChecked(collection != null && collection.contains(dayView.getDate()));
|
|
}
|
|
postInvalidate();
|
|
}
|
|
|
|
protected void updateUi() {
|
|
for (DayView dayView : this.dayViews) {
|
|
CalendarDay date = dayView.getDate();
|
|
dayView.setupSelection(this.showOtherDates, date.isInRange(this.minDate, this.maxDate), isDayEnabled(date));
|
|
}
|
|
postInvalidate();
|
|
}
|
|
|
|
protected void invalidateDecorators() {
|
|
DayViewFacade dayViewFacade = new DayViewFacade();
|
|
for (DayView dayView : this.dayViews) {
|
|
dayViewFacade.reset();
|
|
Iterator<DecoratorResult> it = this.decoratorResults.iterator();
|
|
while (it.hasNext()) {
|
|
DecoratorResult next = it.next();
|
|
if (next.decorator.shouldDecorate(dayView.getDate())) {
|
|
next.result.applyTo(dayViewFacade);
|
|
}
|
|
}
|
|
dayView.applyFacade(dayViewFacade);
|
|
}
|
|
}
|
|
|
|
@Override // android.view.View.OnClickListener
|
|
public void onClick(View view) {
|
|
if (view instanceof DayView) {
|
|
this.mcv.onDateClicked((DayView) view);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
@Override // android.view.ViewGroup
|
|
public LayoutParams generateDefaultLayoutParams() {
|
|
return new LayoutParams();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
protected void onMeasure(int i, int i2) {
|
|
int size = View.MeasureSpec.getSize(i);
|
|
int mode = View.MeasureSpec.getMode(i);
|
|
int size2 = View.MeasureSpec.getSize(i2);
|
|
if (View.MeasureSpec.getMode(i2) == 0 || mode == 0) {
|
|
throw new IllegalStateException("CalendarPagerView should never be left to decide it's size");
|
|
}
|
|
int i3 = size / 7;
|
|
int rows = size2 / getRows();
|
|
setMeasuredDimension(size, size2 + (getDividerHeight() * (getRows() - (this.enableWeekDivider ? 1 : 2))));
|
|
int childCount = getChildCount();
|
|
for (int i4 = 0; i4 < childCount; i4++) {
|
|
getChildAt(i4).measure(View.MeasureSpec.makeMeasureSpec(i3, 1073741824), View.MeasureSpec.makeMeasureSpec(rows, 1073741824));
|
|
}
|
|
}
|
|
|
|
@Override // android.view.ViewGroup, android.view.View
|
|
protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
|
|
int childCount = getChildCount();
|
|
ArrayList arrayList = new ArrayList();
|
|
int i5 = this.dividerSize;
|
|
int i6 = 0;
|
|
int i7 = 0;
|
|
for (int i8 = 0; i8 < childCount; i8++) {
|
|
View childAt = getChildAt(i8);
|
|
int measuredWidth = childAt.getMeasuredWidth() + i6;
|
|
int measuredHeight = childAt.getMeasuredHeight() + i7;
|
|
childAt.layout(i6, i7, measuredWidth, measuredHeight);
|
|
if (i8 % 7 == 6) {
|
|
if (i8 > 7 || !this.enableWeekDivider) {
|
|
i7 = measuredHeight;
|
|
} else {
|
|
View view = new View(getContext());
|
|
view.setBackgroundColor(this.dividerColor);
|
|
int i9 = measuredHeight + i5;
|
|
view.layout(0, measuredHeight, getMeasuredWidth(), i9);
|
|
arrayList.add(view);
|
|
i7 = i9;
|
|
}
|
|
if (i8 <= 7 || !this.enableWeekOfMonthDivider) {
|
|
i6 = 0;
|
|
} else {
|
|
View view2 = new View(getContext());
|
|
view2.setBackgroundColor(this.dividerColor);
|
|
int i10 = i7 + i5;
|
|
view2.layout(0, i7, getMeasuredWidth(), i10);
|
|
arrayList.add(view2);
|
|
i6 = 0;
|
|
i7 = i10;
|
|
}
|
|
} else {
|
|
i6 = measuredWidth;
|
|
}
|
|
}
|
|
if (arrayList.isEmpty()) {
|
|
return;
|
|
}
|
|
Iterator it = arrayList.iterator();
|
|
while (it.hasNext()) {
|
|
addView((View) it.next());
|
|
}
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
public LayoutParams generateLayoutParams(AttributeSet attributeSet) {
|
|
return new LayoutParams();
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
protected boolean checkLayoutParams(ViewGroup.LayoutParams layoutParams) {
|
|
return layoutParams instanceof LayoutParams;
|
|
}
|
|
|
|
@Override // android.view.ViewGroup
|
|
protected ViewGroup.LayoutParams generateLayoutParams(ViewGroup.LayoutParams layoutParams) {
|
|
return new LayoutParams();
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
|
|
super.onInitializeAccessibilityEvent(accessibilityEvent);
|
|
accessibilityEvent.setClassName(CalendarPagerView.class.getName());
|
|
}
|
|
|
|
@Override // android.view.View
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo accessibilityNodeInfo) {
|
|
super.onInitializeAccessibilityNodeInfo(accessibilityNodeInfo);
|
|
accessibilityNodeInfo.setClassName(CalendarPagerView.class.getName());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
/* loaded from: classes3.dex */
|
|
public static class LayoutParams extends ViewGroup.MarginLayoutParams {
|
|
public LayoutParams() {
|
|
super(-2, -2);
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: protected */
|
|
public CalendarDay getFirstViewDay() {
|
|
return this.firstViewDay;
|
|
}
|
|
|
|
protected int getFirstDayOfWeek() {
|
|
return this.firstDayOfWeek;
|
|
}
|
|
|
|
private int getDividerHeight() {
|
|
if (this.enableWeekDivider || this.enableWeekOfMonthDivider) {
|
|
return this.dividerSize;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|