Merge "Implemented nested scrolling parent in TextReadingPreviewPager" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
a5e48292a7
@@ -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"
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
return super.onInterceptTouchEvent(ev);
|
||||
@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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user