Loading core/java/android/widget/OverScroller.java +9 −4 Original line number Diff line number Diff line Loading @@ -299,8 +299,10 @@ public class OverScroller { final int duration = mScrollerX.mDuration; if (elapsedTime < duration) { final float q = mInterpolator.getInterpolation(elapsedTime / (float) duration); mScrollerX.updateScroll(q); mScrollerY.updateScroll(q); final float q2 = mInterpolator.getInterpolation((elapsedTime - 1) / (float) duration); mScrollerX.updateScroll(q, q2); mScrollerY.updateScroll(q, q2); } else { abortAnimation(); } Loading Loading @@ -642,8 +644,11 @@ public class OverScroller { * 0.84f; // look and feel tuning } void updateScroll(float q) { mCurrentPosition = mStart + Math.round(q * (mFinal - mStart)); void updateScroll(float q, float q2) { int distance = mFinal - mStart; mCurrentPosition = mStart + Math.round(q * distance); // q2 is 1ms before q1 mCurrVelocity = 1000f * (q - q2) * distance; } /* Loading core/tests/coretests/res/layout/activity_horizontal_scroll_view.xml +15 −15 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ <HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_height="wrap_content" android:id="@+id/horizontal_scroll_view"> <LinearLayout Loading Loading @@ -133,31 +133,31 @@ <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> android:orientation="horizontal"> <View android:background="#00F" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#0FF" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#0F0" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#FF0" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#F00" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#F0F" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> </LinearLayout> </view> </LinearLayout> core/tests/coretests/res/layout/activity_scroll_view.xml +2 −2 Original line number Diff line number Diff line Loading @@ -18,10 +18,10 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> android:orientation="horizontal"> <ScrollView android:layout_width="match_parent" android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/scroll_view"> Loading core/tests/coretests/src/android/widget/HorizontalScrollViewFunctionalTest.java +22 −6 Original line number Diff line number Diff line Loading @@ -99,13 +99,29 @@ public class HorizontalScrollViewFunctionalTest { mMyHorizontalScrollView.setFrameContentVelocity(0); }); // set setFrameContentVelocity shouldn't do anything. assertEquals(mMyHorizontalScrollView.isSetVelocityCalled, false); assertTrue(mMyHorizontalScrollView.isSetVelocityCalled); assertEquals(0f, mMyHorizontalScrollView.velocity, 0f); mMyHorizontalScrollView.isSetVelocityCalled = false; mActivityRule.runOnUiThread(() -> { mMyHorizontalScrollView.fling(100); }); // set setFrameContentVelocity should be called when fling. assertEquals(mMyHorizontalScrollView.isSetVelocityCalled, true); assertTrue(mMyHorizontalScrollView.isSetVelocityCalled); assertTrue(mMyHorizontalScrollView.velocity > 0f); } @Test @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API) public void hasVelocityInSmoothScrollBy() throws Throwable { int maxScroll = mMyHorizontalScrollView.getChildAt(0).getWidth() - mMyHorizontalScrollView.getWidth(); mActivityRule.runOnUiThread(() -> { mMyHorizontalScrollView.smoothScrollTo(maxScroll, 0); }); PollingCheck.waitFor(() -> mMyHorizontalScrollView.getScrollX() != 0); assertTrue(mMyHorizontalScrollView.isSetVelocityCalled); assertTrue(mMyHorizontalScrollView.velocity > 0f); } static class WatchedEdgeEffect extends EdgeEffect { Loading @@ -122,9 +138,10 @@ public class HorizontalScrollViewFunctionalTest { } } public static class MyHorizontalScrollView extends ScrollView { public static class MyHorizontalScrollView extends HorizontalScrollView { public boolean isSetVelocityCalled; public float velocity; public MyHorizontalScrollView(Context context) { super(context); Loading @@ -140,9 +157,8 @@ public class HorizontalScrollViewFunctionalTest { @Override public void setFrameContentVelocity(float pixelsPerSecond) { if (pixelsPerSecond != 0) { isSetVelocityCalled = true; } velocity = pixelsPerSecond; } } } Loading core/tests/coretests/src/android/widget/ScrollViewFunctionalTest.java +22 −5 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.widget; import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import android.content.Context; Loading Loading @@ -98,13 +99,28 @@ public class ScrollViewFunctionalTest { mMyScrollView.setFrameContentVelocity(0); }); // set setFrameContentVelocity shouldn't do anything. assertEquals(mMyScrollView.isSetVelocityCalled, false); assertTrue(mMyScrollView.isSetVelocityCalled); assertEquals(0f, mMyScrollView.velocity, 0f); mMyScrollView.isSetVelocityCalled = false; mActivityRule.runOnUiThread(() -> { mMyScrollView.fling(100); }); // set setFrameContentVelocity should be called when fling. assertEquals(mMyScrollView.isSetVelocityCalled, true); assertTrue(mMyScrollView.isSetVelocityCalled); assertNotEquals(0f, mMyScrollView.velocity, 0.01f); } @Test @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API) public void hasVelocityInSmoothScrollBy() throws Throwable { int maxScroll = mMyScrollView.getChildAt(0).getHeight() - mMyScrollView.getHeight(); mActivityRule.runOnUiThread(() -> { mMyScrollView.smoothScrollTo(0, maxScroll); }); PollingCheck.waitFor(() -> mMyScrollView.getScrollY() != 0); assertTrue(mMyScrollView.isSetVelocityCalled); assertTrue(mMyScrollView.velocity > 0f); } static class WatchedEdgeEffect extends EdgeEffect { Loading @@ -125,6 +141,8 @@ public class ScrollViewFunctionalTest { public boolean isSetVelocityCalled; public float velocity; public MyScrollView(Context context) { super(context); } Loading @@ -139,9 +157,8 @@ public class ScrollViewFunctionalTest { @Override public void setFrameContentVelocity(float pixelsPerSecond) { if (pixelsPerSecond != 0) { isSetVelocityCalled = true; } velocity = pixelsPerSecond; } } } Loading Loading
core/java/android/widget/OverScroller.java +9 −4 Original line number Diff line number Diff line Loading @@ -299,8 +299,10 @@ public class OverScroller { final int duration = mScrollerX.mDuration; if (elapsedTime < duration) { final float q = mInterpolator.getInterpolation(elapsedTime / (float) duration); mScrollerX.updateScroll(q); mScrollerY.updateScroll(q); final float q2 = mInterpolator.getInterpolation((elapsedTime - 1) / (float) duration); mScrollerX.updateScroll(q, q2); mScrollerY.updateScroll(q, q2); } else { abortAnimation(); } Loading Loading @@ -642,8 +644,11 @@ public class OverScroller { * 0.84f; // look and feel tuning } void updateScroll(float q) { mCurrentPosition = mStart + Math.round(q * (mFinal - mStart)); void updateScroll(float q, float q2) { int distance = mFinal - mStart; mCurrentPosition = mStart + Math.round(q * distance); // q2 is 1ms before q1 mCurrVelocity = 1000f * (q - q2) * distance; } /* Loading
core/tests/coretests/res/layout/activity_horizontal_scroll_view.xml +15 −15 Original line number Diff line number Diff line Loading @@ -22,7 +22,7 @@ <HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_height="wrap_content" android:id="@+id/horizontal_scroll_view"> <LinearLayout Loading Loading @@ -133,31 +133,31 @@ <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> android:orientation="horizontal"> <View android:background="#00F" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#0FF" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#0F0" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#FF0" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#F00" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> <View android:background="#F0F" android:layout_width="90dp" android:layout_height="50dp"/> android:layout_width="100dp" android:layout_height="90dp"/> </LinearLayout> </view> </LinearLayout>
core/tests/coretests/res/layout/activity_scroll_view.xml +2 −2 Original line number Diff line number Diff line Loading @@ -18,10 +18,10 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> android:orientation="horizontal"> <ScrollView android:layout_width="match_parent" android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/scroll_view"> Loading
core/tests/coretests/src/android/widget/HorizontalScrollViewFunctionalTest.java +22 −6 Original line number Diff line number Diff line Loading @@ -99,13 +99,29 @@ public class HorizontalScrollViewFunctionalTest { mMyHorizontalScrollView.setFrameContentVelocity(0); }); // set setFrameContentVelocity shouldn't do anything. assertEquals(mMyHorizontalScrollView.isSetVelocityCalled, false); assertTrue(mMyHorizontalScrollView.isSetVelocityCalled); assertEquals(0f, mMyHorizontalScrollView.velocity, 0f); mMyHorizontalScrollView.isSetVelocityCalled = false; mActivityRule.runOnUiThread(() -> { mMyHorizontalScrollView.fling(100); }); // set setFrameContentVelocity should be called when fling. assertEquals(mMyHorizontalScrollView.isSetVelocityCalled, true); assertTrue(mMyHorizontalScrollView.isSetVelocityCalled); assertTrue(mMyHorizontalScrollView.velocity > 0f); } @Test @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API) public void hasVelocityInSmoothScrollBy() throws Throwable { int maxScroll = mMyHorizontalScrollView.getChildAt(0).getWidth() - mMyHorizontalScrollView.getWidth(); mActivityRule.runOnUiThread(() -> { mMyHorizontalScrollView.smoothScrollTo(maxScroll, 0); }); PollingCheck.waitFor(() -> mMyHorizontalScrollView.getScrollX() != 0); assertTrue(mMyHorizontalScrollView.isSetVelocityCalled); assertTrue(mMyHorizontalScrollView.velocity > 0f); } static class WatchedEdgeEffect extends EdgeEffect { Loading @@ -122,9 +138,10 @@ public class HorizontalScrollViewFunctionalTest { } } public static class MyHorizontalScrollView extends ScrollView { public static class MyHorizontalScrollView extends HorizontalScrollView { public boolean isSetVelocityCalled; public float velocity; public MyHorizontalScrollView(Context context) { super(context); Loading @@ -140,9 +157,8 @@ public class HorizontalScrollViewFunctionalTest { @Override public void setFrameContentVelocity(float pixelsPerSecond) { if (pixelsPerSecond != 0) { isSetVelocityCalled = true; } velocity = pixelsPerSecond; } } } Loading
core/tests/coretests/src/android/widget/ScrollViewFunctionalTest.java +22 −5 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package android.widget; import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import android.content.Context; Loading Loading @@ -98,13 +99,28 @@ public class ScrollViewFunctionalTest { mMyScrollView.setFrameContentVelocity(0); }); // set setFrameContentVelocity shouldn't do anything. assertEquals(mMyScrollView.isSetVelocityCalled, false); assertTrue(mMyScrollView.isSetVelocityCalled); assertEquals(0f, mMyScrollView.velocity, 0f); mMyScrollView.isSetVelocityCalled = false; mActivityRule.runOnUiThread(() -> { mMyScrollView.fling(100); }); // set setFrameContentVelocity should be called when fling. assertEquals(mMyScrollView.isSetVelocityCalled, true); assertTrue(mMyScrollView.isSetVelocityCalled); assertNotEquals(0f, mMyScrollView.velocity, 0.01f); } @Test @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API) public void hasVelocityInSmoothScrollBy() throws Throwable { int maxScroll = mMyScrollView.getChildAt(0).getHeight() - mMyScrollView.getHeight(); mActivityRule.runOnUiThread(() -> { mMyScrollView.smoothScrollTo(0, maxScroll); }); PollingCheck.waitFor(() -> mMyScrollView.getScrollY() != 0); assertTrue(mMyScrollView.isSetVelocityCalled); assertTrue(mMyScrollView.velocity > 0f); } static class WatchedEdgeEffect extends EdgeEffect { Loading @@ -125,6 +141,8 @@ public class ScrollViewFunctionalTest { public boolean isSetVelocityCalled; public float velocity; public MyScrollView(Context context) { super(context); } Loading @@ -139,9 +157,8 @@ public class ScrollViewFunctionalTest { @Override public void setFrameContentVelocity(float pixelsPerSecond) { if (pixelsPerSecond != 0) { isSetVelocityCalled = true; } velocity = pixelsPerSecond; } } } Loading