diff --git a/README.md b/README.md index e032137..d93429a 100644 --- a/README.md +++ b/README.md @@ -31,14 +31,14 @@ Declare a DayPickerView inside your layout XML file: ``` -Next, you have to implement `DatePickerController` in your Activity or your Fragment. You will have to set `getMaxYear` and `onDayOfMonthSelected`. The first one is the max year between the current one and this maxYear. The second one is called every time user selects a new date. +Next, you have to implement `DatePickerController` or instantiate `DatePickerControllerAdapter` in your Activity or your Fragment. You will be able to set `getMaxYear`, `onDayOfMonthSelected`, and `onDateRangeSelected`. The first one is the max year between the current one and this maxYear. The second one is called every time user selects a new date. The third is called when a range is selected. ``` java @Override public int getMaxYear() { - return 2015; + return Calendar.getInstance().get(Calendar.YEAR) + 1; } @Override @@ -47,6 +47,12 @@ Next, you have to implement `DatePickerController` in your Activity or your Frag Log.e("Day Selected", day + " / " + month + " / " + year); } + @Override + public void onDateRangeSelected(SelectedDays selectedDays) + { + Log.e("Date range selected", selectedDays.getFirst().toString() + " --> " + selectedDays.getLast().toString()); + } + ``` --- @@ -70,6 +76,7 @@ CalendarListview is fully customizable: * app:selectedDayRadius [dimension def:16dip] --> Set radius if you use default circle indicator * app:calendarHeight [dimension def:270dip] --> Height of each month/row * app:enablePreviousDay [boolean def:true] --> Enable past days in current month +* app:allowSingleDay [boolean def:true] --> Enable single day selection (same start and end date) * app:currentDaySelected [boolean def:false] --> Select current day by default * app:firstMonth [enum def:-1] --> Start listview at the specified month * app:lastMonth [enum def:-1] --> End listview at the specified month diff --git a/build.gradle b/build.gradle index b1e051f..b831236 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:1.1.0' + classpath 'com.android.tools.build:gradle:1.5.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/library/src/main/java/com/andexert/calendarlistview/library/CalendarUtils.java b/library/src/main/java/com/andexert/calendarlistview/library/CalendarUtils.java index b319554..3887013 100644 --- a/library/src/main/java/com/andexert/calendarlistview/library/CalendarUtils.java +++ b/library/src/main/java/com/andexert/calendarlistview/library/CalendarUtils.java @@ -24,29 +24,20 @@ package com.andexert.calendarlistview.library; import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; public class CalendarUtils { - public static int getDaysInMonth(int month, int year) { - switch (month) { - case Calendar.JANUARY: - case Calendar.MARCH: - case Calendar.MAY: - case Calendar.JULY: - case Calendar.AUGUST: - case Calendar.OCTOBER: - case Calendar.DECEMBER: - return 31; - case Calendar.APRIL: - case Calendar.JUNE: - case Calendar.SEPTEMBER: - case Calendar.NOVEMBER: - return 30; - case Calendar.FEBRUARY: - return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) ? 29 : 28; - default: - throw new IllegalArgumentException("Invalid Month"); - } + public static int getDaysInMonth(int month, int year) + { + return new GregorianCalendar(year, month, 1).getActualMaximum(Calendar.DAY_OF_MONTH); + } + + public static boolean isSameDay(Calendar first, Calendar second) + { + return first.get(Calendar.YEAR) == second.get(Calendar.YEAR) && + first.get(Calendar.DAY_OF_YEAR) == second.get(Calendar.DAY_OF_YEAR); } } diff --git a/library/src/main/java/com/andexert/calendarlistview/library/DatePickerAttributes.java b/library/src/main/java/com/andexert/calendarlistview/library/DatePickerAttributes.java new file mode 100644 index 0000000..02b379b --- /dev/null +++ b/library/src/main/java/com/andexert/calendarlistview/library/DatePickerAttributes.java @@ -0,0 +1,65 @@ +package com.andexert.calendarlistview.library; + +import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; + +import java.util.Calendar; + +public class DatePickerAttributes +{ + protected static final int MONTHS_IN_YEAR = 12; + + final int firstMonth; + final int lastMonth; + + final boolean currentDaySelected; + final boolean allowSingleDay; + final boolean drawRect; + final boolean isPrevDayEnabled; + + final int currentDayTextColor; + final int monthTextColor; + final int dayTextColor; + final int dayNumColor; + final int selectedDayTextColor; + final int previousDayColor; + final int selectedDayBgColor; + + final int dayTextSize; + final int dayNameTextSize; + final int monthHeaderHeight; + final int monthLabelTextSize; + final int selectedDayRadius; + final int rowHeight; + + DatePickerAttributes(Context context, TypedArray typedArray) + { + Calendar calendar = Calendar.getInstance(); + Resources resources = context.getResources(); + + firstMonth = typedArray.getInt(R.styleable.DayPickerView_firstMonth, calendar.get(Calendar.MONTH)); + lastMonth = typedArray.getInt(R.styleable.DayPickerView_lastMonth, (calendar.get(Calendar.MONTH) - 1) % MONTHS_IN_YEAR); + + currentDaySelected = typedArray.getBoolean(R.styleable.DayPickerView_currentDaySelected, false); + allowSingleDay = typedArray.getBoolean(R.styleable.DayPickerView_allowSingleDay, true); + isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true); + drawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false); + + currentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.normal_day)); + monthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day)); + dayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day)); + dayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day)); + previousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day)); + selectedDayBgColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background)); + selectedDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text)); + + dayTextSize = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day)); + monthLabelTextSize = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month)); + dayNameTextSize = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name)); + monthHeaderHeight = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset(R.dimen.header_month_height)); + selectedDayRadius = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius)); + + rowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - monthHeaderHeight) / 6); + } +} diff --git a/library/src/main/java/com/andexert/calendarlistview/library/DatePickerController.java b/library/src/main/java/com/andexert/calendarlistview/library/DatePickerController.java index 3b9da03..c25d163 100644 --- a/library/src/main/java/com/andexert/calendarlistview/library/DatePickerController.java +++ b/library/src/main/java/com/andexert/calendarlistview/library/DatePickerController.java @@ -23,11 +23,11 @@ ***********************************************************************************/ package com.andexert.calendarlistview.library; -public interface DatePickerController { - public abstract int getMaxYear(); +public interface DatePickerController +{ + int getMaxYear(); - public abstract void onDayOfMonthSelected(int year, int month, int day); - - public abstract void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays selectedDays); + void onDayOfMonthSelected(int year, int month, int day); + void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays selectedDays); } \ No newline at end of file diff --git a/library/src/main/java/com/andexert/calendarlistview/library/DatePickerControllerAdapter.java b/library/src/main/java/com/andexert/calendarlistview/library/DatePickerControllerAdapter.java new file mode 100644 index 0000000..1d13321 --- /dev/null +++ b/library/src/main/java/com/andexert/calendarlistview/library/DatePickerControllerAdapter.java @@ -0,0 +1,20 @@ +package com.andexert.calendarlistview.library; + +import com.andexert.calendarlistview.library.SimpleMonthAdapter.SelectedDays; + +import java.util.Calendar; + +public class DatePickerControllerAdapter implements DatePickerController +{ + @Override + public int getMaxYear() + { + return Calendar.getInstance().get(Calendar.YEAR) + 1; + } + + @Override + public void onDayOfMonthSelected(int year, int month, int day) {} + + @Override + public void onDateRangeSelected(SelectedDays selectedDays) {} +} diff --git a/library/src/main/java/com/andexert/calendarlistview/library/DayPickerView.java b/library/src/main/java/com/andexert/calendarlistview/library/DayPickerView.java index 1584aee..5b808e9 100644 --- a/library/src/main/java/com/andexert/calendarlistview/library/DayPickerView.java +++ b/library/src/main/java/com/andexert/calendarlistview/library/DayPickerView.java @@ -29,16 +29,20 @@ import android.support.v7.widget.RecyclerView; import android.util.AttributeSet; +import com.andexert.calendarlistview.library.SimpleMonthAdapter.CalendarDay; + public class DayPickerView extends RecyclerView { - protected Context mContext; - protected SimpleMonthAdapter mAdapter; - private DatePickerController mController; + protected Context mContext; + private DatePickerAttributes mAttributes; + protected SimpleMonthAdapter mAdapter; + private DatePickerController mController; + private OnScrollListener onScrollListener; + protected int mCurrentScrollState = 0; - protected long mPreviousScrollPosition; - protected int mPreviousScrollState = 0; - private TypedArray typedArray; - private OnScrollListener onScrollListener; + protected long mPreviousScrollPosition; + protected int mPreviousScrollState = 0; + public DayPickerView(Context context) { @@ -55,7 +59,10 @@ public DayPickerView(Context context, AttributeSet attrs, int defStyle) super(context, attrs, defStyle); if (!isInEditMode()) { - typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView); + TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView); + mAttributes = new DatePickerAttributes(context, typedArray); + typedArray.recycle(); + setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); init(context); } @@ -68,7 +75,6 @@ public void setController(DatePickerController mController) setAdapter(mAdapter); } - public void init(Context paramContext) { setLayoutManager(new LinearLayoutManager(paramContext)); mContext = paramContext; @@ -91,10 +97,25 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) }; } + public void setSelectedRange(CalendarDay first, CalendarDay last) + { + if (mAdapter != null) + { + if (first != null) + { + mAdapter.setSelectedDay(first); + } + + if (last != null) + { + mAdapter.setSelectedDay(last); + } + } + } protected void setUpAdapter() { if (mAdapter == null) { - mAdapter = new SimpleMonthAdapter(getContext(), mController, typedArray); + mAdapter = new SimpleMonthAdapter(getContext(), mController, mAttributes); } mAdapter.notifyDataSetChanged(); } @@ -105,7 +126,7 @@ protected void setUpListView() { setFadingEdgeLength(0); } - public SimpleMonthAdapter.SelectedDays getSelectedDays() + public SimpleMonthAdapter.SelectedDays getSelectedDays() { return mAdapter.getSelectedDays(); } @@ -115,8 +136,8 @@ protected DatePickerController getController() return mController; } - protected TypedArray getTypedArray() + protected DatePickerAttributes getAttributes() { - return typedArray; + return mAttributes; } } \ No newline at end of file diff --git a/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthAdapter.java b/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthAdapter.java index 20e1b0e..2a523c4 100644 --- a/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthAdapter.java +++ b/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthAdapter.java @@ -24,7 +24,6 @@ package com.andexert.calendarlistview.library; import android.content.Context; -import android.content.res.TypedArray; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; @@ -37,30 +36,28 @@ import java.util.HashMap; public class SimpleMonthAdapter extends RecyclerView.Adapter implements SimpleMonthView.OnDayClickListener { - protected static final int MONTHS_IN_YEAR = 12; - private final TypedArray typedArray; - private final Context mContext; - private final DatePickerController mController; - private final Calendar calendar; - private final SelectedDays selectedDays; - private final Integer firstMonth; - private final Integer lastMonth; - - public SimpleMonthAdapter(Context context, DatePickerController datePickerController, TypedArray typedArray) { - this.typedArray = typedArray; + protected static final int MONTHS_IN_YEAR = DatePickerAttributes.MONTHS_IN_YEAR; + private final Context mContext; + private final DatePickerAttributes mAttributes; + private final DatePickerController mController; + private final Calendar calendar; + private final SelectedDays selectedDays; + + public SimpleMonthAdapter(Context context, DatePickerController datePickerController, DatePickerAttributes attrs) + { + mContext = context; + mAttributes = attrs; calendar = Calendar.getInstance(); - firstMonth = typedArray.getInt(R.styleable.DayPickerView_firstMonth, calendar.get(Calendar.MONTH)); - lastMonth = typedArray.getInt(R.styleable.DayPickerView_lastMonth, (calendar.get(Calendar.MONTH) - 1) % MONTHS_IN_YEAR); - selectedDays = new SelectedDays<>(); - mContext = context; - mController = datePickerController; - init(); - } + selectedDays = new SelectedDays(); + mController = datePickerController; + + init(); + } @Override public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { - final SimpleMonthView simpleMonthView = new SimpleMonthView(mContext, typedArray); + final SimpleMonthView simpleMonthView = new SimpleMonthView(mContext, mAttributes); return new ViewHolder(simpleMonthView, this); } @@ -68,12 +65,12 @@ public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) public void onBindViewHolder(ViewHolder viewHolder, int position) { final SimpleMonthView v = viewHolder.simpleMonthView; - final HashMap drawingParams = new HashMap(); + final HashMap drawingParams = new HashMap<>(); int month; int year; - month = (firstMonth + (position % MONTHS_IN_YEAR)) % MONTHS_IN_YEAR; - year = position / MONTHS_IN_YEAR + calendar.get(Calendar.YEAR) + ((firstMonth + (position % MONTHS_IN_YEAR)) / MONTHS_IN_YEAR); + month = (mAttributes.firstMonth + (position % MONTHS_IN_YEAR)) % MONTHS_IN_YEAR; + year = position / MONTHS_IN_YEAR + calendar.get(Calendar.YEAR) + ((mAttributes.firstMonth + (position % MONTHS_IN_YEAR)) / MONTHS_IN_YEAR); int selectedFirstDay = -1; int selectedLastDay = -1; @@ -120,11 +117,11 @@ public int getItemCount() { int itemCount = (((mController.getMaxYear() - calendar.get(Calendar.YEAR)) + 1) * MONTHS_IN_YEAR); - if (firstMonth != -1) - itemCount -= firstMonth; + if (mAttributes.firstMonth != -1) + itemCount -= mAttributes.firstMonth; - if (lastMonth != -1) - itemCount -= (MONTHS_IN_YEAR - lastMonth) - 1; + if (mAttributes.lastMonth != -1) + itemCount -= (MONTHS_IN_YEAR - mAttributes.lastMonth) - 1; return itemCount; } @@ -144,8 +141,9 @@ public ViewHolder(View itemView, SimpleMonthView.OnDayClickListener onDayClickLi } protected void init() { - if (typedArray.getBoolean(R.styleable.DayPickerView_currentDaySelected, false)) + if (mAttributes.currentDaySelected) { onDayTapped(new CalendarDay(System.currentTimeMillis())); + } } public void onDayClick(SimpleMonthView simpleMonthView, CalendarDay calendarDay) { @@ -155,34 +153,49 @@ public void onDayClick(SimpleMonthView simpleMonthView, CalendarDay calendarDay) } protected void onDayTapped(CalendarDay calendarDay) { - mController.onDayOfMonthSelected(calendarDay.year, calendarDay.month, calendarDay.day); + if (!mAttributes.allowSingleDay && selectedDays.getFirst() != null && selectedDays.getLast() == null && + CalendarUtils.isSameDay(calendarDay.getCalendar(), selectedDays.getFirst().getCalendar())) { + // Don't allow same day selection + return; + } + setSelectedDay(calendarDay); + mController.onDayOfMonthSelected(calendarDay.year, calendarDay.month, calendarDay.day); } public void setSelectedDay(CalendarDay calendarDay) { if (selectedDays.getFirst() != null && selectedDays.getLast() == null) { - selectedDays.setLast(calendarDay); - - if (selectedDays.getFirst().month < calendarDay.month) - { - for (int i = 0; i < selectedDays.getFirst().month - calendarDay.month - 1; ++i) - mController.onDayOfMonthSelected(selectedDays.getFirst().year, selectedDays.getFirst().month + i, selectedDays.getFirst().day); - } - - mController.onDateRangeSelected(selectedDays); + updateLastDay(calendarDay); } else if (selectedDays.getLast() != null) { - selectedDays.setFirst(calendarDay); - selectedDays.setLast(null); - } + selectedDays.setFirst(calendarDay); + selectedDays.setLast(null); + } else - selectedDays.setFirst(calendarDay); + { + selectedDays.setFirst(calendarDay); + } notifyDataSetChanged(); } + private void updateLastDay(CalendarDay calendarDay) + { + selectedDays.setLast(calendarDay); + + if (selectedDays.getFirst().month < calendarDay.month) + { + for (int i = 0; i < selectedDays.getFirst().month - calendarDay.month - 1; ++i) + { + mController.onDayOfMonthSelected(selectedDays.getFirst().year, selectedDays.getFirst().month + i, selectedDays.getFirst().day); + } + } + + mController.onDateRangeSelected(selectedDays); + } + public static class CalendarDay implements Serializable { private static final long serialVersionUID = -5456695978688356202L; @@ -232,13 +245,19 @@ public void setDay(int year, int month, int day) { this.day = day; } - public Date getDate() + public Calendar getCalendar() { if (calendar == null) { calendar = Calendar.getInstance(); } calendar.set(year, month, day); - return calendar.getTime(); + + return calendar; + } + + public Date getDate() + { + return getCalendar().getTime(); } @Override @@ -257,35 +276,43 @@ public String toString() } } - public SelectedDays getSelectedDays() + public SelectedDays getSelectedDays() { return selectedDays; } - public static class SelectedDays implements Serializable + public static class SelectedDays implements Serializable { private static final long serialVersionUID = 3942549765282708376L; - private K first; - private K last; + private CalendarDay first; + private CalendarDay last; - public K getFirst() + public CalendarDay getFirst() { return first; } - public void setFirst(K first) + public void setFirst(CalendarDay first) { this.first = first; } - public K getLast() + public CalendarDay getLast() { return last; } - public void setLast(K last) + public void setLast(CalendarDay last) { - this.last = last; + if (last != null && last.getDate().before(first.getDate())) + { + this.last = this.first; + this.first = last; + } + else + { + this.last = last; + } } } } \ No newline at end of file diff --git a/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthView.java b/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthView.java index f61bdef..d14f7b9 100644 --- a/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthView.java +++ b/library/src/main/java/com/andexert/calendarlistview/library/SimpleMonthView.java @@ -24,8 +24,6 @@ package com.andexert.calendarlistview.library; import android.content.Context; -import android.content.res.Resources; -import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Align; @@ -33,7 +31,6 @@ import android.graphics.RectF; import android.graphics.Typeface; import android.text.format.DateUtils; -import android.text.format.Time; import android.view.MotionEvent; import android.view.View; @@ -45,28 +42,24 @@ class SimpleMonthView extends View { - - public static final String VIEW_PARAMS_HEIGHT = "height"; - public static final String VIEW_PARAMS_MONTH = "month"; - public static final String VIEW_PARAMS_YEAR = "year"; - public static final String VIEW_PARAMS_SELECTED_BEGIN_DAY = "selected_begin_day"; - public static final String VIEW_PARAMS_SELECTED_LAST_DAY = "selected_last_day"; + public static final String VIEW_PARAMS_HEIGHT = "height"; + public static final String VIEW_PARAMS_MONTH = "month"; + public static final String VIEW_PARAMS_YEAR = "year"; + public static final String VIEW_PARAMS_SELECTED_BEGIN_DAY = "selected_begin_day"; + public static final String VIEW_PARAMS_SELECTED_LAST_DAY = "selected_last_day"; public static final String VIEW_PARAMS_SELECTED_BEGIN_MONTH = "selected_begin_month"; - public static final String VIEW_PARAMS_SELECTED_LAST_MONTH = "selected_last_month"; - public static final String VIEW_PARAMS_SELECTED_BEGIN_YEAR = "selected_begin_year"; - public static final String VIEW_PARAMS_SELECTED_LAST_YEAR = "selected_last_year"; - public static final String VIEW_PARAMS_WEEK_START = "week_start"; - - private static final int SELECTED_CIRCLE_ALPHA = 128; - protected static int DEFAULT_HEIGHT = 32; - protected static final int DEFAULT_NUM_ROWS = 6; - protected static int DAY_SELECTED_CIRCLE_SIZE; - protected static int DAY_SEPARATOR_WIDTH = 1; - protected static int MINI_DAY_NUMBER_TEXT_SIZE; - protected static int MIN_HEIGHT = 10; - protected static int MONTH_DAY_LABEL_TEXT_SIZE; - protected static int MONTH_HEADER_SIZE; - protected static int MONTH_LABEL_TEXT_SIZE; + public static final String VIEW_PARAMS_SELECTED_LAST_MONTH = "selected_last_month"; + public static final String VIEW_PARAMS_SELECTED_BEGIN_YEAR = "selected_begin_year"; + public static final String VIEW_PARAMS_SELECTED_LAST_YEAR = "selected_last_year"; + public static final String VIEW_PARAMS_WEEK_START = "week_start"; + + private static final String SANS_SERIF = "sans-serif"; + + protected static int SELECTED_CIRCLE_ALPHA = 128; + protected static int DEFAULT_HEIGHT = 32; + protected static final int DEFAULT_NUM_ROWS = 6; + protected static int DAY_SEPARATOR_WIDTH = 1; + protected static int MIN_HEIGHT = 10; protected int mPadding = 0; @@ -78,92 +71,60 @@ class SimpleMonthView extends View protected Paint mMonthTitleBGPaint; protected Paint mMonthTitlePaint; protected Paint mSelectedCirclePaint; - protected int mCurrentDayTextColor; - protected int mMonthTextColor; - protected int mDayTextColor; - protected int mDayNumColor; - protected int mMonthTitleBGColor; - protected int mPreviousDayColor; - protected int mSelectedDaysColor; - - private final StringBuilder mStringBuilder; - - protected boolean mHasToday = false; - protected boolean mIsPrev = false; - protected int mSelectedBeginDay = -1; - protected int mSelectedLastDay = -1; - protected int mSelectedBeginMonth = -1; - protected int mSelectedLastMonth = -1; - protected int mSelectedBeginYear = -1; - protected int mSelectedLastYear = -1; - protected int mToday = -1; - protected int mWeekStart = 1; - protected int mNumDays = 7; - protected int mNumCells = mNumDays; - private int mDayOfWeekStart = 0; - protected int mMonth; - protected Boolean mDrawRect; - protected int mRowHeight = DEFAULT_HEIGHT; - protected int mWidth; - protected int mYear; - final Time today; - - private final Calendar mCalendar; - private final Calendar mDayLabelCalendar; - private final Boolean isPrevDayEnabled; + + protected DatePickerAttributes mAttributes; + + protected boolean mHasToday = false; + protected boolean mIsPrev = false; + protected int mSelectedBeginDay = -1; + protected int mSelectedLastDay = -1; + protected int mSelectedBeginMonth = -1; + protected int mSelectedLastMonth = -1; + protected int mSelectedBeginYear = -1; + protected int mSelectedLastYear = -1; + protected int mToday = -1; + protected int mWeekStart = 1; + protected int mNumDays = 7; + protected int mNumCells = mNumDays; + private int mDayOfWeekStart = 0; + protected int mMonth; + protected int mWidth; + protected int mRowHeight = DEFAULT_HEIGHT; + + protected int mYear; + final Calendar today; + + private final Calendar mCalendar; + private final Calendar mDayLabelCalendar; private int mNumRows = DEFAULT_NUM_ROWS; - private DateFormatSymbols mDateFormatSymbols = new DateFormatSymbols(); + private DateFormatSymbols mDateFormatSymbols = new DateFormatSymbols(); private OnDayClickListener mOnDayClickListener; - public SimpleMonthView(Context context, TypedArray typedArray) + public SimpleMonthView(Context context, DatePickerAttributes attrs) { super(context); - Resources resources = context.getResources(); + mAttributes = attrs; + mRowHeight = mAttributes.rowHeight; + mDayLabelCalendar = Calendar.getInstance(); mCalendar = Calendar.getInstance(); - today = new Time(Time.getCurrentTimezone()); - today.setToNow(); - mDayOfWeekTypeface = resources.getString(R.string.sans_serif); - mMonthTitleTypeface = resources.getString(R.string.sans_serif); - mCurrentDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorCurrentDay, resources.getColor(R.color.normal_day)); - mMonthTextColor = typedArray.getColor(R.styleable.DayPickerView_colorMonthName, resources.getColor(R.color.normal_day)); - mDayTextColor = typedArray.getColor(R.styleable.DayPickerView_colorDayName, resources.getColor(R.color.normal_day)); - mDayNumColor = typedArray.getColor(R.styleable.DayPickerView_colorNormalDay, resources.getColor(R.color.normal_day)); - mPreviousDayColor = typedArray.getColor(R.styleable.DayPickerView_colorPreviousDay, resources.getColor(R.color.normal_day)); - mSelectedDaysColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayBackground, resources.getColor(R.color.selected_day_background)); - mMonthTitleBGColor = typedArray.getColor(R.styleable.DayPickerView_colorSelectedDayText, resources.getColor(R.color.selected_day_text)); - - mDrawRect = typedArray.getBoolean(R.styleable.DayPickerView_drawRoundRect, false); - - mStringBuilder = new StringBuilder(50); - - MINI_DAY_NUMBER_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDay, resources.getDimensionPixelSize(R.dimen.text_size_day)); - MONTH_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeMonth, resources.getDimensionPixelSize(R.dimen.text_size_month)); - MONTH_DAY_LABEL_TEXT_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_textSizeDayName, resources.getDimensionPixelSize(R.dimen.text_size_day_name)); - MONTH_HEADER_SIZE = typedArray.getDimensionPixelOffset(R.styleable.DayPickerView_headerMonthHeight, resources.getDimensionPixelOffset(R.dimen.header_month_height)); - DAY_SELECTED_CIRCLE_SIZE = typedArray.getDimensionPixelSize(R.styleable.DayPickerView_selectedDayRadius, resources.getDimensionPixelOffset(R.dimen.selected_day_radius)); - - mRowHeight = ((typedArray.getDimensionPixelSize(R.styleable.DayPickerView_calendarHeight, resources.getDimensionPixelOffset(R.dimen.calendar_height)) - MONTH_HEADER_SIZE) / 6); - - isPrevDayEnabled = typedArray.getBoolean(R.styleable.DayPickerView_enablePreviousDay, true); + today = Calendar.getInstance(); + mDayOfWeekTypeface = SANS_SERIF; + mMonthTitleTypeface = SANS_SERIF; initView(); - } private int calculateNumRows() { - int offset = findDayOffset(); - int dividend = (offset + mNumCells) / mNumDays; - int remainder = (offset + mNumCells) % mNumDays; - return (dividend + (remainder > 0 ? 1 : 0)); + return (int)Math.ceil((findDayOffset() + mNumCells) / (double)mNumDays); } private void drawMonthDayLabels(Canvas canvas) { - int y = MONTH_HEADER_SIZE - (MONTH_DAY_LABEL_TEXT_SIZE / 2); + int y = mAttributes.monthHeaderHeight - (mAttributes.dayNameTextSize / 2); int dayWidthHalf = (mWidth - mPadding * 2) / (mNumDays * 2); for (int i = 0; i < mNumDays; i++) { @@ -176,7 +137,7 @@ private void drawMonthDayLabels(Canvas canvas) { private void drawMonthTitle(Canvas canvas) { int x = (mWidth + 2 * mPadding) / 2; - int y = (MONTH_HEADER_SIZE - MONTH_DAY_LABEL_TEXT_SIZE) / 2 + (MONTH_LABEL_TEXT_SIZE / 3); + int y = (mAttributes.monthHeaderHeight - mAttributes.dayNameTextSize) / 2 + (mAttributes.monthLabelTextSize / 3); StringBuilder stringBuilder = new StringBuilder(getMonthAndYearString().toLowerCase()); stringBuilder.setCharAt(0, Character.toUpperCase(stringBuilder.charAt(0))); canvas.drawText(stringBuilder.toString(), x, y, mMonthTitlePaint); @@ -189,106 +150,158 @@ private int findDayOffset() { private String getMonthAndYearString() { int flags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR | DateUtils.FORMAT_NO_MONTH_DAY; - mStringBuilder.setLength(0); long millis = mCalendar.getTimeInMillis(); return DateUtils.formatDateRange(getContext(), millis, millis, flags); } private void onDayClick(SimpleMonthAdapter.CalendarDay calendarDay) { - if (mOnDayClickListener != null && (isPrevDayEnabled || !((calendarDay.month == today.month) && (calendarDay.year == today.year) && calendarDay.day < today.monthDay))) { - mOnDayClickListener.onDayClick(this, calendarDay); - } + if (mOnDayClickListener == null) { + return; + } + + if (!mAttributes.isPrevDayEnabled && prevDay(calendarDay.getCalendar())) { + return; + } + + mOnDayClickListener.onDayClick(this, calendarDay); } - private boolean sameDay(int monthDay, Time time) { - return (mYear == time.year) && (mMonth == time.month) && (monthDay == time.monthDay); + private boolean sameDay(int monthDay) { + Calendar cal = Calendar.getInstance(); + cal.set(mYear, mMonth, monthDay); + return CalendarUtils.isSameDay(cal, today); } - private boolean prevDay(int monthDay, Time time) { - return ((mYear < time.year)) || (mYear == time.year && mMonth < time.month) || ( mMonth == time.month && monthDay < time.monthDay); + private boolean prevDay(int monthDay) { + Calendar cal = Calendar.getInstance(); + cal.set(mYear, mMonth, monthDay); + return prevDay(cal); + } + + private boolean prevDay(Calendar cal) { + return ((cal.get(Calendar.YEAR) < today.get(Calendar.YEAR))) || + (cal.get(Calendar.YEAR) == today.get(Calendar.YEAR) && cal.get(Calendar.DAY_OF_YEAR) < today.get(Calendar.DAY_OF_YEAR)); } - protected void drawMonthNums(Canvas canvas) { - int y = (mRowHeight + MINI_DAY_NUMBER_TEXT_SIZE) / 2 - DAY_SEPARATOR_WIDTH + MONTH_HEADER_SIZE; - int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays); - int dayOffset = findDayOffset(); - int day = 1; + protected void drawMonthNums(Canvas canvas) + { + int y = (mRowHeight + mAttributes.dayTextSize) / 2 - DAY_SEPARATOR_WIDTH + mAttributes.monthHeaderHeight; + int paddingDay = (mWidth - 2 * mPadding) / (2 * mNumDays); + int dayOffset = findDayOffset(); + int day = 1; + + while (day <= mNumCells) + { + int x = paddingDay * (1 + dayOffset * 2) + mPadding; + + boolean isFirst = (mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear); + boolean isLast = (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear); - while (day <= mNumCells) { - int x = paddingDay * (1 + dayOffset * 2) + mPadding; - if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) { - if (mDrawRect) + // Draw Circle/Rect background for selected days + if (isFirst || isLast) + { + // Now draw selected day rect or circle + if (mAttributes.drawRect) { - RectF rectF = new RectF(x - DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) - DAY_SELECTED_CIRCLE_SIZE, x + DAY_SELECTED_CIRCLE_SIZE, (y - MINI_DAY_NUMBER_TEXT_SIZE / 3) + DAY_SELECTED_CIRCLE_SIZE); - canvas.drawRoundRect(rectF, 10.0f, 10.0f,mSelectedCirclePaint); + RectF rectF = new RectF(x - mAttributes.selectedDayRadius, (y - mAttributes.dayTextSize / 3) - mAttributes.selectedDayRadius, x + mAttributes.selectedDayRadius, (y - mAttributes.dayTextSize / 3) + mAttributes.selectedDayRadius); + canvas.drawRoundRect(rectF, 10.0f, 10.0f, mSelectedCirclePaint); } else - canvas.drawCircle(x, y - MINI_DAY_NUMBER_TEXT_SIZE / 3, DAY_SELECTED_CIRCLE_SIZE, mSelectedCirclePaint); - } - if (mHasToday && (mToday == day)) { - mMonthNumPaint.setColor(mCurrentDayTextColor); - mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); - } else { - mMonthNumPaint.setColor(mDayNumColor); - mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); + { + canvas.drawCircle(x, y - mAttributes.dayTextSize / 3, mAttributes.selectedDayRadius, mSelectedCirclePaint); + } } - if ((mMonth == mSelectedBeginMonth && mSelectedBeginDay == day && mSelectedBeginYear == mYear) || (mMonth == mSelectedLastMonth && mSelectedLastDay == day && mSelectedLastYear == mYear)) - mMonthNumPaint.setColor(mMonthTitleBGColor); - - if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && - mSelectedBeginMonth == mSelectedLastMonth && - mSelectedBeginDay == mSelectedLastDay && - day == mSelectedBeginDay && - mMonth == mSelectedBeginMonth && - mYear == mSelectedBeginYear)) - mMonthNumPaint.setColor(mSelectedDaysColor); - - if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mSelectedBeginYear == mYear) && - (((mMonth == mSelectedBeginMonth && mSelectedLastMonth == mSelectedBeginMonth) && ((mSelectedBeginDay < mSelectedLastDay && day > mSelectedBeginDay && day < mSelectedLastDay) || (mSelectedBeginDay > mSelectedLastDay && day < mSelectedBeginDay && day > mSelectedLastDay))) || - ((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) || - ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)))) + // Make today BOLD, previous days italic, otherwise normal + if (mHasToday && (mToday == day)) { - mMonthNumPaint.setColor(mSelectedDaysColor); + mMonthNumPaint.setColor(mAttributes.currentDayTextColor); + mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); } - - if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear && ((mSelectedBeginYear == mYear && mMonth == mSelectedBeginMonth) || (mSelectedLastYear == mYear && mMonth == mSelectedLastMonth)) && - (((mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedBeginMonth && day < mSelectedBeginDay) || (mSelectedBeginMonth < mSelectedLastMonth && mMonth == mSelectedLastMonth && day > mSelectedLastDay)) || - ((mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || (mSelectedBeginMonth > mSelectedLastMonth && mMonth == mSelectedLastMonth && day < mSelectedLastDay))))) + else if (!mAttributes.isPrevDayEnabled && prevDay(day)) { - mMonthNumPaint.setColor(mSelectedDaysColor); + mMonthNumPaint.setColor(mAttributes.previousDayColor); + mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC)); } - - if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) && - ((mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth && mSelectedBeginMonth < mSelectedLastMonth) || - (mMonth < mSelectedBeginMonth && mMonth > mSelectedLastMonth && mSelectedBeginMonth > mSelectedLastMonth))) + else { - mMonthNumPaint.setColor(mSelectedDaysColor); + mMonthNumPaint.setColor(mAttributes.dayNumColor); + mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); } - if ((mSelectedBeginDay != -1 && mSelectedLastDay != -1 && mSelectedBeginYear != mSelectedLastYear) && - ((mSelectedBeginYear < mSelectedLastYear && ((mMonth > mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth < mSelectedLastMonth && mYear == mSelectedLastYear))) || - (mSelectedBeginYear > mSelectedLastYear && ((mMonth < mSelectedBeginMonth && mYear == mSelectedBeginYear) || (mMonth > mSelectedLastMonth && mYear == mSelectedLastYear))))) + // Set color for day + if (isFirst || isLast) { - mMonthNumPaint.setColor(mSelectedDaysColor); + if (isFirst && isLast) + { + // Same Begin and End day + mMonthNumPaint.setColor(mAttributes.selectedDayBgColor); + } + else + { + mMonthNumPaint.setColor(mAttributes.selectedDayTextColor); + } } - - if (!isPrevDayEnabled && prevDay(day, today) && today.month == mMonth && today.year == mYear) + else if (mSelectedBeginDay != -1 && mSelectedLastDay != -1) { - mMonthNumPaint.setColor(mPreviousDayColor); - mMonthNumPaint.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC)); + boolean isSelectedDay = false; + + // There is a selected range + if (mSelectedBeginYear == mSelectedLastYear && mYear == mSelectedBeginYear) + { + if (mMonth == mSelectedBeginMonth && mSelectedBeginMonth == mSelectedLastMonth) + { + if (day > mSelectedBeginDay && day < mSelectedLastDay) + { + // Same month, days between begin day and end day + isSelectedDay = true; + } + } + else if (mMonth > mSelectedBeginMonth && mMonth < mSelectedLastMonth) + { + // All days for months between begin month and end month + isSelectedDay = true; + } + else if ((mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || + (mMonth == mSelectedLastMonth && day < mSelectedLastDay)) + { + // Days of month between begin day and end day + isSelectedDay = true; + } + } + else if (mSelectedBeginYear != mSelectedLastYear) + { + if ((mYear == mSelectedBeginYear && mMonth > mSelectedBeginMonth) || + (mYear == mSelectedLastYear && mMonth < mSelectedLastMonth)) + { + // All days for months between begin month and end month + isSelectedDay = true; + } + else if ((mYear == mSelectedBeginYear && mMonth == mSelectedBeginMonth && day > mSelectedBeginDay) || + (mYear == mSelectedLastYear && mMonth == mSelectedLastMonth && day < mSelectedLastDay)) + { + // Days of month between begin day and end day + isSelectedDay = true; + } + } + + if (isSelectedDay) + { + mMonthNumPaint.setColor(mAttributes.selectedDayBgColor); + } } - canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint); + canvas.drawText(String.format("%d", day), x, y, mMonthNumPaint); - dayOffset++; - if (dayOffset == mNumDays) { - dayOffset = 0; - y += mRowHeight; - } - day++; - } - } + dayOffset++; + if (dayOffset == mNumDays) + { + dayOffset = 0; + y += mRowHeight; + } + day++; + } + } public SimpleMonthAdapter.CalendarDay getDayFromLocation(float x, float y) { int padding = mPadding; @@ -296,7 +309,7 @@ public SimpleMonthAdapter.CalendarDay getDayFromLocation(float x, float y) { return null; } - int yDay = (int) (y - MONTH_HEADER_SIZE) / mRowHeight; + int yDay = (int) (y - mAttributes.monthHeaderHeight) / mRowHeight; int day = 1 + ((int) ((x - padding) * mNumDays / (mWidth - padding - mPadding)) - findDayOffset()) + yDay * mNumDays; if (mMonth > 11 || mMonth < 0 || CalendarUtils.getDaysInMonth(mMonth, mYear) < day || day < 1) @@ -309,31 +322,31 @@ protected void initView() { mMonthTitlePaint = new Paint(); mMonthTitlePaint.setFakeBoldText(true); mMonthTitlePaint.setAntiAlias(true); - mMonthTitlePaint.setTextSize(MONTH_LABEL_TEXT_SIZE); + mMonthTitlePaint.setTextSize(mAttributes.monthLabelTextSize); mMonthTitlePaint.setTypeface(Typeface.create(mMonthTitleTypeface, Typeface.BOLD)); - mMonthTitlePaint.setColor(mMonthTextColor); + mMonthTitlePaint.setColor(mAttributes.monthTextColor); mMonthTitlePaint.setTextAlign(Align.CENTER); mMonthTitlePaint.setStyle(Style.FILL); mMonthTitleBGPaint = new Paint(); mMonthTitleBGPaint.setFakeBoldText(true); mMonthTitleBGPaint.setAntiAlias(true); - mMonthTitleBGPaint.setColor(mMonthTitleBGColor); + mMonthTitleBGPaint.setColor(mAttributes.selectedDayTextColor); mMonthTitleBGPaint.setTextAlign(Align.CENTER); mMonthTitleBGPaint.setStyle(Style.FILL); mSelectedCirclePaint = new Paint(); mSelectedCirclePaint.setFakeBoldText(true); mSelectedCirclePaint.setAntiAlias(true); - mSelectedCirclePaint.setColor(mSelectedDaysColor); + mSelectedCirclePaint.setColor(mAttributes.selectedDayBgColor); mSelectedCirclePaint.setTextAlign(Align.CENTER); mSelectedCirclePaint.setStyle(Style.FILL); mSelectedCirclePaint.setAlpha(SELECTED_CIRCLE_ALPHA); mMonthDayLabelPaint = new Paint(); mMonthDayLabelPaint.setAntiAlias(true); - mMonthDayLabelPaint.setTextSize(MONTH_DAY_LABEL_TEXT_SIZE); - mMonthDayLabelPaint.setColor(mDayTextColor); + mMonthDayLabelPaint.setTextSize(mAttributes.dayNameTextSize); + mMonthDayLabelPaint.setColor(mAttributes.dayTextColor); mMonthDayLabelPaint.setTypeface(Typeface.create(mDayOfWeekTypeface, Typeface.NORMAL)); mMonthDayLabelPaint.setStyle(Style.FILL); mMonthDayLabelPaint.setTextAlign(Align.CENTER); @@ -341,7 +354,7 @@ protected void initView() { mMonthNumPaint = new Paint(); mMonthNumPaint.setAntiAlias(true); - mMonthNumPaint.setTextSize(MINI_DAY_NUMBER_TEXT_SIZE); + mMonthNumPaint.setTextSize(mAttributes.dayTextSize); mMonthNumPaint.setStyle(Style.FILL); mMonthNumPaint.setTextAlign(Align.CENTER); mMonthNumPaint.setFakeBoldText(false); @@ -354,7 +367,7 @@ protected void onDraw(Canvas canvas) { } protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows + MONTH_HEADER_SIZE); + setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mRowHeight * mNumRows + mAttributes.monthHeaderHeight); } protected void onSizeChanged(int w, int h, int oldw, int oldh) { @@ -383,9 +396,9 @@ public void setMonthParams(HashMap params) { setTag(params); if (params.containsKey(VIEW_PARAMS_HEIGHT)) { - mRowHeight = params.get(VIEW_PARAMS_HEIGHT); + mRowHeight = params.get(VIEW_PARAMS_HEIGHT); if (mRowHeight < MIN_HEIGHT) { - mRowHeight = MIN_HEIGHT; + mRowHeight = MIN_HEIGHT; } } if (params.containsKey(VIEW_PARAMS_SELECTED_BEGIN_DAY)) { @@ -427,12 +440,12 @@ public void setMonthParams(HashMap params) { mNumCells = CalendarUtils.getDaysInMonth(mMonth, mYear); for (int i = 0; i < mNumCells; i++) { final int day = i + 1; - if (sameDay(day, today)) { + if (sameDay(day)) { mHasToday = true; mToday = day; } - mIsPrev = prevDay(day, today); + mIsPrev = prevDay(day); } mNumRows = calculateNumRows(); @@ -442,7 +455,7 @@ public void setOnDayClickListener(OnDayClickListener onDayClickListener) { mOnDayClickListener = onDayClickListener; } - public static abstract interface OnDayClickListener { - public abstract void onDayClick(SimpleMonthView simpleMonthView, SimpleMonthAdapter.CalendarDay calendarDay); + public interface OnDayClickListener { + void onDayClick(SimpleMonthView simpleMonthView, SimpleMonthAdapter.CalendarDay calendarDay); } } \ No newline at end of file diff --git a/library/src/main/res/drawable-hdpi/ic_launcher.png b/library/src/main/res/drawable-hdpi/ic_launcher.png deleted file mode 100644 index 96a442e..0000000 Binary files a/library/src/main/res/drawable-hdpi/ic_launcher.png and /dev/null differ diff --git a/library/src/main/res/drawable-mdpi/ic_launcher.png b/library/src/main/res/drawable-mdpi/ic_launcher.png deleted file mode 100644 index 359047d..0000000 Binary files a/library/src/main/res/drawable-mdpi/ic_launcher.png and /dev/null differ diff --git a/library/src/main/res/drawable-xhdpi/ic_launcher.png b/library/src/main/res/drawable-xhdpi/ic_launcher.png deleted file mode 100644 index 71c6d76..0000000 Binary files a/library/src/main/res/drawable-xhdpi/ic_launcher.png and /dev/null differ diff --git a/library/src/main/res/drawable-xxhdpi/ic_launcher.png b/library/src/main/res/drawable-xxhdpi/ic_launcher.png deleted file mode 100644 index 4df1894..0000000 Binary files a/library/src/main/res/drawable-xxhdpi/ic_launcher.png and /dev/null differ diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index c7bda69..32b570b 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -17,6 +17,7 @@ + diff --git a/library/src/main/res/values/strings.xml b/library/src/main/res/values/strings.xml deleted file mode 100644 index d096177..0000000 --- a/library/src/main/res/values/strings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - CalendarListview - - - sans-serif - diff --git a/sample/src/main/java/com/andexert/sample/MainActivity.java b/sample/src/main/java/com/andexert/sample/MainActivity.java index ca37b63..32e5737 100644 --- a/sample/src/main/java/com/andexert/sample/MainActivity.java +++ b/sample/src/main/java/com/andexert/sample/MainActivity.java @@ -9,6 +9,8 @@ import com.andexert.calendarlistview.library.DayPickerView; import com.andexert.calendarlistview.library.SimpleMonthAdapter; +import java.util.Calendar; + public class MainActivity extends Activity implements com.andexert.calendarlistview.library.DatePickerController { @@ -46,7 +48,7 @@ public boolean onOptionsItemSelected(MenuItem item) { @Override public int getMaxYear() { - return 2015; + return Calendar.getInstance().get(Calendar.YEAR) + 1; } @Override @@ -56,9 +58,8 @@ public void onDayOfMonthSelected(int year, int month, int day) } @Override - public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays selectedDays) + public void onDateRangeSelected(SimpleMonthAdapter.SelectedDays selectedDays) { - Log.e("Date range selected", selectedDays.getFirst().toString() + " --> " + selectedDays.getLast().toString()); } }