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:id="@+id/preview_pager"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="217dp"
|
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
|
<com.android.settings.widget.DotsPageIndicator
|
||||||
android:id="@+id/page_indicator"
|
android:id="@+id/page_indicator"
|
||||||
|
@@ -18,8 +18,7 @@ package com.android.settings.accessibility;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.MotionEvent;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
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.
|
* The view pager is used for displaying screen preview with different size configuration changes.
|
||||||
*/
|
*/
|
||||||
public class TextReadingPreviewPager extends ViewPager {
|
public class TextReadingPreviewPager extends ViewPager {
|
||||||
|
|
||||||
public TextReadingPreviewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
|
public TextReadingPreviewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
|
||||||
final ViewGroup parent = (ViewGroup) getParent();
|
return (nestedScrollAxes & View.SCROLL_AXIS_VERTICAL) != 0;
|
||||||
if (parent != null) {
|
|
||||||
// Avoid conflicting with the nested scroll view.
|
|
||||||
parent.requestDisallowInterceptTouchEvent(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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