package androidx.core.view; import android.view.View; import android.view.ViewParent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; public class NestedScrollingChildHelper { private boolean mIsNestedScrollingEnabled; private ViewParent mNestedScrollingParentNonTouch; private ViewParent mNestedScrollingParentTouch; private int[] mTempNestedScrollConsumed; private final View mView; public NestedScrollingChildHelper(@NonNull View view) { this.mView = view; } private boolean dispatchNestedScrollInternal(int i, int i2, int i3, int i4, @Nullable int[] iArr, int i5, @Nullable int[] iArr2) { ViewParent nestedScrollingParentForType; int i6; int i7; int[] iArr3; if (!isNestedScrollingEnabled() || (nestedScrollingParentForType = getNestedScrollingParentForType(i5)) == null) { return false; } if (i == 0 && i2 == 0 && i3 == 0 && i4 == 0) { if (iArr != null) { iArr[0] = 0; iArr[1] = 0; } return false; } if (iArr != null) { this.mView.getLocationInWindow(iArr); i7 = iArr[0]; i6 = iArr[1]; } else { i7 = 0; i6 = 0; } if (iArr2 == null) { int[] tempNestedScrollConsumed = getTempNestedScrollConsumed(); tempNestedScrollConsumed[0] = 0; tempNestedScrollConsumed[1] = 0; iArr3 = tempNestedScrollConsumed; } else { iArr3 = iArr2; } ViewParentCompat.onNestedScroll(nestedScrollingParentForType, this.mView, i, i2, i3, i4, i5, iArr3); if (iArr != null) { this.mView.getLocationInWindow(iArr); iArr[0] = iArr[0] - i7; iArr[1] = iArr[1] - i6; } return true; } private ViewParent getNestedScrollingParentForType(int i) { if (i == 0) { return this.mNestedScrollingParentTouch; } if (i != 1) { return null; } return this.mNestedScrollingParentNonTouch; } private int[] getTempNestedScrollConsumed() { if (this.mTempNestedScrollConsumed == null) { this.mTempNestedScrollConsumed = new int[2]; } return this.mTempNestedScrollConsumed; } private void setNestedScrollingParentForType(int i, ViewParent viewParent) { if (i == 0) { this.mNestedScrollingParentTouch = viewParent; } else if (i == 1) { this.mNestedScrollingParentNonTouch = viewParent; } } public boolean dispatchNestedFling(float f, float f2, boolean z2) { ViewParent nestedScrollingParentForType; if (!isNestedScrollingEnabled() || (nestedScrollingParentForType = getNestedScrollingParentForType(0)) == null) { return false; } return ViewParentCompat.onNestedFling(nestedScrollingParentForType, this.mView, f, f2, z2); } public boolean dispatchNestedPreFling(float f, float f2) { ViewParent nestedScrollingParentForType; if (!isNestedScrollingEnabled() || (nestedScrollingParentForType = getNestedScrollingParentForType(0)) == null) { return false; } return ViewParentCompat.onNestedPreFling(nestedScrollingParentForType, this.mView, f, f2); } public boolean dispatchNestedPreScroll(int i, int i2, @Nullable int[] iArr, @Nullable int[] iArr2) { return dispatchNestedPreScroll(i, i2, iArr, iArr2, 0); } public boolean dispatchNestedPreScroll(int i, int i2, @Nullable int[] iArr, @Nullable int[] iArr2, int i3) { ViewParent nestedScrollingParentForType; int i4; int i5; if (!isNestedScrollingEnabled() || (nestedScrollingParentForType = getNestedScrollingParentForType(i3)) == null) { return false; } if (i != 0 || i2 != 0) { if (iArr2 != null) { this.mView.getLocationInWindow(iArr2); i5 = iArr2[0]; i4 = iArr2[1]; } else { i5 = 0; i4 = 0; } if (iArr == null) { iArr = getTempNestedScrollConsumed(); } iArr[0] = 0; iArr[1] = 0; ViewParentCompat.onNestedPreScroll(nestedScrollingParentForType, this.mView, i, i2, iArr, i3); if (iArr2 != null) { this.mView.getLocationInWindow(iArr2); iArr2[0] = iArr2[0] - i5; iArr2[1] = iArr2[1] - i4; } return (iArr[0] == 0 && iArr[1] == 0) ? false : true; } else if (iArr2 == null) { return false; } else { iArr2[0] = 0; iArr2[1] = 0; return false; } } public void dispatchNestedScroll(int i, int i2, int i3, int i4, @Nullable int[] iArr, int i5, @Nullable int[] iArr2) { dispatchNestedScrollInternal(i, i2, i3, i4, iArr, i5, iArr2); } public boolean dispatchNestedScroll(int i, int i2, int i3, int i4, @Nullable int[] iArr) { return dispatchNestedScrollInternal(i, i2, i3, i4, iArr, 0, null); } public boolean dispatchNestedScroll(int i, int i2, int i3, int i4, @Nullable int[] iArr, int i5) { return dispatchNestedScrollInternal(i, i2, i3, i4, iArr, i5, null); } public boolean hasNestedScrollingParent() { return hasNestedScrollingParent(0); } public boolean hasNestedScrollingParent(int i) { return getNestedScrollingParentForType(i) != null; } public boolean isNestedScrollingEnabled() { return this.mIsNestedScrollingEnabled; } public void onDetachedFromWindow() { ViewCompat.stopNestedScroll(this.mView); } public void onStopNestedScroll(@NonNull View view) { ViewCompat.stopNestedScroll(this.mView); } public void setNestedScrollingEnabled(boolean z2) { if (this.mIsNestedScrollingEnabled) { ViewCompat.stopNestedScroll(this.mView); } this.mIsNestedScrollingEnabled = z2; } public boolean startNestedScroll(int i) { return startNestedScroll(i, 0); } public boolean startNestedScroll(int i, int i2) { if (hasNestedScrollingParent(i2)) { return true; } if (!isNestedScrollingEnabled()) { return false; } View view = this.mView; for (ViewParent parent = this.mView.getParent(); parent != null; parent = parent.getParent()) { if (ViewParentCompat.onStartNestedScroll(parent, view, this.mView, i, i2)) { setNestedScrollingParentForType(i2, parent); ViewParentCompat.onNestedScrollAccepted(parent, view, this.mView, i, i2); return true; } if (parent instanceof View) { view = (View) parent; } } return false; } public void stopNestedScroll() { stopNestedScroll(0); } public void stopNestedScroll(int i) { ViewParent nestedScrollingParentForType = getNestedScrollingParentForType(i); if (nestedScrollingParentForType != null) { ViewParentCompat.onStopNestedScroll(nestedScrollingParentForType, this.mView, i); setNestedScrollingParentForType(i, null); } } }