discord-jadx/app/src/main/java/androidx/core/view/WindowInsetsCompat.java

688 lines
24 KiB
Java

package androidx.core.view;
import android.graphics.Rect;
import android.os.Build;
import android.util.Log;
import android.view.WindowInsets;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;
import androidx.core.graphics.Insets;
import androidx.core.util.ObjectsCompat;
import androidx.core.util.Preconditions;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.Objects;
public class WindowInsetsCompat {
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
public static final WindowInsetsCompat CONSUMED = new Builder().build().consumeDisplayCutout().consumeStableInsets().consumeSystemWindowInsets();
private static final String TAG = "WindowInsetsCompat";
private final Impl mImpl;
public static final class Builder {
private final BuilderImpl mImpl;
public Builder() {
if (Build.VERSION.SDK_INT >= 29) {
this.mImpl = new BuilderImpl29();
} else {
this.mImpl = new BuilderImpl20();
}
}
public Builder(@NonNull WindowInsetsCompat windowInsetsCompat) {
if (Build.VERSION.SDK_INT >= 29) {
this.mImpl = new BuilderImpl29(windowInsetsCompat);
} else {
this.mImpl = new BuilderImpl20(windowInsetsCompat);
}
}
@NonNull
public WindowInsetsCompat build() {
return this.mImpl.build();
}
@NonNull
public Builder setDisplayCutout(@Nullable DisplayCutoutCompat displayCutoutCompat) {
this.mImpl.setDisplayCutout(displayCutoutCompat);
return this;
}
@NonNull
public Builder setMandatorySystemGestureInsets(@NonNull Insets insets) {
this.mImpl.setMandatorySystemGestureInsets(insets);
return this;
}
@NonNull
public Builder setStableInsets(@NonNull Insets insets) {
this.mImpl.setStableInsets(insets);
return this;
}
@NonNull
public Builder setSystemGestureInsets(@NonNull Insets insets) {
this.mImpl.setSystemGestureInsets(insets);
return this;
}
@NonNull
public Builder setSystemWindowInsets(@NonNull Insets insets) {
this.mImpl.setSystemWindowInsets(insets);
return this;
}
@NonNull
public Builder setTappableElementInsets(@NonNull Insets insets) {
this.mImpl.setTappableElementInsets(insets);
return this;
}
}
public static class BuilderImpl {
private final WindowInsetsCompat mInsets;
public BuilderImpl() {
this(new WindowInsetsCompat((WindowInsetsCompat) null));
}
public BuilderImpl(@NonNull WindowInsetsCompat windowInsetsCompat) {
this.mInsets = windowInsetsCompat;
}
@NonNull
public WindowInsetsCompat build() {
return this.mInsets;
}
public void setDisplayCutout(@Nullable DisplayCutoutCompat displayCutoutCompat) {
}
public void setMandatorySystemGestureInsets(@NonNull Insets insets) {
}
public void setStableInsets(@NonNull Insets insets) {
}
public void setSystemGestureInsets(@NonNull Insets insets) {
}
public void setSystemWindowInsets(@NonNull Insets insets) {
}
public void setTappableElementInsets(@NonNull Insets insets) {
}
}
@RequiresApi(api = 20)
public static class BuilderImpl20 extends BuilderImpl {
private static Constructor<WindowInsets> sConstructor = null;
private static boolean sConstructorFetched = false;
private static Field sConsumedField = null;
private static boolean sConsumedFieldFetched = false;
private WindowInsets mInsets;
public BuilderImpl20() {
this.mInsets = createWindowInsetsInstance();
}
public BuilderImpl20(@NonNull WindowInsetsCompat windowInsetsCompat) {
this.mInsets = windowInsetsCompat.toWindowInsets();
}
@Nullable
private static WindowInsets createWindowInsetsInstance() {
if (!sConsumedFieldFetched) {
try {
sConsumedField = WindowInsets.class.getDeclaredField("CONSUMED");
} catch (ReflectiveOperationException e) {
Log.i(WindowInsetsCompat.TAG, "Could not retrieve WindowInsets.CONSUMED field", e);
}
sConsumedFieldFetched = true;
}
Field field = sConsumedField;
if (field != null) {
try {
WindowInsets windowInsets = (WindowInsets) field.get(null);
if (windowInsets != null) {
return new WindowInsets(windowInsets);
}
} catch (ReflectiveOperationException e2) {
Log.i(WindowInsetsCompat.TAG, "Could not get value from WindowInsets.CONSUMED field", e2);
}
}
if (!sConstructorFetched) {
try {
sConstructor = WindowInsets.class.getConstructor(Rect.class);
} catch (ReflectiveOperationException e3) {
Log.i(WindowInsetsCompat.TAG, "Could not retrieve WindowInsets(Rect) constructor", e3);
}
sConstructorFetched = true;
}
Constructor<WindowInsets> constructor = sConstructor;
if (constructor != null) {
try {
return constructor.newInstance(new Rect());
} catch (ReflectiveOperationException e4) {
Log.i(WindowInsetsCompat.TAG, "Could not invoke WindowInsets(Rect) constructor", e4);
}
}
return null;
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
@NonNull
public WindowInsetsCompat build() {
return WindowInsetsCompat.toWindowInsetsCompat(this.mInsets);
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setSystemWindowInsets(@NonNull Insets insets) {
WindowInsets windowInsets = this.mInsets;
if (windowInsets != null) {
this.mInsets = windowInsets.replaceSystemWindowInsets(insets.left, insets.top, insets.right, insets.bottom);
}
}
}
@RequiresApi(api = 29)
public static class BuilderImpl29 extends BuilderImpl {
public final WindowInsets.Builder mPlatBuilder;
public BuilderImpl29() {
this.mPlatBuilder = new WindowInsets.Builder();
}
public BuilderImpl29(@NonNull WindowInsetsCompat windowInsetsCompat) {
WindowInsets windowInsets = windowInsetsCompat.toWindowInsets();
this.mPlatBuilder = windowInsets != null ? new WindowInsets.Builder(windowInsets) : new WindowInsets.Builder();
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
@NonNull
public WindowInsetsCompat build() {
return WindowInsetsCompat.toWindowInsetsCompat(this.mPlatBuilder.build());
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setDisplayCutout(@Nullable DisplayCutoutCompat displayCutoutCompat) {
this.mPlatBuilder.setDisplayCutout(displayCutoutCompat != null ? displayCutoutCompat.unwrap() : null);
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setMandatorySystemGestureInsets(@NonNull Insets insets) {
this.mPlatBuilder.setMandatorySystemGestureInsets(insets.toPlatformInsets());
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setStableInsets(@NonNull Insets insets) {
this.mPlatBuilder.setStableInsets(insets.toPlatformInsets());
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setSystemGestureInsets(@NonNull Insets insets) {
this.mPlatBuilder.setSystemGestureInsets(insets.toPlatformInsets());
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setSystemWindowInsets(@NonNull Insets insets) {
this.mPlatBuilder.setSystemWindowInsets(insets.toPlatformInsets());
}
@Override // androidx.core.view.WindowInsetsCompat.BuilderImpl
public void setTappableElementInsets(@NonNull Insets insets) {
this.mPlatBuilder.setTappableElementInsets(insets.toPlatformInsets());
}
}
public static class Impl {
public final WindowInsetsCompat mHost;
public Impl(@NonNull WindowInsetsCompat windowInsetsCompat) {
this.mHost = windowInsetsCompat;
}
@NonNull
public WindowInsetsCompat consumeDisplayCutout() {
return this.mHost;
}
@NonNull
public WindowInsetsCompat consumeStableInsets() {
return this.mHost;
}
@NonNull
public WindowInsetsCompat consumeSystemWindowInsets() {
return this.mHost;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Impl)) {
return false;
}
Impl impl = (Impl) obj;
return isRound() == impl.isRound() && isConsumed() == impl.isConsumed() && ObjectsCompat.equals(getSystemWindowInsets(), impl.getSystemWindowInsets()) && ObjectsCompat.equals(getStableInsets(), impl.getStableInsets()) && ObjectsCompat.equals(getDisplayCutout(), impl.getDisplayCutout());
}
@Nullable
public DisplayCutoutCompat getDisplayCutout() {
return null;
}
@NonNull
public Insets getMandatorySystemGestureInsets() {
return getSystemWindowInsets();
}
@NonNull
public Insets getStableInsets() {
return Insets.NONE;
}
@NonNull
public Insets getSystemGestureInsets() {
return getSystemWindowInsets();
}
@NonNull
public Insets getSystemWindowInsets() {
return Insets.NONE;
}
@NonNull
public Insets getTappableElementInsets() {
return getSystemWindowInsets();
}
public int hashCode() {
return ObjectsCompat.hash(Boolean.valueOf(isRound()), Boolean.valueOf(isConsumed()), getSystemWindowInsets(), getStableInsets(), getDisplayCutout());
}
@NonNull
public WindowInsetsCompat inset(int i, int i2, int i3, int i4) {
return WindowInsetsCompat.CONSUMED;
}
public boolean isConsumed() {
return false;
}
public boolean isRound() {
return false;
}
}
@RequiresApi(20)
public static class Impl20 extends Impl {
@NonNull
public final WindowInsets mPlatformInsets;
private Insets mSystemWindowInsets;
public Impl20(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull WindowInsets windowInsets) {
super(windowInsetsCompat);
this.mSystemWindowInsets = null;
this.mPlatformInsets = windowInsets;
}
public Impl20(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull Impl20 impl20) {
this(windowInsetsCompat, new WindowInsets(impl20.mPlatformInsets));
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public final Insets getSystemWindowInsets() {
if (this.mSystemWindowInsets == null) {
this.mSystemWindowInsets = Insets.of(this.mPlatformInsets.getSystemWindowInsetLeft(), this.mPlatformInsets.getSystemWindowInsetTop(), this.mPlatformInsets.getSystemWindowInsetRight(), this.mPlatformInsets.getSystemWindowInsetBottom());
}
return this.mSystemWindowInsets;
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public WindowInsetsCompat inset(int i, int i2, int i3, int i4) {
Builder builder = new Builder(WindowInsetsCompat.toWindowInsetsCompat(this.mPlatformInsets));
builder.setSystemWindowInsets(WindowInsetsCompat.insetInsets(getSystemWindowInsets(), i, i2, i3, i4));
builder.setStableInsets(WindowInsetsCompat.insetInsets(getStableInsets(), i, i2, i3, i4));
return builder.build();
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
public boolean isRound() {
return this.mPlatformInsets.isRound();
}
}
@RequiresApi(21)
public static class Impl21 extends Impl20 {
private Insets mStableInsets = null;
public Impl21(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull WindowInsets windowInsets) {
super(windowInsetsCompat, windowInsets);
}
public Impl21(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull Impl21 impl21) {
super(windowInsetsCompat, impl21);
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public WindowInsetsCompat consumeStableInsets() {
return WindowInsetsCompat.toWindowInsetsCompat(this.mPlatformInsets.consumeStableInsets());
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public WindowInsetsCompat consumeSystemWindowInsets() {
return WindowInsetsCompat.toWindowInsetsCompat(this.mPlatformInsets.consumeSystemWindowInsets());
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public final Insets getStableInsets() {
if (this.mStableInsets == null) {
this.mStableInsets = Insets.of(this.mPlatformInsets.getStableInsetLeft(), this.mPlatformInsets.getStableInsetTop(), this.mPlatformInsets.getStableInsetRight(), this.mPlatformInsets.getStableInsetBottom());
}
return this.mStableInsets;
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
public boolean isConsumed() {
return this.mPlatformInsets.isConsumed();
}
}
@RequiresApi(28)
public static class Impl28 extends Impl21 {
public Impl28(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull WindowInsets windowInsets) {
super(windowInsetsCompat, windowInsets);
}
public Impl28(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull Impl28 impl28) {
super(windowInsetsCompat, impl28);
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public WindowInsetsCompat consumeDisplayCutout() {
return WindowInsetsCompat.toWindowInsetsCompat(this.mPlatformInsets.consumeDisplayCutout());
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Impl28)) {
return false;
}
return Objects.equals(this.mPlatformInsets, ((Impl28) obj).mPlatformInsets);
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@Nullable
public DisplayCutoutCompat getDisplayCutout() {
return DisplayCutoutCompat.wrap(this.mPlatformInsets.getDisplayCutout());
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
public int hashCode() {
return this.mPlatformInsets.hashCode();
}
}
@RequiresApi(29)
public static class Impl29 extends Impl28 {
private Insets mMandatorySystemGestureInsets = null;
private Insets mSystemGestureInsets = null;
private Insets mTappableElementInsets = null;
public Impl29(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull WindowInsets windowInsets) {
super(windowInsetsCompat, windowInsets);
}
public Impl29(@NonNull WindowInsetsCompat windowInsetsCompat, @NonNull Impl29 impl29) {
super(windowInsetsCompat, impl29);
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public Insets getMandatorySystemGestureInsets() {
if (this.mMandatorySystemGestureInsets == null) {
this.mMandatorySystemGestureInsets = Insets.toCompatInsets(this.mPlatformInsets.getMandatorySystemGestureInsets());
}
return this.mMandatorySystemGestureInsets;
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public Insets getSystemGestureInsets() {
if (this.mSystemGestureInsets == null) {
this.mSystemGestureInsets = Insets.toCompatInsets(this.mPlatformInsets.getSystemGestureInsets());
}
return this.mSystemGestureInsets;
}
@Override // androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public Insets getTappableElementInsets() {
if (this.mTappableElementInsets == null) {
this.mTappableElementInsets = Insets.toCompatInsets(this.mPlatformInsets.getTappableElementInsets());
}
return this.mTappableElementInsets;
}
@Override // androidx.core.view.WindowInsetsCompat.Impl20, androidx.core.view.WindowInsetsCompat.Impl
@NonNull
public WindowInsetsCompat inset(int i, int i2, int i3, int i4) {
return WindowInsetsCompat.toWindowInsetsCompat(this.mPlatformInsets.inset(i, i2, i3, i4));
}
}
@RequiresApi(20)
private WindowInsetsCompat(@NonNull WindowInsets windowInsets) {
int i = Build.VERSION.SDK_INT;
if (i >= 29) {
this.mImpl = new Impl29(this, windowInsets);
} else if (i >= 28) {
this.mImpl = new Impl28(this, windowInsets);
} else {
this.mImpl = new Impl21(this, windowInsets);
}
}
public WindowInsetsCompat(@Nullable WindowInsetsCompat windowInsetsCompat) {
if (windowInsetsCompat != null) {
Impl impl = windowInsetsCompat.mImpl;
int i = Build.VERSION.SDK_INT;
if (i >= 29 && (impl instanceof Impl29)) {
this.mImpl = new Impl29(this, (Impl29) impl);
} else if (i >= 28 && (impl instanceof Impl28)) {
this.mImpl = new Impl28(this, (Impl28) impl);
} else if (impl instanceof Impl21) {
this.mImpl = new Impl21(this, (Impl21) impl);
} else if (impl instanceof Impl20) {
this.mImpl = new Impl20(this, (Impl20) impl);
} else {
this.mImpl = new Impl(this);
}
} else {
this.mImpl = new Impl(this);
}
}
public static Insets insetInsets(Insets insets, int i, int i2, int i3, int i4) {
int max = Math.max(0, insets.left - i);
int max2 = Math.max(0, insets.top - i2);
int max3 = Math.max(0, insets.right - i3);
int max4 = Math.max(0, insets.bottom - i4);
return (max == i && max2 == i2 && max3 == i3 && max4 == i4) ? insets : Insets.of(max, max2, max3, max4);
}
@NonNull
@RequiresApi(20)
public static WindowInsetsCompat toWindowInsetsCompat(@NonNull WindowInsets windowInsets) {
return new WindowInsetsCompat((WindowInsets) Preconditions.checkNotNull(windowInsets));
}
@NonNull
public WindowInsetsCompat consumeDisplayCutout() {
return this.mImpl.consumeDisplayCutout();
}
@NonNull
public WindowInsetsCompat consumeStableInsets() {
return this.mImpl.consumeStableInsets();
}
@NonNull
public WindowInsetsCompat consumeSystemWindowInsets() {
return this.mImpl.consumeSystemWindowInsets();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof WindowInsetsCompat)) {
return false;
}
return ObjectsCompat.equals(this.mImpl, ((WindowInsetsCompat) obj).mImpl);
}
@Nullable
public DisplayCutoutCompat getDisplayCutout() {
return this.mImpl.getDisplayCutout();
}
@NonNull
public Insets getMandatorySystemGestureInsets() {
return this.mImpl.getMandatorySystemGestureInsets();
}
public int getStableInsetBottom() {
return getStableInsets().bottom;
}
public int getStableInsetLeft() {
return getStableInsets().left;
}
public int getStableInsetRight() {
return getStableInsets().right;
}
public int getStableInsetTop() {
return getStableInsets().top;
}
@NonNull
public Insets getStableInsets() {
return this.mImpl.getStableInsets();
}
@NonNull
public Insets getSystemGestureInsets() {
return this.mImpl.getSystemGestureInsets();
}
public int getSystemWindowInsetBottom() {
return getSystemWindowInsets().bottom;
}
public int getSystemWindowInsetLeft() {
return getSystemWindowInsets().left;
}
public int getSystemWindowInsetRight() {
return getSystemWindowInsets().right;
}
public int getSystemWindowInsetTop() {
return getSystemWindowInsets().top;
}
@NonNull
public Insets getSystemWindowInsets() {
return this.mImpl.getSystemWindowInsets();
}
@NonNull
public Insets getTappableElementInsets() {
return this.mImpl.getTappableElementInsets();
}
public boolean hasInsets() {
if (!hasSystemWindowInsets() && !hasStableInsets() && getDisplayCutout() == null) {
Insets systemGestureInsets = getSystemGestureInsets();
Insets insets = Insets.NONE;
if (systemGestureInsets.equals(insets) && getMandatorySystemGestureInsets().equals(insets) && getTappableElementInsets().equals(insets)) {
return false;
}
}
return true;
}
public boolean hasStableInsets() {
return !getStableInsets().equals(Insets.NONE);
}
public boolean hasSystemWindowInsets() {
return !getSystemWindowInsets().equals(Insets.NONE);
}
public int hashCode() {
Impl impl = this.mImpl;
if (impl == null) {
return 0;
}
return impl.hashCode();
}
@NonNull
public WindowInsetsCompat inset(@IntRange(from = 0) int i, @IntRange(from = 0) int i2, @IntRange(from = 0) int i3, @IntRange(from = 0) int i4) {
return this.mImpl.inset(i, i2, i3, i4);
}
@NonNull
public WindowInsetsCompat inset(@NonNull Insets insets) {
return inset(insets.left, insets.top, insets.right, insets.bottom);
}
public boolean isConsumed() {
return this.mImpl.isConsumed();
}
public boolean isRound() {
return this.mImpl.isRound();
}
@NonNull
@Deprecated
public WindowInsetsCompat replaceSystemWindowInsets(int i, int i2, int i3, int i4) {
return new Builder(this).setSystemWindowInsets(Insets.of(i, i2, i3, i4)).build();
}
@NonNull
@Deprecated
public WindowInsetsCompat replaceSystemWindowInsets(@NonNull Rect rect) {
return new Builder(this).setSystemWindowInsets(Insets.of(rect)).build();
}
@Nullable
@RequiresApi(20)
public WindowInsets toWindowInsets() {
Impl impl = this.mImpl;
if (impl instanceof Impl20) {
return ((Impl20) impl).mPlatformInsets;
}
return null;
}
}