Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Change week day text gravity #1067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +40,7 @@ abstract class CalendarPagerAdapter<V extends CalendarPagerView> extends PagerAd
private DateRangeIndex rangeIndex;
private List<CalendarDay> selectedDates = new ArrayList<>();
private WeekDayFormatter weekDayFormatter = WeekDayFormatter.DEFAULT;
private int weekDayGravity = Gravity.CENTER;
private DayFormatter dayFormatter = DayFormatter.DEFAULT;
private DayFormatter dayFormatterContentDescription = dayFormatter;
private List<DayViewDecorator> decorators = new ArrayList<>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)));
Expand Down