Skip to content

Commit

Permalink
-updated sdks
Browse files Browse the repository at this point in the history
-added ability to scroll whole view (entire week, for example) like a ViewPager.
-made default first day of week to be the one of the calendar.
  • Loading branch information
AndroidDeveloperLB committed May 7, 2018
1 parent 2a5f09a commit 472162d
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 103 deletions.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.2.0-alpha13'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -19,5 +20,6 @@ allprojects {

repositories {
jcenter()
google()
}
}
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Aug 06 18:02:35 CEST 2017
#Mon May 07 11:03:02 IDT 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
13 changes: 6 additions & 7 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ repositories {
}

android {
compileSdkVersion 25
buildToolsVersion '25.0.2'
compileSdkVersion 27

defaultConfig {
minSdkVersion 9
targetSdkVersion 25
minSdkVersion 14
targetSdkVersion 27
}
}

configurations {
javadocDeps
}
dependencies {
compile 'com.android.support:appcompat-v7:25.1.0'
javadocDeps 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:appcompat-v7:27.1.1'
javadocDeps 'com.android.support:appcompat-v7:27.1.1'
}

apply from: 'gradle-mvn-push.gradle'
apply from: 'gradle-mvn-push.gradle'
125 changes: 96 additions & 29 deletions library/src/main/java/com/alamkanak/weekview/WeekView.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ private enum Direction {
private int mScaledTouchSlop = 0;
private EventRect mNewEventRect;
private TextColorPicker textColorPicker;
private float mSizeOfWeekView;
private float mDistanceDone = 0;
private float mDistanceMin;
protected int mOffsetValueToSecureScreen = 9;
private float mStartOriginForScroll = 0;

// Attributes and their default values.
private int mHourHeight = 50;
Expand All @@ -118,7 +123,7 @@ private enum Direction {
private int mEffectiveMinHourHeight = mMinHourHeight; //compensates for the fact that you can't keep zooming out.
private int mMaxHourHeight = 250;
private int mColumnGap = 10;
private int mFirstDayOfWeek = Calendar.MONDAY;
private int mFirstDayOfWeek = Calendar.getInstance().getFirstDayOfWeek();
private int mTextSize = 12;
private int mHeaderColumnPadding = 10;
private int mHeaderColumnTextColor = Color.BLACK;
Expand Down Expand Up @@ -174,6 +179,7 @@ private enum Direction {
private boolean mAutoLimitTime = false;
private boolean mEnableDropListener = false;
private int mMinOverlappingMinutes = 0;
private boolean mIsScrollNumberOfVisibleDays = false;

// Listeners.
private EventClickListener mEventClickListener;
Expand All @@ -190,6 +196,7 @@ private enum Direction {

@Override
public boolean onDown(MotionEvent e) {
mStartOriginForScroll = mCurrentOrigin.x;
goToNearestOrigin();
return true;
}
Expand Down Expand Up @@ -238,6 +245,13 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d
case RIGHT:
float minX = getXMinLimit();
float maxX = getXMaxLimit();

if (e2.getX() < 0) {
mDistanceDone = e2.getX() - e1.getX();
} else {
mDistanceDone = e1.getX() - e2.getX();
}

if ((mCurrentOrigin.x - (distanceX * mXScrollingSpeed)) > maxX) {
mCurrentOrigin.x = maxX;
} else if ((mCurrentOrigin.x - (distanceX * mXScrollingSpeed)) < minX) {
Expand Down Expand Up @@ -282,7 +296,9 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
switch (mCurrentFlingDirection) {
case LEFT:
case RIGHT:
mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (velocityX * mXScrollingSpeed), 0, (int) getXMinLimit(), (int) getXMaxLimit(), (int) getYMinLimit(), (int) getYMaxLimit());
if (!mIsScrollNumberOfVisibleDays) {
mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (velocityX * mXScrollingSpeed), 0, (int) getXMinLimit(), (int) getXMaxLimit(), (int) getYMinLimit(), (int) getYMaxLimit());
}
break;
case VERTICAL:
mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, 0, (int) velocityY, (int) getXMinLimit(), (int) getXMaxLimit(), (int) getYMinLimit(), (int) getYMaxLimit());
Expand Down Expand Up @@ -494,6 +510,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
if (a.getBoolean(R.styleable.WeekView_dropListenerEnabled, false))
this.enableDropListener();
mMinOverlappingMinutes = a.getInt(R.styleable.WeekView_minOverlappingMinutes, 0);
mIsScrollNumberOfVisibleDays = a.getBoolean(R.styleable.WeekView_isScrollNumberOfVisibleDays, false);
} finally {
a.recycle();
}
Expand Down Expand Up @@ -2517,6 +2534,15 @@ public int getMinOverlappingMinutes() {
return this.mMinOverlappingMinutes;
}

public boolean isScrollNumberOfVisibleDays() {
return this.mIsScrollNumberOfVisibleDays;
}

public void setScrollNumberOfVisibleDays(boolean scrollNumberOfVisibleDays) {
this.mIsScrollNumberOfVisibleDays = scrollNumberOfVisibleDays;
invalidate();
}

/////////////////////////////////////////////////////////////////
//
// Functions related to scrolling.
Expand All @@ -2525,6 +2551,10 @@ public int getMinOverlappingMinutes() {

@Override
public boolean onTouchEvent(MotionEvent event) {

mSizeOfWeekView = (mWidthPerDay + mColumnGap) * getNumberOfVisibleDays();
mDistanceMin = mSizeOfWeekView / mOffsetValueToSecureScreen;

mScaleDetector.onTouchEvent(event);
boolean val = mGestureDetector.onTouchEvent(event);

Expand All @@ -2542,41 +2572,78 @@ public boolean onTouchEvent(MotionEvent event) {
private void goToNearestOrigin() {
double leftDays = mCurrentOrigin.x / (mWidthPerDay + mColumnGap);

if (mCurrentFlingDirection != Direction.NONE) {
// snap to nearest day
leftDays = Math.round(leftDays);
} else if (mCurrentScrollDirection == Direction.LEFT) {
// snap to last day
leftDays = Math.floor(leftDays);
} else if (mCurrentScrollDirection == Direction.RIGHT) {
// snap to next day
leftDays = Math.ceil(leftDays);
} else {
// snap to nearest day
leftDays = Math.round(leftDays);
}
float beforeScroll = mStartOriginForScroll;
boolean isPassed = false;

if (mDistanceDone > mDistanceMin || mDistanceDone < -mDistanceMin || !mIsScrollNumberOfVisibleDays) {

if (!mIsScrollNumberOfVisibleDays && mCurrentFlingDirection != Direction.NONE) {
// snap to nearest day
leftDays = Math.round(leftDays);
} else if (mCurrentScrollDirection == Direction.LEFT) {
// snap to last day
leftDays = Math.floor(leftDays);
mStartOriginForScroll -= mSizeOfWeekView;
isPassed = true;
} else if (mCurrentScrollDirection == Direction.RIGHT) {
// snap to next day
leftDays = Math.floor(leftDays);
mStartOriginForScroll += mSizeOfWeekView;
isPassed = true;
} else {
// snap to nearest day
leftDays = Math.round(leftDays);
}

int nearestOrigin = (int) (mCurrentOrigin.x - leftDays * (mWidthPerDay + mColumnGap));
boolean mayScrollHorizontal = mCurrentOrigin.x - nearestOrigin < getXMaxLimit()
&& mCurrentOrigin.x - nearestOrigin > getXMinLimit();

if (mayScrollHorizontal) {
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0);
ViewCompat.postInvalidateOnAnimation(WeekView.this);
}
if (mIsScrollNumberOfVisibleDays) {
boolean mayScrollHorizontal = beforeScroll - mStartOriginForScroll < getXMaxLimit() && mCurrentOrigin.x - mStartOriginForScroll > getXMinLimit();
if (isPassed && mayScrollHorizontal) {
// Stop current animation.
mScroller.forceFinished(true);
// Snap to date.
if (mCurrentScrollDirection == Direction.LEFT) {
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) ((beforeScroll - mCurrentOrigin.x) - mSizeOfWeekView), 0, 200);
} else if (mCurrentScrollDirection == Direction.RIGHT) {
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (mSizeOfWeekView - (mCurrentOrigin.x - beforeScroll)), 0, 200);
}
ViewCompat.postInvalidateOnAnimation(WeekView.this);
}
} else {
int nearestOrigin = (int) (mCurrentOrigin.x - leftDays * (mWidthPerDay + mColumnGap));
boolean mayScrollHorizontal = mCurrentOrigin.x - nearestOrigin < getXMaxLimit() && mCurrentOrigin.x - nearestOrigin > getXMinLimit();
if (mayScrollHorizontal) {
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0);
ViewCompat.postInvalidateOnAnimation(WeekView.this);
}

if (nearestOrigin != 0 && mayScrollHorizontal) {
// Stop current animation.
if (nearestOrigin != 0 && mayScrollHorizontal) {
// Stop current animation.
mScroller.forceFinished(true);
// Snap to date.
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0, (int) (Math.abs(nearestOrigin) / mWidthPerDay * mScrollDuration));
ViewCompat.postInvalidateOnAnimation(WeekView.this);
}
}

// Reset scrolling and fling direction.
mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE;


} else {
mScroller.forceFinished(true);
// Snap to date.
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, -nearestOrigin, 0, (int) (Math.abs(nearestOrigin) / mWidthPerDay * mScrollDuration));
if (mCurrentScrollDirection == Direction.LEFT) {
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) beforeScroll - (int) mCurrentOrigin.x, 0, 200);
} else if (mCurrentScrollDirection == Direction.RIGHT) {
mScroller.startScroll((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) beforeScroll - (int) mCurrentOrigin.x, 0, 200);
}
ViewCompat.postInvalidateOnAnimation(WeekView.this);

