diff --git a/gradle.properties b/gradle.properties index 06ce1887d..3856eacad 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -VERSION_NAME=2.1.0 +VERSION_NAME=2.1.1 GROUP=com.github.quivr POM_DESCRIPTION=An android library to show day view, week view, 3 day view etc. in your app. diff --git a/library/src/main/java/com/alamkanak/weekview/WeekView.java b/library/src/main/java/com/alamkanak/weekview/WeekView.java index 9d4ee6079..cc1871217 100755 --- a/library/src/main/java/com/alamkanak/weekview/WeekView.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekView.java @@ -2070,23 +2070,66 @@ public void setAutoLimitTime(boolean isAuto){ invalidate(); } + private void recalculateHourHeight(){ + int height = (int) ((getHeight() - (mHeaderHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom)) / (this.mMaxTime - this.mMinTime)); + if(height > mHourHeight){ + if(height > mMaxHourHeight) + mMaxHourHeight = height; + mNewHourHeight = height; + } + } + /** - * set fix visible time. + * Set visible time span. * @param startHour limit time display on top (between 0~24) - * @param endHour limit time display at bottom (between 0~24 and > startHour) + * @param endHour limit time display at bottom (between 0~24 and larger than startHour) * */ public void setLimitTime(int startHour, int endHour){ - if(endHour <= startHour || startHour < 0 || endHour > 24){ - throw new IllegalArgumentException("endHour must larger startHour"); + if(endHour <= startHour){ + throw new IllegalArgumentException("endHour must larger startHour."); + } + else if(startHour < 0){ + throw new IllegalArgumentException("startHour must be at least 0."); + } + else if(endHour > 24){ + throw new IllegalArgumentException("endHour can't be higher than 24."); } this.mMinTime = startHour; this.mMaxTime = endHour; - int height = (int) ((getHeight() - (mHeaderHeight + mHeaderRowPadding * 2 + mTimeTextHeight/2 + mHeaderMarginBottom)) / (this.mMaxTime - this.mMinTime)); - if(height > mHourHeight){ - if(height > mMaxHourHeight) - mMaxHourHeight = height; - mNewHourHeight = height; + recalculateHourHeight(); + invalidate(); + } + + /** + * Set minimal shown time + * + * @param startHour limit time display on top (between 0~24) and smaller than endHour + * */ + public void setMinTime(int startHour){ + if(mMaxTime <= startHour){ + throw new IllegalArgumentException("startHour must smaller than endHour"); + } + else if(startHour < 0){ + throw new IllegalArgumentException("startHour must be at least 0."); } + this.mMinTime = startHour; + recalculateHourHeight(); + } + + /** + * Set highest shown time + * + * @param endHour limit time display at bottom (between 0~24 and larger than startHour) + * */ + public void setMaxTime(int endHour){ + if(endHour <= mMinTime){ + throw new IllegalArgumentException("endHour must larger startHour."); + } + else if(endHour > 24){ + throw new IllegalArgumentException("endHour can't be higher than 24."); + } + this.mMaxTime = endHour; + recalculateHourHeight(); invalidate(); } @@ -2274,6 +2317,66 @@ public void setScrollDuration(int scrollDuration) { mScrollDuration = scrollDuration; } + public int getMaxHourHeight() { + return mMaxHourHeight; + } + + public void setMaxHourHeight(int maxHourHeight) { + mMaxHourHeight = maxHourHeight; + } + + public int getMinHourHeight() { + return mMinHourHeight; + } + + public void setMinHourHeight(int minHourHeight) { + this.mMinHourHeight = minHourHeight; + } + + public int getPastBackgroundColor() { + return mPastBackgroundColor; + } + + public void setPastBackgroundColor(int pastBackgroundColor) { + this.mPastBackgroundColor = pastBackgroundColor; + mPastBackgroundPaint.setColor(mPastBackgroundColor); + } + + public int getFutureBackgroundColor() { + return mFutureBackgroundColor; + } + + public void setFutureBackgroundColor(int futureBackgroundColor) { + this.mFutureBackgroundColor = futureBackgroundColor; + mFutureBackgroundPaint.setColor(mFutureBackgroundColor); + } + + public int getPastWeekendBackgroundColor() { + return mPastWeekendBackgroundColor; + } + + public void setPastWeekendBackgroundColor(int pastWeekendBackgroundColor) { + this.mPastWeekendBackgroundColor = pastWeekendBackgroundColor; + this.mPastWeekendBackgroundPaint.setColor(mPastWeekendBackgroundColor); + } + + public int getFutureWeekendBackgroundColor() { + return mFutureWeekendBackgroundColor; + } + + public void setFutureWeekendBackgroundColor(int futureWeekendBackgroundColor) { + this.mFutureWeekendBackgroundColor = futureWeekendBackgroundColor; + this.mFutureWeekendBackgroundPaint.setColor(mFutureWeekendBackgroundColor); + } + + public Drawable getNewEventIconDrawable() { + return mNewEventIconDrawable; + } + + public void setNewEventIconDrawable(Drawable newEventIconDrawable) { + this.mNewEventIconDrawable = newEventIconDrawable; + } + ///////////////////////////////////////////////////////////////// // // Functions related to scrolling. diff --git a/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java b/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java index a037d03db..6ffb5523a 100644 --- a/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java +++ b/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java @@ -1,5 +1,6 @@ package com.alamkanak.weekview.sample; +import android.graphics.Color; import android.graphics.RectF; import android.graphics.Typeface; import android.os.Bundle; @@ -79,12 +80,25 @@ protected void onCreate(Bundle savedInstanceState) { //mWeekView.setAutoLimitTime(true); //mWeekView.setLimitTime(4, 16); + //mWeekView.setMinTime(10); + //mWeekView.setMaxTime(20); // Set up a date time interpreter to interpret how the date and time will be formatted in // the week view. This is optional. setupDateTimeInterpreter(false); } + @Override + protected void onResume() { + super.onResume(); + /*mWeekView.setShowDistinctPastFutureColor(true); + mWeekView.setShowDistinctWeekendColor(true); + mWeekView.setFutureBackgroundColor(Color.rgb(24,85,96)); + mWeekView.setFutureWeekendBackgroundColor(Color.rgb(255,0,0)); + mWeekView.setPastBackgroundColor(Color.rgb(85,189,200)); + mWeekView.setPastWeekendBackgroundColor(Color.argb(50, 0,255,0)); + */ + } @Override public boolean onCreateOptionsMenu(Menu menu) {