Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
alamkanak committed Jan 4, 2016
2 parents 59ab623 + cc34a54 commit 84fd531
Show file tree
Hide file tree
Showing 16 changed files with 649 additions and 276 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ Usage
<dependency>
<groupId>com.github.alamkanak</groupId>
<artifactId>android-week-view</artifactId>
<version>1.2.5</version>
<version>1.2.6</version>
<type>aar</type>
</dependency>
```
* Grab via gradle

```groovy
compile 'com.github.alamkanak:android-week-view:1.2.5'
compile 'com.github.alamkanak:android-week-view:1.2.6'
```
2. Add WeekView in your xml layout.

Expand Down Expand Up @@ -155,9 +155,17 @@ To do
Changelog
---------

**Version 1.2.6**

* Add empty view click listener
* Fix padding bug
* Fix bug when setting colors of different components
* Add ability to turn off fling gesture
* Add example of how to load events asynchronously in the sample app

**Version 1.2.5**

* Add support for subclasses of `WeekViewEvent`
* Add support for using subclasses of `WeekViewEvent`
* Fix scroll animation
* Add support for semi-transparent header colors

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION_NAME=1.2.5
VERSION_NAME=1.2.6
GROUP=com.github.alamkanak

POM_DESCRIPTION=An android library to show day view, week view, 3 day view etc. in your app.
Expand Down
69 changes: 59 additions & 10 deletions library/src/main/java/com/alamkanak/weekview/WeekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ private enum Direction {
private boolean mShowDistinctWeekendColor = false;
private boolean mShowNowLine = false;
private boolean mShowDistinctPastFutureColor = false;
private boolean mHorizontalFlingEnabled = true;
private boolean mVerticalFlingEnabled = true;

// Listeners.
private EventClickListener mEventClickListener;
Expand Down Expand Up @@ -210,6 +212,12 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
if (mIsZooming)
return true;

if ((mCurrentFlingDirection == Direction.LEFT && !mHorizontalFlingEnabled) ||
(mCurrentFlingDirection == Direction.RIGHT && !mHorizontalFlingEnabled) ||
(mCurrentFlingDirection == Direction.VERTICAL && !mVerticalFlingEnabled)) {
return true;
}

mScroller.forceFinished(true);

mCurrentFlingDirection = mCurrentScrollDirection;
Expand Down Expand Up @@ -324,7 +332,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
mTodayHeaderTextColor = a.getColor(R.styleable.WeekView_todayHeaderTextColor, mTodayHeaderTextColor);
mEventTextSize = a.getDimensionPixelSize(R.styleable.WeekView_eventTextSize, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mEventTextSize, context.getResources().getDisplayMetrics()));
mEventTextColor = a.getColor(R.styleable.WeekView_eventTextColor, mEventTextColor);
mEventPadding = a.getDimensionPixelSize(R.styleable.WeekView_hourSeparatorHeight, mEventPadding);
mEventPadding = a.getDimensionPixelSize(R.styleable.WeekView_eventPadding, mEventPadding);
mHeaderColumnBackgroundColor = a.getColor(R.styleable.WeekView_headerColumnBackground, mHeaderColumnBackgroundColor);
mDayNameLength = a.getInteger(R.styleable.WeekView_dayNameLength, mDayNameLength);
mOverlappingEventGap = a.getDimensionPixelSize(R.styleable.WeekView_overlappingEventGap, mOverlappingEventGap);
Expand All @@ -334,7 +342,8 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
mShowDistinctPastFutureColor = a.getBoolean(R.styleable.WeekView_showDistinctPastFutureColor, mShowDistinctPastFutureColor);
mShowDistinctWeekendColor = a.getBoolean(R.styleable.WeekView_showDistinctWeekendColor, mShowDistinctWeekendColor);
mShowNowLine = a.getBoolean(R.styleable.WeekView_showNowLine, mShowNowLine);

mHorizontalFlingEnabled = a.getBoolean(R.styleable.WeekView_horizontalFlingEnabled, mHorizontalFlingEnabled);
mVerticalFlingEnabled = a.getBoolean(R.styleable.WeekView_verticalFlingEnabled, mVerticalFlingEnabled);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -748,15 +757,13 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
right -= mOverlappingEventGap;

// Draw the event and the event name on top of it.
RectF eventRectF = new RectF(left, top, right, bottom);
if (bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 && left < right &&
eventRectF.right > mHeaderColumnWidth &&
eventRectF.left < getWidth() &&
eventRectF.bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom &&
eventRectF.top < getHeight() &&
left < right
if (left < right &&
left < getWidth() &&
top < getHeight() &&
right > mHeaderColumnWidth &&
bottom > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom
) {
mEventRects.get(i).rectF = eventRectF;
mEventRects.get(i).rectF = new RectF(left, top, right, bottom);
mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor());
canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, top, left);
Expand Down Expand Up @@ -1359,6 +1366,8 @@ public int getHeaderColumnTextColor() {

public void setHeaderColumnTextColor(int headerColumnTextColor) {
mHeaderColumnTextColor = headerColumnTextColor;
mHeaderTextPaint.setColor(mHeaderColumnTextColor);
mTimeTextPaint.setColor(mHeaderColumnTextColor);
invalidate();
}

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

public void setHeaderRowBackgroundColor(int headerRowBackgroundColor) {
mHeaderRowBackgroundColor = headerRowBackgroundColor;
mHeaderBackgroundPaint.setColor(mHeaderRowBackgroundColor);
invalidate();
}

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

public void setDayBackgroundColor(int dayBackgroundColor) {
mDayBackgroundColor = dayBackgroundColor;
mDayBackgroundPaint.setColor(mDayBackgroundColor);
invalidate();
}

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

public void setHourSeparatorColor(int hourSeparatorColor) {
mHourSeparatorColor = hourSeparatorColor;
mHourSeparatorPaint.setColor(mHourSeparatorColor);
invalidate();
}

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

public void setTodayBackgroundColor(int todayBackgroundColor) {
mTodayBackgroundColor = todayBackgroundColor;
mTodayBackgroundPaint.setColor(mTodayBackgroundColor);
invalidate();
}

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

public void setHourSeparatorHeight(int hourSeparatorHeight) {
mHourSeparatorHeight = hourSeparatorHeight;
mHourSeparatorPaint.setStrokeWidth(mHourSeparatorHeight);
invalidate();
}

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

public void setTodayHeaderTextColor(int todayHeaderTextColor) {
mTodayHeaderTextColor = todayHeaderTextColor;
mTodayHeaderTextPaint.setColor(mTodayHeaderTextColor);
invalidate();
}

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

public void setEventTextColor(int eventTextColor) {
mEventTextColor = eventTextColor;
mEventTextPaint.setColor(mEventTextColor);
invalidate();
}

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

public void setHeaderColumnBackgroundColor(int headerColumnBackgroundColor) {
mHeaderColumnBackgroundColor = headerColumnBackgroundColor;
mHeaderColumnBackgroundPaint.setColor(mHeaderColumnBackgroundColor);
invalidate();
}

Expand Down Expand Up @@ -1666,6 +1683,38 @@ public void setNowLineThickness(int nowLineThickness) {
invalidate();
}

/**
* Get whether the week view should fling horizontally.
* @return True if the week view has horizontal fling enabled.
*/
public boolean isHorizontalFlingEnabled() {
return mHorizontalFlingEnabled;
}

/**
* Set whether the week view should fling horizontally.
* @return True if it should have horizontal fling enabled.
*/
public void setHorizontalFlingEnabled(boolean enabled) {
mHorizontalFlingEnabled = enabled;
}

/**
* Get whether the week view should fling vertically.
* @return True if the week view has vertical fling enabled.
*/
public boolean isVerticalFlingEnabled() {
return mVerticalFlingEnabled;
}

/**
* Set whether the week view should fling vertically.
* @return True if it should have vertical fling enabled.
*/
public void setVerticalFlingEnabled(boolean enabled) {
mVerticalFlingEnabled = enabled;
}

/////////////////////////////////////////////////////////////////
//
// Functions related to scrolling.
Expand Down
4 changes: 3 additions & 1 deletion library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,7 @@
<attr name="showNowLine" format="boolean"/>
<attr name="nowLineColor" format="color"/>
<attr name="nowLineThickness" format="dimension"/>
<attr name="horizontalFlingEnabled" format="boolean"/>
<attr name="verticalFlingEnabled" format="boolean"/>
</declare-styleable>
</resources>
</resources>
3 changes: 2 additions & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ android {
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
}
10 changes: 10 additions & 0 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alamkanak.weekview.sample" >

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
Expand All @@ -15,6 +17,14 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".BasicActivity"
android:label="@string/title_activity_basic" >
</activity>
<activity
android:name=".AsynchronousActivity"
android:label="@string/title_activity_asynchronous" >
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.alamkanak.weekview.sample;

import android.widget.Toast;

import com.alamkanak.weekview.WeekViewEvent;
import com.alamkanak.weekview.sample.apiclient.Event;
import com.alamkanak.weekview.sample.apiclient.MyJsonService;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;

/**
* An example of how events can be fetched from network and be displayed on the week view.
* Created by Raquib-ul-Alam Kanak on 1/3/2014.
* Website: http://alamkanak.github.io
*/
public class AsynchronousActivity extends BaseActivity implements Callback<List<Event>> {

private List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
boolean calledNetwork = false;

@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {

// Download events from network if it hasn't been done already. To understand how events are
// downloaded using retrofit, visit http://square.github.io/retrofit
if (!calledNetwork) {
RestAdapter retrofit = new RestAdapter.Builder()
.setEndpoint("https://api.myjson.com/bins")
.build();
MyJsonService service = retrofit.create(MyJsonService.class);
service.listEvents(this);
calledNetwork = true;
}

// Return only the events that matches newYear and newMonth.
List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
for (WeekViewEvent event : events) {
if (eventMatches(event, newYear, newMonth)) {
matchedEvents.add(event);
}
}
return matchedEvents;
}

/**
* Checks if an event falls into a specific year and month.
* @param event The event to check for.
* @param year The year.
* @param month The month.
* @return True if the event matches the year and month.
*/
private boolean eventMatches(WeekViewEvent event, int year, int month) {
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);
}

@Override
public void success(List<Event> events, Response response) {
this.events.clear();
for (Event event : events) {
this.events.add(event.toWeekViewEvent());
}
getWeekView().notifyDatasetChanged();
}

@Override
public void failure(RetrofitError error) {
error.printStackTrace();
Toast.makeText(this, R.string.async_error, Toast.LENGTH_SHORT).show();
}
}
Loading

0 comments on commit 84fd531

Please sign in to comment.