// Reset scrolling and fling direction.
mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE;
}
// Reset scrolling and fling direction.
mCurrentScrollDirection = mCurrentFlingDirection = Direction.NONE;
}


@Override
public void computeScroll() {
super.computeScroll();
Expand Down
121 changes: 61 additions & 60 deletions library/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="WeekView">
<attr name="allDayEventHeight" format="dimension" />
<attr name="autoLimitTime" format="boolean" />
<attr name="columnGap" format="dimension" />
<attr name="dayBackgroundColor" format="color" />
<attr name="allDayEventHeight" format="dimension"/>
<attr name="autoLimitTime" format="boolean"/>
<attr name="columnGap" format="dimension"/>
<attr name="dayBackgroundColor" format="color"/>
<attr name="dayNameLength" format="enum">
<enum name="length_short" value="1" />
<enum name="length_long" value="2" />
<enum name="length_short" value="1"/>
<enum name="length_long" value="2"/>
</attr>
<attr name="eventCornerRadius" format="dimension" />
<attr name="eventMarginVertical" format="dimension" />
<attr name="eventPadding" format="dimension" />
<attr name="eventTextColor" format="color" />
<attr name="eventTextSize" format="dimension" />
<attr name="eventCornerRadius" format="dimension"/>
<attr name="eventMarginVertical" format="dimension"/>
<attr name="eventPadding" format="dimension"/>
<attr name="eventTextColor" format="color"/>
<attr name="eventTextSize" format="dimension"/>
<attr name="firstDayOfWeek" format="enum">
<enum name="sunday" value="1" />
<enum name="monday" value="2" />
<enum name="tuesday" value="3" />
<enum name="wednesday" value="4" />
<enum name="thursday" value="5" />
<enum name="friday" value="6" />
<enum name="saturday" value="7" />
<enum name="sunday" value="1"/>
<enum name="monday" value="2"/>
<enum name="tuesday" value="3"/>
<enum name="wednesday" value="4"/>
<enum name="thursday" value="5"/>
<enum name="friday" value="6"/>
<enum name="saturday" value="7"/>
</attr>
<attr name="futureBackgroundColor" format="color" />
<attr name="futureWeekendBackgroundColor" format="color" />
<attr name="headerColumnBackground" format="color" />
<attr name="headerColumnPadding" format="dimension" />
<attr name="headerColumnTextColor" format="color" />
<attr name="headerRowBackgroundColor" format="color" />
<attr name="headerRowPadding" format="dimension" />
<attr name="horizontalFlingEnabled" format="boolean" />
<attr name="hourHeight" format="dimension" />
<attr name="hourSeparatorColor" format="color" />
<attr name="hourSeparatorHeight" format="dimension" />
<attr name="maxHourHeight" format="dimension" />
<attr name="maxTime" format="integer" />
<attr name="minHourHeight" format="dimension" />
<attr name="minTime" format="integer" />
<attr name="minOverlappingMinutes" format="integer" />
<attr name="newEventColor" format="color" />
<attr name="newEventId" format="integer" />
<attr name="newEventIdentifier" format="string" />
<attr name="newEventIconResource" format="integer" />
<attr name="newEventLengthInMinutes" format="integer" />
<attr name="newEventTimeResolutionInMinutes" format="integer" />
<attr name="noOfVisibleDays" format="integer" />
<attr name="nowLineColor" format="color" />
<attr name="nowLineThickness" format="dimension" />
<attr name="overlappingEventGap" format="dimension" />
<attr name="pastBackgroundColor" format="color" />
<attr name="pastWeekendBackgroundColor" format="color" />
<attr name="scrollDuration" format="integer" />
<attr name="showDistinctPastFutureColor" format="boolean" />
<attr name="showDistinctWeekendColor" format="boolean" />
<attr name="showFirstDayOfWeekFirst" format="boolean" />
<attr name="showNowLine" format="boolean" />
<attr name="textSize" format="dimension" />
<attr name="timeColumnResolution" format="integer" />
<attr name="todayBackgroundColor" format="color" />
<attr name="todayHeaderTextColor" format="color" />
<attr name="verticalFlingEnabled" format="boolean" />
<attr name="xScrollingSpeed" format="float" />
<attr name="zoomFocusPoint" format="fraction" />
<attr name="zoomFocusPointEnabled" format="boolean" />
<attr name="dropListenerEnabled" format="boolean" />
<attr name="futureBackgroundColor" format="color"/>
<attr name="futureWeekendBackgroundColor" format="color"/>
<attr name="headerColumnBackground" format="color"/>
<attr name="headerColumnPadding" format="dimension"/>
<attr name="headerColumnTextColor" format="color"/>
<attr name="headerRowBackgroundColor" format="color"/>
<attr name="headerRowPadding" format="dimension"/>
<attr name="horizontalFlingEnabled" format="boolean"/>
<attr name="hourHeight" format="dimension"/>
<attr name="hourSeparatorColor" format="color"/>
<attr name="hourSeparatorHeight" format="dimension"/>
<attr name="maxHourHeight" format="dimension"/>
<attr name="maxTime" format="integer"/>
<attr name="minHourHeight" format="dimension"/>
<attr name="minTime" format="integer"/>
<attr name="minOverlappingMinutes" format="integer"/>
<attr name="newEventColor" format="color"/>
<attr name="newEventId" format="integer"/>
<attr name="newEventIdentifier" format="string"/>
<attr name="newEventIconResource" format="integer"/>
<attr name="newEventLengthInMinutes" format="integer"/>
<attr name="newEventTimeResolutionInMinutes" format="integer"/>
<attr name="noOfVisibleDays" format="integer"/>
<attr name="nowLineColor" format="color"/>
<attr name="nowLineThickness" format="dimension"/>
<attr name="overlappingEventGap" format="dimension"/>
<attr name="pastBackgroundColor" format="color"/>
<attr name="pastWeekendBackgroundColor" format="color"/>
<attr name="scrollDuration" format="integer"/>
<attr name="showDistinctPastFutureColor" format="boolean"/>
<attr name="showDistinctWeekendColor" format="boolean"/>
<attr name="showFirstDayOfWeekFirst" format="boolean"/>
<attr name="showNowLine" format="boolean"/>
<attr name="textSize" format="dimension"/>
<attr name="timeColumnResolution" format="integer"/>
<attr name="todayBackgroundColor" format="color"/>
<attr name="todayHeaderTextColor" format="color"/>
<attr name="verticalFlingEnabled" format="boolean"/>
<attr name="xScrollingSpeed" format="float"/>
<attr name="zoomFocusPoint" format="fraction"/>
<attr name="zoomFocusPointEnabled" format="boolean"/>
<attr name="dropListenerEnabled" format="boolean"/>
<attr name="isScrollNumberOfVisibleDays" format="boolean"/>
</declare-styleable>
</resources>
Loading

0 comments on commit 472162d

Please sign in to comment.