package android.support.v4.view;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewParent;
/**
* This interface should be implemented by {@link android.view.View View} subclasses that wish
* to support dispatching nested scrolling operations to a cooperating parent
* {@link android.view.ViewGroup ViewGroup}.
*
* <p>Classes implementing this interface should create a final instance of a
* {@link NestedScrollingChildHelper} as a field and delegate any View methods to the
* <code>NestedScrollingChildHelper</code> methods of the same signature.</p>
*
* <p>Views invoking nested scrolling functionality should always do so from the relevant
* {@link ViewCompat}, {@link ViewGroupCompat} or {@link ViewParentCompat} compatibility
* shim static methods. This ensures interoperability with nested scrolling views on Android
* 5.0 Lollipop and newer.</p>
*/
/**
*此接口应该由@link android.view.view view希望的子类实现
*支持将嵌套滚动操作分派给合作的父级
*@link android.view.viewgroup查看组。
*
*<p>实现此接口的类应创建
*@link nestedsrolling childhelper作为字段,并将任何视图方法委托给
*<code>NestedScrollingChildHelper<code>methods of the same signature.<p>
*
*<p>调用嵌套滚动功能的视图应该始终从相关的
*@link viewcompat,@link viewgroupcompat或@link viewparentcompat兼容性
*填隙静态方法。这确保了与Android上的嵌套滚动视图的互操作性。
*5.0 Lollipop和更新的。<p>
*/
public interface NestedScrollingChild {
/**
* Enable or disable nested scrolling for this view.
*
* <p>If this property is set to true the view will be permitted to initiate nested
* scrolling operations with a compatible parent view in the current hierarchy. If this
* view does not implement nested scrolling this will have no effect. Disabling nested scrolling
* while a nested scroll is in progress has the effect of {@link #stopNestedScroll() stopping}
* the nested scroll.</p>
*
* @param enabled true to enable nested scrolling, false to disable
*
* @see #isNestedScrollingEnabled()
*/
/**
*为此视图启用或禁用嵌套滚动。
*
*<p>如果此属性设置为true,则将允许视图启动嵌套
*当前层次结构中具有兼容父视图的滚动操作。如果这样
*视图不实现嵌套滚动,这将不起作用。禁用嵌套滚动
*当嵌套滚动正在进行时,会产生@link stopNestedScroll()停止
*嵌套滚动。<p>
*
*@param enabled true启用嵌套滚动,false禁用
*
*@请参见已停止使用
*/
public void setNestedScrollingEnabled(boolean enabled);
/**
* Returns true if nested scrolling is enabled for this view.
*
* <p>If nested scrolling is enabled and this View class implementation supports it,
* this view will act as a nested scrolling child view when applicable, forwarding data
* about the scroll operation in progress to a compatible and cooperating nested scrolling
* parent.</p>
*
* @return true if nested scrolling is enabled
*
* @see #setNestedScrollingEnabled(boolean)
*/
/**
*如果为此视图启用嵌套滚动,则返回true。
*
*<p>如果启用了嵌套滚动,并且此视图类实现支持它,
*此视图将作为嵌套滚动子视图(如果适用)转发数据
*关于正在进行的滚动操作到兼容且协作的嵌套滚动
*父母。</P>
*
*@如果启用嵌套滚动,则返回true
*
*@请参见setNestedScrollingEnabled(布尔值)
*/
public boolean isNestedScrollingEnabled();
/**
* Begin a nestable scroll operation along the given axes.
*
* <p>A view starting a nested scroll promises to abide by the following contract:</p>
*
* <p>The view will call startNestedScroll upon initiating a scroll operation. In the case
* of a touch scroll this corresponds to the initial {@link MotionEvent#ACTION_DOWN}.
* In the case of touch scrolling the nested scroll will be terminated automatically in
* the same manner as {@link ViewParent#requestDisallowInterceptTouchEvent(boolean)}.
* In the event of programmatic scrolling the caller must explicitly call
* {@link #stopNestedScroll()} to indicate the end of the nested scroll.</p>
*
* <p>If <code>startNestedScroll</code> returns true, a cooperative parent was found.
* If it returns false the caller may ignore the rest of this contract until the next scroll.
* Calling startNestedScroll while a nested scroll is already in progress will return true.</p>
*
* <p>At each incremental step of the scroll the caller should invoke
* {@link #dispatchNestedPreScroll(int, int, int[], int[]) dispatchNestedPreScroll}
* once it has calculated the requested scrolling delta. If it returns true the nested scrolling
* parent at least partially consumed the scroll and the caller should adjust the amount it
* scrolls by.</p>
*
* <p>After applying the remainder of the scroll delta the caller should invoke
* {@link #dispatchNestedScroll(int, int, int, int, int[]) dispatchNestedScroll}, passing
* both the delta consumed and the delta unconsumed. A nested scrolling parent may treat
* these values differently. See
* {@link NestedScrollingParent#onNestedScroll(View, int, int, int, int)}.
* </p>
*
* @param axes Flags consisting of a combination of {@link ViewCompat#SCROLL_AXIS_HORIZONTAL}
* and/or {@link ViewCompat#SCROLL_AXIS_VERTICAL}.
* @return true if a cooperative parent was found and nested scrolling has been enabled for
* the current gesture.
*
* @see #stopNestedScroll()
* @see #dispatchNestedPreScroll(int, int, int[], int[])
* @see #dispatchNestedScroll(int, int, int, int, int[])
*/
/**
*沿着给定的轴开始可嵌套的滚动操作。
*
*<p>启动嵌套滚动的视图承诺遵守以下约定:</p>
*
*<p>启动滚动操作后,视图将调用StartNestedScroll。在这种情况下
*对于触摸屏,这与初始@link motionevent动作向下相对应。
*如果触摸滚动,嵌套滚动将在
*与@link viewparent requestdisallowinterceptouchevent(boolean)相同。
*在程序滚动的情况下,调用方必须显式调用
*@link stopNestedScroll()表示嵌套滚动的结束。<p>
*
*<p>如果<code>startNestedScroll<code>返回true,则会找到一个合作的父级。
*如果返回false,调用者可以忽略此契约的其余部分,直到下一个滚动。
*当嵌套滚动已在进行中时调用StartNestedScroll将返回true。<p>
*
*<p>在滚动的每个增量步骤中,调用方应调用
*@link DispatchNestedPescroll(int,int,int[],int[])DispatchNestedPescroll_
*一旦它计算了所请求的滚动增量。如果返回true,则嵌套滚动
*父级至少部分使用了滚动,调用方应调整滚动的数量。
*滚动方式。<p>
*
*<p>应用滚动增量的其余部分后,调用方应调用
*@link Dispatchnestedscroll(int,int,int,int,int[])Dispatchnestedscroll,传递
*消耗的三角洲和未消耗的三角洲。嵌套的滚动父级可以处理
*这些价值观不同。见
*@link nestedcollingparent onnestedcoll(view,int,int,int,int)。
*</P>
*
*@参数轴标志,由@link viewcompat滚动轴水平组合组成
*和/或@link viewcompat滚动轴垂直。
*@如果找到合作父级并且为启用了嵌套滚动,则返回true
*当前手势。
*
*@请参见StopNestedScroll()。
*@参见DispatchnestedPescroll(int,int,int[],int[])
*@见Dispatchnestedscroll(int,int,int,int,int,int[])
*/
public boolean startNestedScroll(int axes);
/**
* Stop a nested scroll in progress.
*
* <p>Calling this method when a nested scroll is not currently in progress is harmless.</p>
*
* @see #startNestedScroll(int)
*/
/**
*停止正在进行的嵌套滚动。
*
*<p>当嵌套滚动当前未进行时调用此方法是无害的。<p>
*
*@请参见StartNestedScroll(int)
*/
public void stopNestedScroll();
/**
* Returns true if this view has a nested scrolling parent.
*
* <p>The presence of a nested scrolling parent indicates that this view has initiated
* a nested scroll and it was accepted by an ancestor view further up the view hierarchy.</p>
*
* @return whether this view has a nested scrolling parent
*/
/**
*如果此视图具有嵌套滚动父级,则返回true。
*
*<p>嵌套滚动父级的存在表明此视图已启动
*一个嵌套的滚动,它被一个祖先视图接受,在视图层次结构的更上一层。<p>
*
*@返回此视图是否具有嵌套的滚动父级
*/
public boolean hasNestedScrollingParent();
/**
* Dispatch one step of a nested scroll in progress.
*
* <p>Implementations of views that support nested scrolling should call this to report
* info about a scroll in progress to the current nested scrolling parent. If a nested scroll
* is not currently in progress or nested scrolling is not
* {@link #isNestedScrollingEnabled() enabled} for this view this method does nothing.</p>
*
* <p>Compatible View implementations should also call
* {@link #dispatchNestedPreScroll(int, int, int[], int[]) dispatchNestedPreScroll} before
* consuming a component of the scroll event themselves.</p>
*
* @param dxConsumed Horizontal distance in pixels consumed by this view during this scroll step
* @param dyConsumed Vertical distance in pixels consumed by this view during this scroll step
* @param dxUnconsumed Horizontal scroll distance in pixels not consumed by this view
* @param dyUnconsumed Horizontal scroll distance in pixels not consumed by this view
* @param offsetInWindow Optional. If not null, on return this will contain the offset
* in local view coordinates of this view from before this operation
* to after it completes. View implementations may use this to adjust
* expected input coordinate tracking.
* @return true if the event was dispatched, false if it could not be dispatched.
* @see #dispatchNestedPreScroll(int, int, int[], int[])
*/
/**
*调度正在进行的嵌套滚动的一个步骤。
*
*<p>支持嵌套滚动的视图的实现应该调用它来报告
*有关当前嵌套滚动父级的滚动进行中的信息。如果是嵌套滚动
*当前没有进行,或者嵌套滚动没有
*@link is estedscrollingenaled()enabled for this view this method does nothing.@p>
*
*<p>兼容的视图实现还应调用
*@link dispatchnestedpescroll(int,int,int[],int[])dispatchnestedpescroll之前
*使用滚动事件本身的组件。<p>
*
*@在此滚动步骤中,此视图使用的水平距离(以像素为单位)
*@在此滚动步骤中,此视图使用的垂直距离(以像素为单位)
*@param dx未使用的水平滚动距离(像素),此视图未使用
*@参数d未使用的水平滚动距离(像素),此视图未使用
*@参数offsettinWindow可选。如果不为空,返回时将包含偏移量
*在此操作之前在此视图的本地视图坐标中
*完成后。视图实现可以使用此来调整
*预期的输入坐标跟踪。
*@如果已调度事件,则返回true;如果无法调度事件,则返回false。
*@参见DispatchnestedPescroll(int,int,int[],int[])
*/
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed,
int dxUnconsumed, int dyUnconsumed, int[] offsetInWindow);
/**
* Dispatch one step of a nested scroll in progress before this view consumes any portion of it.
*
* <p>Nested pre-scroll events are to nested scroll events what touch intercept is to touch.
* <code>dispatchNestedPreScroll</code> offers an opportunity for the parent view in a nested
* scrolling operation to consume some or all of the scroll operation before the child view
* consumes it.</p>
*
* @param dx Horizontal scroll distance in pixels
* @param dy Vertical scroll distance in pixels
* @param consumed Output. If not null, consumed[0] will contain the consumed component of dx
* and consumed[1] the consumed dy.
* @param offsetInWindow Optional. If not null, on return this will contain the offset
* in local view coordinates of this view from before this operation
* to after it completes. View implementations may use this to adjust
* expected input coordinate tracking.
* @return true if the parent consumed some or all of the scroll delta
* @see #dispatchNestedScroll(int, int, int, int, int[])
*/
/**
*在该视图使用嵌套滚动的任何部分之前,调度正在进行的滚动的一个步骤。
*
*<p>嵌套的预滚动事件是指嵌套的滚动事件,即触摸截获要触摸的内容。
*<code>dispatchnestedpescroll<code>为嵌套中的父视图提供机会
*滚动操作使用子视图之前的部分或全部滚动操作
*消耗它。<p>
*
*@参数dx水平滚动距离(像素)
*@以像素为单位的垂直滚动距离
*@参数消耗的输出。如果不为空,则消耗的[0]将包含消耗的dx组件。
*消耗了[1]的dy。
*@参数offsettinWindow可选。如果不为空,返回时将包含偏移量
*在此操作之前在此视图的本地视图坐标中
*完成后。视图实现可以使用它来调整
*需要输入坐标跟踪。
*@如果父级消耗了部分或全部滚动增量,则返回true
*@见Dispatchnestedscroll(int,int,int,int,int,int[])
*/
public boolean dispatchNestedPreScroll(int dx, int dy, int[] consumed, int[] offsetInWindow);
/**
* Dispatch a fling to a nested scrolling parent.
*
* <p>This method should be used to indicate that a nested scrolling child has detected
* suitable conditions for a fling. Generally this means that a touch scroll has ended with a
* {@link VelocityTracker velocity} in the direction of scrolling that meets or exceeds
* the {@link ViewConfiguration#getScaledMinimumFlingVelocity() minimum fling velocity}
* along a scrollable axis.</p>
*
* <p>If a nested scrolling child view would normally fling but it is at the edge of
* its own content, it can use this method to delegate the fling to its nested scrolling
* parent instead. The parent may optionally consume the fling or observe a child fling.</p>
*
* @param velocityX Horizontal fling velocity in pixels per second
* @param velocityY Vertical fling velocity in pixels per second
* @param consumed true if the child consumed the fling, false otherwise
* @return true if the nested scrolling parent consumed or otherwise reacted to the fling
*/
/**
*向嵌套的滚动父对象发送一个Fling。
*
*<p>此方法应用于指示已检测到嵌套滚动子级
*适合抛掷的条件。一般来说,这意味着触摸屏以
*@link velocitytracker velocity在满足或超过滚动方向
*@link viewconfiguration_getscaledMinimumFlingvelocity()最小Fling速度
*沿着可滚动轴。<p>
*
*<p>如果一个嵌套的滚动子视图通常会抛出,但它位于
*它自己的内容,可以使用此方法将Fling委托给它的嵌套滚动
*而不是父级。家长可以选择使用投掷或观察儿童投掷。<p>
*
*@参数速度x水平投掷速度(像素/秒)
*@以像素/秒为单位的参数速度垂直投掷速度
*@如果子对象使用了Fling,则参数消耗为true,否则为false
*@如果嵌套的滚动父级已使用或以其他方式对Fling作出响应,则返回true。
*/
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed);
/**
* Dispatch a fling to a nested scrolling parent before it is processed by this view.
*
* <p>Nested pre-fling events are to nested fling events what touch intercept is to touch
* and what nested pre-scroll is to nested scroll. <code>dispatchNestedPreFling</code>
* offsets an opportunity for the parent view in a nested fling to fully consume the fling
* before the child view consumes it. If this method returns <code>true</code>, a nested
* parent view consumed the fling and this view should not scroll as a result.</p>
*
* <p>For a better user experience, only one view in a nested scrolling chain should consume
* the fling at a time. If a parent view consumed the fling this method will return false.
* Custom view implementations should account for this in two ways:</p>
*
* <ul>
* <li>If a custom view is paged and needs to settle to a fixed page-point, do not
* call <code>dispatchNestedPreFling</code>; consume the fling and settle to a valid
* position regardless.</li>
* <li>If a nested parent does consume the fling, this view should not scroll at all,
* even to settle back to a valid idle position.</li>
* </ul>
*
* <p>Views should also not offer fling velocities to nested parent views along an axis
* where scrolling is not currently supported; a {@link android.widget.ScrollView ScrollView}
* should not offer a horizontal fling velocity to its parents since scrolling along that
* axis is not permitted and carrying velocity along that motion does not make sense.</p>
*
* @param velocityX Horizontal fling velocity in pixels per second
* @param velocityY Vertical fling velocity in pixels per second
* @return true if a nested scrolling parent consumed the fling
*/
/**
*在这个视图处理前,将一个fling分派给一个嵌套的滚动父对象。
*
*<p>嵌套的预触发事件是指嵌套的触发事件,即触摸截获要触摸的事件。
*嵌套的预滚动是指嵌套的滚动。<code>dispatchnestedprefling<code>
*在嵌套的fling中为父视图抵消完全使用fling的机会
*在子视图使用它之前。如果此方法返回<code>true,则返回一个嵌套的
*父视图使用了Fling,因此该视图不应滚动。<p>
*
*<p>为了获得更好的用户体验,嵌套滚动链中只应使用一个视图
*一次抛一次。如果父视图使用了Fling,则此方法将返回false。
*自定义视图实现应该以两种方式解释这一点:</p>
*
*UL>
*<li>如果自定义视图已分页,并且需要固定到固定的页点,则不要
*call<code>dispatchnestedprefling<code>;consume the fling and settle to a valid
*无论位置如何。<li>
*<li>如果嵌套的父对象确实使用了Fling,则此视图根本不应该滚动,
*即使是回到一个有效的空闲位置。<li>
*</UL>
*
*<p>视图也不应该为沿着轴嵌套的父视图提供抛出速度。
*当前不支持滚动;a@link android.widget.scrollview scrollview
*不应该给它的双亲提供水平的投掷速度,因为沿着它滚动
*轴是不允许的,沿该运动的承载速度是没有意义的。<p>
*
*@参数速度x水平投掷速度(像素/秒)
*@以像素/秒为单位的参数速度垂直投掷速度
*@如果嵌套滚动父级使用了Fling,则返回true
*/
public boolean dispatchNestedPreFling(float velocityX, float velocityY);
}