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 overridden 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 android.support.v4.view.ViewCompat}, {@link android.support.v4.view.ViewGroupCompat} or 35 * {@link android.support.v4.view.ViewParentCompat} compatibility 36 * shim static methods. This ensures interoperability with nested scrolling views on Android 37 * 5.0 Lollipop and newer.</p> 38 */ 39public class NestedScrollingParentHelper { 40 private final ViewGroup mViewGroup; 41 private int mNestedScrollAxes; 42 43 /** 44 * Construct a new helper for a given ViewGroup 45 */ 46 public NestedScrollingParentHelper(ViewGroup viewGroup) { 47 mViewGroup = viewGroup; 48 } 49 50 /** 51 * Called when a nested scrolling operation initiated by a descendant view is accepted 52 * by this ViewGroup. 53 * 54 * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup} 55 * subclass method/{@link android.support.v4.view.NestedScrollingParent} interface method with 56 * the same signature to implement the standard policy.</p> 57 */ 58 public void onNestedScrollAccepted(View child, View target, int axes) { 59 mNestedScrollAxes = axes; 60 } 61 62 /** 63 * Return the current axes of nested scrolling for this ViewGroup. 64 * 65 * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup} 66 * subclass method/{@link android.support.v4.view.NestedScrollingParent} interface method with 67 * the same signature to implement the standard policy.</p> 68 */ 69 public int getNestedScrollAxes() { 70 return mNestedScrollAxes; 71 } 72 73 /** 74 * React to a nested scroll operation ending. 75 * 76 * <p>This is a delegate method. Call it from your {@link android.view.ViewGroup ViewGroup} 77 * subclass method/{@link android.support.v4.view.NestedScrollingParent} interface method with 78 * the same signature to implement the standard policy.</p> 79 * 80 * @param target View that initiated the nested scroll 81 */ 82 public void onStopNestedScroll(View target) { 83 mNestedScrollAxes = 0; 84 } 85} 86