diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerAdapter.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerAdapter.java index d4c68eae..6731bb6b 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerAdapter.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerAdapter.java @@ -3,17 +3,21 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.view.PagerAdapter; +import android.view.Gravity; import android.view.View; import android.view.ViewGroup; + import com.prolificinteractive.materialcalendarview.MaterialCalendarView.ShowOtherDates; import com.prolificinteractive.materialcalendarview.format.DayFormatter; import com.prolificinteractive.materialcalendarview.format.TitleFormatter; import com.prolificinteractive.materialcalendarview.format.WeekDayFormatter; + +import org.threeten.bp.LocalDate; + import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.threeten.bp.LocalDate; /** * Pager adapter backing the calendar view @@ -36,6 +40,7 @@ abstract class CalendarPagerAdapter extends PagerAd private DateRangeIndex rangeIndex; private List selectedDates = new ArrayList<>(); private WeekDayFormatter weekDayFormatter = WeekDayFormatter.DEFAULT; + private int weekDayGravity = Gravity.CENTER; private DayFormatter dayFormatter = DayFormatter.DEFAULT; private DayFormatter dayFormatterContentDescription = dayFormatter; private List decorators = new ArrayList<>(); @@ -90,6 +95,7 @@ public CalendarPagerAdapter migrateStateAndReturn(CalendarPagerAdapter new newAdapter.maxDate = maxDate; newAdapter.selectedDates = selectedDates; newAdapter.weekDayFormatter = weekDayFormatter; + newAdapter.weekDayGravity = weekDayGravity; newAdapter.dayFormatter = dayFormatter; newAdapter.dayFormatterContentDescription = dayFormatterContentDescription; newAdapter.decorators = decorators; @@ -156,6 +162,7 @@ public Object instantiateItem(@NonNull ViewGroup container, int position) { if (weekDayTextAppearance != null) { pagerView.setWeekDayTextAppearance(weekDayTextAppearance); } + pagerView.setWeekDayTextGravity(weekDayGravity); pagerView.setShowOtherDates(showOtherDates); pagerView.setMinimumDate(minDate); pagerView.setMaximumDate(maxDate); @@ -262,6 +269,13 @@ public void setWeekDayTextAppearance(int taId) { } } + public void setWeekDayTextGravity(int gravity) { + this.weekDayGravity = gravity; + for (V pagerView : currentViews) { + pagerView.setWeekDayTextGravity(gravity); + } + } + public void setRangeDates(CalendarDay min, CalendarDay max) { this.minDate = min; this.maxDate = max; diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerView.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerView.java index f3a4fa9a..0053e3e2 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerView.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/CalendarPagerView.java @@ -7,17 +7,20 @@ import android.view.ViewGroup; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; + import com.prolificinteractive.materialcalendarview.MaterialCalendarView.ShowOtherDates; import com.prolificinteractive.materialcalendarview.format.DayFormatter; import com.prolificinteractive.materialcalendarview.format.WeekDayFormatter; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; + import org.threeten.bp.DayOfWeek; import org.threeten.bp.LocalDate; import org.threeten.bp.temporal.TemporalField; import org.threeten.bp.temporal.WeekFields; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import static com.prolificinteractive.materialcalendarview.MaterialCalendarView.SHOW_DEFAULTS; import static com.prolificinteractive.materialcalendarview.MaterialCalendarView.showOtherMonths; @@ -118,6 +121,13 @@ public void setWeekDayTextAppearance(int taId) { } } + public void setWeekDayTextGravity(int gravity) { + for (WeekDayView weekDayView : weekDayViews) { + weekDayView.setGravity(gravity); + weekDayView.invalidate(); + } + } + public void setDateTextAppearance(int taId) { for (DayView dayView : dayViews) { dayView.setTextAppearance(getContext(), taId); diff --git a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java index 623b4a69..133f5a3c 100644 --- a/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java +++ b/library/src/main/java/com/prolificinteractive/materialcalendarview/MaterialCalendarView.java @@ -750,6 +750,10 @@ public void setWeekDayTextAppearance(int resourceId) { adapter.setWeekDayTextAppearance(resourceId); } + public void setWeekDayTextGravity(int gravity) { + adapter.setWeekDayTextGravity(gravity); + } + /** * Get the currently selected date, or null if no selection. Depending on the selection mode, * you might get different results. diff --git a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/CustomizeCodeActivity.java b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/CustomizeCodeActivity.java index 2cdbda24..0f0095eb 100644 --- a/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/CustomizeCodeActivity.java +++ b/sample/src/main/java/com/prolificinteractive/materialcalendarview/sample/CustomizeCodeActivity.java @@ -3,15 +3,19 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.TypedValue; -import butterknife.BindView; -import butterknife.ButterKnife; +import android.view.Gravity; + import com.prolificinteractive.materialcalendarview.CalendarDay; import com.prolificinteractive.materialcalendarview.CalendarMode; import com.prolificinteractive.materialcalendarview.MaterialCalendarView; import com.prolificinteractive.materialcalendarview.format.ArrayWeekDayFormatter; import com.prolificinteractive.materialcalendarview.format.MonthArrayTitleFormatter; + import org.threeten.bp.DayOfWeek; +import butterknife.BindView; +import butterknife.ButterKnife; + public class CustomizeCodeActivity extends AppCompatActivity { @BindView(R.id.calendarView) @@ -28,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) { widget.setRightArrow(R.drawable.ic_arrow_forward); widget.setSelectionColor(getResources().getColor(R.color.sample_primary)); widget.setWeekDayTextAppearance(R.style.CustomTextAppearance); + widget.setWeekDayTextGravity(Gravity.BOTTOM); widget.setHeaderTextAppearance(R.style.CustomTextAppearance); widget.setDateTextAppearance(R.style.CustomTextAppearance); widget.setTitleFormatter(new MonthArrayTitleFormatter(getResources().getTextArray(R.array.custom_months)));