Skip to content

Commit 1ff6067

Browse files
author
Jens Claes
committed
Option to slow down the speed of horizontal scrolling
1 parent 3aaf5c6 commit 1ff6067

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public class WeekView extends View {
9696
private int mEventMarginVertical = 0;
9797
private Calendar mFirstVisibleDay;
9898
private Calendar mLastVisibleDay;
99+
private float mXScrollingSpeed = 1f;
99100

100101
// Listeners.
101102
private EventClickListener mEventClickListener;
@@ -138,7 +139,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve
138139
mStickyScroller.forceFinished(true);
139140

140141
if (mCurrentFlingDirection.isHorizontal()){
141-
mScroller.fling((int) mCurrentOrigin.x, 0, (int) velocityX, 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0);
142+
mScroller.fling((int) mCurrentOrigin.x, 0, (int) (velocityX*mXScrollingSpeed), 0, Integer.MIN_VALUE, Integer.MAX_VALUE, 0, 0);
142143
}
143144
else if (mCurrentFlingDirection == Direction.VERTICAL){
144145
mScroller.fling(0, (int) mCurrentOrigin.y, 0, (int) velocityY, 0, 0, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 - getHeight()), 0);
@@ -235,6 +236,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
235236
mDayNameLength = a.getInteger(R.styleable.WeekView_dayNameLength, mDayNameLength);
236237
mOverlappingEventGap = a.getDimensionPixelSize(R.styleable.WeekView_overlappingEventGap, mOverlappingEventGap);
237238
mEventMarginVertical = a.getDimensionPixelSize(R.styleable.WeekView_eventMarginVertical, mEventMarginVertical);
239+
mXScrollingSpeed = a.getFloat(R.styleable.WeekView_xScrollingSpeed, mXScrollingSpeed);
238240
} finally {
239241
a.recycle();
240242
}
@@ -1137,6 +1139,17 @@ public Calendar getLastVisibleDay() {
11371139
return mLastVisibleDay;
11381140
}
11391141

1142+
public float getXScrollingSpeed() {
1143+
return mXScrollingSpeed;
1144+
}
1145+
1146+
/**
1147+
* Sets the speed for horizontal scrolling.
1148+
* @param xScrollingSpeed The new horizontal scrolling speed.
1149+
*/
1150+
public void setXScrollingSpeed(float xScrollingSpeed) {
1151+
this.mXScrollingSpeed = xScrollingSpeed;
1152+
}
11401153
/////////////////////////////////////////////////////////////////
11411154
//
11421155
// Functions related to scrolling.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
</attr>
3434
<attr name="overlappingEventGap" format="dimension"/>
3535
<attr name="eventMarginVertical" format="dimension"/>
36-
36+
<attr name="xScrollingSpeed" format="float"/>
3737
</declare-styleable>
3838
</resources>

0 commit comments

Comments
 (0)