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

Commit 3bd8d8e9 authored by George Mount's avatar George Mount
Browse files

Fix ScrollView and HorizontalScrollView overscroll retraction

Bug: 288270962

When overscrolling, the scroll was being stuck beyond the range
of the scroll. This left it in a funny position and the next
time the ScrollView or HorizontalScrollView had an interaction,
it would snap to a valid scroll offset.

This CL allows the scrolling to move the content back to the
expected position without affecting the stretch.

Test: new tests, manual testing
Change-Id: I8f5ae18d44adf55d9ce026b0e31f3d1a140d57c6
parent e806a0d3
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1498,6 +1498,11 @@ public class HorizontalScrollView extends FrameLayout {
     * @return The unconsumed delta after the EdgeEffects have had an opportunity to consume.
     */
    private int consumeFlingInStretch(int unconsumed) {
        int scrollX = getScrollX();
        if (scrollX < 0 || scrollX > getScrollRange()) {
            // We've overscrolled, so don't stretch
            return unconsumed;
        }
        if (unconsumed > 0 && mEdgeGlowLeft != null && mEdgeGlowLeft.getDistance() != 0f) {
            int size = getWidth();
            float deltaDistance = -unconsumed * FLING_DESTRETCH_FACTOR / size;
+5 −0
Original line number Diff line number Diff line
@@ -1566,6 +1566,11 @@ public class ScrollView extends FrameLayout {
     * @return The unconsumed delta after the EdgeEffects have had an opportunity to consume.
     */
    private int consumeFlingInStretch(int unconsumed) {
        int scrollY = getScrollY();
        if (scrollY < 0 || scrollY > getScrollRange()) {
            // We've overscrolled, so don't stretch
            return unconsumed;
        }
        if (unconsumed > 0 && mEdgeGlowTop != null && mEdgeGlowTop.getDistance() != 0f) {
            int size = getHeight();
            float deltaDistance = -unconsumed * FLING_DESTRETCH_FACTOR / size;
+22 −0
Original line number Diff line number Diff line
@@ -231,6 +231,28 @@
            </intent-filter>
        </activity>

        <activity android:name="android.widget.HorizontalScrollViewActivity"
                android:label="HorizontalScrollViewActivity"
                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.ScrollViewActivity"
                android:label="ScrollViewActivity"
                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"
+118 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2015 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
  -->

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/horizontal_scroll_view">

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

        <View
            android:background="#F00"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#880"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#0F0"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#088"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#00F"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#808"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#F00"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#880"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#0F0"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#088"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#00F"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#808"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#F00"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#880"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#0F0"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#088"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#00F"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#808"
            android:layout_width="100dp"
            android:layout_height="100dp" />

    </LinearLayout>
</HorizontalScrollView>
+118 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2015 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
  -->

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/scroll_view">

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

        <View
            android:background="#F00"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#880"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#0F0"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#088"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#00F"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#808"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#F00"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#880"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#0F0"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#088"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#00F"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#808"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#F00"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#880"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#0F0"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#088"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#00F"
            android:layout_width="100dp"
            android:layout_height="100dp" />

        <View
            android:background="#808"
            android:layout_width="100dp"
            android:layout_height="100dp" />

    </LinearLayout>
</ScrollView>
Loading