|
1 | 1 | Android Week View
|
2 | 2 | =================
|
3 | 3 |
|
4 |
| -**Android Week View** is an Android library to display calendar views within an app. It was developed by [Raquib-ul Alam](https://github.com/alamkanak). Because it is not currently maintained and does not work when using API level 28, I’m providing this fork. |
| 4 | +**Android Week View** is an Android library for displaying calendar views within an app. It was initially developed by [Raquib-ul Alam](https://github.com/alamkanak), but is not currently maintained and does not work when using API level 28. Therefore, I’m providing this fork. |
5 | 5 |
|
6 | 6 | Usage
|
7 | 7 | ---------
|
8 |
| -1. Add JitPack repository to your build file. |
| 8 | +1. Add the JitPack repository to your project-level build file and the dependency to the app-level build file. |
9 | 9 | ```groovy
|
| 10 | +// build.gradle (project-level) |
10 | 11 | allprojects {
|
11 | 12 | repositories {
|
12 |
| - ... |
13 |
| - maven { url 'https://jitpack.io' } |
| 13 | + ... |
| 14 | + maven { url 'https://jitpack.io' } |
14 | 15 | }
|
15 | 16 | }
|
| 17 | +
|
| 18 | +// build.gradle (app-level) |
| 19 | +implementation 'com.github.thellmund:Android-Week-View:1.3' // Bugfix-only version |
| 20 | +implementation 'com.github.thellmund:Android-Week-View:3.0' // Version with updated API |
16 | 21 | ```
|
17 | 22 |
|
18 |
| -2. Add the dependency. |
19 |
| -```groovy |
20 |
| -// For the bugfix-only version |
21 |
| -implementation 'com.github.thellmund:Android-Week-View:1.3' |
| 23 | +2. Add `WeekView` in your XML layout. |
| 24 | +```xml |
| 25 | +<com.alamkanak.weekview.ui.WeekView |
| 26 | + android:id="@+id/weekView" |
| 27 | + android:layout_width="match_parent" |
| 28 | + android:layout_height="match_parent" |
| 29 | + app:eventTextColor="@color/white" |
| 30 | + app:textSize="12sp" |
| 31 | + app:hourHeight="60dp" |
| 32 | + app:headerColumnPadding="8dp" |
| 33 | + app:headerColumnTextColor="@color/light_blue" |
| 34 | + app:headerRowPadding="12dp" |
| 35 | + app:columnGap="8dp" |
| 36 | + app:noOfVisibleDays="3" |
| 37 | + app:headerRowBackgroundColor="@color/light_gray" |
| 38 | + app:dayBackgroundColor="@color/white" |
| 39 | + app:todayBackgroundColor="@color/light_blue" |
| 40 | + app:headerColumnBackground="@color/white"/> |
| 41 | +``` |
| 42 | + |
| 43 | +3. Prepare the class of objects that you want to display in `WeekView` by implementing `WeekViewDisplayable<T>`. |
| 44 | +```java |
| 45 | +public class CalendarItem implements WeekViewDisplayable<CalendarItem> { |
| 46 | + |
| 47 | + private long id; |
| 48 | + private String title; |
| 49 | + private DateTime startTime; |
| 50 | + private DateTime endTime; |
| 51 | + private String location; |
| 52 | + private int color; |
| 53 | + |
| 54 | + /* ... */ |
| 55 | + |
| 56 | + @Override |
| 57 | + public WeekViewEvent<CalendarItem> toWeekViewEvent() { |
| 58 | + // Note: It's important to pass "this" as the last argument to WeekViewEvent's constructor. |
| 59 | + // This way, the EventClickListener can return this object in its onEventClick() method. |
| 60 | + boolean isAllDay = DateUtils.isAllDay(startTime, endTime); |
| 61 | + return new WeekViewEvent<>( |
| 62 | + id, title, startTime.toGregorianCalendar(), |
| 63 | + endTime.toGregorianCalendar(), location, color, isAllDay, this |
| 64 | + ); |
| 65 | + } |
| 66 | + |
| 67 | +} |
| 68 | +``` |
22 | 69 |
|
23 |
| -// For the version with an updated API |
24 |
| -implementation 'com.github.thellmund:Android-Week-View:2.0' |
| 70 | +4. Configure `WeekView` in code. |
| 71 | +```java |
| 72 | +WeekView<CalendarItem> weekView = (WeekView) findViewById(R.id.weekView); |
| 73 | +weekView.setOnEventClickListener(new EventClickListener<CalendarItem>() { |
| 74 | + @Override |
| 75 | + public void onEventClick(CalendarItem event, RectF eventRect) { |
| 76 | + // Do something with the CalendarItem |
| 77 | + } |
| 78 | +}); |
| 79 | + |
| 80 | +// WeekView has infinite horizontal scrolling. Therefore, you need to provide the events |
| 81 | +// of a month whenever that the currently displayed month changes. |
| 82 | +weekView.setMonthChangeListener(new MonthLoader.MonthChangeListener<CalendarItem>() { |
| 83 | + @Override |
| 84 | + public List<WeekViewDisplayable<CalendarItem>> onMonthChange(Calendar startDate, Calendar endDate) { |
| 85 | + return mDatabase.getCalendarItemsInRange(startDate, endDate); |
| 86 | + } |
| 87 | +}); |
25 | 88 | ```
|
26 |
| -More info about version 2.0 here: [Release 2.0](https://github.com/thellmund/Android-Week-View/releases/tag/2.0) |
27 | 89 |
|
28 |
| -Below, you find the original README by [Raquib-ul Alam](https://github.com/alamkanak). |
| 90 | +--- |
| 91 | + |
| 92 | +Customization |
| 93 | +------------------- |
| 94 | + |
| 95 | +Many aspects of `WeekView` and the individual event chips can be customized. |
| 96 | + |
| 97 | +- `allDayEventHeight`: All-day events are displayed in a header row at the top. This attributes specifies their height. If not set, these events will be set to the height of their content. |
| 98 | +- `columnGap`: The horizontal gap between individual days. |
| 99 | +- `dayBackgroundColor`: The background color of the current day, e.g. to emphasize it in a multi-day view. |
| 100 | +- `eventMarginVertical`: The vertical gap between back-to-back events. |
| 101 | +- `eventPadding`: The gap between the event title and the border of its event chip. |
| 102 | +- `eventTextColor`: The color of the event title and location in the event chip. |
| 103 | +- `eventTextSize`: The size of text in the event chip. |
| 104 | +- `firstDayOfWeek`: The first day of the week. Default is Monday. |
| 105 | +- `headerColumnBackground`: The background of the time column which is displayed on the left-hand side. |
| 106 | +- `headerColumnPadding` |
| 107 | +- `headerColumnTextColor`: The color of the hour text in the time column. |
| 108 | +- `headerRowBackgroundColor`: The background color of the header row which runs at the top of `WeekView`. |
| 109 | +- `headerRowPadding`: The padding within the header row. |
| 110 | +- `hourHeight`: The height with with one hour is displayed. Default is 50dp. |
| 111 | +- `hourSeparatorColor`: The color of the horizontal lines that indicate the hours. |
| 112 | +- `hourSeparatorHeight`: The height of the horizontal hour lines. |
| 113 | +- `noOfVisibleDays`: The number of days that are visible. Default is 3. |
| 114 | +- `overlappingEventGap`: The horizontal gap between events that occur concurrently. |
| 115 | +- `textSize`: The text size used for text in the time column and the days row, which contains the currently displayed days. |
| 116 | +- `todayBackgroundColor`: The background color of the current day. |
| 117 | +- `todayHeaderTextColor`: The text color of the current day in the days row. |
| 118 | +- `showDistinctPastFutureColor`: Indicates whether distinct background colors should be used for past and future days. Default is false. |
| 119 | +- `futureBackgroundColor`: The background color to use for future days. Requires `showDistinctPastFutureColor` to be true. |
| 120 | +- `pastBackgroundColor`: The background color to use for past days. Requires `showDistinctPastFutureColor` to be true. |
| 121 | +- `showDistinctWeekendColor`: Indicates whether weekends should be marked with a distinct color. Default is false. |
| 122 | +- `futureWeekendBackgroundColor`: The background color of future weekend days. Requires `showDistinctWeekendColor` to be true. |
| 123 | +- `pastWeekendBackgroundColor`: The background color of past weekend days. Requires `showDistinctWeekendColor` to be true. |
| 124 | +- `showNowLine`: Indicates whether a horizontal line should be displayed at the current time. Default is false. |
| 125 | +- `nowLineColor`: The color of the now line. |
| 126 | +- `nowLineThickness`: The height of the now line. |
| 127 | +- `scrollDuration`: The duration of automatic scrolling. The value determines how fast `WeekView` scrolls to a particular day. |
29 | 128 |
|
30 | 129 | ---
|
31 | 130 |
|
32 |
| -Android Week View |
| 131 | +Customization |
| 132 | +------------------- |
| 133 | + |
| 134 | +The following interfaces are used to provide data and interactability to `WeekView`. |
| 135 | +- `setMonthChangeListener()` to provide events to the calendar by months |
| 136 | +- `setOnEventClickListener()` to get a callback when an event is clicked |
| 137 | +- `setEventLongPressListener()` to get a callback when an event is long pressed |
| 138 | +- `setDateTimeInterpreter()` to set your own labels for the calendar header row and header column |
| 139 | +- `setWeekViewLoader()` to provide events to the calendar |
| 140 | +- `setEmptyViewClickListener()` to get a callback when any empty space is clicked |
| 141 | +- `setEmptyViewLongPressListener()` to get a callback when any empty space is long pressed |
| 142 | +- `setScrollListener()` to get an event every time the first visible day has changed |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +[Original README] Android Week View |
33 | 147 | =================
|
34 | 148 |
|
35 | 149 | 
|
|
0 commit comments