Loading core/java/android/widget/AbsListView.java +11 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.widget; import static android.view.flags.Flags.viewVelocityApi; import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.NonNull; Loading Loading @@ -5098,6 +5100,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te boolean more = scroller.computeScrollOffset(); final int y = scroller.getCurrY(); // For variable refresh rate project to track the current velocity of this View if (viewVelocityApi()) { setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity())); } // Flip sign to convert finger direction to list items direction // (e.g. finger moving down means list is moving towards the top) int delta = consumeFlingInStretch(mLastFlingY - y); Loading Loading @@ -5192,6 +5199,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te invalidate(); postOnAnimation(this); } // For variable refresh rate project to track the current velocity of this View if (viewVelocityApi()) { setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity())); } } else { endFling(); } Loading core/tests/coretests/AndroidManifest.xml +11 −0 Original line number Diff line number Diff line Loading @@ -254,6 +254,17 @@ </intent-filter> </activity> <activity android:name="android.widget.AbsListViewActivity" android:label="AbsListViewActivity" android:screenOrientation="portrait" android:exported="true" android:theme="@android:style/Theme.Material.Light"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" /> </intent-filter> </activity> <activity android:name="android.widget.DatePickerActivity" android:label="DatePickerActivity" android:screenOrientation="portrait" Loading core/tests/coretests/res/layout/activity_abslist_view.xml 0 → 100644 +28 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2024 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <view class="android.widget.AbsListViewFunctionalTest$MyListView" android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> No newline at end of file core/tests/coretests/src/android/widget/AbsListViewActivity.java 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.widget; import android.app.Activity; import android.os.Bundle; import com.android.frameworks.coretests.R; /** * An activity for testing the AbsListView widget. */ public class AbsListViewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_abslist_view); } } core/tests/coretests/src/android/widget/AbsListViewFunctionalTest.java 0 → 100644 +126 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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.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; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import com.android.compatibility.common.util.WidgetTestUtils; import com.android.frameworks.coretests.R; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Arrays; @RunWith(AndroidJUnit4.class) @MediumTest public class AbsListViewFunctionalTest { private final String[] mCountryList = new String[] { "Argentina", "Australia", "Belize", "Botswana", "Brazil", "Cameroon", "China", "Cyprus", "Denmark", "Djibouti", "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Germany", "Ghana", "Haiti", "Honduras", "Iceland", "India", "Indonesia", "Ireland", "Italy", "Japan", "Kiribati", "Laos", "Lesotho", "Liberia", "Malaysia", "Mongolia", "Myanmar", "Nauru", "Norway", "Oman", "Pakistan", "Philippines", "Portugal", "Romania", "Russia", "Rwanda", "Singapore", "Slovakia", "Slovenia", "Somalia", "Swaziland", "Togo", "Tuvalu", "Uganda", "Ukraine", "United States", "Vanuatu", "Venezuela", "Zimbabwe" }; private AbsListViewActivity mActivity; private MyListView mMyListView; @Rule public ActivityTestRule<AbsListViewActivity> mActivityRule = new ActivityTestRule<>( AbsListViewActivity.class); @Rule public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); @Before public void setUp() throws Exception { mActivity = mActivityRule.getActivity(); mMyListView = (MyListView) mActivity.findViewById(R.id.list_view); } @Test @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API) public void testLsitViewSetVelocity() throws Throwable { final ArrayList<String> items = new ArrayList<>(Arrays.asList(mCountryList)); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActivity, android.R.layout.simple_list_item_1, items); WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mMyListView, () -> mMyListView.setAdapter(adapter)); mActivityRule.runOnUiThread(() -> { // Create an adapter to display the list mMyListView.setFrameContentVelocity(0); }); // set setFrameContentVelocity shouldn't do anything. assertEquals(mMyListView.isSetVelocityCalled, false); mActivityRule.runOnUiThread(() -> { mMyListView.fling(100); }); PollingCheck.waitFor(100, () -> mMyListView.isSetVelocityCalled); // set setFrameContentVelocity should be called when fling. assertTrue(mMyListView.isSetVelocityCalled); } public static class MyListView extends ListView { public boolean isSetVelocityCalled; public MyListView(Context context) { super(context); } public MyListView(Context context, AttributeSet attrs) { super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public void setFrameContentVelocity(float pixelsPerSecond) { if (pixelsPerSecond != 0) { isSetVelocityCalled = true; } } } } Loading
core/java/android/widget/AbsListView.java +11 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.widget; import static android.view.flags.Flags.viewVelocityApi; import android.annotation.ColorInt; import android.annotation.DrawableRes; import android.annotation.NonNull; Loading Loading @@ -5098,6 +5100,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te boolean more = scroller.computeScrollOffset(); final int y = scroller.getCurrY(); // For variable refresh rate project to track the current velocity of this View if (viewVelocityApi()) { setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity())); } // Flip sign to convert finger direction to list items direction // (e.g. finger moving down means list is moving towards the top) int delta = consumeFlingInStretch(mLastFlingY - y); Loading Loading @@ -5192,6 +5199,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te invalidate(); postOnAnimation(this); } // For variable refresh rate project to track the current velocity of this View if (viewVelocityApi()) { setFrameContentVelocity(Math.abs(mScroller.getCurrVelocity())); } } else { endFling(); } Loading
core/tests/coretests/AndroidManifest.xml +11 −0 Original line number Diff line number Diff line Loading @@ -254,6 +254,17 @@ </intent-filter> </activity> <activity android:name="android.widget.AbsListViewActivity" android:label="AbsListViewActivity" android:screenOrientation="portrait" android:exported="true" android:theme="@android:style/Theme.Material.Light"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" /> </intent-filter> </activity> <activity android:name="android.widget.DatePickerActivity" android:label="DatePickerActivity" android:screenOrientation="portrait" Loading
core/tests/coretests/res/layout/activity_abslist_view.xml 0 → 100644 +28 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?><!-- ~ Copyright (C) 2024 The Android Open Source Project ~ ~ Licensed under the Apache License, Version 2.0 (the "License"); ~ you may not use this file except in compliance with the License. ~ You may obtain a copy of the License at ~ ~ http://www.apache.org/licenses/LICENSE-2.0 ~ ~ Unless required by applicable law or agreed to in writing, software ~ distributed under the License is distributed on an "AS IS" BASIS, ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ~ See the License for the specific language governing permissions and ~ limitations under the License --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <view class="android.widget.AbsListViewFunctionalTest$MyListView" android:id="@+id/list_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> No newline at end of file
core/tests/coretests/src/android/widget/AbsListViewActivity.java 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.widget; import android.app.Activity; import android.os.Bundle; import com.android.frameworks.coretests.R; /** * An activity for testing the AbsListView widget. */ public class AbsListViewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_abslist_view); } }
core/tests/coretests/src/android/widget/AbsListViewFunctionalTest.java 0 → 100644 +126 −0 Original line number Diff line number Diff line /* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ 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.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; import androidx.test.rule.ActivityTestRule; import androidx.test.runner.AndroidJUnit4; import com.android.compatibility.common.util.WidgetTestUtils; import com.android.frameworks.coretests.R; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.ArrayList; import java.util.Arrays; @RunWith(AndroidJUnit4.class) @MediumTest public class AbsListViewFunctionalTest { private final String[] mCountryList = new String[] { "Argentina", "Australia", "Belize", "Botswana", "Brazil", "Cameroon", "China", "Cyprus", "Denmark", "Djibouti", "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Germany", "Ghana", "Haiti", "Honduras", "Iceland", "India", "Indonesia", "Ireland", "Italy", "Japan", "Kiribati", "Laos", "Lesotho", "Liberia", "Malaysia", "Mongolia", "Myanmar", "Nauru", "Norway", "Oman", "Pakistan", "Philippines", "Portugal", "Romania", "Russia", "Rwanda", "Singapore", "Slovakia", "Slovenia", "Somalia", "Swaziland", "Togo", "Tuvalu", "Uganda", "Ukraine", "United States", "Vanuatu", "Venezuela", "Zimbabwe" }; private AbsListViewActivity mActivity; private MyListView mMyListView; @Rule public ActivityTestRule<AbsListViewActivity> mActivityRule = new ActivityTestRule<>( AbsListViewActivity.class); @Rule public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule(); @Before public void setUp() throws Exception { mActivity = mActivityRule.getActivity(); mMyListView = (MyListView) mActivity.findViewById(R.id.list_view); } @Test @RequiresFlagsEnabled(FLAG_VIEW_VELOCITY_API) public void testLsitViewSetVelocity() throws Throwable { final ArrayList<String> items = new ArrayList<>(Arrays.asList(mCountryList)); final ArrayAdapter<String> adapter = new ArrayAdapter<String>(mActivity, android.R.layout.simple_list_item_1, items); WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mMyListView, () -> mMyListView.setAdapter(adapter)); mActivityRule.runOnUiThread(() -> { // Create an adapter to display the list mMyListView.setFrameContentVelocity(0); }); // set setFrameContentVelocity shouldn't do anything. assertEquals(mMyListView.isSetVelocityCalled, false); mActivityRule.runOnUiThread(() -> { mMyListView.fling(100); }); PollingCheck.waitFor(100, () -> mMyListView.isSetVelocityCalled); // set setFrameContentVelocity should be called when fling. assertTrue(mMyListView.isSetVelocityCalled); } public static class MyListView extends ListView { public boolean isSetVelocityCalled; public MyListView(Context context) { super(context); } public MyListView(Context context, AttributeSet attrs) { super(context, attrs); } public MyListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public MyListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public void setFrameContentVelocity(float pixelsPerSecond) { if (pixelsPerSecond != 0) { isSetVelocityCalled = true; } } } }