content: package com.google.android.material.appbar;
  
  import android.content.Context;
  import android.util.AttributeSet;
  import android.view.MotionEvent;
  import android.view.VelocityTracker;
  import android.view.View;
  import android.view.ViewConfiguration;
  import android.widget.OverScroller;
  import androidx.coordinatorlayout.widget.CoordinatorLayout;
  import androidx.core.math.MathUtils;
  import androidx.core.view.ViewCompat;
  
  abstract class HeaderBehavior<V extends View> extends ViewOffsetBehavior<V> {
      private static final int INVALID_POINTER = -1;
      private int activePointerId = -1;
      private Runnable flingRunnable;
      private boolean isBeingDragged;
      private int lastMotionY;
      OverScroller scroller;
      private int touchSlop = -1;
      private VelocityTracker velocityTracker;
  
      private class FlingRunnable implements Runnable {
          private final V layout;
          private final CoordinatorLayout parent;
  
          FlingRunnable(CoordinatorLayout parent2, V v) {
              this.parent = parent2;
              this.layout = v;
          }
  
          public void run() {
              if (this.layout != null && HeaderBehavior.this.scroller != null) {
                  if (HeaderBehavior.this.scroller.computeScrollOffset()) {
                      HeaderBehavior headerBehavior = HeaderBehavior.this;
                      headerBehavior.setHeaderTopBottomOffset(this.parent, this.layout, headerBehavior.scroller.getCurrY());
                      ViewCompat.postOnAnimation(this.layout, this);
                      return;
                  }
                  HeaderBehavior.this.onFlingFinished(this.parent, this.layout);
              }
          }
      }
  
      public HeaderBehavior() {
      }
  
      public HeaderBehavior(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      private void ensureVelocityTracker() {
          if (this.velocityTracker == null) {
              this.velocityTracker = VelocityTracker.obtain();
          }
      }
  
      /* access modifiers changed from: package-private */
      public boolean canDragView(V v) {
          return false;
      }
  
      /* access modifiers changed from: package-private */
      public final boolean fling(CoordinatorLayout coordinatorLayout, V v, int minOffset, int maxOffset, float velocityY) {
          V v2 = v;
          Runnable runnable = this.flingRunnable;
          if (runnable != null) {
              v.removeCallbacks(runnable);
              this.flingRunnable = null;
          }
          if (this.scroller == null) {
              this.scroller = new OverScroller(v.getContext());
          }
          this.scroller.fling(0, getTopAndBottomOffset(), 0, Math.round(velocityY), 0, 0, minOffset, maxOffset);
          if (this.scroller.computeScrollOffset()) {
              CoordinatorLayout coordinatorLayout2 = coordinatorLayout;
              FlingRunnable flingRunnable2 = new FlingRunnable(coordinatorLayout, v);
              this.flingRunnable = flingRunnable2;
              ViewCompat.postOnAnimation(v, flingRunnable2);
              return true;
          }
          CoordinatorLayout coordinatorLayout3 = coordinatorLayout;
          onFlingFinished(coordinatorLayout, v);
          return false;
      }
  
      /* access modifiers changed from: package-private */
      public int getMaxDragOffset(V v) {
          return -v.getHeight();
      }
  
      /* access modifiers changed from: package-private */
      public int getScrollRangeForDragFling(V v) {
          return v.getHeight();
      }
  
      /* access modifiers changed from: package-private */
      public int getTopBottomOffsetForScrollingSibling() {
          return getTopAndBottomOffset();
      }
  
      /* access modifiers changed from: package-private */
      public void onFlingFinished(CoordinatorLayout parent, V v) {
      }
  
      public boolean onInterceptTouchEvent(CoordinatorLayout parent, V v, MotionEvent ev) {
          int findPointerIndex;
          if (this.touchSlop < 0) {
              this.touchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
          }
          if (ev.getActionMasked() == 2 && this.isBeingDragged) {
              int i = this.activePointerId;
              if (i == -1 || (findPointerIndex = ev.findPointerIndex(i)) == -1) {
                  return false;
              }
              int y = (int) ev.getY(findPointerIndex);
              if (Math.abs(y - this.lastMotionY) > this.touchSlop) {
                  this.lastMotionY = y;
                  return true;
              }
          }
          if (ev.getActionMasked() == 0) {
              this.activePointerId = -1;
              int x = (int) ev.getX();
              int y2 = (int) ev.getY();
              boolean z = canDragView(v) && parent.isPointInChildBounds(v, x, y2);
              this.isBeingDragged = z;
              if (z) {
                  this.lastMotionY = y2;
                  this.activePointerId = ev.getPointerId(0);
                  ensureVelocityTracker();
                  OverScroller overScroller = this.scroller;
                  if (overScroller != null && !overScroller.isFinished()) {
                      this.scroller.abortAnimation();
                      return true;
                  }
              }
          }
          VelocityTracker velocityTracker2 = this.velocityTracker;
          if (velocityTracker2 != null) {
              velocityTracker2.addMovement(ev);
          }
          return false;
      }
  
      public boolean onTouchEvent(CoordinatorLayout parent, V v, MotionEvent ev) {
          boolean z = false;
          switch (ev.getActionMasked()) {
              case 1:
                  VelocityTracker velocityTracker2 = this.velocityTracker;
                  if (velocityTracker2 != null) {
                      z = true;
                      velocityTracker2.addMovement(ev);
                      this.velocityTracker.computeCurrentVelocity(1000);
                      fling(parent, v, -getScrollRangeForDragFling(v), 0, this.velocityTracker.getYVelocity(this.activePointerId));
                      break;
                  }
                  break;
              case 2:
                  int findPointerIndex = ev.findPointerIndex(this.activePointerId);
                  if (findPointerIndex != -1) {
                      int y = (int) ev.getY(findPointerIndex);
                      this.lastMotionY = y;
                      scroll(parent, v, this.lastMotionY - y, getMaxDragOffset(v), 0);
                      break;
                  } else {
                      return false;
                  }
              case 3:
                  break;
              case 6:
                  int i = ev.getActionIndex() == 0 ? 1 : 0;
                  this.activePointerId = ev.getPointerId(i);
                  this.lastMotionY = (int) (ev.getY(i) + 0.5f);
                  break;
          }
          this.isBeingDragged = false;
          this.activePointerId = -1;
          VelocityTracker velocityTracker3 = this.velocityTracker;
          if (velocityTracker3 != null) {
              velocityTracker3.recycle();
              this.velocityTracker = null;
          }
          VelocityTracker velocityTracker4 = this.velocityTracker;
          if (velocityTracker4 != null) {
              velocityTracker4.addMovement(ev);
          }
          return this.isBeingDragged || z;
      }
  
      /* access modifiers changed from: package-private */
      public final int scroll(CoordinatorLayout coordinatorLayout, V v, int dy, int minOffset, int maxOffset) {
          return setHeaderTopBottomOffset(coordinatorLayout, v, getTopBottomOffsetForScrollingSibling() - dy, minOffset, maxOffset);
      }
  
      /* access modifiers changed from: package-private */
      public int setHeaderTopBottomOffset(CoordinatorLayout parent, V v, int newOffset) {
          return setHeaderTopBottomOffset(parent, v, newOffset, Integer.MIN_VALUE, Integer.MAX_VALUE);
      }
  
      /* access modifiers changed from: package-private */
      public int setHeaderTopBottomOffset(CoordinatorLayout parent, V v, int newOffset, int minOffset, int maxOffset) {
          int newOffset2;
          int topAndBottomOffset = getTopAndBottomOffset();
          if (minOffset == 0 || topAndBottomOffset < minOffset || topAndBottomOffset > maxOffset || topAndBottomOffset == (newOffset2 = MathUtils.clamp(newOffset, minOffset, maxOffset))) {
              return 0;
          }
          setTopAndBottomOffset(newOffset2);
          return topAndBottomOffset - newOffset2;
      }
  }
  