Skip to content
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
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}

```

---
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SimpleMonthAdapter.CalendarDay> selectedDays);
void onDayOfMonthSelected(int year, int month, int day);

void onDateRangeSelected(final SimpleMonthAdapter.SelectedDays selectedDays);
}
Original file line number Diff line number Diff line change
@@ -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) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}
Expand All @@ -68,7 +75,6 @@ public void setController(DatePickerController mController)
setAdapter(mAdapter);
}


public void init(Context paramContext) {
setLayoutManager(new LinearLayoutManager(paramContext));
mContext = paramContext;
Expand All @@ -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();
}
Expand All @@ -105,7 +126,7 @@ protected void setUpListView() {
setFadingEdgeLength(0);
}

public SimpleMonthAdapter.SelectedDays<SimpleMonthAdapter.CalendarDay> getSelectedDays()
public SimpleMonthAdapter.SelectedDays getSelectedDays()
{
return mAdapter.getSelectedDays();
}
Expand All @@ -115,8 +136,8 @@ protected DatePickerController getController()
return mController;
}

protected TypedArray getTypedArray()
protected DatePickerAttributes getAttributes()
{
return typedArray;
return mAttributes;
}
}
Loading