Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a53d1af3 authored by Jian-Syuan (Shane) Wong's avatar Jian-Syuan (Shane) Wong Committed by Android (Google) Code Review
Browse files

Merge "Call setFrameContentVelocity in ScrollView and HorizontalScrollView." into main

parents 1cfa8a9e 8b93b360
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.widget;

import static android.view.flags.Flags.viewVelocityApi;

import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
@@ -1488,6 +1490,11 @@ public class HorizontalScrollView extends FrameLayout {
            if (!awakenScrollBars()) {
                postInvalidateOnAnimation();
            }

            // For variable refresh rate project to track the current velocity of this View
            if (viewVelocityApi()) {
                setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity()));
            }
        }
    }

@@ -1810,6 +1817,11 @@ public class HorizontalScrollView extends FrameLayout {
                mScroller.fling(mScrollX, mScrollY, velocityX, 0, 0,
                        maxScroll, 0, 0, width / 2, 0);

                // For variable refresh rate project to track the current velocity of this View
                if (viewVelocityApi()) {
                    setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity()));
                }

                final boolean movingRight = velocityX > 0;

                View currentFocused = findFocus();
+17 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.widget;

import static android.view.flags.Flags.viewVelocityApi;

import android.annotation.ColorInt;
import android.annotation.NonNull;
import android.compat.annotation.UnsupportedAppUsage;
@@ -726,6 +728,12 @@ public class ScrollView extends FrameLayout {
                 * isFinished() is correct.
                */
                mScroller.computeScrollOffset();

                // For variable refresh rate project to track the current velocity of this View
                if (viewVelocityApi()) {
                    setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity()));
                }

                mIsBeingDragged = !mScroller.isFinished() || !mEdgeGlowBottom.isFinished()
                    || !mEdgeGlowTop.isFinished();
                // Catch the edge effect if it is active.
@@ -1573,6 +1581,11 @@ public class ScrollView extends FrameLayout {
                // Keep on drawing until the animation has finished.
                postInvalidateOnAnimation();
            }

            // For variable refresh rate project to track the current velocity of this View
            if (viewVelocityApi()) {
                setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity()));
            }
        } else {
            if (mFlingStrictSpan != null) {
                mFlingStrictSpan.finish();
@@ -1884,6 +1897,10 @@ public class ScrollView extends FrameLayout {
            mScroller.fling(mScrollX, mScrollY, 0, velocityY, 0, 0, 0,
                    Math.max(0, bottom - height), 0, height/2);

            // For variable refresh rate project to track the current velocity of this View
            if (viewVelocityApi()) {
                setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity()));
            }
            if (mFlingStrictSpan == null) {
                mFlingStrictSpan = StrictMode.enterCriticalSpan("ScrollView-fling");
            }
+143 −98
Original line number Diff line number Diff line
@@ -14,13 +14,19 @@
  ~ limitations under the License
  -->

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <HorizontalScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/horizontal_scroll_view">

        <LinearLayout
        android:layout_width="match_parent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

@@ -116,3 +122,42 @@

        </LinearLayout>
    </HorizontalScrollView>

    <view
        class="android.widget.HorizontalScrollViewFunctionalTest$MyHorizontalScrollView"
        android:id="@+id/my_horizontal_scroll_view"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:background="#FFF"
        android:defaultFocusHighlightEnabled="false">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <View
                android:background="#00F"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#0FF"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#0F0"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#FF0"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#F00"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#F0F"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
        </LinearLayout>
    </view>
</LinearLayout>
 No newline at end of file
+143 −98
Original line number Diff line number Diff line
@@ -14,7 +14,13 @@
  ~ limitations under the License
  -->

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/scroll_view">
@@ -116,3 +122,42 @@

        </LinearLayout>
    </ScrollView>

    <view
        class="android.widget.ScrollViewFunctionalTest$MyScrollView"
        android:id="@+id/my_scroll_view"
        android:layout_width="90dp"
        android:layout_height="90dp"
        android:background="#FFF"
        android:defaultFocusHighlightEnabled="false">
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <View
                android:background="#00F"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#0FF"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#0F0"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#FF0"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#F00"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
            <View
                android:background="#F0F"
                android:layout_width="90dp"
                android:layout_height="50dp"/>
        </LinearLayout>
    </view>
</LinearLayout>
+53 −0
Original line number Diff line number Diff line
@@ -16,11 +16,17 @@

package android.widget;

import static android.view.flags.Flags.FLAG_VIEW_VELOCITY_API;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.content.Context;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
import android.util.AttributeSet;
import android.util.PollingCheck;

import androidx.test.filters.MediumTest;
@@ -43,14 +49,21 @@ import java.util.concurrent.TimeUnit;
public class HorizontalScrollViewFunctionalTest {
    private HorizontalScrollViewActivity mActivity;
    private HorizontalScrollView mHorizontalScrollView;
    private MyHorizontalScrollView mMyHorizontalScrollView;
    @Rule
    public ActivityTestRule<HorizontalScrollViewActivity> mActivityRule = new ActivityTestRule<>(
            HorizontalScrollViewActivity.class);

    @Rule
    public final CheckFlagsRule mCheckFlagsRule =
            DeviceFlagsValueProvider.createCheckFlagsRule();

    @Before
    public void setUp() throws Exception {
        mActivity = mActivityRule.getActivity();
        mHorizontalScrollView = mActivity.findViewById(R.id.horizontal_scroll_view);
        mMyHorizontalScrollView =
                (MyHorizontalScrollView) mActivity.findViewById(R.id.my_horizontal_scroll_view);
    }

    @Test
@@ -79,6 +92,22 @@ public class HorizontalScrollViewFunctionalTest {
        assertEquals(maxScroll, mHorizontalScrollView.getScrollX());
    }

    @Test
    @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API)
    public void testSetVelocity() throws Throwable {
        mActivityRule.runOnUiThread(() -> {
            mMyHorizontalScrollView.setFrameContentVelocity(0);
        });
        // set setFrameContentVelocity shouldn't do anything.
        assertEquals(mMyHorizontalScrollView.isSetVelocityCalled, false);

        mActivityRule.runOnUiThread(() -> {
            mMyHorizontalScrollView.fling(100);
        });
        // set setFrameContentVelocity should be called when fling.
        assertEquals(mMyHorizontalScrollView.isSetVelocityCalled, true);
    }

    static class WatchedEdgeEffect extends EdgeEffect {
        public CountDownLatch onAbsorbLatch = new CountDownLatch(1);

@@ -92,5 +121,29 @@ public class HorizontalScrollViewFunctionalTest {
            onAbsorbLatch.countDown();
        }
    }

    public static class MyHorizontalScrollView extends ScrollView {

        public boolean isSetVelocityCalled;

        public MyHorizontalScrollView(Context context) {
            super(context);
        }

        public MyHorizontalScrollView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }

        public MyHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }

        @Override
        public void setFrameContentVelocity(float pixelsPerSecond) {
            if (pixelsPerSecond != 0) {
                isSetVelocityCalled = true;
            }
        }
    }
}
Loading