summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Chan <mchan@android.com>2012-02-14 11:01:21 -0800
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-02-14 11:01:21 -0800
commitb7b37a5f5527b5636924446f4892361fff9627e4 (patch)
tree26bf7853d68074cf540e69dfcd7d1be8be3b46ea /src
parentf58faf32bbce943eb4791cef2ad6c327e3724cc7 (diff)
parent2d30ee13aa8f1a4f0a11b91c316de64b3051d637 (diff)
downloadandroid_packages_apps_Calendar-b7b37a5f5527b5636924446f4892361fff9627e4.tar.gz
android_packages_apps_Calendar-b7b37a5f5527b5636924446f4892361fff9627e4.tar.bz2
android_packages_apps_Calendar-b7b37a5f5527b5636924446f4892361fff9627e4.zip
Merge "Fling month view one month at a time."
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calendar/month/MonthByWeekFragment.java82
-rw-r--r--src/com/android/calendar/month/SimpleDayPickerFragment.java15
2 files changed, 63 insertions, 34 deletions
diff --git a/src/com/android/calendar/month/MonthByWeekFragment.java b/src/com/android/calendar/month/MonthByWeekFragment.java
index 62d30d82..a4c60e9d 100644
--- a/src/com/android/calendar/month/MonthByWeekFragment.java
+++ b/src/com/android/calendar/month/MonthByWeekFragment.java
@@ -92,6 +92,14 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements
private static float mScale = 0;
private static int SPACING_WEEK_NUMBER = 19;
+ // These define the behavior of the fling. Below MIN_VELOCITY_FOR_FLING, do the system fling
+ // behavior. Between MIN_VELOCITY_FOR_FLING and MULTIPLE_MONTH_VELOCITY_THRESHOLD, do one month
+ // fling. Above MULTIPLE_MONTH_VELOCITY_THRESHOLD, do multiple month flings according to the
+ // fling strength. When doing multiple month fling, the velocity is reduced by this threshold
+ // to prevent moving from one month fling to 4 months and above flings.
+ private static int MIN_VELOCITY_FOR_FLING = 750;
+ private static int MULTIPLE_MONTH_VELOCITY_THRESHOLD = 4000;
+
private Runnable mTZUpdater = new Runnable() {
@Override
public void run() {
@@ -186,36 +194,48 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
- // TODO decide how to handle flings
-// float absX = Math.abs(velocityX);
-// float absY = Math.abs(velocityY);
-// Log.d(TAG, "velX: " + velocityX + " velY: " + velocityY);
-// if (absX > absY && absX > mMinimumFlingVelocity) {
-// mTempTime.set(mFirstDayOfMonth);
-// if(velocityX > 0) {
-// mTempTime.month++;
-// } else {
-// mTempTime.month--;
-// }
-// mTempTime.normalize(true);
-// goTo(mTempTime, true, false, true);
-//
-// } else if (absY > absX && absY > mMinimumFlingVelocity) {
-// mTempTime.set(mFirstDayOfMonth);
-// int diff = 1;
-// if (absY > mMinimumTwoMonthFlingVelocity) {
-// diff = 2;
-// }
-// if(velocityY < 0) {
-// mTempTime.month += diff;
-// } else {
-// mTempTime.month -= diff;
-// }
-// mTempTime.normalize(true);
-//
-// goTo(mTempTime, true, false, true);
-// }
- return false;
+
+ // Small flings are just that, do not change the behavior
+ if (Math.abs(velocityY) < MIN_VELOCITY_FOR_FLING) {
+ return false;
+ }
+
+ // Below the threshold, fling one month. Above the threshold , fling according
+ // to the speed of the fling.
+ int monthsToJump;
+ if (Math.abs(velocityY) < MULTIPLE_MONTH_VELOCITY_THRESHOLD) {
+ if (velocityY < 0) {
+ monthsToJump = 1;
+ } else {
+ // value here is zero and not -1 since by the time the fling is detected
+ // the list moved back one month.
+ monthsToJump = 0;
+ }
+ } else {
+ if (velocityY < 0) {
+ monthsToJump = 1 -
+ (int)((velocityY + MULTIPLE_MONTH_VELOCITY_THRESHOLD) / 1000);
+ } else {
+ monthsToJump = -(int)((velocityY - MULTIPLE_MONTH_VELOCITY_THRESHOLD) / 1000);
+ }
+ }
+
+ // Get the day at the top right corner
+ int day = getUpperRightJulianDay();
+ // Get the day of the first day of the next/previous month
+ // (according to scroll direction)
+ mTempTime.setJulianDay(day);
+ mTempTime.monthDay = 1;
+ mTempTime.month += monthsToJump;
+ long timeInMillis = mTempTime.normalize(true);
+ // Since each view is 7 days, round the target day up to make sure the scroll will be
+ // at least one view.
+ int scrollToDay = Time.getJulianDay(timeInMillis, mTempTime.gmtoff) +
+ ((monthsToJump > 0) ? 6 : 0);
+ int curPosition = mListView.getPositionForView(mListView.getChildAt(0));
+ mListView.smoothScrollToPositionFromTop(curPosition + (scrollToDay - day) / 7,
+ LIST_TOP_OFFSET);
+ return true;
}
}
@@ -237,6 +257,8 @@ public class MonthByWeekFragment extends SimpleDayPickerFragment implements
mShowDetailsInMonth = res.getBoolean(R.bool.show_details_in_month);
if (mScale != 1) {
SPACING_WEEK_NUMBER *= mScale;
+ MIN_VELOCITY_FOR_FLING *= mScale;
+ MULTIPLE_MONTH_VELOCITY_THRESHOLD *= mScale;
}
}
}
diff --git a/src/com/android/calendar/month/SimpleDayPickerFragment.java b/src/com/android/calendar/month/SimpleDayPickerFragment.java
index da3e4ebe..4f7bf78d 100644
--- a/src/com/android/calendar/month/SimpleDayPickerFragment.java
+++ b/src/com/android/calendar/month/SimpleDayPickerFragment.java
@@ -82,8 +82,7 @@ public class SimpleDayPickerFragment extends ListFragment implements OnScrollLis
protected int mDaysPerWeek = 7;
// These affect the scroll speed and feel
- protected float mFriction = .05f;
- protected float mVelocityScale = 0.333f;
+ protected float mFriction = 1.0f;
protected Context mContext;
protected Handler mHandler;
@@ -273,8 +272,7 @@ public class SimpleDayPickerFragment extends ListFragment implements OnScrollLis
mListView.setOnScrollListener(this);
mListView.setFadingEdgeLength(0);
// Make the scrolling behavior nicer
- mListView.setFriction(mFriction);
- mListView.setVelocityScale(mVelocityScale);
+ mListView.setFriction(ViewConfiguration.getScrollFriction() * mFriction);
}
@Override
@@ -466,6 +464,15 @@ public class SimpleDayPickerFragment extends ListFragment implements OnScrollLis
return false;
}
+ // Returns the julian day of the day in the upper right corner
+ public int getUpperRightJulianDay() {
+ SimpleWeekView child = (SimpleWeekView)mListView.getChildAt(0);
+ if (child == null) {
+ return -1;
+ }
+ return child.getFirstJulianDay() + DAYS_PER_WEEK - 1;
+ }
+
/**
* Updates the title and selected month if the view has moved to a new
* month.