From b521a6a0f53240297d852db8b9a4a569758fdec8 Mon Sep 17 00:00:00 2001 From: Romain Vermot Date: Sun, 24 Jan 2016 23:11:31 +0100 Subject: [PATCH 1/3] Add the possibility to add an icon to an event --- .../java/com/alamkanak/weekview/WeekView.java | 296 ++++++++++++------ .../com/alamkanak/weekview/WeekViewEvent.java | 118 +++++-- library/src/main/res/values/attrs.xml | 1 + 3 files changed, 288 insertions(+), 127 deletions(-) diff --git a/library/src/main/java/com/alamkanak/weekview/WeekView.java b/library/src/main/java/com/alamkanak/weekview/WeekView.java index cb22eefca..57876a978 100755 --- a/library/src/main/java/com/alamkanak/weekview/WeekView.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekView.java @@ -6,10 +6,12 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.PointF; +import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Region; import android.graphics.Typeface; +import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.Nullable; import android.support.v4.view.GestureDetectorCompat; @@ -121,12 +123,14 @@ private enum Direction { private int mHourSeparatorHeight = 2; private int mTodayHeaderTextColor = Color.rgb(39, 137, 228); private int mEventTextSize = 12; + private int mEventIconSize = 12; private int mEventTextColor = Color.BLACK; private int mEventPadding = 8; private int mHeaderColumnBackgroundColor = Color.WHITE; private boolean mIsFirstDraw = true; private boolean mAreDimensionsInvalid = true; - @Deprecated private int mDayNameLength = LENGTH_LONG; + @Deprecated + private int mDayNameLength = LENGTH_LONG; private int mOverlappingEventGap = 0; private int mEventMarginVertical = 0; private float mXScrollingSpeed = 1f; @@ -227,7 +231,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (velocityX * mXScrollingSpeed), 0, Integer.MIN_VALUE, Integer.MAX_VALUE, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - getHeight()), 0); break; case VERTICAL: - mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, 0, (int) velocityY, Integer.MIN_VALUE, Integer.MAX_VALUE, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 - getHeight()), 0); + mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, 0, (int) velocityY, Integer.MIN_VALUE, Integer.MAX_VALUE, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - getHeight()), 0); break; } @@ -331,6 +335,7 @@ public WeekView(Context context, AttributeSet attrs, int defStyleAttr) { mHourSeparatorHeight = a.getDimensionPixelSize(R.styleable.WeekView_hourSeparatorHeight, mHourSeparatorHeight); mTodayHeaderTextColor = a.getColor(R.styleable.WeekView_todayHeaderTextColor, mTodayHeaderTextColor); mEventTextSize = a.getDimensionPixelSize(R.styleable.WeekView_eventTextSize, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mEventTextSize, context.getResources().getDisplayMetrics())); + mEventIconSize = a.getDimensionPixelSize(R.styleable.WeekView_eventIconSize, (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, mEventIconSize, context.getResources().getDisplayMetrics())); mEventTextColor = a.getColor(R.styleable.WeekView_eventTextColor, mEventTextColor); mEventPadding = a.getDimensionPixelSize(R.styleable.WeekView_eventPadding, mEventPadding); mHeaderColumnBackgroundColor = a.getColor(R.styleable.WeekView_headerColumnBackground, mHeaderColumnBackgroundColor); @@ -505,58 +510,59 @@ private void drawTimeColumnAndAxes(Canvas canvas) { String time = getDateTimeInterpreter().interpretTime(i); if (time == null) throw new IllegalStateException("A DateTimeInterpreter must not return null time"); - if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint); + if (top < getHeight()) + canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint); } } private void drawHeaderRowAndEvents(Canvas canvas) { // Calculate the available width for each day. - mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding *2; + mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding * 2; mWidthPerDay = getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1); - mWidthPerDay = mWidthPerDay/mNumberOfVisibleDays; + mWidthPerDay = mWidthPerDay / mNumberOfVisibleDays; Calendar today = today(); if (mAreDimensionsInvalid) { - mEffectiveMinHourHeight= Math.max(mMinHourHeight, (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 24)); + mEffectiveMinHourHeight = Math.max(mMinHourHeight, (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 24)); mAreDimensionsInvalid = false; - if(mScrollToDay != null) + if (mScrollToDay != null) goToDate(mScrollToDay); mAreDimensionsInvalid = false; - if(mScrollToHour >= 0) + if (mScrollToHour >= 0) goToHour(mScrollToHour); mScrollToDay = null; mScrollToHour = -1; mAreDimensionsInvalid = false; } - if (mIsFirstDraw){ + if (mIsFirstDraw) { mIsFirstDraw = false; // If the week view is being drawn for the first time, then consider the first day of the week. - if(mNumberOfVisibleDays >= 7 && today.get(Calendar.DAY_OF_WEEK) != mFirstDayOfWeek) { + if (mNumberOfVisibleDays >= 7 && today.get(Calendar.DAY_OF_WEEK) != mFirstDayOfWeek) { int difference = 7 + (today.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek); mCurrentOrigin.x += (mWidthPerDay + mColumnGap) * difference; } } // Calculate the new height due to the zooming. - if (mNewHourHeight > 0){ + if (mNewHourHeight > 0) { if (mNewHourHeight < mEffectiveMinHourHeight) mNewHourHeight = mEffectiveMinHourHeight; else if (mNewHourHeight > mMaxHourHeight) mNewHourHeight = mMaxHourHeight; - mCurrentOrigin.y = (mCurrentOrigin.y/mHourHeight)*mNewHourHeight; + mCurrentOrigin.y = (mCurrentOrigin.y / mHourHeight) * mNewHourHeight; mHourHeight = mNewHourHeight; mNewHourHeight = -1; } // If the new mCurrentOrigin.y is invalid, make it valid. - if (mCurrentOrigin.y < getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight/2) - mCurrentOrigin.y = getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight/2; + if (mCurrentOrigin.y < getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight / 2) + mCurrentOrigin.y = getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight / 2; // Don't put an "else if" because it will trigger a glitch when completely zoomed out and // scrolling vertically. @@ -577,24 +583,24 @@ else if (mNewHourHeight > mMaxHourHeight) // Prepare to iterate for each hour to draw the hour lines. int lineCount = (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / mHourHeight) + 1; - lineCount = (lineCount) * (mNumberOfVisibleDays+1); + lineCount = (lineCount) * (mNumberOfVisibleDays + 1); float[] hourLines = new float[lineCount * 4]; // Clear the cache for event rectangles. if (mEventRects != null) { - for (EventRect eventRect: mEventRects) { + for (EventRect eventRect : mEventRects) { eventRect.rectF = null; } } // Clip to paint events only. - canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2, getWidth(), getHeight(), Region.Op.REPLACE); + canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2, getWidth(), getHeight(), Region.Op.REPLACE); // Iterate through each day. Calendar oldFirstVisibleDay = mFirstVisibleDay; mFirstVisibleDay = (Calendar) today.clone(); mFirstVisibleDay.add(Calendar.DATE, -(Math.round(mCurrentOrigin.x / (mWidthPerDay + mColumnGap)))); - if(!mFirstVisibleDay.equals(oldFirstVisibleDay) && mScrollListener != null){ + if (!mFirstVisibleDay.equals(oldFirstVisibleDay) && mScrollListener != null) { mScrollListener.onFirstVisibleDayChanged(mFirstVisibleDay, oldFirstVisibleDay); } for (int dayNumber = leftDaysWithGaps + 1; @@ -618,28 +624,25 @@ else if (mNewHourHeight > mMaxHourHeight) } // Draw background color for each day. - float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); - if (mWidthPerDay + startPixel - start > 0){ - if (mShowDistinctPastFutureColor){ + float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); + if (mWidthPerDay + startPixel - start > 0) { + if (mShowDistinctPastFutureColor) { boolean isWeekend = day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY; Paint pastPaint = isWeekend && mShowDistinctWeekendColor ? mPastWeekendBackgroundPaint : mPastBackgroundPaint; Paint futurePaint = isWeekend && mShowDistinctWeekendColor ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint; - float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y; + float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y; - if (sameDay){ + if (sameDay) { Calendar now = Calendar.getInstance(); - float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE)/60.0f) * mHourHeight; - canvas.drawRect(start, startY, startPixel + mWidthPerDay, startY+beforeNow, pastPaint); - canvas.drawRect(start, startY+beforeNow, startPixel + mWidthPerDay, getHeight(), futurePaint); - } - else if (day.before(today)) { + float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight; + canvas.drawRect(start, startY, startPixel + mWidthPerDay, startY + beforeNow, pastPaint); + canvas.drawRect(start, startY + beforeNow, startPixel + mWidthPerDay, getHeight(), futurePaint); + } else if (day.before(today)) { canvas.drawRect(start, startY, startPixel + mWidthPerDay, getHeight(), pastPaint); - } - else { + } else { canvas.drawRect(start, startY, startPixel + mWidthPerDay, getHeight(), futurePaint); } - } - else { + } else { canvas.drawRect(start, mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom, startPixel + mWidthPerDay, getHeight(), sameDay ? mTodayBackgroundPaint : mDayBackgroundPaint); } } @@ -647,8 +650,8 @@ else if (day.before(today)) { // Prepare the separator lines for hours. int i = 0; for (int hourNumber = 0; hourNumber < 24; hourNumber++) { - float top = mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * hourNumber + mTimeTextHeight/2 + mHeaderMarginBottom; - if (top > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0){ + float top = mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * hourNumber + mTimeTextHeight / 2 + mHeaderMarginBottom; + if (top > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0) { hourLines[i * 4] = start; hourLines[i * 4 + 1] = top; hourLines[i * 4 + 2] = startPixel + mWidthPerDay; @@ -664,10 +667,10 @@ else if (day.before(today)) { drawEvents(day, startPixel, canvas); // Draw the line at the current time. - if (mShowNowLine && sameDay){ - float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y; + if (mShowNowLine && sameDay) { + float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y; Calendar now = Calendar.getInstance(); - float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE)/60.0f) * mHourHeight; + float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight; canvas.drawLine(start, startY + beforeNow, startPixel + mWidthPerDay, startY + beforeNow, mNowLinePaint); } @@ -684,7 +687,7 @@ else if (day.before(today)) { // Draw the header row texts. startPixel = startFromPixel; - for (int dayNumber=leftDaysWithGaps+1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) { + for (int dayNumber = leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) { // Check if the day is today. day = (Calendar) today.clone(); day.add(Calendar.DATE, dayNumber - 1); @@ -702,24 +705,25 @@ else if (day.before(today)) { /** * Get the time and date where the user clicked on. + * * @param x The x position of the touch event. * @param y The y position of the touch event. * @return The time and date at the clicked position. */ - private Calendar getTimeFromPoint(float x, float y){ + private Calendar getTimeFromPoint(float x, float y) { int leftDaysWithGaps = (int) -(Math.ceil(mCurrentOrigin.x / (mWidthPerDay + mColumnGap))); float startPixel = mCurrentOrigin.x + (mWidthPerDay + mColumnGap) * leftDaysWithGaps + mHeaderColumnWidth; for (int dayNumber = leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) { - float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); - if (mWidthPerDay + startPixel - start > 0 && x > start && x < startPixel + mWidthPerDay){ + float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); + if (mWidthPerDay + startPixel - start > 0 && x > start && x < startPixel + mWidthPerDay) { Calendar day = today(); day.add(Calendar.DATE, dayNumber - 1); float pixelsFromZero = y - mCurrentOrigin.y - mHeaderTextHeight - - mHeaderRowPadding * 2 - mTimeTextHeight/2 - mHeaderMarginBottom; - int hour = (int)(pixelsFromZero / mHourHeight); + - mHeaderRowPadding * 2 - mTimeTextHeight / 2 - mHeaderMarginBottom; + int hour = (int) (pixelsFromZero / mHourHeight); int minute = (int) (60 * (pixelsFromZero - hour * mHourHeight) / mHourHeight); day.add(Calendar.HOUR, hour); day.set(Calendar.MINUTE, minute); @@ -732,9 +736,10 @@ private Calendar getTimeFromPoint(float x, float y){ /** * Draw all the events of a particular day. - * @param date The day. + * + * @param date The day. * @param startFromPixel The left position of the day area. The events will never go any left from this value. - * @param canvas The canvas to draw upon. + * @param canvas The canvas to draw upon. */ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) { if (mEventRects != null && mEventRects.size() > 0) { @@ -742,11 +747,11 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) { if (isSameDay(mEventRects.get(i).event.getStartTime(), date)) { // Calculate top. - float top = mHourHeight * 24 * mEventRects.get(i).top / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 + mEventMarginVertical; + float top = mHourHeight * 24 * mEventRects.get(i).top / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 + mEventMarginVertical; // Calculate bottom. float bottom = mEventRects.get(i).bottom; - bottom = mHourHeight * 24 * bottom / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 - mEventMarginVertical; + bottom = mHourHeight * 24 * bottom / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - mEventMarginVertical; // Calculate left and right. float left = startFromPixel + mEventRects.get(i).left * mWidthPerDay; @@ -767,8 +772,8 @@ top < getHeight() && mEventBackgroundPaint.setColor(mEventRects.get(i).event.getColor() == 0 ? mDefaultEventColor : mEventRects.get(i).event.getColor()); canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint); drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, top, left); - } - else + drawEventIcon(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas); + } else mEventRects.get(i).rectF = null; } } @@ -778,10 +783,11 @@ top < getHeight() && /** * Draw the name of the event on top of the event rectangle. - * @param event The event of which the title (and location) should be drawn. - * @param rect The rectangle on which the text is to be drawn. - * @param canvas The canvas to draw upon. - * @param originalTop The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area. + * + * @param event The event of which the title (and location) should be drawn. + * @param rect The rectangle on which the text is to be drawn. + * @param canvas The canvas to draw upon. + * @param originalTop The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area. * @param originalLeft The original left position of the rectangle. The rectangle may have some of its portion outside of the visible area. */ private void drawEventTitle(WeekViewEvent event, RectF rect, Canvas canvas, float originalTop, float originalLeft) { @@ -804,6 +810,10 @@ private void drawEventTitle(WeekViewEvent event, RectF rect, Canvas canvas, floa int availableHeight = (int) (rect.bottom - originalTop - mEventPadding * 2); int availableWidth = (int) (rect.right - originalLeft - mEventPadding * 2); + if (event.getIconId() != 0) { + availableWidth -= mEventIconSize + mEventPadding; + } + // Get text dimensions. StaticLayout textLayout = new StaticLayout(bob, mEventTextPaint, availableWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); @@ -831,6 +841,42 @@ private void drawEventTitle(WeekViewEvent event, RectF rect, Canvas canvas, floa } + /** + * Draw the icon associated at the event on right bottom of the event rectangle. + * + * @param event The event of which the title (and location) should be drawn. + * @param rect The rectangle on which the text is to be drawn. + * @param canvas The canvas to draw upon. + */ + private void drawEventIcon(WeekViewEvent event, RectF rect, Canvas canvas) { + if (rect.right - rect.left - mEventPadding * 2 - mEventIconSize < 0) return; + if (rect.bottom - rect.top - mEventPadding * 2 - mEventIconSize < 0) return; + + int iconId = event.getIconId(); + + if (iconId != 0) { + Drawable drawable = mContext.getResources().getDrawable(iconId); + + if (drawable != null) { + int left = 0; + int top = 0; + int right = mEventIconSize; + int bottom = mEventIconSize; + int color = event.getIconColor() == 0 ? mEventTextColor : event.getIconColor(); + + drawable.setBounds(left, top, right, bottom); + drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN); + + canvas.save(); + canvas.translate(rect.right - mEventIconSize - mEventPadding, + rect.bottom - mEventIconSize - mEventPadding); + drawable.draw(canvas); + canvas.restore(); + } + } + } + + /** * A class to hold reference to the events and their visual representation. An EventRect is * actually the rectangle that is drawn on the calendar for a given event. There may be more @@ -855,9 +901,10 @@ private class EventRect { * EventRect will be used for a single event. The given event will be stored in * "originalEvent". But the event that corresponds to rectangle the rectangle instance will * be stored in "event". - * @param event Represents the event which this instance of rectangle represents. + * + * @param event Represents the event which this instance of rectangle represents. * @param originalEvent The original event that was passed by the user. - * @param rectF The rectangle. + * @param rectF The rectangle. */ public EventRect(WeekViewEvent event, WeekViewEvent originalEvent, RectF rectF) { this.event = event; @@ -871,6 +918,7 @@ public EventRect(WeekViewEvent event, WeekViewEvent originalEvent, RectF rectF) * Gets more events of one/more month(s) if necessary. This method is called when the user is * scrolling the week view. The week view stores the events of three months: the visible month, * the previous month, the next month. + * * @param day The day where the user is currently is. */ private void getMoreEvents(Calendar day) { @@ -890,24 +938,22 @@ private void getMoreEvents(Calendar day) { mFetchedPeriod = -1; } - if (mWeekViewLoader != null){ + if (mWeekViewLoader != null) { int periodToFetch = (int) mWeekViewLoader.toWeekViewPeriodIndex(day); if (!isInEditMode() && (mFetchedPeriod < 0 || mFetchedPeriod != periodToFetch || mRefreshEvents)) { List previousPeriodEvents = null; List currentPeriodEvents = null; List nextPeriodEvents = null; - if (mPreviousPeriodEvents != null && mCurrentPeriodEvents != null && mNextPeriodEvents != null){ - if (periodToFetch == mFetchedPeriod-1){ + if (mPreviousPeriodEvents != null && mCurrentPeriodEvents != null && mNextPeriodEvents != null) { + if (periodToFetch == mFetchedPeriod - 1) { currentPeriodEvents = mPreviousPeriodEvents; nextPeriodEvents = mCurrentPeriodEvents; - } - else if (periodToFetch == mFetchedPeriod){ + } else if (periodToFetch == mFetchedPeriod) { previousPeriodEvents = mPreviousPeriodEvents; currentPeriodEvents = mCurrentPeriodEvents; nextPeriodEvents = mNextPeriodEvents; - } - else if (periodToFetch == mFetchedPeriod+1){ + } else if (periodToFetch == mFetchedPeriod + 1) { previousPeriodEvents = mCurrentPeriodEvents; currentPeriodEvents = mNextPeriodEvents; } @@ -915,9 +961,9 @@ else if (periodToFetch == mFetchedPeriod+1){ if (currentPeriodEvents == null) currentPeriodEvents = mWeekViewLoader.onLoad(periodToFetch); if (previousPeriodEvents == null) - previousPeriodEvents = mWeekViewLoader.onLoad(periodToFetch-1); + previousPeriodEvents = mWeekViewLoader.onLoad(periodToFetch - 1); if (nextPeriodEvents == null) - nextPeriodEvents = mWeekViewLoader.onLoad(periodToFetch+1); + nextPeriodEvents = mWeekViewLoader.onLoad(periodToFetch + 1); // Clear events. @@ -962,10 +1008,11 @@ else if (periodToFetch == mFetchedPeriod+1){ /** * Cache the event for smooth scrolling functionality. + * * @param event The event to cache. */ private void cacheEvent(WeekViewEvent event) { - if(event.getStartTime().compareTo(event.getEndTime()) >= 0) + if (event.getStartTime().compareTo(event.getEndTime()) >= 0) return; if (!isSameDay(event.getStartTime(), event.getEndTime())) { // Add first day. @@ -1001,14 +1048,14 @@ private void cacheEvent(WeekViewEvent event) { WeekViewEvent event2 = new WeekViewEvent(event.getId(), event.getName(), event.getLocation(), startTime, event.getEndTime()); event2.setColor(event.getColor()); mEventRects.add(new EventRect(event2, event, null)); - } - else { + } else { mEventRects.add(new EventRect(event, event, null)); } } /** * Sort and cache events. + * * @param events The events to be sorted and cached. */ private void sortAndCacheEvents(List events) { @@ -1020,6 +1067,7 @@ private void sortAndCacheEvents(List events) { /** * Sorts the events in ascending order. + * * @param events The events to be sorted. */ private void sortEvents(List events) { @@ -1042,6 +1090,7 @@ public int compare(WeekViewEvent event1, WeekViewEvent event2) { /** * Calculates the left and right positions of each events. This comes handy specially if events * are overlapping. + * * @param eventRects The events along with their wrapper class. */ private void computePositionOfEvents(List eventRects) { @@ -1074,6 +1123,7 @@ private void computePositionOfEvents(List eventRects) { /** * Expands all the events to maximum possible width. The events will try to occupy maximum * space available horizontally. + * * @param collisionGroup The group of events which overlap with each other. */ private void expandEventsToMaxWidth(List collisionGroup) { @@ -1086,8 +1136,7 @@ private void expandEventsToMaxWidth(List collisionGroup) { if (column.size() == 0) { column.add(eventRect); isPlaced = true; - } - else if (!isEventsCollide(eventRect.event, column.get(column.size()-1).event)) { + } else if (!isEventsCollide(eventRect.event, column.get(column.size() - 1).event)) { column.add(eventRect); isPlaced = true; break; @@ -1104,14 +1153,14 @@ else if (!isEventsCollide(eventRect.event, column.get(column.size()-1).event)) { // Calculate left and right position for all the events. // Get the maxRowCount by looking in all columns. int maxRowCount = 0; - for (List column : columns){ + for (List column : columns) { maxRowCount = Math.max(maxRowCount, column.size()); } for (int i = 0; i < maxRowCount; i++) { // Set the left and right values of the event. float j = 0; for (List column : columns) { - if (column.size() >= i+1) { + if (column.size() >= i + 1) { EventRect eventRect = column.get(i); eventRect.width = 1f / columns.size(); eventRect.left = j / columns.size(); @@ -1127,6 +1176,7 @@ else if (!isEventsCollide(eventRect.event, column.get(column.size()-1).event)) { /** * Checks if two events overlap. + * * @param event1 The first event. * @param event2 The second event. * @return true if the events overlap. @@ -1142,6 +1192,7 @@ private boolean isEventsCollide(WeekViewEvent event1, WeekViewEvent event2) { /** * Checks if time1 occurs after (or at the same time) time2. + * * @param time1 The time to check. * @param time2 The time to check against. * @return true if time1 and time2 are equal or if time1 is after time2. Otherwise false. @@ -1162,7 +1213,7 @@ public void invalidate() { // ///////////////////////////////////////////////////////////////// - public void setOnEventClickListener (EventClickListener listener) { + public void setOnEventClickListener(EventClickListener listener) { this.mEventClickListener = listener; } @@ -1170,7 +1221,9 @@ public EventClickListener getEventClickListener() { return mEventClickListener; } - public @Nullable MonthLoader.MonthChangeListener getMonthChangeListener() { + public + @Nullable + MonthLoader.MonthChangeListener getMonthChangeListener() { if (mWeekViewLoader instanceof MonthLoader) return ((MonthLoader) mWeekViewLoader).getOnMonthChangeListener(); return null; @@ -1184,9 +1237,10 @@ public void setMonthChangeListener(MonthLoader.MonthChangeListener monthChangeLi * Get event loader in the week view. Event loaders define the interval after which the events * are loaded in week view. For a MonthLoader events are loaded for every month. You can define * your custom event loader by extending WeekViewLoader. + * * @return The event loader. */ - public WeekViewLoader getWeekViewLoader(){ + public WeekViewLoader getWeekViewLoader() { return mWeekViewLoader; } @@ -1194,9 +1248,10 @@ public WeekViewLoader getWeekViewLoader(){ * Set event loader in the week view. For example, a MonthLoader. Event loaders define the * interval after which the events are loaded in week view. For a MonthLoader events are loaded * for every month. You can define your custom event loader by extending WeekViewLoader. + * * @param loader The event loader. */ - public void setWeekViewLoader(WeekViewLoader loader){ + public void setWeekViewLoader(WeekViewLoader loader) { this.mWeekViewLoader = loader; } @@ -1208,32 +1263,33 @@ public void setEventLongPressListener(EventLongPressListener eventLongPressListe this.mEventLongPressListener = eventLongPressListener; } - public void setEmptyViewClickListener(EmptyViewClickListener emptyViewClickListener){ + public void setEmptyViewClickListener(EmptyViewClickListener emptyViewClickListener) { this.mEmptyViewClickListener = emptyViewClickListener; } - public EmptyViewClickListener getEmptyViewClickListener(){ + public EmptyViewClickListener getEmptyViewClickListener() { return mEmptyViewClickListener; } - public void setEmptyViewLongPressListener(EmptyViewLongPressListener emptyViewLongPressListener){ + public void setEmptyViewLongPressListener(EmptyViewLongPressListener emptyViewLongPressListener) { this.mEmptyViewLongPressListener = emptyViewLongPressListener; } - public EmptyViewLongPressListener getEmptyViewLongPressListener(){ + public EmptyViewLongPressListener getEmptyViewLongPressListener() { return mEmptyViewLongPressListener; } - public void setScrollListener(ScrollListener scrolledListener){ + public void setScrollListener(ScrollListener scrolledListener) { this.mScrollListener = scrolledListener; } - public ScrollListener getScrollListener(){ + public ScrollListener getScrollListener() { return mScrollListener; } /** * Get the interpreter which provides the text to show in the header column and the header row. + * * @return The date, time interpreter. */ public DateTimeInterpreter getDateTimeInterpreter() { @@ -1271,9 +1327,10 @@ public String interpretTime(int hour) { /** * Set the interpreter which provides the text to show in the header column and the header row. + * * @param dateTimeInterpreter The date, time interpreter. */ - public void setDateTimeInterpreter(DateTimeInterpreter dateTimeInterpreter){ + public void setDateTimeInterpreter(DateTimeInterpreter dateTimeInterpreter) { this.mDateTimeInterpreter = dateTimeInterpreter; // Refresh time column width. @@ -1283,6 +1340,7 @@ public void setDateTimeInterpreter(DateTimeInterpreter dateTimeInterpreter){ /** * Get the number of visible days in a week. + * * @return The number of visible days in a week. */ public int getNumberOfVisibleDays() { @@ -1291,6 +1349,7 @@ public int getNumberOfVisibleDays() { /** * Set the number of visible days in a week. + * * @param numberOfVisibleDays The number of visible days in a week. */ public void setNumberOfVisibleDays(int numberOfVisibleDays) { @@ -1326,13 +1385,14 @@ public int getFirstDayOfWeek() { * Set the first day of the week. First day of the week is used only when the week view is first * drawn. It does not of any effect after user starts scrolling horizontally. *

- * Note: This method will only work if the week view is set to display more than 6 days at - * once. + * Note: This method will only work if the week view is set to display more than 6 days at + * once. *

+ * * @param firstDayOfWeek The supported values are {@link java.util.Calendar#SUNDAY}, - * {@link java.util.Calendar#MONDAY}, {@link java.util.Calendar#TUESDAY}, - * {@link java.util.Calendar#WEDNESDAY}, {@link java.util.Calendar#THURSDAY}, - * {@link java.util.Calendar#FRIDAY}. + * {@link java.util.Calendar#MONDAY}, {@link java.util.Calendar#TUESDAY}, + * {@link java.util.Calendar#WEDNESDAY}, {@link java.util.Calendar#THURSDAY}, + * {@link java.util.Calendar#FRIDAY}. */ public void setFirstDayOfWeek(int firstDayOfWeek) { mFirstDayOfWeek = firstDayOfWeek; @@ -1491,6 +1551,7 @@ public void setDefaultEventColor(int defaultEventColor) { /** * Note: Use {@link #setDateTimeInterpreter(DateTimeInterpreter)} and * {@link #getDateTimeInterpreter()} instead. + * * @return Either long or short day name is being used. */ @Deprecated @@ -1502,10 +1563,11 @@ public int getDayNameLength() { * Set the length of the day name displayed in the header row. Example of short day names is * 'M' for 'Monday' and example of long day names is 'Mon' for 'Monday'. *

- * Note: Use {@link #setDateTimeInterpreter(DateTimeInterpreter)} instead. + * Note: Use {@link #setDateTimeInterpreter(DateTimeInterpreter)} instead. *

+ * * @param length Supported values are {@link com.alamkanak.weekview.WeekView#LENGTH_SHORT} and - * {@link com.alamkanak.weekview.WeekView#LENGTH_LONG}. + * {@link com.alamkanak.weekview.WeekView#LENGTH_LONG}. */ @Deprecated public void setDayNameLength(int length) { @@ -1521,6 +1583,7 @@ public int getOverlappingEventGap() { /** * Set the gap between overlapping events. + * * @param overlappingEventGap The gap between overlapping events. */ public void setOverlappingEventGap(int overlappingEventGap) { @@ -1548,6 +1611,7 @@ public int getEventMarginVertical() { /** * Set the top and bottom margin of the event. The event will release this margin from the top * and bottom edge. This margin is useful for differentiation consecutive events. + * * @param eventMarginVertical The top and bottom margin. */ public void setEventMarginVertical(int eventMarginVertical) { @@ -1557,6 +1621,7 @@ public void setEventMarginVertical(int eventMarginVertical) { /** * Returns the first visible day in the week view. + * * @return The first visible day in the week view. */ public Calendar getFirstVisibleDay() { @@ -1565,6 +1630,7 @@ public Calendar getFirstVisibleDay() { /** * Returns the last visible day in the week view. + * * @return The last visible day in the week view. */ public Calendar getLastVisibleDay() { @@ -1573,6 +1639,7 @@ public Calendar getLastVisibleDay() { /** * Get the scrolling speed factor in horizontal direction. + * * @return The speed factor in horizontal direction. */ public float getXScrollingSpeed() { @@ -1581,6 +1648,7 @@ public float getXScrollingSpeed() { /** * Sets the speed for horizontal scrolling. + * * @param xScrollingSpeed The new horizontal scrolling speed. */ public void setXScrollingSpeed(float xScrollingSpeed) { @@ -1591,6 +1659,7 @@ public void setXScrollingSpeed(float xScrollingSpeed) { * Whether weekends should have a background color different from the normal day background * color. The weekend background colors are defined by the attributes * `futureWeekendBackgroundColor` and `pastWeekendBackgroundColor`. + * * @return True if weekends should have different background colors. */ public boolean isShowDistinctWeekendColor() { @@ -1601,6 +1670,7 @@ public boolean isShowDistinctWeekendColor() { * Set whether weekends should have a background color different from the normal day background * color. The weekend background colors are defined by the attributes * `futureWeekendBackgroundColor` and `pastWeekendBackgroundColor`. + * * @param showDistinctWeekendColor True if weekends should have different background colors. */ public void setShowDistinctWeekendColor(boolean showDistinctWeekendColor) { @@ -1612,6 +1682,7 @@ public void setShowDistinctWeekendColor(boolean showDistinctWeekendColor) { * Whether past and future days should have two different background colors. The past and * future day colors are defined by the attributes `futureBackgroundColor` and * `pastBackgroundColor`. + * * @return True if past and future days should have two different background colors. */ public boolean isShowDistinctPastFutureColor() { @@ -1622,6 +1693,7 @@ public boolean isShowDistinctPastFutureColor() { * Set whether weekends should have a background color different from the normal day background * color. The past and future day colors are defined by the attributes `futureBackgroundColor` * and `pastBackgroundColor`. + * * @param showDistinctPastFutureColor True if past and future should have two different * background colors. */ @@ -1633,6 +1705,7 @@ public void setShowDistinctPastFutureColor(boolean showDistinctPastFutureColor) /** * Get whether "now" line should be displayed. "Now" line is defined by the attributes * `nowLineColor` and `nowLineThickness`. + * * @return True if "now" line should be displayed. */ public boolean isShowNowLine() { @@ -1642,6 +1715,7 @@ public boolean isShowNowLine() { /** * Set whether "now" line should be displayed. "Now" line is defined by the attributes * `nowLineColor` and `nowLineThickness`. + * * @param showNowLine True if "now" line should be displayed. */ public void setShowNowLine(boolean showNowLine) { @@ -1651,6 +1725,7 @@ public void setShowNowLine(boolean showNowLine) { /** * Get the "now" line color. + * * @return The color of the "now" line. */ public int getNowLineColor() { @@ -1659,6 +1734,7 @@ public int getNowLineColor() { /** * Set the "now" line color. + * * @param nowLineColor The color of the "now" line. */ public void setNowLineColor(int nowLineColor) { @@ -1668,6 +1744,7 @@ public void setNowLineColor(int nowLineColor) { /** * Get the "now" line thickness. + * * @return The thickness of the "now" line. */ public int getNowLineThickness() { @@ -1676,6 +1753,7 @@ public int getNowLineThickness() { /** * Set the "now" line thickness. + * * @param nowLineThickness The thickness of the "now" line. */ public void setNowLineThickness(int nowLineThickness) { @@ -1685,6 +1763,7 @@ public void setNowLineThickness(int nowLineThickness) { /** * Get whether the week view should fling horizontally. + * * @return True if the week view has horizontal fling enabled. */ public boolean isHorizontalFlingEnabled() { @@ -1693,6 +1772,7 @@ public boolean isHorizontalFlingEnabled() { /** * Set whether the week view should fling horizontally. + * * @return True if it should have horizontal fling enabled. */ public void setHorizontalFlingEnabled(boolean enabled) { @@ -1701,6 +1781,7 @@ public void setHorizontalFlingEnabled(boolean enabled) { /** * Get whether the week view should fling vertically. + * * @return True if the week view has vertical fling enabled. */ public boolean isVerticalFlingEnabled() { @@ -1709,6 +1790,7 @@ public boolean isVerticalFlingEnabled() { /** * Set whether the week view should fling vertically. + * * @return True if it should have vertical fling enabled. */ public void setVerticalFlingEnabled(boolean enabled) { @@ -1737,7 +1819,7 @@ public boolean onTouchEvent(MotionEvent event) { return val; } - private void goToNearestOrigin(){ + private void goToNearestOrigin() { double leftDays = mCurrentOrigin.x / (mWidthPerDay + mColumnGap); if (mCurrentFlingDirection != Direction.NONE) { @@ -1790,6 +1872,7 @@ public void computeScroll() { /** * Check if scrolling should be stopped. + * * @return true if scrolling should be stopped before reaching the end of animation. */ private boolean forceFinishScroll() { @@ -1818,6 +1901,7 @@ public void goToToday() { /** * Show a specific day on the week view. + * * @param date The date to show. */ public void goToDate(Calendar date) { @@ -1829,7 +1913,7 @@ public void goToDate(Calendar date) { date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); - if(mAreDimensionsInvalid) { + if (mAreDimensionsInvalid) { mScrollToDay = date; return; } @@ -1845,24 +1929,25 @@ public void goToDate(Calendar date) { long day = 1000L * 60L * 60L * 24L; long dateInMillis = date.getTimeInMillis() + date.getTimeZone().getOffset(date.getTimeInMillis()); long todayInMillis = today.getTimeInMillis() + today.getTimeZone().getOffset(today.getTimeInMillis()); - long dateDifference = (dateInMillis/day) - (todayInMillis/day); - mCurrentOrigin.x = - dateDifference * (mWidthPerDay + mColumnGap); + long dateDifference = (dateInMillis / day) - (todayInMillis / day); + mCurrentOrigin.x = -dateDifference * (mWidthPerDay + mColumnGap); invalidate(); } /** * Refreshes the view and loads the events again. */ - public void notifyDatasetChanged(){ + 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){ + public void goToHour(double hour) { if (mAreDimensionsInvalid) { mScrollToHour = hour; return; @@ -1875,7 +1960,7 @@ else if (hour > 0) verticalOffset = (int) (mHourHeight * hour); if (verticalOffset > mHourHeight * 24 - getHeight() + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom) - verticalOffset = (int)(mHourHeight * 24 - getHeight() + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom); + verticalOffset = (int) (mHourHeight * 24 - getHeight() + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom); mCurrentOrigin.y = -verticalOffset; invalidate(); @@ -1883,14 +1968,14 @@ else if (hour > 0) /** * Get the first hour that is visible on the screen. + * * @return The first hour that is visible. */ - public double getFirstVisibleHour(){ + public double getFirstVisibleHour() { return -mCurrentOrigin.y / mHourHeight; } - ///////////////////////////////////////////////////////////////// // // Interfaces. @@ -1900,7 +1985,8 @@ public double getFirstVisibleHour(){ public interface EventClickListener { /** * Triggered when clicked on one existing event - * @param event: event clicked. + * + * @param event: event clicked. * @param eventRect: view containing the clicked event. */ void onEventClick(WeekViewEvent event, RectF eventRect); @@ -1909,7 +1995,8 @@ public interface EventClickListener { public interface EventLongPressListener { /** * Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press. - * @param event: event clicked. + * + * @param event: event clicked. * @param eventRect: view containing the clicked event. */ void onEventLongPress(WeekViewEvent event, RectF eventRect); @@ -1918,6 +2005,7 @@ public interface EventLongPressListener { public interface EmptyViewClickListener { /** * Triggered when the users clicks on a empty space of the calendar. + * * @param time: {@link Calendar} object set with the date and time of the clicked position on the view. */ void onEmptyViewClicked(Calendar time); @@ -1926,6 +2014,7 @@ public interface EmptyViewClickListener { public interface EmptyViewLongPressListener { /** * Similar to {@link com.alamkanak.weekview.WeekView.EmptyViewClickListener} but with long press. + * * @param time: {@link Calendar} object set with the date and time of the long pressed position on the view. */ void onEmptyViewLongPress(Calendar time); @@ -1934,8 +2023,9 @@ public interface EmptyViewLongPressListener { 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). */ @@ -1951,6 +2041,7 @@ public interface ScrollListener { /** * Checks if two times are on the same day. + * * @param dayOne The first day. * @param dayTwo The second day. * @return Whether the times are on the same day. @@ -1961,9 +2052,10 @@ private boolean isSameDay(Calendar dayOne, Calendar dayTwo) { /** * Returns a calendar instance at the start of this day + * * @return the calendar instance */ - private Calendar today(){ + private Calendar today() { Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); diff --git a/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java b/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java index e0d4765a8..1c9f976f1 100644 --- a/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java @@ -13,73 +13,125 @@ public class WeekViewEvent { private String mName; private String mLocation; private int mColor; + private int mIconId; + private int mIconColor; - public WeekViewEvent(){ + public WeekViewEvent() { } /** * Initializes the event for week view. - * @param id The id of the event. - * @param name Name of the event. - * @param startYear Year when the event starts. - * @param startMonth Month when the event starts. - * @param startDay Day when the event starts. - * @param startHour Hour (in 24-hour format) when the event starts. + * + * @param id The id of the event. + * @param name Name of the event. + * @param startYear Year when the event starts. + * @param startMonth Month when the event starts. + * @param startDay Day when the event starts. + * @param startHour Hour (in 24-hour format) when the event starts. * @param startMinute Minute when the event starts. - * @param endYear Year when the event ends. - * @param endMonth Month when the event ends. - * @param endDay Day when the event ends. - * @param endHour Hour (in 24-hour format) when the event ends. - * @param endMinute Minute when the event ends. + * @param endYear Year when the event ends. + * @param endMonth Month when the event ends. + * @param endDay Day when the event ends. + * @param endHour Hour (in 24-hour format) when the event ends. + * @param endMinute Minute when the event ends. + * @param iconId Icon associated at the event. + * @param iconColor Color of the icon associated at the event. */ - public WeekViewEvent(long id, String name, int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, int endHour, int endMinute) { + public WeekViewEvent(long id, String name, int startYear, int startMonth, int startDay, + int startHour, int startMinute, int endYear, int endMonth, int endDay, + int endHour, int endMinute, int iconId, int iconColor) { this.mId = id; this.mStartTime = Calendar.getInstance(); this.mStartTime.set(Calendar.YEAR, startYear); - this.mStartTime.set(Calendar.MONTH, startMonth-1); + this.mStartTime.set(Calendar.MONTH, startMonth - 1); this.mStartTime.set(Calendar.DAY_OF_MONTH, startDay); this.mStartTime.set(Calendar.HOUR_OF_DAY, startHour); this.mStartTime.set(Calendar.MINUTE, startMinute); this.mEndTime = Calendar.getInstance(); this.mEndTime.set(Calendar.YEAR, endYear); - this.mEndTime.set(Calendar.MONTH, endMonth-1); + this.mEndTime.set(Calendar.MONTH, endMonth - 1); this.mEndTime.set(Calendar.DAY_OF_MONTH, endDay); this.mEndTime.set(Calendar.HOUR_OF_DAY, endHour); this.mEndTime.set(Calendar.MINUTE, endMinute); this.mName = name; + + this.mIconId = iconId; + this.mIconColor = iconColor; + } + + /** + * Initializes the event for week view. + * + * @param id The id of the event. + * @param name Name of the event. + * @param startYear Year when the event starts. + * @param startMonth Month when the event starts. + * @param startDay Day when the event starts. + * @param startHour Hour (in 24-hour format) when the event starts. + * @param startMinute Minute when the event starts. + * @param endYear Year when the event ends. + * @param endMonth Month when the event ends. + * @param endDay Day when the event ends. + * @param endHour Hour (in 24-hour format) when the event ends. + * @param endMinute Minute when the event ends. + */ + public WeekViewEvent(long id, String name, int startYear, int startMonth, int startDay, + int startHour, int startMinute, int endYear, int endMonth, int endDay, + int endHour, int endMinute) { + this(id, name, startYear, startMonth, startDay, startHour, startMinute, + endYear, endMonth, endDay, endHour, endMinute, 0, 0); } /** * Initializes the event for week view. - * @param id The id of the event. - * @param name Name of the event. - * @param location The location of the event. + * + * @param id The id of the event. + * @param name Name of the event. + * @param location The location of the event. * @param startTime The time when the event starts. - * @param endTime The time when the event ends. + * @param endTime The time when the event ends. + * @param iconId Icon associated at the event. + * @param iconColor Color of the icon associated at the event. */ - public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime) { + public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime, + int iconId, int iconColor) { this.mId = id; this.mName = name; this.mLocation = location; this.mStartTime = startTime; this.mEndTime = endTime; + this.mIconId = iconId; + this.mIconColor = iconColor; } /** * Initializes the event for week view. - * @param id The id of the event. - * @param name Name of the event. + * + * @param id The id of the event. + * @param name Name of the event. + * @param location The location of the event. * @param startTime The time when the event starts. - * @param endTime The time when the event ends. + * @param endTime The time when the event ends. */ - public WeekViewEvent(long id, String name, Calendar startTime, Calendar endTime) { - this(id, name, null, startTime, endTime); + public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime) { + this(id, name, location, startTime, endTime, 0, 0); } + /** + * Initializes the event for week view. + * + * @param id The id of the event. + * @param name Name of the event. + * @param startTime The time when the event starts. + * @param endTime The time when the event ends. + */ + public WeekViewEvent(long id, String name, Calendar startTime, Calendar endTime) { + this(id, name, null, startTime, endTime, 0, 0); + } public Calendar getStartTime() { return mStartTime; @@ -129,6 +181,22 @@ public void setId(long id) { this.mId = id; } + public int getIconId() { + return mIconId; + } + + public void setIconId(int iconId) { + this.mIconId = iconId; + } + + public int getIconColor() { + return mIconColor; + } + + public void setIconColor(int iconColor) { + this.mIconColor = iconColor; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/library/src/main/res/values/attrs.xml b/library/src/main/res/values/attrs.xml index 6db63dd96..b8df3a72a 100644 --- a/library/src/main/res/values/attrs.xml +++ b/library/src/main/res/values/attrs.xml @@ -15,6 +15,7 @@ + From 6ceda4824a96bae5c8d0dfb0f93b3cbc035e5df1 Mon Sep 17 00:00:00 2001 From: Romain Vermot Date: Sat, 30 Jan 2016 16:01:14 +0100 Subject: [PATCH 2/3] Remove all the formatting updates (AndroidStudio format code) --- .../java/com/alamkanak/weekview/WeekView.java | 253 +++++++----------- .../com/alamkanak/weekview/WeekViewEvent.java | 80 +++--- 2 files changed, 143 insertions(+), 190 deletions(-) diff --git a/library/src/main/java/com/alamkanak/weekview/WeekView.java b/library/src/main/java/com/alamkanak/weekview/WeekView.java index 57876a978..dd8f16601 100755 --- a/library/src/main/java/com/alamkanak/weekview/WeekView.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekView.java @@ -129,8 +129,7 @@ private enum Direction { private int mHeaderColumnBackgroundColor = Color.WHITE; private boolean mIsFirstDraw = true; private boolean mAreDimensionsInvalid = true; - @Deprecated - private int mDayNameLength = LENGTH_LONG; + @Deprecated private int mDayNameLength = LENGTH_LONG; private int mOverlappingEventGap = 0; private int mEventMarginVertical = 0; private float mXScrollingSpeed = 1f; @@ -231,7 +230,7 @@ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float ve mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, (int) (velocityX * mXScrollingSpeed), 0, Integer.MIN_VALUE, Integer.MAX_VALUE, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - getHeight()), 0); break; case VERTICAL: - mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, 0, (int) velocityY, Integer.MIN_VALUE, Integer.MAX_VALUE, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - getHeight()), 0); + mScroller.fling((int) mCurrentOrigin.x, (int) mCurrentOrigin.y, 0, (int) velocityY, Integer.MIN_VALUE, Integer.MAX_VALUE, (int) -(mHourHeight * 24 + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 - getHeight()), 0); break; } @@ -510,59 +509,58 @@ private void drawTimeColumnAndAxes(Canvas canvas) { String time = getDateTimeInterpreter().interpretTime(i); if (time == null) throw new IllegalStateException("A DateTimeInterpreter must not return null time"); - if (top < getHeight()) - canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint); + if (top < getHeight()) canvas.drawText(time, mTimeTextWidth + mHeaderColumnPadding, top + mTimeTextHeight, mTimeTextPaint); } } private void drawHeaderRowAndEvents(Canvas canvas) { // Calculate the available width for each day. - mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding * 2; + mHeaderColumnWidth = mTimeTextWidth + mHeaderColumnPadding *2; mWidthPerDay = getWidth() - mHeaderColumnWidth - mColumnGap * (mNumberOfVisibleDays - 1); - mWidthPerDay = mWidthPerDay / mNumberOfVisibleDays; + mWidthPerDay = mWidthPerDay/mNumberOfVisibleDays; Calendar today = today(); if (mAreDimensionsInvalid) { - mEffectiveMinHourHeight = Math.max(mMinHourHeight, (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 24)); + mEffectiveMinHourHeight= Math.max(mMinHourHeight, (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / 24)); mAreDimensionsInvalid = false; - if (mScrollToDay != null) + if(mScrollToDay != null) goToDate(mScrollToDay); mAreDimensionsInvalid = false; - if (mScrollToHour >= 0) + if(mScrollToHour >= 0) goToHour(mScrollToHour); mScrollToDay = null; mScrollToHour = -1; mAreDimensionsInvalid = false; } - if (mIsFirstDraw) { + if (mIsFirstDraw){ mIsFirstDraw = false; // If the week view is being drawn for the first time, then consider the first day of the week. - if (mNumberOfVisibleDays >= 7 && today.get(Calendar.DAY_OF_WEEK) != mFirstDayOfWeek) { + if(mNumberOfVisibleDays >= 7 && today.get(Calendar.DAY_OF_WEEK) != mFirstDayOfWeek) { int difference = 7 + (today.get(Calendar.DAY_OF_WEEK) - mFirstDayOfWeek); mCurrentOrigin.x += (mWidthPerDay + mColumnGap) * difference; } } // Calculate the new height due to the zooming. - if (mNewHourHeight > 0) { + if (mNewHourHeight > 0){ if (mNewHourHeight < mEffectiveMinHourHeight) mNewHourHeight = mEffectiveMinHourHeight; else if (mNewHourHeight > mMaxHourHeight) mNewHourHeight = mMaxHourHeight; - mCurrentOrigin.y = (mCurrentOrigin.y / mHourHeight) * mNewHourHeight; + mCurrentOrigin.y = (mCurrentOrigin.y/mHourHeight)*mNewHourHeight; mHourHeight = mNewHourHeight; mNewHourHeight = -1; } // If the new mCurrentOrigin.y is invalid, make it valid. - if (mCurrentOrigin.y < getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight / 2) - mCurrentOrigin.y = getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight / 2; + if (mCurrentOrigin.y < getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight/2) + mCurrentOrigin.y = getHeight() - mHourHeight * 24 - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom - mTimeTextHeight/2; // Don't put an "else if" because it will trigger a glitch when completely zoomed out and // scrolling vertically. @@ -583,24 +581,24 @@ else if (mNewHourHeight > mMaxHourHeight) // Prepare to iterate for each hour to draw the hour lines. int lineCount = (int) ((getHeight() - mHeaderTextHeight - mHeaderRowPadding * 2 - mHeaderMarginBottom) / mHourHeight) + 1; - lineCount = (lineCount) * (mNumberOfVisibleDays + 1); + lineCount = (lineCount) * (mNumberOfVisibleDays+1); float[] hourLines = new float[lineCount * 4]; // Clear the cache for event rectangles. if (mEventRects != null) { - for (EventRect eventRect : mEventRects) { + for (EventRect eventRect: mEventRects) { eventRect.rectF = null; } } // Clip to paint events only. - canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2, getWidth(), getHeight(), Region.Op.REPLACE); + canvas.clipRect(mHeaderColumnWidth, mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2, getWidth(), getHeight(), Region.Op.REPLACE); // Iterate through each day. Calendar oldFirstVisibleDay = mFirstVisibleDay; mFirstVisibleDay = (Calendar) today.clone(); mFirstVisibleDay.add(Calendar.DATE, -(Math.round(mCurrentOrigin.x / (mWidthPerDay + mColumnGap)))); - if (!mFirstVisibleDay.equals(oldFirstVisibleDay) && mScrollListener != null) { + if(!mFirstVisibleDay.equals(oldFirstVisibleDay) && mScrollListener != null){ mScrollListener.onFirstVisibleDayChanged(mFirstVisibleDay, oldFirstVisibleDay); } for (int dayNumber = leftDaysWithGaps + 1; @@ -624,25 +622,28 @@ else if (mNewHourHeight > mMaxHourHeight) } // Draw background color for each day. - float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); - if (mWidthPerDay + startPixel - start > 0) { - if (mShowDistinctPastFutureColor) { + float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); + if (mWidthPerDay + startPixel - start > 0){ + if (mShowDistinctPastFutureColor){ boolean isWeekend = day.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY || day.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY; Paint pastPaint = isWeekend && mShowDistinctWeekendColor ? mPastWeekendBackgroundPaint : mPastBackgroundPaint; Paint futurePaint = isWeekend && mShowDistinctWeekendColor ? mFutureWeekendBackgroundPaint : mFutureBackgroundPaint; - float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y; + float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y; - if (sameDay) { + if (sameDay){ Calendar now = Calendar.getInstance(); - float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight; - canvas.drawRect(start, startY, startPixel + mWidthPerDay, startY + beforeNow, pastPaint); - canvas.drawRect(start, startY + beforeNow, startPixel + mWidthPerDay, getHeight(), futurePaint); - } else if (day.before(today)) { + float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE)/60.0f) * mHourHeight; + canvas.drawRect(start, startY, startPixel + mWidthPerDay, startY+beforeNow, pastPaint); + canvas.drawRect(start, startY+beforeNow, startPixel + mWidthPerDay, getHeight(), futurePaint); + } + else if (day.before(today)) { canvas.drawRect(start, startY, startPixel + mWidthPerDay, getHeight(), pastPaint); - } else { + } + else { canvas.drawRect(start, startY, startPixel + mWidthPerDay, getHeight(), futurePaint); } - } else { + } + else { canvas.drawRect(start, mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom, startPixel + mWidthPerDay, getHeight(), sameDay ? mTodayBackgroundPaint : mDayBackgroundPaint); } } @@ -650,8 +651,8 @@ else if (mNewHourHeight > mMaxHourHeight) // Prepare the separator lines for hours. int i = 0; for (int hourNumber = 0; hourNumber < 24; hourNumber++) { - float top = mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * hourNumber + mTimeTextHeight / 2 + mHeaderMarginBottom; - if (top > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0) { + float top = mHeaderTextHeight + mHeaderRowPadding * 2 + mCurrentOrigin.y + mHourHeight * hourNumber + mTimeTextHeight/2 + mHeaderMarginBottom; + if (top > mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom - mHourSeparatorHeight && top < getHeight() && startPixel + mWidthPerDay - start > 0){ hourLines[i * 4] = start; hourLines[i * 4 + 1] = top; hourLines[i * 4 + 2] = startPixel + mWidthPerDay; @@ -667,10 +668,10 @@ else if (mNewHourHeight > mMaxHourHeight) drawEvents(day, startPixel, canvas); // Draw the line at the current time. - if (mShowNowLine && sameDay) { - float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight / 2 + mHeaderMarginBottom + mCurrentOrigin.y; + if (mShowNowLine && sameDay){ + float startY = mHeaderTextHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom + mCurrentOrigin.y; Calendar now = Calendar.getInstance(); - float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE) / 60.0f) * mHourHeight; + float beforeNow = (now.get(Calendar.HOUR_OF_DAY) + now.get(Calendar.MINUTE)/60.0f) * mHourHeight; canvas.drawLine(start, startY + beforeNow, startPixel + mWidthPerDay, startY + beforeNow, mNowLinePaint); } @@ -687,7 +688,7 @@ else if (mNewHourHeight > mMaxHourHeight) // Draw the header row texts. startPixel = startFromPixel; - for (int dayNumber = leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) { + for (int dayNumber=leftDaysWithGaps+1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) { // Check if the day is today. day = (Calendar) today.clone(); day.add(Calendar.DATE, dayNumber - 1); @@ -705,25 +706,24 @@ else if (mNewHourHeight > mMaxHourHeight) /** * Get the time and date where the user clicked on. - * * @param x The x position of the touch event. * @param y The y position of the touch event. * @return The time and date at the clicked position. */ - private Calendar getTimeFromPoint(float x, float y) { + private Calendar getTimeFromPoint(float x, float y){ int leftDaysWithGaps = (int) -(Math.ceil(mCurrentOrigin.x / (mWidthPerDay + mColumnGap))); float startPixel = mCurrentOrigin.x + (mWidthPerDay + mColumnGap) * leftDaysWithGaps + mHeaderColumnWidth; for (int dayNumber = leftDaysWithGaps + 1; dayNumber <= leftDaysWithGaps + mNumberOfVisibleDays + 1; dayNumber++) { - float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); - if (mWidthPerDay + startPixel - start > 0 && x > start && x < startPixel + mWidthPerDay) { + float start = (startPixel < mHeaderColumnWidth ? mHeaderColumnWidth : startPixel); + if (mWidthPerDay + startPixel - start > 0 && x > start && x < startPixel + mWidthPerDay){ Calendar day = today(); day.add(Calendar.DATE, dayNumber - 1); float pixelsFromZero = y - mCurrentOrigin.y - mHeaderTextHeight - - mHeaderRowPadding * 2 - mTimeTextHeight / 2 - mHeaderMarginBottom; - int hour = (int) (pixelsFromZero / mHourHeight); + - mHeaderRowPadding * 2 - mTimeTextHeight/2 - mHeaderMarginBottom; + int hour = (int)(pixelsFromZero / mHourHeight); int minute = (int) (60 * (pixelsFromZero - hour * mHourHeight) / mHourHeight); day.add(Calendar.HOUR, hour); day.set(Calendar.MINUTE, minute); @@ -736,10 +736,9 @@ private Calendar getTimeFromPoint(float x, float y) { /** * Draw all the events of a particular day. - * - * @param date The day. + * @param date The day. * @param startFromPixel The left position of the day area. The events will never go any left from this value. - * @param canvas The canvas to draw upon. + * @param canvas The canvas to draw upon. */ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) { if (mEventRects != null && mEventRects.size() > 0) { @@ -747,11 +746,11 @@ private void drawEvents(Calendar date, float startFromPixel, Canvas canvas) { if (isSameDay(mEventRects.get(i).event.getStartTime(), date)) { // Calculate top. - float top = mHourHeight * 24 * mEventRects.get(i).top / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 + mEventMarginVertical; + float top = mHourHeight * 24 * mEventRects.get(i).top / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 + mEventMarginVertical; // Calculate bottom. float bottom = mEventRects.get(i).bottom; - bottom = mHourHeight * 24 * bottom / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight / 2 - mEventMarginVertical; + bottom = mHourHeight * 24 * bottom / 1440 + mCurrentOrigin.y + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom + mTimeTextHeight/2 - mEventMarginVertical; // Calculate left and right. float left = startFromPixel + mEventRects.get(i).left * mWidthPerDay; @@ -773,7 +772,8 @@ top < getHeight() && canvas.drawRoundRect(mEventRects.get(i).rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint); drawEventTitle(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas, top, left); drawEventIcon(mEventRects.get(i).event, mEventRects.get(i).rectF, canvas); - } else + } + else mEventRects.get(i).rectF = null; } } @@ -783,11 +783,10 @@ top < getHeight() && /** * Draw the name of the event on top of the event rectangle. - * - * @param event The event of which the title (and location) should be drawn. - * @param rect The rectangle on which the text is to be drawn. - * @param canvas The canvas to draw upon. - * @param originalTop The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area. + * @param event The event of which the title (and location) should be drawn. + * @param rect The rectangle on which the text is to be drawn. + * @param canvas The canvas to draw upon. + * @param originalTop The original top position of the rectangle. The rectangle may have some of its portion outside of the visible area. * @param originalLeft The original left position of the rectangle. The rectangle may have some of its portion outside of the visible area. */ private void drawEventTitle(WeekViewEvent event, RectF rect, Canvas canvas, float originalTop, float originalLeft) { @@ -901,10 +900,9 @@ private class EventRect { * EventRect will be used for a single event. The given event will be stored in * "originalEvent". But the event that corresponds to rectangle the rectangle instance will * be stored in "event". - * - * @param event Represents the event which this instance of rectangle represents. + * @param event Represents the event which this instance of rectangle represents. * @param originalEvent The original event that was passed by the user. - * @param rectF The rectangle. + * @param rectF The rectangle. */ public EventRect(WeekViewEvent event, WeekViewEvent originalEvent, RectF rectF) { this.event = event; @@ -918,7 +916,6 @@ public EventRect(WeekViewEvent event, WeekViewEvent originalEvent, RectF rectF) * Gets more events of one/more month(s) if necessary. This method is called when the user is * scrolling the week view. The week view stores the events of three months: the visible month, * the previous month, the next month. - * * @param day The day where the user is currently is. */ private void getMoreEvents(Calendar day) { @@ -938,22 +935,24 @@ private void getMoreEvents(Calendar day) { mFetchedPeriod = -1; } - if (mWeekViewLoader != null) { + if (mWeekViewLoader != null){ int periodToFetch = (int) mWeekViewLoader.toWeekViewPeriodIndex(day); if (!isInEditMode() && (mFetchedPeriod < 0 || mFetchedPeriod != periodToFetch || mRefreshEvents)) { List previousPeriodEvents = null; List currentPeriodEvents = null; List nextPeriodEvents = null; - if (mPreviousPeriodEvents != null && mCurrentPeriodEvents != null && mNextPeriodEvents != null) { - if (periodToFetch == mFetchedPeriod - 1) { + if (mPreviousPeriodEvents != null && mCurrentPeriodEvents != null && mNextPeriodEvents != null){ + if (periodToFetch == mFetchedPeriod-1){ currentPeriodEvents = mPreviousPeriodEvents; nextPeriodEvents = mCurrentPeriodEvents; - } else if (periodToFetch == mFetchedPeriod) { + } + else if (periodToFetch == mFetchedPeriod){ previousPeriodEvents = mPreviousPeriodEvents; currentPeriodEvents = mCurrentPeriodEvents; nextPeriodEvents = mNextPeriodEvents; - } else if (periodToFetch == mFetchedPeriod + 1) { + } + else if (periodToFetch == mFetchedPeriod+1){ previousPeriodEvents = mCurrentPeriodEvents; currentPeriodEvents = mNextPeriodEvents; } @@ -961,9 +960,9 @@ private void getMoreEvents(Calendar day) { if (currentPeriodEvents == null) currentPeriodEvents = mWeekViewLoader.onLoad(periodToFetch); if (previousPeriodEvents == null) - previousPeriodEvents = mWeekViewLoader.onLoad(periodToFetch - 1); + previousPeriodEvents = mWeekViewLoader.onLoad(periodToFetch-1); if (nextPeriodEvents == null) - nextPeriodEvents = mWeekViewLoader.onLoad(periodToFetch + 1); + nextPeriodEvents = mWeekViewLoader.onLoad(periodToFetch+1); // Clear events. @@ -1008,11 +1007,10 @@ private void getMoreEvents(Calendar day) { /** * Cache the event for smooth scrolling functionality. - * * @param event The event to cache. */ private void cacheEvent(WeekViewEvent event) { - if (event.getStartTime().compareTo(event.getEndTime()) >= 0) + if(event.getStartTime().compareTo(event.getEndTime()) >= 0) return; if (!isSameDay(event.getStartTime(), event.getEndTime())) { // Add first day. @@ -1048,14 +1046,14 @@ private void cacheEvent(WeekViewEvent event) { WeekViewEvent event2 = new WeekViewEvent(event.getId(), event.getName(), event.getLocation(), startTime, event.getEndTime()); event2.setColor(event.getColor()); mEventRects.add(new EventRect(event2, event, null)); - } else { + } + else { mEventRects.add(new EventRect(event, event, null)); } } /** * Sort and cache events. - * * @param events The events to be sorted and cached. */ private void sortAndCacheEvents(List events) { @@ -1067,7 +1065,6 @@ private void sortAndCacheEvents(List events) { /** * Sorts the events in ascending order. - * * @param events The events to be sorted. */ private void sortEvents(List events) { @@ -1090,7 +1087,6 @@ public int compare(WeekViewEvent event1, WeekViewEvent event2) { /** * Calculates the left and right positions of each events. This comes handy specially if events * are overlapping. - * * @param eventRects The events along with their wrapper class. */ private void computePositionOfEvents(List eventRects) { @@ -1123,7 +1119,6 @@ private void computePositionOfEvents(List eventRects) { /** * Expands all the events to maximum possible width. The events will try to occupy maximum * space available horizontally. - * * @param collisionGroup The group of events which overlap with each other. */ private void expandEventsToMaxWidth(List collisionGroup) { @@ -1136,7 +1131,8 @@ private void expandEventsToMaxWidth(List collisionGroup) { if (column.size() == 0) { column.add(eventRect); isPlaced = true; - } else if (!isEventsCollide(eventRect.event, column.get(column.size() - 1).event)) { + } + else if (!isEventsCollide(eventRect.event, column.get(column.size()-1).event)) { column.add(eventRect); isPlaced = true; break; @@ -1153,14 +1149,14 @@ private void expandEventsToMaxWidth(List collisionGroup) { // Calculate left and right position for all the events. // Get the maxRowCount by looking in all columns. int maxRowCount = 0; - for (List column : columns) { + for (List column : columns){ maxRowCount = Math.max(maxRowCount, column.size()); } for (int i = 0; i < maxRowCount; i++) { // Set the left and right values of the event. float j = 0; for (List column : columns) { - if (column.size() >= i + 1) { + if (column.size() >= i+1) { EventRect eventRect = column.get(i); eventRect.width = 1f / columns.size(); eventRect.left = j / columns.size(); @@ -1176,7 +1172,6 @@ private void expandEventsToMaxWidth(List collisionGroup) { /** * Checks if two events overlap. - * * @param event1 The first event. * @param event2 The second event. * @return true if the events overlap. @@ -1192,7 +1187,6 @@ private boolean isEventsCollide(WeekViewEvent event1, WeekViewEvent event2) { /** * Checks if time1 occurs after (or at the same time) time2. - * * @param time1 The time to check. * @param time2 The time to check against. * @return true if time1 and time2 are equal or if time1 is after time2. Otherwise false. @@ -1213,7 +1207,7 @@ public void invalidate() { // ///////////////////////////////////////////////////////////////// - public void setOnEventClickListener(EventClickListener listener) { + public void setOnEventClickListener (EventClickListener listener) { this.mEventClickListener = listener; } @@ -1221,9 +1215,7 @@ public EventClickListener getEventClickListener() { return mEventClickListener; } - public - @Nullable - MonthLoader.MonthChangeListener getMonthChangeListener() { + public @Nullable MonthLoader.MonthChangeListener getMonthChangeListener() { if (mWeekViewLoader instanceof MonthLoader) return ((MonthLoader) mWeekViewLoader).getOnMonthChangeListener(); return null; @@ -1237,10 +1229,9 @@ public void setMonthChangeListener(MonthLoader.MonthChangeListener monthChangeLi * Get event loader in the week view. Event loaders define the interval after which the events * are loaded in week view. For a MonthLoader events are loaded for every month. You can define * your custom event loader by extending WeekViewLoader. - * * @return The event loader. */ - public WeekViewLoader getWeekViewLoader() { + public WeekViewLoader getWeekViewLoader(){ return mWeekViewLoader; } @@ -1248,10 +1239,9 @@ public WeekViewLoader getWeekViewLoader() { * Set event loader in the week view. For example, a MonthLoader. Event loaders define the * interval after which the events are loaded in week view. For a MonthLoader events are loaded * for every month. You can define your custom event loader by extending WeekViewLoader. - * * @param loader The event loader. */ - public void setWeekViewLoader(WeekViewLoader loader) { + public void setWeekViewLoader(WeekViewLoader loader){ this.mWeekViewLoader = loader; } @@ -1263,33 +1253,32 @@ public void setEventLongPressListener(EventLongPressListener eventLongPressListe this.mEventLongPressListener = eventLongPressListener; } - public void setEmptyViewClickListener(EmptyViewClickListener emptyViewClickListener) { + public void setEmptyViewClickListener(EmptyViewClickListener emptyViewClickListener){ this.mEmptyViewClickListener = emptyViewClickListener; } - public EmptyViewClickListener getEmptyViewClickListener() { + public EmptyViewClickListener getEmptyViewClickListener(){ return mEmptyViewClickListener; } - public void setEmptyViewLongPressListener(EmptyViewLongPressListener emptyViewLongPressListener) { + public void setEmptyViewLongPressListener(EmptyViewLongPressListener emptyViewLongPressListener){ this.mEmptyViewLongPressListener = emptyViewLongPressListener; } - public EmptyViewLongPressListener getEmptyViewLongPressListener() { + public EmptyViewLongPressListener getEmptyViewLongPressListener(){ return mEmptyViewLongPressListener; } - public void setScrollListener(ScrollListener scrolledListener) { + public void setScrollListener(ScrollListener scrolledListener){ this.mScrollListener = scrolledListener; } - public ScrollListener getScrollListener() { + public ScrollListener getScrollListener(){ return mScrollListener; } /** * Get the interpreter which provides the text to show in the header column and the header row. - * * @return The date, time interpreter. */ public DateTimeInterpreter getDateTimeInterpreter() { @@ -1327,10 +1316,9 @@ public String interpretTime(int hour) { /** * Set the interpreter which provides the text to show in the header column and the header row. - * * @param dateTimeInterpreter The date, time interpreter. */ - public void setDateTimeInterpreter(DateTimeInterpreter dateTimeInterpreter) { + public void setDateTimeInterpreter(DateTimeInterpreter dateTimeInterpreter){ this.mDateTimeInterpreter = dateTimeInterpreter; // Refresh time column width. @@ -1340,7 +1328,6 @@ public void setDateTimeInterpreter(DateTimeInterpreter dateTimeInterpreter) { /** * Get the number of visible days in a week. - * * @return The number of visible days in a week. */ public int getNumberOfVisibleDays() { @@ -1349,7 +1336,6 @@ public int getNumberOfVisibleDays() { /** * Set the number of visible days in a week. - * * @param numberOfVisibleDays The number of visible days in a week. */ public void setNumberOfVisibleDays(int numberOfVisibleDays) { @@ -1385,14 +1371,13 @@ public int getFirstDayOfWeek() { * Set the first day of the week. First day of the week is used only when the week view is first * drawn. It does not of any effect after user starts scrolling horizontally. *

- * Note: This method will only work if the week view is set to display more than 6 days at - * once. + * Note: This method will only work if the week view is set to display more than 6 days at + * once. *

- * * @param firstDayOfWeek The supported values are {@link java.util.Calendar#SUNDAY}, - * {@link java.util.Calendar#MONDAY}, {@link java.util.Calendar#TUESDAY}, - * {@link java.util.Calendar#WEDNESDAY}, {@link java.util.Calendar#THURSDAY}, - * {@link java.util.Calendar#FRIDAY}. + * {@link java.util.Calendar#MONDAY}, {@link java.util.Calendar#TUESDAY}, + * {@link java.util.Calendar#WEDNESDAY}, {@link java.util.Calendar#THURSDAY}, + * {@link java.util.Calendar#FRIDAY}. */ public void setFirstDayOfWeek(int firstDayOfWeek) { mFirstDayOfWeek = firstDayOfWeek; @@ -1551,7 +1536,6 @@ public void setDefaultEventColor(int defaultEventColor) { /** * Note: Use {@link #setDateTimeInterpreter(DateTimeInterpreter)} and * {@link #getDateTimeInterpreter()} instead. - * * @return Either long or short day name is being used. */ @Deprecated @@ -1563,11 +1547,10 @@ public int getDayNameLength() { * Set the length of the day name displayed in the header row. Example of short day names is * 'M' for 'Monday' and example of long day names is 'Mon' for 'Monday'. *

- * Note: Use {@link #setDateTimeInterpreter(DateTimeInterpreter)} instead. + * Note: Use {@link #setDateTimeInterpreter(DateTimeInterpreter)} instead. *

- * * @param length Supported values are {@link com.alamkanak.weekview.WeekView#LENGTH_SHORT} and - * {@link com.alamkanak.weekview.WeekView#LENGTH_LONG}. + * {@link com.alamkanak.weekview.WeekView#LENGTH_LONG}. */ @Deprecated public void setDayNameLength(int length) { @@ -1583,7 +1566,6 @@ public int getOverlappingEventGap() { /** * Set the gap between overlapping events. - * * @param overlappingEventGap The gap between overlapping events. */ public void setOverlappingEventGap(int overlappingEventGap) { @@ -1611,7 +1593,6 @@ public int getEventMarginVertical() { /** * Set the top and bottom margin of the event. The event will release this margin from the top * and bottom edge. This margin is useful for differentiation consecutive events. - * * @param eventMarginVertical The top and bottom margin. */ public void setEventMarginVertical(int eventMarginVertical) { @@ -1621,7 +1602,6 @@ public void setEventMarginVertical(int eventMarginVertical) { /** * Returns the first visible day in the week view. - * * @return The first visible day in the week view. */ public Calendar getFirstVisibleDay() { @@ -1630,7 +1610,6 @@ public Calendar getFirstVisibleDay() { /** * Returns the last visible day in the week view. - * * @return The last visible day in the week view. */ public Calendar getLastVisibleDay() { @@ -1639,7 +1618,6 @@ public Calendar getLastVisibleDay() { /** * Get the scrolling speed factor in horizontal direction. - * * @return The speed factor in horizontal direction. */ public float getXScrollingSpeed() { @@ -1648,7 +1626,6 @@ public float getXScrollingSpeed() { /** * Sets the speed for horizontal scrolling. - * * @param xScrollingSpeed The new horizontal scrolling speed. */ public void setXScrollingSpeed(float xScrollingSpeed) { @@ -1659,7 +1636,6 @@ public void setXScrollingSpeed(float xScrollingSpeed) { * Whether weekends should have a background color different from the normal day background * color. The weekend background colors are defined by the attributes * `futureWeekendBackgroundColor` and `pastWeekendBackgroundColor`. - * * @return True if weekends should have different background colors. */ public boolean isShowDistinctWeekendColor() { @@ -1670,7 +1646,6 @@ public boolean isShowDistinctWeekendColor() { * Set whether weekends should have a background color different from the normal day background * color. The weekend background colors are defined by the attributes * `futureWeekendBackgroundColor` and `pastWeekendBackgroundColor`. - * * @param showDistinctWeekendColor True if weekends should have different background colors. */ public void setShowDistinctWeekendColor(boolean showDistinctWeekendColor) { @@ -1682,7 +1657,6 @@ public void setShowDistinctWeekendColor(boolean showDistinctWeekendColor) { * Whether past and future days should have two different background colors. The past and * future day colors are defined by the attributes `futureBackgroundColor` and * `pastBackgroundColor`. - * * @return True if past and future days should have two different background colors. */ public boolean isShowDistinctPastFutureColor() { @@ -1693,7 +1667,6 @@ public boolean isShowDistinctPastFutureColor() { * Set whether weekends should have a background color different from the normal day background * color. The past and future day colors are defined by the attributes `futureBackgroundColor` * and `pastBackgroundColor`. - * * @param showDistinctPastFutureColor True if past and future should have two different * background colors. */ @@ -1705,7 +1678,6 @@ public void setShowDistinctPastFutureColor(boolean showDistinctPastFutureColor) /** * Get whether "now" line should be displayed. "Now" line is defined by the attributes * `nowLineColor` and `nowLineThickness`. - * * @return True if "now" line should be displayed. */ public boolean isShowNowLine() { @@ -1715,7 +1687,6 @@ public boolean isShowNowLine() { /** * Set whether "now" line should be displayed. "Now" line is defined by the attributes * `nowLineColor` and `nowLineThickness`. - * * @param showNowLine True if "now" line should be displayed. */ public void setShowNowLine(boolean showNowLine) { @@ -1725,7 +1696,6 @@ public void setShowNowLine(boolean showNowLine) { /** * Get the "now" line color. - * * @return The color of the "now" line. */ public int getNowLineColor() { @@ -1734,7 +1704,6 @@ public int getNowLineColor() { /** * Set the "now" line color. - * * @param nowLineColor The color of the "now" line. */ public void setNowLineColor(int nowLineColor) { @@ -1744,7 +1713,6 @@ public void setNowLineColor(int nowLineColor) { /** * Get the "now" line thickness. - * * @return The thickness of the "now" line. */ public int getNowLineThickness() { @@ -1753,7 +1721,6 @@ public int getNowLineThickness() { /** * Set the "now" line thickness. - * * @param nowLineThickness The thickness of the "now" line. */ public void setNowLineThickness(int nowLineThickness) { @@ -1763,7 +1730,6 @@ public void setNowLineThickness(int nowLineThickness) { /** * Get whether the week view should fling horizontally. - * * @return True if the week view has horizontal fling enabled. */ public boolean isHorizontalFlingEnabled() { @@ -1772,7 +1738,6 @@ public boolean isHorizontalFlingEnabled() { /** * Set whether the week view should fling horizontally. - * * @return True if it should have horizontal fling enabled. */ public void setHorizontalFlingEnabled(boolean enabled) { @@ -1781,7 +1746,6 @@ public void setHorizontalFlingEnabled(boolean enabled) { /** * Get whether the week view should fling vertically. - * * @return True if the week view has vertical fling enabled. */ public boolean isVerticalFlingEnabled() { @@ -1790,7 +1754,6 @@ public boolean isVerticalFlingEnabled() { /** * Set whether the week view should fling vertically. - * * @return True if it should have vertical fling enabled. */ public void setVerticalFlingEnabled(boolean enabled) { @@ -1819,7 +1782,7 @@ public boolean onTouchEvent(MotionEvent event) { return val; } - private void goToNearestOrigin() { + private void goToNearestOrigin(){ double leftDays = mCurrentOrigin.x / (mWidthPerDay + mColumnGap); if (mCurrentFlingDirection != Direction.NONE) { @@ -1872,7 +1835,6 @@ public void computeScroll() { /** * Check if scrolling should be stopped. - * * @return true if scrolling should be stopped before reaching the end of animation. */ private boolean forceFinishScroll() { @@ -1901,7 +1863,6 @@ public void goToToday() { /** * Show a specific day on the week view. - * * @param date The date to show. */ public void goToDate(Calendar date) { @@ -1913,7 +1874,7 @@ public void goToDate(Calendar date) { date.set(Calendar.SECOND, 0); date.set(Calendar.MILLISECOND, 0); - if (mAreDimensionsInvalid) { + if(mAreDimensionsInvalid) { mScrollToDay = date; return; } @@ -1929,25 +1890,24 @@ public void goToDate(Calendar date) { long day = 1000L * 60L * 60L * 24L; long dateInMillis = date.getTimeInMillis() + date.getTimeZone().getOffset(date.getTimeInMillis()); long todayInMillis = today.getTimeInMillis() + today.getTimeZone().getOffset(today.getTimeInMillis()); - long dateDifference = (dateInMillis / day) - (todayInMillis / day); - mCurrentOrigin.x = -dateDifference * (mWidthPerDay + mColumnGap); + long dateDifference = (dateInMillis/day) - (todayInMillis/day); + mCurrentOrigin.x = - dateDifference * (mWidthPerDay + mColumnGap); invalidate(); } /** * Refreshes the view and loads the events again. */ - public void notifyDatasetChanged() { + 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) { + public void goToHour(double hour){ if (mAreDimensionsInvalid) { mScrollToHour = hour; return; @@ -1960,7 +1920,7 @@ else if (hour > 0) verticalOffset = (int) (mHourHeight * hour); if (verticalOffset > mHourHeight * 24 - getHeight() + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom) - verticalOffset = (int) (mHourHeight * 24 - getHeight() + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom); + verticalOffset = (int)(mHourHeight * 24 - getHeight() + mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom); mCurrentOrigin.y = -verticalOffset; invalidate(); @@ -1968,14 +1928,14 @@ else if (hour > 0) /** * Get the first hour that is visible on the screen. - * * @return The first hour that is visible. */ - public double getFirstVisibleHour() { + public double getFirstVisibleHour(){ return -mCurrentOrigin.y / mHourHeight; } + ///////////////////////////////////////////////////////////////// // // Interfaces. @@ -1985,8 +1945,7 @@ public double getFirstVisibleHour() { public interface EventClickListener { /** * Triggered when clicked on one existing event - * - * @param event: event clicked. + * @param event: event clicked. * @param eventRect: view containing the clicked event. */ void onEventClick(WeekViewEvent event, RectF eventRect); @@ -1995,8 +1954,7 @@ public interface EventClickListener { public interface EventLongPressListener { /** * Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press. - * - * @param event: event clicked. + * @param event: event clicked. * @param eventRect: view containing the clicked event. */ void onEventLongPress(WeekViewEvent event, RectF eventRect); @@ -2005,7 +1963,6 @@ public interface EventLongPressListener { public interface EmptyViewClickListener { /** * Triggered when the users clicks on a empty space of the calendar. - * * @param time: {@link Calendar} object set with the date and time of the clicked position on the view. */ void onEmptyViewClicked(Calendar time); @@ -2014,7 +1971,6 @@ public interface EmptyViewClickListener { public interface EmptyViewLongPressListener { /** * Similar to {@link com.alamkanak.weekview.WeekView.EmptyViewClickListener} but with long press. - * * @param time: {@link Calendar} object set with the date and time of the long pressed position on the view. */ void onEmptyViewLongPress(Calendar time); @@ -2023,9 +1979,8 @@ public interface EmptyViewLongPressListener { public interface ScrollListener { /** * Called when the first visible day has changed. - *

- * (this will also be called during the first draw of the weekview) * + * (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). */ @@ -2041,7 +1996,6 @@ public interface ScrollListener { /** * Checks if two times are on the same day. - * * @param dayOne The first day. * @param dayTwo The second day. * @return Whether the times are on the same day. @@ -2052,10 +2006,9 @@ private boolean isSameDay(Calendar dayOne, Calendar dayTwo) { /** * Returns a calendar instance at the start of this day - * * @return the calendar instance */ - private Calendar today() { + private Calendar today(){ Calendar today = Calendar.getInstance(); today.set(Calendar.HOUR_OF_DAY, 0); today.set(Calendar.MINUTE, 0); @@ -2064,4 +2017,4 @@ private Calendar today() { return today; } -} +} \ No newline at end of file diff --git a/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java b/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java index 1c9f976f1..27006f8d6 100644 --- a/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekViewEvent.java @@ -16,27 +16,27 @@ public class WeekViewEvent { private int mIconId; private int mIconColor; - public WeekViewEvent() { + public WeekViewEvent(){ } /** * Initializes the event for week view. * - * @param id The id of the event. - * @param name Name of the event. - * @param startYear Year when the event starts. - * @param startMonth Month when the event starts. - * @param startDay Day when the event starts. - * @param startHour Hour (in 24-hour format) when the event starts. + * @param id The id of the event. + * @param name Name of the event. + * @param startYear Year when the event starts. + * @param startMonth Month when the event starts. + * @param startDay Day when the event starts. + * @param startHour Hour (in 24-hour format) when the event starts. * @param startMinute Minute when the event starts. - * @param endYear Year when the event ends. - * @param endMonth Month when the event ends. - * @param endDay Day when the event ends. - * @param endHour Hour (in 24-hour format) when the event ends. - * @param endMinute Minute when the event ends. - * @param iconId Icon associated at the event. - * @param iconColor Color of the icon associated at the event. + * @param endYear Year when the event ends. + * @param endMonth Month when the event ends. + * @param endDay Day when the event ends. + * @param endHour Hour (in 24-hour format) when the event ends. + * @param endMinute Minute when the event ends. + * @param iconId Icon associated at the event. + * @param iconColor Color of the icon associated at the event. */ public WeekViewEvent(long id, String name, int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, @@ -45,14 +45,14 @@ public WeekViewEvent(long id, String name, int startYear, int startMonth, int st this.mStartTime = Calendar.getInstance(); this.mStartTime.set(Calendar.YEAR, startYear); - this.mStartTime.set(Calendar.MONTH, startMonth - 1); + this.mStartTime.set(Calendar.MONTH, startMonth-1); this.mStartTime.set(Calendar.DAY_OF_MONTH, startDay); this.mStartTime.set(Calendar.HOUR_OF_DAY, startHour); this.mStartTime.set(Calendar.MINUTE, startMinute); this.mEndTime = Calendar.getInstance(); this.mEndTime.set(Calendar.YEAR, endYear); - this.mEndTime.set(Calendar.MONTH, endMonth - 1); + this.mEndTime.set(Calendar.MONTH, endMonth-1); this.mEndTime.set(Calendar.DAY_OF_MONTH, endDay); this.mEndTime.set(Calendar.HOUR_OF_DAY, endHour); this.mEndTime.set(Calendar.MINUTE, endMinute); @@ -66,18 +66,18 @@ public WeekViewEvent(long id, String name, int startYear, int startMonth, int st /** * Initializes the event for week view. * - * @param id The id of the event. - * @param name Name of the event. - * @param startYear Year when the event starts. - * @param startMonth Month when the event starts. - * @param startDay Day when the event starts. - * @param startHour Hour (in 24-hour format) when the event starts. + * @param id The id of the event. + * @param name Name of the event. + * @param startYear Year when the event starts. + * @param startMonth Month when the event starts. + * @param startDay Day when the event starts. + * @param startHour Hour (in 24-hour format) when the event starts. * @param startMinute Minute when the event starts. - * @param endYear Year when the event ends. - * @param endMonth Month when the event ends. - * @param endDay Day when the event ends. - * @param endHour Hour (in 24-hour format) when the event ends. - * @param endMinute Minute when the event ends. + * @param endYear Year when the event ends. + * @param endMonth Month when the event ends. + * @param endDay Day when the event ends. + * @param endHour Hour (in 24-hour format) when the event ends. + * @param endMinute Minute when the event ends. */ public WeekViewEvent(long id, String name, int startYear, int startMonth, int startDay, int startHour, int startMinute, int endYear, int endMonth, int endDay, @@ -89,12 +89,12 @@ public WeekViewEvent(long id, String name, int startYear, int startMonth, int st /** * Initializes the event for week view. * - * @param id The id of the event. - * @param name Name of the event. - * @param location The location of the event. + * @param id The id of the event. + * @param name Name of the event. + * @param location The location of the event. * @param startTime The time when the event starts. - * @param endTime The time when the event ends. - * @param iconId Icon associated at the event. + * @param endTime The time when the event ends. + * @param iconId Icon associated at the event. * @param iconColor Color of the icon associated at the event. */ public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime, @@ -111,11 +111,11 @@ public WeekViewEvent(long id, String name, String location, Calendar startTime, /** * Initializes the event for week view. * - * @param id The id of the event. - * @param name Name of the event. - * @param location The location of the event. + * @param id The id of the event. + * @param name Name of the event. + * @param location The location of the event. * @param startTime The time when the event starts. - * @param endTime The time when the event ends. + * @param endTime The time when the event ends. */ public WeekViewEvent(long id, String name, String location, Calendar startTime, Calendar endTime) { this(id, name, location, startTime, endTime, 0, 0); @@ -124,10 +124,10 @@ public WeekViewEvent(long id, String name, String location, Calendar startTime, /** * Initializes the event for week view. * - * @param id The id of the event. - * @param name Name of the event. + * @param id The id of the event. + * @param name Name of the event. * @param startTime The time when the event starts. - * @param endTime The time when the event ends. + * @param endTime The time when the event ends. */ public WeekViewEvent(long id, String name, Calendar startTime, Calendar endTime) { this(id, name, null, startTime, endTime, 0, 0); @@ -212,4 +212,4 @@ public boolean equals(Object o) { public int hashCode() { return (int) (mId ^ (mId >>> 32)); } -} +} \ No newline at end of file From 071cd0a29a76b943be473c33849ef472c33c0a9f Mon Sep 17 00:00:00 2001 From: Romain Vermot Date: Sat, 30 Jan 2016 16:24:43 +0100 Subject: [PATCH 3/3] Update the README with instructions on how to set an icon --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index e83c54ec7..ef64b887d 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,17 @@ Usage }; ``` +6. Add an icon at a WeekViewEvent with `WeekViewEvent.setIconId(int iconId)` and change its color with `WeekViewEvent.setIconColor(int iconColor)`. + + ```java + WeekViewEvent event = new WeekViewEvent(1, "My title", startTime, endTime); + + // Add a vector asset + event.setIconId(R.drawable.ic_my_vector); + // Change the color of the asset (by default, it's the same that the title color) + event.setIconColor(R.color.myColor); + ``` + Customization ------------------- @@ -126,6 +137,7 @@ You can customize the look of the `WeekView` in xml. Use the following attribute - `showNowLine` - `nowLineColor` - `nowLineThickness` +- `eventIconSize` Interfaces ----------