Skip to content

Commit a9cc17a

Browse files
author
Kevin Ménager
committed
Fix Scroll problem and add option to enable zooming
1 parent f654712 commit a9cc17a

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class WeekView extends View {
5656
private int mHeaderSeparator = 12;
5757
private int mHeaderSeparatorColor;
5858
private Paint mDaySeparatorPaint;
59+
private boolean mZoomEnabled = true;
5960

6061
private enum Direction {
6162
NONE, LEFT, RIGHT, VERTICAL
@@ -203,6 +204,7 @@ public void setSpanEvent(MetricAffectingSpan typefaceEvent) {
203204

204205
@Override
205206
public boolean onDown(MotionEvent e) {
207+
mScroller.forceFinished(true);
206208
goToNearestOrigin();
207209
return true;
208210
}
@@ -413,6 +415,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) {
413415
mBorderEventThickness = a.getDimensionPixelSize(R.styleable.WeekView_borderEventThickness, mBorderEventThickness);
414416
mBorderEventPosition = a.getInteger(R.styleable.WeekView_borderEventPosition, mBorderEventPosition);
415417
mShowBorderEvent = a.getBoolean(R.styleable.WeekView_showBorderEvent, mShowBorderEvent);
418+
mZoomEnabled = a.getBoolean(R.styleable.WeekView_enableZoom, mZoomEnabled);
416419
} finally {
417420
a.recycle();
418421
}
@@ -1944,7 +1947,9 @@ public void setScrollDuration(int scrollDuration) {
19441947

19451948
@Override
19461949
public boolean onTouchEvent(MotionEvent event) {
1947-
mScaleDetector.onTouchEvent(event);
1950+
if (mZoomEnabled) {
1951+
mScaleDetector.onTouchEvent(event);
1952+
}
19481953
boolean val = mGestureDetector.onTouchEvent(event);
19491954

19501955
// Check after call of mGestureDetector, so mCurrentFlingDirection and mCurrentScrollDirection are set.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,7 @@
7171
<enum name="left" value="40"/>
7272
<enum name="right" value="80"/>
7373
</attr>
74+
75+
<attr name="enableZoom" format="boolean"/>
7476
</declare-styleable>
7577
</resources>

sample/src/main/res/layout/activity_base.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
app:todayHeaderTextColor="@color/accent"
2929
app:showBorderEvent="true"
3030
app:borderEventColor="@color/event_color_border"
31-
app:borderEventThickness="5dp"/>
31+
app:borderEventThickness="5dp"
32+
app:enableZoom="false"/>
3233

3334
</RelativeLayout>

0 commit comments

Comments
 (0)