summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2012-09-07 14:31:19 -0700
committerThe Android Automerger <android-build@android.com>2012-09-10 15:25:42 -0700
commit02fd9828bd92ce0dd377a9bdb93c413e0e5bf4b7 (patch)
tree656dacb754de7abc1e8dba90f8e0817021597577
parenteb1639cbe1a311090b5121e38901193bc1b2263c (diff)
downloadCalendar-jb-mr0-release.tar.gz
Modify doScroll to move based on the average of the touch pointsandroid-4.1.2_r2.1android-4.1.2_r2android-4.1.2_r1jb-mr0-release
Change-Id: Id23158a43910875953077244eb7086dd38a3f7c5
-rw-r--r--src/com/android/calendar/DayView.java52
1 files changed, 42 insertions, 10 deletions
diff --git a/src/com/android/calendar/DayView.java b/src/com/android/calendar/DayView.java
index afa0c45b..cd32f354 100644
--- a/src/com/android/calendar/DayView.java
+++ b/src/com/android/calendar/DayView.java
@@ -392,8 +392,6 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
private static int NEW_EVENT_WIDTH = 2;
private static int NEW_EVENT_MAX_LENGTH = 16;
- private static int CURRENT_TIME_LINE_HEIGHT = 2;
- private static int CURRENT_TIME_LINE_BORDER_WIDTH = 1;
private static int CURRENT_TIME_LINE_SIDE_BUFFER = 4;
private static int CURRENT_TIME_LINE_TOP_OFFSET = 2;
@@ -408,7 +406,6 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
private static int DAY_HEADER_ONE_DAY_LEFT_MARGIN = 0;
private static int DAY_HEADER_ONE_DAY_RIGHT_MARGIN = 5;
private static int DAY_HEADER_ONE_DAY_BOTTOM_MARGIN = 6;
- private static int DAY_HEADER_LEFT_MARGIN = 5;
private static int DAY_HEADER_RIGHT_MARGIN = 4;
private static int DAY_HEADER_BOTTOM_MARGIN = 3;
private static float DAY_HEADER_FONT_SIZE = 14;
@@ -484,6 +481,9 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
private int mCellHeightBeforeScaleGesture;
/** The hour at the center two touch points */
private float mGestureCenterHour = 0;
+
+ private boolean mRecalCenterHour = false;
+
/**
* Flag to decide whether to handle the up event. Cases where up events
* should be ignored are 1) right after a scale gesture and 2) finger was
@@ -611,6 +611,7 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
private boolean mScrolling = false;
+ // Pixels scrolled
private float mInitialScrollX;
private float mInitialScrollY;
@@ -705,8 +706,6 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
MAX_UNEXPANDED_ALLDAY_HEIGHT *= mScale;
mAnimateDayEventHeight = (int) MIN_UNEXPANDED_ALLDAY_EVENT_HEIGHT;
- CURRENT_TIME_LINE_HEIGHT *= mScale;
- CURRENT_TIME_LINE_BORDER_WIDTH *= mScale;
CURRENT_TIME_LINE_SIDE_BUFFER *= mScale;
CURRENT_TIME_LINE_TOP_OFFSET *= mScale;
@@ -714,7 +713,6 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
MAX_CELL_HEIGHT *= mScale;
DEFAULT_CELL_HEIGHT *= mScale;
DAY_HEADER_HEIGHT *= mScale;
- DAY_HEADER_LEFT_MARGIN *= mScale;
DAY_HEADER_RIGHT_MARGIN *= mScale;
DAY_HEADER_ONE_DAY_LEFT_MARGIN *= mScale;
DAY_HEADER_ONE_DAY_RIGHT_MARGIN *= mScale;
@@ -1086,6 +1084,7 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
sendAccessibilityEventAsNeeded(false);
}
+ // Called from animation framework via reflection. Do not remove
public void setViewStartY(int viewStartY) {
if (viewStartY > mMaxViewStartY) {
viewStartY = mMaxViewStartY;
@@ -3974,6 +3973,14 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
int distanceX = (int) mInitialScrollX;
int distanceY = (int) mInitialScrollY;
+ final float focusY = getAverageY(e2);
+ if (mRecalCenterHour) {
+ // Calculate the hour that correspond to the average of the Y touch points
+ mGestureCenterHour = (mViewStartY + focusY - DAY_HEADER_HEIGHT - mAlldayHeight)
+ / (mCellHeight + DAY_GAP);
+ mRecalCenterHour = false;
+ }
+
// If we haven't figured out the predominant scroll direction yet,
// then do it now.
if (mTouchMode == TOUCH_MODE_DOWN) {
@@ -4006,7 +4013,10 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
}
if ((mTouchMode & TOUCH_MODE_VSCROLL) != 0) {
- mViewStartY = mScrollStartY + distanceY;
+ // Calculate the top of the visible region in the calendar grid.
+ // Increasing/decrease this will scroll the calendar grid up/down.
+ mViewStartY = (int) ((mGestureCenterHour * (mCellHeight + DAY_GAP))
+ - focusY + DAY_HEADER_HEIGHT + mAlldayHeight);
// If dragging while already at the end, do a glow
final int pulledToY = (int) (mScrollStartY + deltaY);
@@ -4024,8 +4034,16 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
if (mViewStartY < 0) {
mViewStartY = 0;
+ mRecalCenterHour = true;
} else if (mViewStartY > mMaxViewStartY) {
mViewStartY = mMaxViewStartY;
+ mRecalCenterHour = true;
+ }
+ if (mRecalCenterHour) {
+ // Calculate the hour that correspond to the average of the Y touch points
+ mGestureCenterHour = (mViewStartY + focusY - DAY_HEADER_HEIGHT - mAlldayHeight)
+ / (mCellHeight + DAY_GAP);
+ mRecalCenterHour = false;
}
computeFirstHour();
}
@@ -4036,6 +4054,16 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
invalidate();
}
+ private float getAverageY(MotionEvent me) {
+ int count = me.getPointerCount();
+ float focusY = 0;
+ for (int i = 0; i < count; i++) {
+ focusY += me.getY(i);
+ }
+ focusY /= count;
+ return focusY;
+ }
+
private void cancelAnimation() {
Animation in = mViewSwitcher.getInAnimation();
if (in != null) {
@@ -4199,11 +4227,15 @@ public class DayView extends View implements View.OnCreateContextMenuListener,
int action = ev.getAction();
if (DEBUG) Log.e(TAG, "" + action + " ev.getPointerCount() = " + ev.getPointerCount());
+ if ((ev.getActionMasked() == MotionEvent.ACTION_DOWN) ||
+ (ev.getActionMasked() == MotionEvent.ACTION_UP) ||
+ (ev.getActionMasked() == MotionEvent.ACTION_POINTER_UP) ||
+ (ev.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN)) {
+ mRecalCenterHour = true;
+ }
+
if ((mTouchMode & TOUCH_MODE_HSCROLL) == 0) {
mScaleGestureDetector.onTouchEvent(ev);
- if (mScaleGestureDetector.isInProgress()) {
- return true;
- }
}
switch (action) {