1/*
2 * Copyright (C) 2015 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
18package android.support.v4.view;
19
20import android.view.View;
21import android.view.ViewGroup;
22
23/**
24 * Helper class for implementing nested scrolling parent views compatible with Android platform
25 * versions earlier than Android 5.0 Lollipop (API 21).
26 *
27 * <p>{@link android.view.ViewGroup ViewGroup} subclasses should instantiate a final instance
28 * of this class as a field at construction. For each <code>ViewGroup</code> method that has
29 * a matching method signature in this class, delegate the operation to the helper instance
30 * in an overriden method implementation. This implements the standard framework policy
31 * for nested scrolling.</p>
32 *
33 * <p>Views invoking nested scrolling functionality should always do so from the relevant
34 * {@link ViewCompat}, {@link ViewGroupCompat} or {@link ViewParentCompat} compatibility
35 * shim static methods. This ensures interoperability with nested scrolling views on Android
36 * 5.0 Lollipop and newer.</p>
37 */
38public class NestedScrollingParentHelper {
39    private final ViewGroup mViewGroup;
40    private int mNestedScrollAxes;
41
42    /**
43     * Construct a new helper for a given ViewGroup
44     */
45    public NestedScrollingParentHelper(ViewGroup viewGroup) {
46        mViewGroup = viewGroup;
47    }
48
49    /**
50     * Called when a nested scrolling operation initiated by a descendant view is accepted
51     * by this ViewGroup.
52     *
53     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
54     * subclass method/{@link NestedScrollingParent} interface method with the same signature
55     * to implement the standard policy.</p>
56     */
57    public void onNestedScrollAccepted(View child, View target, int axes) {
58        mNestedScrollAxes = axes;
59    }
60
61    /**
62     * Return the current axes of nested scrolling for this ViewGroup.
63     *
64     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
65     * subclass method/{@link NestedScrollingParent} interface method with the same signature
66     * to implement the standard policy.</p>
67     */
68    public int getNestedScrollAxes() {
69        return mNestedScrollAxes;
70    }
71
72    /**
73     * React to a nested scroll operation ending.
74     *
75     * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup}
76     * subclass method/{@link NestedScrollingParent} interface method with the same signature
77     * to implement the standard policy.</p>
78     *
79     * @param target View that initiated the nested scroll
80     */
81    public void onStopNestedScroll(View target) {
82        mNestedScrollAxes = 0;
83    }
84}
85