///////////////////////////////////////////////////////////////// // // Public methods. // ///////////////////////////////////////////////////////////////// public Calendar getLastVisibleDay() { if (firstVisibleDay == null) return null; Calendar result = (Calendar) firstVisibleDay.clone(); result.add(Calendar.DATE, realNumberOfVisibleDays - 1); return result; }

/**

  • Show today on the week view. */ public void goToToday() { Calendar today = Calendar.getInstance(); goToDate(today); }

/**

  • Show a specific day on the week view.

  • @param date The date to show. */ public void goToDate(Calendar date) { mScroller.forceFinished(true); mCurrentFlingDirection = Direction.NONE; mCurrentScrollDirection = mCurrentFlingDirection;

    date.set(Calendar.HOUR_OF_DAY, 0); date.set(Calendar.MINUTE, 0); date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0);

    if (mAreDimensionsInvalid) { mScrollToDay = date; return; }

    mRefreshEvents = true;

    mCurrentOrigin.x = -daysBetween(mHomeDate, date) * (widthPerDay + columnGap); mStartOriginForScroll = mCurrentOrigin.x; invalidate(); }

/**

  • Refreshes the view and loads the events again. */ public void notifyDataSetChanged() { mRefreshEvents = true; invalidate(); }

/**

  • Vertically scroll to a specific hour in the week view.

  • @param hour The hour to scroll to in 24-hour format. Supported values are 0-24. */ public void goToHour(double hour) { if (mAreDimensionsInvalid) { mScrollToHour = hour; return; }

    int verticalOffset = 0; if (hour > mMaxTime) verticalOffset = hourHeight * (mMaxTime - mMinTime); else if (hour > mMinTime) verticalOffset = (int) (hourHeight * hour);

    if (verticalOffset > (hourHeight * (mMaxTime - mMinTime) - height) + headerHeight + weekDaysHeaderRowTotalPadding + spaceBelowAllDayEvents) verticalOffset = (int) ((hourHeight * (mMaxTime - mMinTime) - height) + headerHeight + weekDaysHeaderRowTotalPadding + spaceBelowAllDayEvents);

    mCurrentOrigin.y = -verticalOffset; invalidate(); }

/**

  • Determine whether a given calendar day falls within the scroll limits set for this view.
  • @param day the day to check
  • @return True if there are no limit or the date is within the limits.
  • @see .setMinDate
  • @see .setMaxDate */ public boolean dateIsValid(Calendar day) { if (minDate != null && day.before(minDate)) return false; return !(maxDate != null && day.after(maxDate)); }

//region interfaces

public interface DropListener { /** * Triggered when view dropped * * @param view: dropped view. * @param date: object set with the date and time of the dropped coordinates on the view. */ void onDrop(View view, Calendar date); }

public interface EventClickListener { /** * Triggered when clicked on one existing event * * @param event: event clicked. * @param eventRect: view containing the clicked event. */ void onEventClick(WeekViewEvent event, RectF eventRect); }

public interface EventLongPressListener { void onEventLongPress(WeekViewEvent event, RectF eventRect); }

public interface EmptyViewClickListener { /** * Triggered when the users clicks on a empty space of the calendar. * * @param date: [Calendar] object set with the date and time of the clicked position on the view. */ void onEmptyViewClicked(Calendar date);

}

public interface EmptyViewLongPressListener { /** * Similar to [com.alamkanak.weekview.WeekView.EmptyViewClickListener] but with long press. * * @param time: [Calendar] object set with the date and time of the long pressed position on the view. */ void onEmptyViewLongPress(Calendar time); }

public interface ScrollListener { /** * Called when the first visible day has changed. * * * (this will also be called during the first draw of the weekview) * * @param newFirstVisibleDay The new first visible day * @param oldFirstVisibleDay The old first visible day (is null on the first call). */ void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay); }

public interface AddEventClickListener { /** * Triggered when the users clicks to create a new event. * * @param startTime The startTime of a new event * @param endTime The endTime of a new event */ void onAddEventClicked(Calendar startTime, Calendar endTime); }

/**

  • A simple GestureListener that holds the focused hour while scaling. */ private class WeekViewGestureListener implements ScaleGestureDetector.OnScaleGestureListener { private float mFocusedPointY;

    @Override public void onScaleEnd(ScaleGestureDetector detector) { mIsZooming = false; }

    @Override public boolean onScaleBegin(ScaleGestureDetector detector) { mIsZooming = true; goToNearestOrigin();

     // Calculate focused point for scale action
     mFocusedPointY = isZoomFocusPointEnabled ? (height - headerHeight - weekDaysHeaderRowTotalPadding - spaceBelowAllDayEvents) * zoomFocusPoint : detector.getFocusY();
    
     return true;
    

    }

    @Override public boolean onScale(ScaleGestureDetector detector) { float scale = detector.getScaleFactor();

     mNewHourHeight = Math.round(hourHeight * scale);
    
     // Calculating difference
     float diffY = mFocusedPointY - mCurrentOrigin.y;
     // Scaling difference
     diffY = diffY * scale - diffY;
     // Updating week view origin
     mCurrentOrigin.y -= diffY;
    
     invalidate();
     return true;
    

    }

}

private class DragListener implements View.OnDragListener { @Override public boolean onDrag(View v, DragEvent e) { switch (e.getAction()) { case DragEvent.ACTION_DROP: float headerTitleAndSubtitleTextHeight = headerWeekDayTitleTextHeight + (isSubtitleHeaderEnabled ? headerWeekDaySubtitleTextHeight + spaceBetweenHeaderWeekDayTitleAndSubtitle : 0.0f); if (e.getX() > mHeaderColumnWidth && e.getY() > headerTitleAndSubtitleTextHeight + weekDaysHeaderRowTotalPadding + spaceBelowAllDayEvents) { Calendar selectedTime = getTimeFromPoint(e.getX(), e.getY()); if (selectedTime != null) { dropListener.onDrop(v, selectedTime); } } break; } return true; } }

//endregion interfaces

public static final int LENGTH_SHORT = 1; public static final int LENGTH_LONG = 2;

Convert Kotlin Class to Java Code - WeekView Methods

原文地址: https://www.cveoy.top/t/topic/fsGl 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录