title: Custom CoordinatorLayout behavior
body: <p>This is my layout:</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
     android:id="@+id/coordinator_layout"
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"&gt;
  
  &lt;include layout="@layout/view_product_details"/&gt;  // This contains a NestedScrollView
  
  &lt;LinearLayout android:id="@+id/indicator"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="right|bottom"
                android:layout_marginBottom="16dp"
                android:gravity="right|bottom"
                android:orientation="horizontal"
                app:layout_behavior="utils.CustomBehavior"&gt;
  
              // Some views.. 
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>I want the indicator layout to be shown when the user opens the Activity but it should hide when the user scrolls a bit down.<br>
  When the user scrolls back to the top of the page I want it to show again. </p>
  
  <p>So I wrote a custom behavior class:</p>
  
  <pre><code>public class CustomBehavior extends CoordinatorLayout.Behavior {
  
  private int totalY;
  
  public CustomBehavior(Context context, AttributeSet attrs) {
      super();
  }
  
  @Override
  public boolean layoutDependsOn(CoordinatorLayout parent, View child, View dependency) {
      return dependency instanceof NestedScrollView;
  }
  
  @Override
  public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
      return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL || super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
  }
  
  @Override
  public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
      super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
  
      totalY += dyConsumed;
  
      Log.d("Scroll", "Total Y : " + totalY);
  
      LinearLayout fabMenu = (LinearLayout) child;
      FloatingActionButton wishListButton = (FloatingActionButton) fabMenu.findViewById(R.id.fab_wishlist);
      FloatingActionButton collectionButton = (FloatingActionButton) fabMenu.findViewById(R.id.fab_collection);
      FloatingActionButton tastedButton = (FloatingActionButton) fabMenu.findViewById(R.id.fab_tasted_list);
  
      if (totalY &gt; 10) {
          wishListButton.hide(true);
          collectionButton.hide(true);
          tastedButton.hide(true);
      } else if (totalY &lt; 10) {
          wishListButton.show(true);
          collectionButton.show(true);
          tastedButton.show(true);
      }
  }
  }
  </code></pre>
  
  <p>But the adding and subtracting of total Y value is not reliable.<br>
  How can I detect that the user has reached the top of the NestedScrollView? </p>
  
  <p>Or is there a better way to implement something like this? 
  Thanks!</p>