From 28c6f91d6c695139584ea1c2530c1b79ad4e74a4 Mon Sep 17 00:00:00 2001 From: Thomas Goureau Date: Mon, 1 Feb 2016 15:32:19 +0100 Subject: [PATCH 1/4] Clean Code (refractor move --> interfaces) --- .../weekview/DateTimeInterpreter.java | 11 --- .../com/alamkanak/weekview/MonthLoader.java | 2 + .../java/com/alamkanak/weekview/WeekView.java | 70 +++++-------------- .../alamkanak/weekview/WeekViewLoader.java | 24 ------- 4 files changed, 19 insertions(+), 88 deletions(-) delete mode 100644 library/src/main/java/com/alamkanak/weekview/DateTimeInterpreter.java delete mode 100644 library/src/main/java/com/alamkanak/weekview/WeekViewLoader.java diff --git a/library/src/main/java/com/alamkanak/weekview/DateTimeInterpreter.java b/library/src/main/java/com/alamkanak/weekview/DateTimeInterpreter.java deleted file mode 100644 index 383c5570d..000000000 --- a/library/src/main/java/com/alamkanak/weekview/DateTimeInterpreter.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.alamkanak.weekview; - -import java.util.Calendar; - -/** - * Created by Raquib on 1/6/2015. - */ -public interface DateTimeInterpreter { - String interpretDate(Calendar date); - String interpretTime(int hour); -} diff --git a/library/src/main/java/com/alamkanak/weekview/MonthLoader.java b/library/src/main/java/com/alamkanak/weekview/MonthLoader.java index 424d67c1b..e3eeb7e8a 100644 --- a/library/src/main/java/com/alamkanak/weekview/MonthLoader.java +++ b/library/src/main/java/com/alamkanak/weekview/MonthLoader.java @@ -1,5 +1,7 @@ package com.alamkanak.weekview; +import com.alamkanak.weekview.interfaces.WeekViewLoader; + import java.util.Calendar; import java.util.List; diff --git a/library/src/main/java/com/alamkanak/weekview/WeekView.java b/library/src/main/java/com/alamkanak/weekview/WeekView.java index cb22eefca..9c8b9d7e8 100755 --- a/library/src/main/java/com/alamkanak/weekview/WeekView.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekView.java @@ -1,5 +1,13 @@ package com.alamkanak.weekview; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; + import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; @@ -33,13 +41,13 @@ import android.view.ViewConfiguration; import android.widget.OverScroller; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Locale; +import com.alamkanak.weekview.interfaces.DateTimeInterpreter; +import com.alamkanak.weekview.interfaces.EmptyViewClickListener; +import com.alamkanak.weekview.interfaces.EmptyViewLongPressListener; +import com.alamkanak.weekview.interfaces.EventClickListener; +import com.alamkanak.weekview.interfaces.EventLongPressListener; +import com.alamkanak.weekview.interfaces.ScrollListener; +import com.alamkanak.weekview.interfaces.WeekViewLoader; /** * Created by Raquib-ul-Alam Kanak on 7/21/2014. @@ -280,7 +288,8 @@ public void onLongPress(MotionEvent e) { } // If the tap was on in an empty space, then trigger the callback. - if (mEmptyViewLongPressListener != null && e.getX() > mHeaderColumnWidth && e.getY() > (mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom)) { + if (mEmptyViewLongPressListener != null +&& e.getX() > mHeaderColumnWidth && e.getY() > (mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom)) { Calendar selectedTime = getTimeFromPoint(e.getX(), e.getY()); if (selectedTime != null) { performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); @@ -1891,56 +1900,11 @@ public double getFirstVisibleHour(){ - ///////////////////////////////////////////////////////////////// - // - // Interfaces. - // - ///////////////////////////////////////////////////////////////// - public interface EventClickListener { - /** - * Triggered when clicked on one existing event - * @param event: event clicked. - * @param eventRect: view containing the clicked event. - */ - void onEventClick(WeekViewEvent event, RectF eventRect); - } - public interface EventLongPressListener { - /** - * Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press. - * @param event: event clicked. - * @param eventRect: view containing the clicked event. - */ - void onEventLongPress(WeekViewEvent event, RectF eventRect); - } - 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); - } - 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); - } - public interface ScrollListener { - /** - * Called when the first visible day has changed. - * - * (this will also be called during the first draw of the weekview) - * @param newFirstVisibleDay The new first visible day - * @param oldFirstVisibleDay The old first visible day (is null on the first call). - */ - void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay); - } ///////////////////////////////////////////////////////////////// diff --git a/library/src/main/java/com/alamkanak/weekview/WeekViewLoader.java b/library/src/main/java/com/alamkanak/weekview/WeekViewLoader.java deleted file mode 100644 index dcedfe988..000000000 --- a/library/src/main/java/com/alamkanak/weekview/WeekViewLoader.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.alamkanak.weekview; - -import java.util.Calendar; -import java.util.List; - -public interface WeekViewLoader { - /** - * Convert a date into a double that will be used to reference when you're loading data. - * - * All periods that have the same integer part, define one period. Dates that are later in time - * should have a greater return value. - * - * @param instance the date - * @return The period index in which the date falls (floating point number). - */ - double toWeekViewPeriodIndex(Calendar instance); - - /** - * Load the events within the period - * @param periodIndex the period to load - * @return A list with the events of this period - */ - List onLoad(int periodIndex); -} From 5cc93c799c0a37603f62f0c29da6fb1873167c23 Mon Sep 17 00:00:00 2001 From: Thomas Goureau Date: Thu, 4 Feb 2016 11:28:30 +0100 Subject: [PATCH 2/4] Clean Code (refractor move --> interfaces) part 2 --- .../interfaces/DateTimeInterpreter.java | 11 ++++++++ .../interfaces/EmptyViewClickListener.java | 14 ++++++++++ .../EmptyViewLongPressListener.java | 14 ++++++++++ .../interfaces/EventClickListener.java | 17 ++++++++++++ .../interfaces/EventLongPressListener.java | 17 ++++++++++++ .../weekview/interfaces/ScrollListener.java | 17 ++++++++++++ .../weekview/interfaces/WeekViewLoader.java | 26 +++++++++++++++++++ .../weekview/sample/BaseActivity.java | 2 +- 8 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/DateTimeInterpreter.java create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewClickListener.java create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewLongPressListener.java create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/EventClickListener.java create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/EventLongPressListener.java create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/ScrollListener.java create mode 100644 library/src/main/java/com/alamkanak/weekview/interfaces/WeekViewLoader.java diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/DateTimeInterpreter.java b/library/src/main/java/com/alamkanak/weekview/interfaces/DateTimeInterpreter.java new file mode 100644 index 000000000..814715e64 --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/DateTimeInterpreter.java @@ -0,0 +1,11 @@ +package com.alamkanak.weekview.interfaces; + +import java.util.Calendar; + +/** + * Created by Raquib on 1/6/2015. + */ +public interface DateTimeInterpreter { + String interpretDate(Calendar date); + String interpretTime(int hour); +} diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewClickListener.java b/library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewClickListener.java new file mode 100644 index 000000000..85d4cfd5d --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewClickListener.java @@ -0,0 +1,14 @@ +package com.alamkanak.weekview.interfaces; + +import java.util.Calendar; + +/** + * Created by Thomas on 01/02/2016. + */ +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); +} diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewLongPressListener.java b/library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewLongPressListener.java new file mode 100644 index 000000000..c02076a40 --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/EmptyViewLongPressListener.java @@ -0,0 +1,14 @@ +package com.alamkanak.weekview.interfaces; + +import java.util.Calendar; + +/** + * Created by Thomas on 01/02/2016. + */ +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); +} diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/EventClickListener.java b/library/src/main/java/com/alamkanak/weekview/interfaces/EventClickListener.java new file mode 100644 index 000000000..5532f5249 --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/EventClickListener.java @@ -0,0 +1,17 @@ +package com.alamkanak.weekview.interfaces; + +import android.graphics.RectF; + +import com.alamkanak.weekview.WeekViewEvent; + +/** + * Created by Thomas on 01/02/2016. + */ +public interface EventClickListener { + /** + * Triggered when clicked on one existing event + * @param event: event clicked. + * @param eventRect: view containing the clicked event. + */ + void onEventClick(WeekViewEvent event, RectF eventRect); +} diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/EventLongPressListener.java b/library/src/main/java/com/alamkanak/weekview/interfaces/EventLongPressListener.java new file mode 100644 index 000000000..0bb4fe435 --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/EventLongPressListener.java @@ -0,0 +1,17 @@ +package com.alamkanak.weekview.interfaces; + +import android.graphics.RectF; + +import com.alamkanak.weekview.WeekViewEvent; + +/** + * Created by Thomas on 01/02/2016. + */ +public interface EventLongPressListener { + /** + * Similar to {@link com.alamkanak.weekview.WeekView.EventClickListener} but with a long press. + * @param event: event clicked. + * @param eventRect: view containing the clicked event. + */ + void onEventLongPress(WeekViewEvent event, RectF eventRect); +} diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/ScrollListener.java b/library/src/main/java/com/alamkanak/weekview/interfaces/ScrollListener.java new file mode 100644 index 000000000..7697a18c5 --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/ScrollListener.java @@ -0,0 +1,17 @@ +package com.alamkanak.weekview.interfaces; + +import java.util.Calendar; + +/** + * Created by Thomas on 01/02/2016. + */ +public interface ScrollListener { + /** + * Called when the first visible day has changed. + * + * (this will also be called during the first draw of the weekview) + * @param newFirstVisibleDay The new first visible day + * @param oldFirstVisibleDay The old first visible day (is null on the first call). + */ + void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay); +} diff --git a/library/src/main/java/com/alamkanak/weekview/interfaces/WeekViewLoader.java b/library/src/main/java/com/alamkanak/weekview/interfaces/WeekViewLoader.java new file mode 100644 index 000000000..47d157a48 --- /dev/null +++ b/library/src/main/java/com/alamkanak/weekview/interfaces/WeekViewLoader.java @@ -0,0 +1,26 @@ +package com.alamkanak.weekview.interfaces; + +import com.alamkanak.weekview.WeekViewEvent; + +import java.util.Calendar; +import java.util.List; + +public interface WeekViewLoader { + /** + * Convert a date into a double that will be used to reference when you're loading data. + * + * All periods that have the same integer part, define one period. Dates that are later in time + * should have a greater return value. + * + * @param instance the date + * @return The period index in which the date falls (floating point number). + */ + double toWeekViewPeriodIndex(Calendar instance); + + /** + * Load the events within the period + * @param periodIndex the period to load + * @return A list with the events of this period + */ + List onLoad(int periodIndex); +} 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 e311d1943..fb7762f13 100644 --- a/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java +++ b/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java @@ -8,7 +8,7 @@ import android.view.MenuItem; import android.widget.Toast; -import com.alamkanak.weekview.DateTimeInterpreter; +import com.alamkanak.weekview.interfaces.DateTimeInterpreter; import com.alamkanak.weekview.MonthLoader; import com.alamkanak.weekview.WeekView; import com.alamkanak.weekview.WeekViewEvent; From acc494684428bc4a47fac637848f4226665d4d94 Mon Sep 17 00:00:00 2001 From: Thomas Goureau Date: Thu, 4 Feb 2016 11:30:19 +0100 Subject: [PATCH 3/4] Clean Code (refractor move --> interfaces) part 3 --- .../java/com/alamkanak/weekview/sample/BaseActivity.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 fb7762f13..04432754c 100644 --- a/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java +++ b/sample/src/main/java/com/alamkanak/weekview/sample/BaseActivity.java @@ -8,10 +8,13 @@ import android.view.MenuItem; import android.widget.Toast; -import com.alamkanak.weekview.interfaces.DateTimeInterpreter; import com.alamkanak.weekview.MonthLoader; import com.alamkanak.weekview.WeekView; import com.alamkanak.weekview.WeekViewEvent; +import com.alamkanak.weekview.interfaces.DateTimeInterpreter; +import com.alamkanak.weekview.interfaces.EmptyViewLongPressListener; +import com.alamkanak.weekview.interfaces.EventClickListener; +import com.alamkanak.weekview.interfaces.EventLongPressListener; import java.text.SimpleDateFormat; import java.util.Calendar; @@ -23,7 +26,7 @@ * Created by Raquib-ul-Alam Kanak on 1/3/2014. * Website: http://alamkanak.github.io */ -public abstract class BaseActivity extends AppCompatActivity implements WeekView.EventClickListener, MonthLoader.MonthChangeListener, WeekView.EventLongPressListener, WeekView.EmptyViewLongPressListener { +public abstract class BaseActivity extends AppCompatActivity implements EventClickListener, MonthLoader.MonthChangeListener, EventLongPressListener, EmptyViewLongPressListener { private static final int TYPE_DAY_VIEW = 1; private static final int TYPE_THREE_DAY_VIEW = 2; private static final int TYPE_WEEK_VIEW = 3; From 06b622752854582dadd03b8bb2093ace6eb0f3ee Mon Sep 17 00:00:00 2001 From: Thomas Goureau Date: Thu, 11 Feb 2016 11:12:06 +0100 Subject: [PATCH 4/4] Fix bad zoom : Zoom is now centers where you start the zoom (from the middle of the tow fingers) --- .../java/com/alamkanak/weekview/WeekView.java | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/library/src/main/java/com/alamkanak/weekview/WeekView.java b/library/src/main/java/com/alamkanak/weekview/WeekView.java index 748e17342..fcca71c21 100755 --- a/library/src/main/java/com/alamkanak/weekview/WeekView.java +++ b/library/src/main/java/com/alamkanak/weekview/WeekView.java @@ -1,5 +1,8 @@ package com.alamkanak.weekview; +import static com.alamkanak.weekview.WeekViewUtil.isSameDay; +import static com.alamkanak.weekview.WeekViewUtil.today; + import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -49,8 +52,6 @@ import com.alamkanak.weekview.interfaces.ScrollListener; import com.alamkanak.weekview.interfaces.WeekViewLoader; -import static com.alamkanak.weekview.WeekViewUtil.*; - /** * Created by Raquib-ul-Alam Kanak on 7/21/2014. * Website: http://alamkanak.github.io/ @@ -467,6 +468,31 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { @Override public boolean onScale(ScaleGestureDetector detector) { mNewHourHeight = Math.round(mHourHeight * detector.getScaleFactor()); + + int minHourHeight = (int) (getHeight() - (mHeaderTextHeight + mHeaderRowPadding * 2 + mHeaderMarginBottom)) / 24 + 1; + int maxHourHeight = 200; + float maxHeight = -(mHourHeight * 24 - (getHeight() - (mHeaderTextHeight + mHeaderRowPadding * 2 +mHeaderMarginBottom))); + if (detector.getScaleFactor() > 1 && mHourHeight < maxHourHeight) { + mHourHeight=(mHourHeight + 4 * (int) detector.getScaleFactor()); + if (mHourHeight > maxHourHeight) + mHourHeight=(maxHourHeight); + // Zoom + + } + else if (detector.getScaleFactor() < 1 && mHourHeight > minHourHeight) { + mHourHeight=(mHourHeight - 4 * (int) (detector.getScaleFactor() + 1)); + if (mHourHeight < minHourHeight) + mHourHeight=(minHourHeight); + // deZoom + } + double focusedHour =12; + int verticalOffset = (int) (mHourHeight * focusedHour); + mCurrentOrigin.y = -verticalOffset + getHeight() / 2; + if (mCurrentOrigin.y > 0) + mCurrentOrigin.y = 0; + if (mCurrentOrigin.y < maxHeight) + mCurrentOrigin.y = maxHeight; + invalidate(); return true; } @@ -1994,22 +2020,4 @@ else if (hour > 0) public double getFirstVisibleHour(){ return -mCurrentOrigin.y / mHourHeight; } - - - - - - - - - public interface ScrollListener { - /** - * Called when the first visible day has changed. - * - * (this will also be called during the first draw of the weekview) - * @param newFirstVisibleDay The new first visible day - * @param oldFirstVisibleDay The old first visible day (is null on the first call). - */ - void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay); - } }