Skip to content

Commit 84fd531

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/develop'
2 parents 59ab623 + cc34a54 commit 84fd531

File tree

16 files changed

+649
-276
lines changed

16 files changed

+649
-276
lines changed

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ Usage
3131
<dependency>
3232
<groupId>com.github.alamkanak</groupId>
3333
<artifactId>android-week-view</artifactId>
34-
<version>1.2.5</version>
34+
<version>1.2.6</version>
3535
<type>aar</type>
3636
</dependency>
3737
```
3838
* Grab via gradle
3939

4040
```groovy
41-
compile 'com.github.alamkanak:android-week-view:1.2.5'
41+
compile 'com.github.alamkanak:android-week-view:1.2.6'
4242
```
4343
2. Add WeekView in your xml layout.
4444

@@ -155,9 +155,17 @@ To do
155155
Changelog
156156
---------
157157

158+
**Version 1.2.6**
159+
160+
* Add empty view click listener
161+
* Fix padding bug
162+
* Fix bug when setting colors of different components
163+
* Add ability to turn off fling gesture
164+
* Add example of how to load events asynchronously in the sample app
165+
158166
**Version 1.2.5**
159167

160-
* Add support for subclasses of `WeekViewEvent`
168+
* Add support for using subclasses of `WeekViewEvent`
161169
* Fix scroll animation
162170
* Add support for semi-transparent header colors
163171

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION_NAME=1.2.5
1+
VERSION_NAME=1.2.6
22
GROUP=com.github.alamkanak
33

44
POM_DESCRIPTION=An android library to show day view, week view, 3 day view etc. in your app.

library/src/main/java/com/alamkanak/weekview/WeekView.java

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ private enum Direction {
136136
private boolean mShowDistinctWeekendColor = false;
137137
private boolean mShowNowLine = false;
138138
private boolean mShowDistinctPastFutureColor = false;
139+
private boolean mHorizontalFlingEnabled = true;
140+
private boolean mVerticalFlingEnabled = true;
139141

140142
// Listeners.
141143
private EventClickListener mEventClickListener;
@@ -210,6 +212,12 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
210212
if (mIsZooming)
211213
return true;
212214

215+
if ((mCurrentFlingDirection == Direction.LEFT && !mHorizontalFlingEnabled) ||
216+
(mCurrentFlingDirection == Direction.RIGHT && !mHorizontalFlingEnabled) ||
217+
(mCurrentFlingDirection == Direction.VERTICAL && !mVerticalFlingEnabled)) {
218+
return true;
219+
}
220+
213221
mScroller.forceFinished(true);
214222

215223
mCurrentFlingDirection = mCurrentScrollDirection;
@@ -324,7 +332,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
324332
mTodayHeaderTextColor = a.getColor(R.styleable.WeekView_todayHeaderTextColor, mTodayHeaderTextColor);
325333
mEventTextSize = a.getDimensionPixelSize(R.styleable.WeekView_eventTextSize, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mEventTextSize, context.getResources().getDisplayMetrics()));
326334
mEventTextColor = a.getColor(R.styleable.WeekView_eventTextColor, mEventTextColor);
327-
mEventPadding = a.getDimensionPixelSize(R.styleable.WeekView_hourSeparatorHeight, mEventPadding);
335+
mEventPadding = a.getDimensionPixelSize(R.styleable.WeekView_eventPadding, mEventPadding);
328336
mHeaderColumnBackgroundColor = a.getColor(R.styleable.WeekView_headerColumnBackground, mHeaderColumnBackgroundColor);
329337
mDayNameLength = a.getInteger(R.styleable.WeekView_dayNameLength, mDayNameLength);
330338
mOverlappingEventGap = a.getDimensionPixelSize(R.styleable.WeekView_overlappingEventGap, mOverlappingEventGap);
@@ -334,7 +342,8 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
334342
mShowDistinctPastFutureColor = a.getBoolean(R.styleable.WeekView_showDistinctPastFutureColor, mShowDistinctPastFutureColor);
335343
mShowDistinctWeekendColor = a.getBoolean(R.styleable.WeekView_showDistinctWeekendColor, mShowDistinctWeekendColor);
336344
mShowNowLine = a.getBoolean(R.styleable.WeekView_showNowLine, mShowNowLine);
337-
345+
mHorizontalFlingEnabled = a.getBoolean(R.styleable.WeekView_horizontalFlingEnabled, mHorizontalFlingEnabled);
346+
mVerticalFlingEnabled = a.getBoolean(R.styleable.WeekView_verticalFlingEnabled, mVerticalFlingEnabled);
338347
} finally {
339348
a.recycle();
340349
}
@@ -748,15 +757,13 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
748757
right -= mOverlappingEventGap;
749758

750759
// Draw the event and the event name on top of it.
751-
RectF eventRectF = new RectF(left, top, right, bottom);
752-
if (bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 && left < right &&
753-
eventRectF.right > mHeaderColumnWidth &&
754-
eventRectF.left < getWidth() &&
755-
eventRectF.bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom &&
756-
eventRectF.top < getHeight() &&
757-
left < right
760+
if (left < right &&
761+
left < getWidth() &&
762+
top < getHeight() &&
763+
right > mHeaderColumnWidth &&
764+
bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom
758765
) {
759-
mEventRects.get(i).rectF = eventRectF;
766+
mEventRects.get(i).rectF = new RectF(left, top, right, bottom);
760767
mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor());
761768
canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
762769
drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, top, left);
@@ -1359,6 +1366,8 @@ public int getHeaderColumnTextColor() {
13591366

13601367
public void setHeaderColumnTextColor(int headerColumnTextColor) {
13611368
mHeaderColumnTextColor = headerColumnTextColor;
1369+
mHeaderTextPaint.setColor(mHeaderColumnTextColor);
1370+
mTimeTextPaint.setColor(mHeaderColumnTextColor);
13621371
invalidate();
13631372
}
13641373

@@ -1377,6 +1386,7 @@ public int getHeaderRowBackgroundColor() {
13771386

13781387
public void setHeaderRowBackgroundColor(int headerRowBackgroundColor) {
13791388
mHeaderRowBackgroundColor = headerRowBackgroundColor;
1389+
mHeaderBackgroundPaint.setColor(mHeaderRowBackgroundColor);
13801390
invalidate();
13811391
}
13821392

@@ -1386,6 +1396,7 @@ public int getDayBackgroundColor() {
13861396

13871397
public void setDayBackgroundColor(int dayBackgroundColor) {
13881398
mDayBackgroundColor = dayBackgroundColor;
1399+
mDayBackgroundPaint.setColor(mDayBackgroundColor);
13891400
invalidate();
13901401
}
13911402

@@ -1395,6 +1406,7 @@ public int getHourSeparatorColor() {
13951406

13961407
public void setHourSeparatorColor(int hourSeparatorColor) {
13971408
mHourSeparatorColor = hourSeparatorColor;
1409+
mHourSeparatorPaint.setColor(mHourSeparatorColor);
13981410
invalidate();
13991411
}
14001412

@@ -1404,6 +1416,7 @@ public int getTodayBackgroundColor() {
14041416

14051417
public void setTodayBackgroundColor(int todayBackgroundColor) {
14061418
mTodayBackgroundColor = todayBackgroundColor;
1419+
mTodayBackgroundPaint.setColor(mTodayBackgroundColor);
14071420
invalidate();
14081421
}
14091422

@@ -1413,6 +1426,7 @@ public int getHourSeparatorHeight() {
14131426

14141427
public void setHourSeparatorHeight(int hourSeparatorHeight) {
14151428
mHourSeparatorHeight = hourSeparatorHeight;
1429+
mHourSeparatorPaint.setStrokeWidth(mHourSeparatorHeight);
14161430
invalidate();
14171431
}
14181432

@@ -1422,6 +1436,7 @@ public int getTodayHeaderTextColor() {
14221436

14231437
public void setTodayHeaderTextColor(int todayHeaderTextColor) {
14241438
mTodayHeaderTextColor = todayHeaderTextColor;
1439+
mTodayHeaderTextPaint.setColor(mTodayHeaderTextColor);
14251440
invalidate();
14261441
}
14271442

@@ -1441,6 +1456,7 @@ public int getEventTextColor() {
14411456

14421457
public void setEventTextColor(int eventTextColor) {
14431458
mEventTextColor = eventTextColor;
1459+
mEventTextPaint.setColor(mEventTextColor);
14441460
invalidate();
14451461
}
14461462

@@ -1459,6 +1475,7 @@ public int getHeaderColumnBackgroundColor() {
14591475

14601476
public void setHeaderColumnBackgroundColor(int headerColumnBackgroundColor) {
14611477
mHeaderColumnBackgroundColor = headerColumnBackgroundColor;
1478+
mHeaderColumnBackgroundPaint.setColor(mHeaderColumnBackgroundColor);
14621479
invalidate();
14631480
}
14641481

@@ -1666,6 +1683,38 @@ public void setNowLineThickness(int nowLineThickness) {
16661683
invalidate();
16671684
}
16681685

1686+
/**
1687+
* Get whether the week view should fling horizontally.
1688+
* @return True if the week view has horizontal fling enabled.
1689+
*/
1690+
public boolean isHorizontalFlingEnabled() {
1691+
return mHorizontalFlingEnabled;
1692+
}
1693+
1694+
/**
1695+
* Set whether the week view should fling horizontally.
1696+
* @return True if it should have horizontal fling enabled.
1697+
*/
1698+
public void setHorizontalFlingEnabled(boolean enabled) {
1699+
mHorizontalFlingEnabled = enabled;
1700+
}
1701+
1702+
/**
1703+
* Get whether the week view should fling vertically.
1704+
* @return True if the week view has vertical fling enabled.
1705+
*/
1706+
public boolean isVerticalFlingEnabled() {
1707+
return mVerticalFlingEnabled;
1708+
}
1709+
1710+
/**
1711+
* Set whether the week view should fling vertically.
1712+
* @return True if it should have vertical fling enabled.
1713+
*/
1714+
public void setVerticalFlingEnabled(boolean enabled) {
1715+
mVerticalFlingEnabled = enabled;
1716+
}
1717+
16691718
/////////////////////////////////////////////////////////////////
16701719
//
16711720
// Functions related to scrolling.

library/src/main/res/values/attrs.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@
4646
<attr name="showNowLine" format="boolean"/>
4747
<attr name="nowLineColor" format="color"/>
4848
<attr name="nowLineThickness" format="dimension"/>
49+
<attr name="horizontalFlingEnabled" format="boolean"/>
50+
<attr name="verticalFlingEnabled" format="boolean"/>
4951
</declare-styleable>
50-
</resources>
52+
</resources>

sample/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ android {
2222
dependencies {
2323
compile fileTree(dir: 'libs', include: ['*.jar'])
2424
compile project(':library')
25-
compile 'com.android.support:appcompat-v7:23.0.1'
25+
compile 'com.android.support:appcompat-v7:23.1.1'
26+
compile 'com.squareup.retrofit:retrofit:1.9.0'
2627
}

sample/src/main/AndroidManifest.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.alamkanak.weekview.sample" >
44

5+
<uses-permission android:name="android.permission.INTERNET" />
6+
57
<application
68
android:allowBackup="true"
79
android:icon="@drawable/ic_launcher"
@@ -15,6 +17,14 @@
1517
<category android:name="android.intent.category.LAUNCHER" />
1618
</intent-filter>
1719
</activity>
20+
<activity
21+
android:name=".BasicActivity"
22+
android:label="@string/title_activity_basic" >
23+
</activity>
24+
<activity
25+
android:name=".AsynchronousActivity"
26+
android:label="@string/title_activity_asynchronous" >
27+
</activity>
1828
</application>
1929

2030
</manifest>
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.alamkanak.weekview.sample;
2+
3+
import android.widget.Toast;
4+
5+
import com.alamkanak.weekview.WeekViewEvent;
6+
import com.alamkanak.weekview.sample.apiclient.Event;
7+
import com.alamkanak.weekview.sample.apiclient.MyJsonService;
8+
9+
import java.util.ArrayList;
10+
import java.util.Calendar;
11+
import java.util.List;
12+
13+
import retrofit.Callback;
14+
import retrofit.RestAdapter;
15+
import retrofit.RetrofitError;
16+
import retrofit.client.Response;
17+
18+
/**
19+
* An example of how events can be fetched from network and be displayed on the week view.
20+
* Created by Raquib-ul-Alam Kanak on 1/3/2014.
21+
* Website: http://alamkanak.github.io
22+
*/
23+
public class AsynchronousActivity extends BaseActivity implements Callback<List<Event>> {
24+
25+
private List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
26+
boolean calledNetwork = false;
27+
28+
@Override
29+
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
30+
31+
// Download events from network if it hasn't been done already. To understand how events are
32+
// downloaded using retrofit, visit http://square.github.io/retrofit
33+
if (!calledNetwork) {
34+
RestAdapter retrofit = new RestAdapter.Builder()
35+
.setEndpoint("https://api.myjson.com/bins")
36+
.build();
37+
MyJsonService service = retrofit.create(MyJsonService.class);
38+
service.listEvents(this);
39+
calledNetwork = true;
40+
}
41+
42+
// Return only the events that matches newYear and newMonth.
43+
List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
44+
for (WeekViewEvent event : events) {
45+
if (eventMatches(event, newYear, newMonth)) {
46+
matchedEvents.add(event);
47+
}
48+
}
49+
return matchedEvents;
50+
}
51+
52+
/**
53+
* Checks if an event falls into a specific year and month.
54+
* @param event The event to check for.
55+
* @param year The year.
56+
* @param month The month.
57+
* @return True if the event matches the year and month.
58+
*/
59+
private boolean eventMatches(WeekViewEvent event, int year, int month) {
60+
return (event.getStartTime().get(Calendar.YEAR) == year && event.getStartTime().get(Calendar.MONTH) == month - 1) || (event.getEndTime().get(Calendar.YEAR) == year && event.getEndTime().get(Calendar.MONTH) == month - 1);
61+
}
62+
63+
@Override
64+
public void success(List<Event> events, Response response) {
65+
this.events.clear();
66+
for (Event event : events) {
67+
this.events.add(event.toWeekViewEvent());
68+
}
69+
getWeekView().notifyDatasetChanged();
70+
}
71+
72+
@Override
73+
public void failure(RetrofitError error) {
74+
error.printStackTrace();
75+
Toast.makeText(this, R.string.async_error, Toast.LENGTH_SHORT).show();
76+
}
77+
}

0 commit comments

Comments
 (0)