1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settings.accessibility;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.View;
22 
23 import androidx.annotation.NonNull;
24 import androidx.annotation.Nullable;
25 import androidx.viewpager.widget.ViewPager;
26 
27 /**
28  * The view pager is used for displaying screen preview with different size configuration changes.
29  */
30 public class TextReadingPreviewPager extends ViewPager {
31 
TextReadingPreviewPager(@onNull Context context, @Nullable AttributeSet attrs)32     public TextReadingPreviewPager(@NonNull Context context, @Nullable AttributeSet attrs) {
33         super(context, attrs);
34     }
35 
36     @Override
onStartNestedScroll(View child, View target, int nestedScrollAxes)37     public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
38         return (nestedScrollAxes & View.SCROLL_AXIS_VERTICAL) != 0;
39     }
40 
41     @Override
onNestedScrollAccepted(View child, View target, int axes)42     public void onNestedScrollAccepted(View child, View target, int axes) {
43         super.onNestedScrollAccepted(child, target, axes);
44         // Allow the nested scrollview inside of the view pager to be scrollable.
45         getParent().requestDisallowInterceptTouchEvent(true);
46     }
47 
48     @Override
onNestedScroll( View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)49     public void onNestedScroll(
50             View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
51         if (dyUnconsumed != 0) {
52             // Assume dyUnconsumed != 0 means the target has been scrolled to the end vertically.
53             // We could let the parent to consume the rest of the dyUnconsumed
54             getParent().requestDisallowInterceptTouchEvent(false);
55         }
56         super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
57     }
58 }
59