@@ -312,8 +312,13 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
312
312
}
313
313
}
314
314
315
+ float xOffset = getXStartPixel ();
316
+
317
+ float x = e .getX () - xOffset ;
318
+ float y = e .getY () - mCurrentOrigin .y ;
315
319
// If the tap was on add new Event space, then trigger the callback
316
- if (mAddEventClickListener != null && mNewEventRect != null && mNewEventRect .rectF != null && e .getX () > mNewEventRect .rectF .left && e .getX () < mNewEventRect .rectF .right && e .getY () > mNewEventRect .rectF .top && e .getY () < mNewEventRect .rectF .bottom ) {
320
+ if (mAddEventClickListener != null && mNewEventRect != null && mNewEventRect .rectF != null &&
321
+ mNewEventRect .rectF .contains (x ,y )){
317
322
mAddEventClickListener .onAddEventClicked (mNewEventRect .event .getStartTime (), mNewEventRect .event .getEndTime ());
318
323
return super .onSingleTapConfirmed (e );
319
324
}
@@ -358,23 +363,21 @@ public boolean onSingleTapConfirmed(MotionEvent e) {
358
363
359
364
WeekViewEvent newEvent = new WeekViewEvent (mNewEventIdentifier , "" , null , selectedTime , endTime );
360
365
361
- int marginTop = mHourHeight * mMinTime ;
362
- float top = selectedTime .get (Calendar .HOUR_OF_DAY ) * 60 ;
363
- top = mHourHeight * top / 60 + mCurrentOrigin .y + mHeaderHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 + mEventMarginVertical - marginTop ;
364
- float bottom = endTime .get (Calendar .HOUR_OF_DAY ) * 60 ;
365
- bottom = mHourHeight * bottom / 60 + mCurrentOrigin .y + mHeaderHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - mEventMarginVertical - marginTop ;
366
+ float top = mHourHeight * getPassedMinutesInDay (selectedTime ) / 60 + getEventsTop ();
367
+ float bottom = mHourHeight * getPassedMinutesInDay (endTime ) / 60 + getEventsTop ();
366
368
367
369
// Calculate left and right.
368
- float left = 0 ;
370
+ float left = mWidthPerDay * WeekViewUtil . daysBetween ( getFirstVisibleDay (), selectedTime ) ;
369
371
float right = left + mWidthPerDay ;
372
+
370
373
// Add the new event if its bounds are valid
371
374
if (left < right &&
372
375
left < getWidth () &&
373
376
top < getHeight () &&
374
377
right > mHeaderColumnWidth &&
375
378
bottom > 0
376
379
) {
377
- RectF dayRectF = new RectF (left , top , right , bottom );
380
+ RectF dayRectF = new RectF (left , top , right , bottom - mCurrentOrigin . y );
378
381
newEvent .setColor (mNewEventColor );
379
382
mNewEventRect = new EventRect (newEvent , newEvent , dayRectF );
380
383
tempEvents .add (newEvent );
@@ -815,10 +818,9 @@ else if (mNewHourHeight > mMaxHourHeight)
815
818
mCurrentOrigin .y = 0 ;
816
819
}
817
820
821
+ int leftDaysWithGaps = getLeftDaysWithGaps ();
818
822
// Consider scroll offset.
819
- int leftDaysWithGaps = (int ) -(Math .ceil (mCurrentOrigin .x / (mWidthPerDay + mColumnGap )));
820
- float startFromPixel = mCurrentOrigin .x + (mWidthPerDay + mColumnGap ) * leftDaysWithGaps +
821
- mHeaderColumnWidth ;
823
+ float startFromPixel = getXStartPixel ();
822
824
float startPixel = startFromPixel ;
823
825
824
826
// Prepare to iterate for each day.
@@ -985,9 +987,8 @@ else if (mNewHourHeight > mMaxHourHeight)
985
987
* @return The time and date at the clicked position.
986
988
*/
987
989
private Calendar getTimeFromPoint (float x , float y ) {
988
- int leftDaysWithGaps = (int ) -(Math .ceil (mCurrentOrigin .x / (mWidthPerDay + mColumnGap )));
989
- float startPixel = mCurrentOrigin .x + (mWidthPerDay + mColumnGap ) * leftDaysWithGaps +
990
- mHeaderColumnWidth ;
990
+ int leftDaysWithGaps = getLeftDaysWithGaps ();
991
+ float startPixel = getXStartPixel ();
991
992
for (int dayNumber = leftDaysWithGaps + 1 ;
992
993
dayNumber <= leftDaysWithGaps + getRealNumberOfVisibleDays () + 1 ;
993
994
dayNumber ++) {
@@ -1040,6 +1041,25 @@ private void limitEventTime(List<Calendar> dates) {
1040
1041
}
1041
1042
}
1042
1043
1044
+ private int getMinHourOffset (){
1045
+ return mHourHeight * mMinTime ;
1046
+ }
1047
+
1048
+ private float getEventsTop (){
1049
+ // Calculate top.
1050
+ return mCurrentOrigin .y + mHeaderHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 + mEventMarginVertical - getMinHourOffset ();
1051
+
1052
+ }
1053
+
1054
+ private int getLeftDaysWithGaps (){
1055
+ return (int ) -(Math .ceil (mCurrentOrigin .x / (mWidthPerDay + mColumnGap )));
1056
+ }
1057
+
1058
+ private float getXStartPixel (){
1059
+ return mCurrentOrigin .x + (mWidthPerDay + mColumnGap ) * getLeftDaysWithGaps () +
1060
+ mHeaderColumnWidth ;
1061
+ }
1062
+
1043
1063
/**
1044
1064
* Draw all the events of a particular day.
1045
1065
*
@@ -1051,14 +1071,8 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) {
1051
1071
if (mEventRects != null && mEventRects .size () > 0 ) {
1052
1072
for (int i = 0 ; i < mEventRects .size (); i ++) {
1053
1073
if (isSameDay (mEventRects .get (i ).event .getStartTime (), date ) && !mEventRects .get (i ).event .isAllDay ()) {
1054
-
1055
- int marginTop = mHourHeight * mMinTime ;
1056
- // Calculate top.
1057
- float top = mHourHeight * mEventRects .get (i ).top / 60 + mCurrentOrigin .y + mHeaderHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 + mEventMarginVertical - marginTop ;
1058
-
1059
- // Calculate bottom.
1060
- float bottom = mEventRects .get (i ).bottom ;
1061
- bottom = mHourHeight * bottom / 60 + mCurrentOrigin .y + mHeaderHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - mEventMarginVertical - marginTop ;
1074
+ float top = mHourHeight * mEventRects .get (i ).top / 60 + getEventsTop ();
1075
+ float bottom = mHourHeight * mEventRects .get (i ).bottom / 60 + getEventsTop ();
1062
1076
1063
1077
// Calculate left and right.
1064
1078
float left = startFromPixel + mEventRects .get (i ).left * mWidthPerDay ;
@@ -1081,7 +1095,7 @@ top < getHeight() &&
1081
1095
canvas .drawRoundRect (mEventRects .get (i ).rectF , mEventCornerRadius , mEventCornerRadius , mEventBackgroundPaint );
1082
1096
float topToUse = top ;
1083
1097
if (mEventRects .get (i ).event .getStartTime ().get (Calendar .HOUR_OF_DAY ) < mMinTime )
1084
- topToUse = mHourHeight * getPassedMinutesInDay (mMinTime , 0 ) / 60 + mCurrentOrigin . y + mHeaderHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 + mEventMarginVertical - marginTop ;
1098
+ topToUse = mHourHeight * getPassedMinutesInDay (mMinTime , 0 ) / 60 + getEventsTop () ;
1085
1099
1086
1100
if (!mNewEventIdentifier .equals (mEventRects .get (i ).event .getIdentifier ()))
1087
1101
drawEventTitle (mEventRects .get (i ).event , mEventRects .get (i ).rectF , canvas , topToUse , left );
@@ -1334,6 +1348,7 @@ private void cacheEvent(WeekViewEvent event) {
1334
1348
for (WeekViewEvent splitedEvent : splitedEvents ) {
1335
1349
mEventRects .add (new EventRect (splitedEvent , event , null ));
1336
1350
}
1351
+
1337
1352
mEvents .add (event );
1338
1353
}
1339
1354
0 commit comments