116 lines
4.3 KiB
Java
116 lines
4.3 KiB
Java
package androidx.viewpager2.widget;
|
|
|
|
import android.animation.LayoutTransition;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
import java.lang.reflect.Array;
|
|
import java.util.Arrays;
|
|
import java.util.Comparator;
|
|
public final class AnimateLayoutChangeDetector {
|
|
private static final ViewGroup.MarginLayoutParams ZERO_MARGIN_LAYOUT_PARAMS;
|
|
private LinearLayoutManager mLayoutManager;
|
|
|
|
/* renamed from: androidx.viewpager2.widget.AnimateLayoutChangeDetector$1 reason: invalid class name */
|
|
public class AnonymousClass1 implements Comparator<int[]> {
|
|
public AnonymousClass1() {
|
|
}
|
|
|
|
public int compare(int[] iArr, int[] iArr2) {
|
|
return iArr[0] - iArr2[0];
|
|
}
|
|
}
|
|
|
|
static {
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(-1, -1);
|
|
ZERO_MARGIN_LAYOUT_PARAMS = marginLayoutParams;
|
|
marginLayoutParams.setMargins(0, 0, 0, 0);
|
|
}
|
|
|
|
public AnimateLayoutChangeDetector(@NonNull LinearLayoutManager linearLayoutManager) {
|
|
this.mLayoutManager = linearLayoutManager;
|
|
}
|
|
|
|
private boolean arePagesLaidOutContiguously() {
|
|
int i;
|
|
int i2;
|
|
int i3;
|
|
int i4;
|
|
int childCount = this.mLayoutManager.getChildCount();
|
|
if (childCount == 0) {
|
|
return true;
|
|
}
|
|
boolean z2 = this.mLayoutManager.getOrientation() == 0;
|
|
int[] iArr = new int[2];
|
|
iArr[1] = 2;
|
|
iArr[0] = childCount;
|
|
int[][] iArr2 = (int[][]) Array.newInstance(int.class, iArr);
|
|
for (int i5 = 0; i5 < childCount; i5++) {
|
|
View childAt = this.mLayoutManager.getChildAt(i5);
|
|
if (childAt != null) {
|
|
ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
|
|
ViewGroup.MarginLayoutParams marginLayoutParams = layoutParams instanceof ViewGroup.MarginLayoutParams ? (ViewGroup.MarginLayoutParams) layoutParams : ZERO_MARGIN_LAYOUT_PARAMS;
|
|
int[] iArr3 = iArr2[i5];
|
|
if (z2) {
|
|
i2 = childAt.getLeft();
|
|
i = marginLayoutParams.leftMargin;
|
|
} else {
|
|
i2 = childAt.getTop();
|
|
i = marginLayoutParams.topMargin;
|
|
}
|
|
iArr3[0] = i2 - i;
|
|
int[] iArr4 = iArr2[i5];
|
|
if (z2) {
|
|
i4 = childAt.getRight();
|
|
i3 = marginLayoutParams.rightMargin;
|
|
} else {
|
|
i4 = childAt.getBottom();
|
|
i3 = marginLayoutParams.bottomMargin;
|
|
}
|
|
iArr4[1] = i4 + i3;
|
|
} else {
|
|
throw new IllegalStateException("null view contained in the view hierarchy");
|
|
}
|
|
}
|
|
Arrays.sort(iArr2, new AnonymousClass1());
|
|
for (int i6 = 1; i6 < childCount; i6++) {
|
|
if (iArr2[i6 - 1][1] != iArr2[i6][0]) {
|
|
return false;
|
|
}
|
|
}
|
|
return iArr2[0][0] <= 0 && iArr2[childCount - 1][1] >= iArr2[0][1] - iArr2[0][0];
|
|
}
|
|
|
|
private boolean hasRunningChangingLayoutTransition() {
|
|
int childCount = this.mLayoutManager.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
if (hasRunningChangingLayoutTransition(this.mLayoutManager.getChildAt(i))) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static boolean hasRunningChangingLayoutTransition(View view) {
|
|
if (view instanceof ViewGroup) {
|
|
ViewGroup viewGroup = (ViewGroup) view;
|
|
LayoutTransition layoutTransition = viewGroup.getLayoutTransition();
|
|
if (layoutTransition != null && layoutTransition.isChangingLayout()) {
|
|
return true;
|
|
}
|
|
int childCount = viewGroup.getChildCount();
|
|
for (int i = 0; i < childCount; i++) {
|
|
if (hasRunningChangingLayoutTransition(viewGroup.getChildAt(i))) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean mayHaveInterferingAnimations() {
|
|
return (!arePagesLaidOutContiguously() || this.mLayoutManager.getChildCount() <= 1) && hasRunningChangingLayoutTransition();
|
|
}
|
|
}
|