Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A lot of changes: Kotlin, time/date formatting fixes, demo activity for whole view snapping... #97

Open
wants to merge 48 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
472162d
-updated sdks
AndroidDeveloperLB May 7, 2018
2b59062
-converted project to Kotlin. Code can be shortened a lot, but requir…
AndroidDeveloperLB May 7, 2018
9865f5e
-added fix for day&month formatting, to be according to current locale:
AndroidDeveloperLB May 8, 2018
1406c08
Fixed possible null issues with providing null as list of events.
AndroidDeveloperLB May 8, 2018
1f9e199
Cleaned code a bit.
AndroidDeveloperLB May 8, 2018
c37823c
Handled some warnings...
AndroidDeveloperLB May 8, 2018
3438aad
further consideration of current locale to use the best format for th…
AndroidDeveloperLB May 9, 2018
9523d1b
handled auto-refreshing of the view every minute, to reflect changes …
AndroidDeveloperLB May 9, 2018
291461b
Some code cleaning
AndroidDeveloperLB May 9, 2018
8873a5d
Using proper conversion of dp units as the default values of the Week…
AndroidDeveloperLB May 9, 2018
b1a88c0
Replaced "compile" with "implementation
AndroidDeveloperLB May 9, 2018
e58f6f5
minor tweaks to sample of the WholeViewSnappingActivity.
AndroidDeveloperLB May 9, 2018
078b791
reduced Calendar instance creation a bit
AndroidDeveloperLB May 9, 2018
99c423a
Fix scroll snapping
May 9, 2018
0be2f1d
Merge pull request #1 from SkyleKayma/ScrollFix
AndroidDeveloperLB May 10, 2018
0228dad
-a lot of conversions (and fixes) from fields to properties.
AndroidDeveloperLB May 10, 2018
79d8e04
-a lot of conversions (and fixes) from fields to properties.
AndroidDeveloperLB May 10, 2018
1bc68ab
Merge branch 'develop' of https://github.com/AndroidDeveloperLB/Andro…
AndroidDeveloperLB May 10, 2018
f2a4226
sample bug fix (reported here: https://github.com/Quivr/Android-Week-…
AndroidDeveloperLB May 10, 2018
10a7614
Refactored some attributes to make it easier to understand what they …
AndroidDeveloperLB May 13, 2018
4241b17
fixed text alignment and spacing issues
AndroidDeveloperLB May 14, 2018
ae17dee
-removed dropping from WholeViewSnappingActivity. It makes scrolling …
AndroidDeveloperLB May 15, 2018
7cb7cd8
-added a way to put text on the left of the all-day events.
AndroidDeveloperLB May 15, 2018
edd87c1
fixed background color of samples.
AndroidDeveloperLB May 15, 2018
50585ff
fixed positioning of events and their lines.
AndroidDeveloperLB May 16, 2018
ef94b8d
- fixed issue of not being able to add an all-day event with same sta…
AndroidDeveloperLB May 17, 2018
8ebc646
Restored prefetching mechanism, fixing this issue:
AndroidDeveloperLB May 27, 2018
9d6f070
fixed possible OOM when setting a time of 0:00 to events, due to spli…
AndroidDeveloperLB May 28, 2018
0be8d77
fixed various issues with all-day events.
AndroidDeveloperLB May 29, 2018
d021bc1
moved implementation of textColorPicker to default one of WeekView.
AndroidDeveloperLB May 29, 2018
2c8ca57
made WeekViewEvent to be extendable, yet made most of its fields final
AndroidDeveloperLB May 29, 2018
eacd593
handled NPE in PrefetchingWeekViewLoader.
AndroidDeveloperLB May 29, 2018
610bd21
added feature to set a default title for events that don't have a tit…
AndroidDeveloperLB May 29, 2018
068fdfb
allowed using extended classes of WeekViewEvent in various functions
AndroidDeveloperLB May 30, 2018
3e11806
split the padding of the header into top+bottom
AndroidDeveloperLB May 31, 2018
09435f8
optimized code a bit.
AndroidDeveloperLB May 31, 2018
b73991c
More optimizations, by caching formatted dates and times.
AndroidDeveloperLB May 31, 2018
125c9dc
fixed weird issue in sample about January events
AndroidDeveloperLB May 31, 2018
46e5259
setting a default gap between overlapping events as 1dp, because when…
AndroidDeveloperLB Jun 10, 2018
7fd7e08
setting a default gap between overlapping events as 1dp, because when…
AndroidDeveloperLB Jun 10, 2018
da67353
Merge branch 'develop' of https://github.com/AndroidDeveloperLB/Andro…
AndroidDeveloperLB Jun 10, 2018
b0b098f
added side subtitle text, so you can show the year in case it's not t…
AndroidDeveloperLB Jun 10, 2018
a6ff5c8
targeting Android P
AndroidDeveloperLB Jun 10, 2018
6f829dd
trying to fix not being able to use the library.
AndroidDeveloperLB Jun 11, 2018
2f9b1b9
Updated SDKs.
AndroidDeveloperLB Sep 30, 2018
5688b50
updated gradle version
AndroidDeveloperLB Oct 23, 2018
91ab45f
updated sdks
AndroidDeveloperLB Feb 8, 2019
88c9020
Update README.md
AndroidDeveloperLB Feb 10, 2019
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
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