mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-13 17:37:16 +01:00
327 lines
13 KiB
Java
327 lines
13 KiB
Java
package com.google.android.material.carousel;
|
|
|
|
import androidx.annotation.FloatRange;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import androidx.annotation.RestrictTo;
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import com.google.android.material.animation.AnimationUtils;
|
|
import com.google.errorprone.annotations.CanIgnoreReturnValue;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
|
|
/* loaded from: classes7.dex */
|
|
public final class KeylineState {
|
|
private final int carouselSize;
|
|
private final int firstFocalKeylineIndex;
|
|
private final float itemSize;
|
|
private final List<Keyline> keylines;
|
|
private final int lastFocalKeylineIndex;
|
|
private int totalVisibleFocalItems;
|
|
|
|
private KeylineState(float f, List<Keyline> list, int i, int i2, int i3) {
|
|
this.itemSize = f;
|
|
this.keylines = Collections.unmodifiableList(list);
|
|
this.firstFocalKeylineIndex = i;
|
|
this.lastFocalKeylineIndex = i2;
|
|
while (i <= i2) {
|
|
if (list.get(i).cutoff == 0.0f) {
|
|
this.totalVisibleFocalItems++;
|
|
}
|
|
i++;
|
|
}
|
|
this.carouselSize = i3;
|
|
}
|
|
|
|
public static KeylineState lerp(KeylineState keylineState, KeylineState keylineState2, float f) {
|
|
if (keylineState.getItemSize() != keylineState2.getItemSize()) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Keylines being linearly interpolated must have the same item size.");
|
|
return null;
|
|
}
|
|
List<Keyline> keylines = keylineState.getKeylines();
|
|
List<Keyline> keylines2 = keylineState2.getKeylines();
|
|
if (keylines.size() != keylines2.size()) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Keylines being linearly interpolated must have the same number of keylines.");
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
for (int i = 0; i < keylineState.getKeylines().size(); i++) {
|
|
arrayList.add(Keyline.lerp(keylines.get(i), keylines2.get(i), f));
|
|
}
|
|
return new KeylineState(keylineState.getItemSize(), arrayList, AnimationUtils.lerp(keylineState.getFirstFocalKeylineIndex(), keylineState2.getFirstFocalKeylineIndex(), f), AnimationUtils.lerp(keylineState.getLastFocalKeylineIndex(), keylineState2.getLastFocalKeylineIndex(), f), keylineState.carouselSize);
|
|
}
|
|
|
|
public static KeylineState reverse(KeylineState keylineState, int i) {
|
|
Builder builder = new Builder(keylineState.getItemSize(), i);
|
|
float f = (i - keylineState.getLastKeyline().locOffset) - (keylineState.getLastKeyline().maskedItemSize / 2.0f);
|
|
int size = keylineState.getKeylines().size() - 1;
|
|
while (size >= 0) {
|
|
Keyline keyline = keylineState.getKeylines().get(size);
|
|
builder.addKeyline((keyline.maskedItemSize / 2.0f) + f, keyline.mask, keyline.maskedItemSize, size >= keylineState.getFirstFocalKeylineIndex() && size <= keylineState.getLastFocalKeylineIndex(), keyline.isAnchor);
|
|
f += keyline.maskedItemSize;
|
|
size--;
|
|
}
|
|
return builder.build();
|
|
}
|
|
|
|
public int getCarouselSize() {
|
|
return this.carouselSize;
|
|
}
|
|
|
|
public Keyline getFirstFocalKeyline() {
|
|
return this.keylines.get(this.firstFocalKeylineIndex);
|
|
}
|
|
|
|
public int getFirstFocalKeylineIndex() {
|
|
return this.firstFocalKeylineIndex;
|
|
}
|
|
|
|
public Keyline getFirstKeyline() {
|
|
return this.keylines.get(0);
|
|
}
|
|
|
|
@Nullable
|
|
public Keyline getFirstNonAnchorKeyline() {
|
|
for (int i = 0; i < this.keylines.size(); i++) {
|
|
Keyline keyline = this.keylines.get(i);
|
|
if (!keyline.isAnchor) {
|
|
return keyline;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public List<Keyline> getFocalKeylines() {
|
|
return this.keylines.subList(this.firstFocalKeylineIndex, this.lastFocalKeylineIndex + 1);
|
|
}
|
|
|
|
public float getItemSize() {
|
|
return this.itemSize;
|
|
}
|
|
|
|
public List<Keyline> getKeylines() {
|
|
return this.keylines;
|
|
}
|
|
|
|
public Keyline getLastFocalKeyline() {
|
|
return this.keylines.get(this.lastFocalKeylineIndex);
|
|
}
|
|
|
|
public int getLastFocalKeylineIndex() {
|
|
return this.lastFocalKeylineIndex;
|
|
}
|
|
|
|
public Keyline getLastKeyline() {
|
|
return (Keyline) ErrorUtils$$ExternalSyntheticOutline0.m(this.keylines, 1);
|
|
}
|
|
|
|
@Nullable
|
|
public Keyline getLastNonAnchorKeyline() {
|
|
for (int size = this.keylines.size() - 1; size >= 0; size--) {
|
|
Keyline keyline = this.keylines.get(size);
|
|
if (!keyline.isAnchor) {
|
|
return keyline;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public int getNumberOfNonAnchorKeylines() {
|
|
Iterator<Keyline> it2 = this.keylines.iterator();
|
|
int i = 0;
|
|
while (it2.hasNext()) {
|
|
if (it2.next().isAnchor) {
|
|
i++;
|
|
}
|
|
}
|
|
return this.keylines.size() - i;
|
|
}
|
|
|
|
public int getTotalVisibleFocalItems() {
|
|
return this.totalVisibleFocalItems;
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static final class Keyline {
|
|
final float cutoff;
|
|
final boolean isAnchor;
|
|
final float leftOrTopPaddingShift;
|
|
final float loc;
|
|
final float locOffset;
|
|
final float mask;
|
|
final float maskedItemSize;
|
|
final float rightOrBottomPaddingShift;
|
|
|
|
public Keyline(float f, float f2, float f3, float f4, boolean z, float f5, float f6, float f7) {
|
|
this.loc = f;
|
|
this.locOffset = f2;
|
|
this.mask = f3;
|
|
this.maskedItemSize = f4;
|
|
this.isAnchor = z;
|
|
this.cutoff = f5;
|
|
this.leftOrTopPaddingShift = f6;
|
|
this.rightOrBottomPaddingShift = f7;
|
|
}
|
|
|
|
public static Keyline lerp(Keyline keyline, Keyline keyline2, @FloatRange(from = 0.0d, to = 1.0d) float f) {
|
|
return new Keyline(AnimationUtils.lerp(keyline.loc, keyline2.loc, f), AnimationUtils.lerp(keyline.locOffset, keyline2.locOffset, f), AnimationUtils.lerp(keyline.mask, keyline2.mask, f), AnimationUtils.lerp(keyline.maskedItemSize, keyline2.maskedItemSize, f));
|
|
}
|
|
|
|
public Keyline(float f, float f2, float f3, float f4) {
|
|
this(f, f2, f3, f4, false, 0.0f, 0.0f, 0.0f);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static final class Builder {
|
|
private static final int NO_INDEX = -1;
|
|
private static final float UNKNOWN_LOC = Float.MIN_VALUE;
|
|
private final int carouselSize;
|
|
private final float itemSize;
|
|
private Keyline tmpFirstFocalKeyline;
|
|
private Keyline tmpLastFocalKeyline;
|
|
private final List<Keyline> tmpKeylines = new ArrayList();
|
|
private int firstFocalKeylineIndex = -1;
|
|
private int lastFocalKeylineIndex = -1;
|
|
private float lastKeylineMaskedSize = 0.0f;
|
|
private int latestAnchorKeylineIndex = -1;
|
|
|
|
public Builder(float f, int i) {
|
|
this.itemSize = f;
|
|
this.carouselSize = i;
|
|
}
|
|
|
|
private static float calculateKeylineLocationForItemPosition(float f, float f2, int i, int i2) {
|
|
return (i2 * f2) + (f - (i * f2));
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addAnchorKeyline(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3) {
|
|
return addKeyline(f, f2, f3, false, true);
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeyline(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3, boolean z, boolean z2, float f4, float f5, float f6) {
|
|
if (f3 <= 0.0f) {
|
|
return this;
|
|
}
|
|
if (z2) {
|
|
if (z) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Anchor keylines cannot be focal.");
|
|
return null;
|
|
}
|
|
int i = this.latestAnchorKeylineIndex;
|
|
if (i != -1 && i != 0) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Anchor keylines must be either the first or last keyline.");
|
|
return null;
|
|
}
|
|
this.latestAnchorKeylineIndex = this.tmpKeylines.size();
|
|
}
|
|
Keyline keyline = new Keyline(Float.MIN_VALUE, f, f2, f3, z2, f4, f5, f6);
|
|
Keyline keyline2 = this.tmpFirstFocalKeyline;
|
|
if (z) {
|
|
if (keyline2 == null) {
|
|
this.tmpFirstFocalKeyline = keyline;
|
|
this.firstFocalKeylineIndex = this.tmpKeylines.size();
|
|
}
|
|
if (this.lastFocalKeylineIndex != -1 && this.tmpKeylines.size() - this.lastFocalKeylineIndex > 1) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Keylines marked as focal must be placed next to each other. There cannot be non-focal keylines between focal keylines.");
|
|
return null;
|
|
}
|
|
if (f3 != this.tmpFirstFocalKeyline.maskedItemSize) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Keylines that are marked as focal must all have the same masked item size.");
|
|
return null;
|
|
}
|
|
this.tmpLastFocalKeyline = keyline;
|
|
this.lastFocalKeylineIndex = this.tmpKeylines.size();
|
|
} else {
|
|
if (keyline2 == null && keyline.maskedItemSize < this.lastKeylineMaskedSize) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Keylines before the first focal keyline must be ordered by incrementing masked item size.");
|
|
return null;
|
|
}
|
|
if (this.tmpLastFocalKeyline != null && keyline.maskedItemSize > this.lastKeylineMaskedSize) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Keylines after the last focal keyline must be ordered by decreasing masked item size.");
|
|
return null;
|
|
}
|
|
}
|
|
this.lastKeylineMaskedSize = keyline.maskedItemSize;
|
|
this.tmpKeylines.add(keyline);
|
|
return this;
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeylineRange(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3, int i, boolean z) {
|
|
if (i > 0 && f3 > 0.0f) {
|
|
for (int i2 = 0; i2 < i; i2++) {
|
|
addKeyline((i2 * f3) + f, f2, f3, z);
|
|
}
|
|
}
|
|
return this;
|
|
}
|
|
|
|
@NonNull
|
|
public KeylineState build() {
|
|
if (this.tmpFirstFocalKeyline == null) {
|
|
Single$$ExternalSyntheticBUOutline0.m$2("There must be a keyline marked as focal.");
|
|
return null;
|
|
}
|
|
ArrayList arrayList = new ArrayList();
|
|
for (int i = 0; i < this.tmpKeylines.size(); i++) {
|
|
Keyline keyline = this.tmpKeylines.get(i);
|
|
arrayList.add(new Keyline(calculateKeylineLocationForItemPosition(this.tmpFirstFocalKeyline.locOffset, this.itemSize, this.firstFocalKeylineIndex, i), keyline.locOffset, keyline.mask, keyline.maskedItemSize, keyline.isAnchor, keyline.cutoff, keyline.leftOrTopPaddingShift, keyline.rightOrBottomPaddingShift));
|
|
}
|
|
return new KeylineState(this.itemSize, arrayList, this.firstFocalKeylineIndex, this.lastFocalKeylineIndex, this.carouselSize);
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeylineRange(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3, int i) {
|
|
return addKeylineRange(f, f2, f3, i, false);
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeyline(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3) {
|
|
return addKeyline(f, f2, f3, false);
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeyline(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3, boolean z) {
|
|
return addKeyline(f, f2, f3, z, false);
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeyline(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3, boolean z, boolean z2, float f4) {
|
|
return addKeyline(f, f2, f3, z, z2, f4, 0.0f, 0.0f);
|
|
}
|
|
|
|
@NonNull
|
|
@CanIgnoreReturnValue
|
|
public Builder addKeyline(float f, @FloatRange(from = 0.0d, to = 1.0d) float f2, float f3, boolean z, boolean z2) {
|
|
float f4;
|
|
float f5 = f3 / 2.0f;
|
|
float f6 = f - f5;
|
|
float f7 = f5 + f;
|
|
int i = this.carouselSize;
|
|
if (f7 > i) {
|
|
f4 = Math.abs(f7 - Math.max(f7 - f3, i));
|
|
} else {
|
|
f4 = 0.0f;
|
|
if (f6 < 0.0f) {
|
|
f4 = Math.abs(f6 - Math.min(f6 + f3, 0.0f));
|
|
}
|
|
}
|
|
return addKeyline(f, f2, f3, z, z2, f4);
|
|
}
|
|
}
|
|
}
|