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

Commit ed3d2f91 authored by Chun-Ku Lin's avatar Chun-Ku Lin
Browse files

Implemented nested scrolling parent in TextReadingPreviewPager

Flag: N/A
Bug: 317947238
Test: manual

Change-Id: I173881b84d5c5ff81c15a80a4de65fda59f5bf65
parent 946f52b2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@
            android:id="@+id/preview_pager"
            android:layout_width="match_parent"
            android:layout_height="217dp"
            android:contentDescription="@string/preview_pager_content_description" />
            android:contentDescription="@string/preview_pager_content_description"
            android:nestedScrollingEnabled="true" />

        <com.android.settings.widget.DotsPageIndicator
            android:id="@+id/page_indicator"
+21 −9
Original line number Diff line number Diff line
@@ -18,8 +18,7 @@ package com.android.settings.accessibility;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@@ -29,18 +28,31 @@ import androidx.viewpager.widget.ViewPager;
 * The view pager is used for displaying screen preview with different size configuration changes.
 */
public class TextReadingPreviewPager extends ViewPager {

    public TextReadingPreviewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        final ViewGroup parent = (ViewGroup) getParent();
        if (parent != null) {
            // Avoid conflicting with the nested scroll view.
            parent.requestDisallowInterceptTouchEvent(true);
    public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
        return (nestedScrollAxes & View.SCROLL_AXIS_VERTICAL) != 0;
    }

    @Override
    public void onNestedScrollAccepted(View child, View target, int axes) {
        super.onNestedScrollAccepted(child, target, axes);
        // Allow the nested scrollview inside of the view pager to be scrollable.
        getParent().requestDisallowInterceptTouchEvent(true);
    }

        return super.onInterceptTouchEvent(ev);
    @Override
    public void onNestedScroll(
            View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
        if (dyUnconsumed != 0) {
            // Assume dyUnconsumed != 0 means the target has been scrolled to the end vertically.
            // We could let the parent to consume the rest of the dyUnconsumed
            getParent().requestDisallowInterceptTouchEvent(false);
        }
        super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
    }
}