Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zoom center issue #281

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions library/src/main/java/com/alamkanak/weekview/MonthLoader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.alamkanak.weekview;

import com.alamkanak.weekview.interfaces.WeekViewLoader;

import java.util.Calendar;
import java.util.List;

Expand Down
105 changes: 43 additions & 62 deletions library/src/main/java/com/alamkanak/weekview/WeekView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
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;
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;
Expand Down Expand Up @@ -33,15 +44,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 static com.alamkanak.weekview.WeekViewUtil.*;
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.
Expand Down Expand Up @@ -459,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;
}
Expand Down Expand Up @@ -1986,57 +2020,4 @@ else if (hour > 0)
public double getFirstVisibleHour(){
return -mCurrentOrigin.y / mHourHeight;
}



/////////////////////////////////////////////////////////////////
//
// 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.alamkanak.weekview;
package com.alamkanak.weekview.interfaces;

import java.util.Calendar;

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.alamkanak.weekview;
package com.alamkanak.weekview.interfaces;

import com.alamkanak.weekview.WeekViewEvent;

import java.util.Calendar;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import android.view.MenuItem;
import android.widget.Toast;

import com.alamkanak.weekview.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;
Expand All @@ -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;
Expand Down