alexandroid/decompiled/jadx/sources/com/google/android/material/internal/ViewUtils.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

326 lines
13 KiB
Java

package com.google.android.material.internal;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import androidx.annotation.Dimension;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
import androidx.core.content.ContextCompat;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.core.view.WindowInsetsControllerCompat;
import com.google.android.material.R;
import com.google.android.material.drawable.DrawableUtils;
import com.mapbox.common.LifecycleUtils$$ExternalSyntheticLambda2;
import java.util.ArrayList;
import java.util.List;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
/* loaded from: classes7.dex */
public class ViewUtils {
public static final int EDGE_TO_EDGE_FLAGS = 768;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public interface OnApplyWindowInsetsListener {
WindowInsetsCompat onApplyWindowInsets(View view, WindowInsetsCompat windowInsetsCompat, RelativePadding relativePadding);
}
private ViewUtils() {
}
public static void addOnGlobalLayoutListener(@Nullable View view, @NonNull ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener) {
if (view != null) {
view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayoutListener);
}
}
@NonNull
public static Rect calculateOffsetRectFromBounds(@NonNull View view, @NonNull View view2) {
int[] iArr = new int[2];
view2.getLocationOnScreen(iArr);
int i = iArr[0];
int i2 = iArr[1];
int[] iArr2 = new int[2];
view.getLocationOnScreen(iArr2);
int i3 = i - iArr2[0];
int i4 = i2 - iArr2[1];
return new Rect(i3, i4, view2.getWidth() + i3, view2.getHeight() + i4);
}
@NonNull
public static Rect calculateRectFromBounds(@NonNull View view, int i) {
return new Rect(view.getLeft(), view.getTop() + i, view.getRight(), view.getBottom() + i);
}
public static void doOnApplyWindowInsets(@NonNull View view, @Nullable AttributeSet attributeSet, int i, int i2, @Nullable final OnApplyWindowInsetsListener onApplyWindowInsetsListener) {
TypedArray obtainStyledAttributes = view.getContext().obtainStyledAttributes(attributeSet, R.styleable.Insets, i, i2);
final boolean z = obtainStyledAttributes.getBoolean(R.styleable.Insets_paddingBottomSystemWindowInsets, false);
final boolean z2 = obtainStyledAttributes.getBoolean(R.styleable.Insets_paddingLeftSystemWindowInsets, false);
final boolean z3 = obtainStyledAttributes.getBoolean(R.styleable.Insets_paddingRightSystemWindowInsets, false);
obtainStyledAttributes.recycle();
doOnApplyWindowInsets(view, new OnApplyWindowInsetsListener() { // from class: com.google.android.material.internal.ViewUtils.1
@Override // com.google.android.material.internal.ViewUtils.OnApplyWindowInsetsListener
@NonNull
public WindowInsetsCompat onApplyWindowInsets(View view2, @NonNull WindowInsetsCompat windowInsetsCompat, @NonNull RelativePadding relativePadding) {
if (z) {
relativePadding.bottom = windowInsetsCompat.getSystemWindowInsetBottom() + relativePadding.bottom;
}
boolean isLayoutRtl = ViewUtils.isLayoutRtl(view2);
if (z2) {
if (isLayoutRtl) {
relativePadding.end = windowInsetsCompat.getSystemWindowInsetLeft() + relativePadding.end;
} else {
relativePadding.start = windowInsetsCompat.getSystemWindowInsetLeft() + relativePadding.start;
}
}
if (z3) {
if (isLayoutRtl) {
relativePadding.start = windowInsetsCompat.getSystemWindowInsetRight() + relativePadding.start;
} else {
relativePadding.end = windowInsetsCompat.getSystemWindowInsetRight() + relativePadding.end;
}
}
relativePadding.applyToView(view2);
OnApplyWindowInsetsListener onApplyWindowInsetsListener2 = onApplyWindowInsetsListener;
return onApplyWindowInsetsListener2 != null ? onApplyWindowInsetsListener2.onApplyWindowInsets(view2, windowInsetsCompat, relativePadding) : windowInsetsCompat;
}
});
}
public static float dpToPx(@NonNull Context context, @Dimension(unit = 0) int i) {
return TypedValue.applyDimension(1, i, context.getResources().getDisplayMetrics());
}
@Nullable
public static Integer getBackgroundColor(@NonNull View view) {
ColorStateList colorStateListOrNull = DrawableUtils.getColorStateListOrNull(view.getBackground());
if (colorStateListOrNull != null) {
return Integer.valueOf(colorStateListOrNull.getDefaultColor());
}
return null;
}
@NonNull
public static List<View> getChildren(@Nullable View view) {
ArrayList arrayList = new ArrayList();
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int i = 0; i < viewGroup.getChildCount(); i++) {
arrayList.add(viewGroup.getChildAt(i));
}
}
return arrayList;
}
@Nullable
public static ViewGroup getContentView(@Nullable View view) {
if (view == null) {
return null;
}
View rootView = view.getRootView();
ViewGroup viewGroup = (ViewGroup) rootView.findViewById(android.R.id.content);
if (viewGroup != null) {
return viewGroup;
}
if (rootView == view || !(rootView instanceof ViewGroup)) {
return null;
}
return (ViewGroup) rootView;
}
@Nullable
@Deprecated
public static ViewOverlayImpl getContentViewOverlay(@NonNull View view) {
return getOverlay(getContentView(view));
}
@Nullable
private static InputMethodManager getInputMethodManager(@NonNull View view) {
return (InputMethodManager) ContextCompat.getSystemService(view.getContext(), InputMethodManager.class);
}
@Nullable
@Deprecated
public static ViewOverlayImpl getOverlay(@Nullable final View view) {
if (view == null) {
return null;
}
return new ViewOverlayImpl() { // from class: com.google.android.material.internal.ViewUtils.4
@Override // com.google.android.material.internal.ViewOverlayImpl
public void add(@NonNull Drawable drawable) {
view.getOverlay().add(drawable);
}
@Override // com.google.android.material.internal.ViewOverlayImpl
public void remove(@NonNull Drawable drawable) {
view.getOverlay().remove(drawable);
}
};
}
public static float getParentAbsoluteElevation(@NonNull View view) {
float f = 0.0f;
for (ViewParent parent = view.getParent(); parent instanceof View; parent = parent.getParent()) {
f += ((View) parent).getElevation();
}
return f;
}
public static void hideKeyboard(@NonNull View view, boolean z) {
WindowInsetsControllerCompat windowInsetsController;
if (z && (windowInsetsController = ViewCompat.getWindowInsetsController(view)) != null) {
windowInsetsController.hide(WindowInsetsCompat.Type.ime());
return;
}
InputMethodManager inputMethodManager = getInputMethodManager(view);
if (inputMethodManager != null) {
inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public static boolean isLayoutRtl(View view) {
return view.getLayoutDirection() == 1;
}
public static PorterDuff.Mode parseTintMode(int i, PorterDuff.Mode mode) {
if (i == 3) {
return PorterDuff.Mode.SRC_OVER;
}
if (i == 5) {
return PorterDuff.Mode.SRC_IN;
}
if (i == 9) {
return PorterDuff.Mode.SRC_ATOP;
}
switch (i) {
case 14:
return PorterDuff.Mode.MULTIPLY;
case 15:
return PorterDuff.Mode.SCREEN;
case 16:
return PorterDuff.Mode.ADD;
default:
return mode;
}
}
public static void removeOnGlobalLayoutListener(@Nullable View view, @NonNull ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener) {
if (view != null) {
removeOnGlobalLayoutListener(view.getViewTreeObserver(), onGlobalLayoutListener);
}
}
public static void requestApplyInsetsWhenAttached(@NonNull View view) {
if (view.isAttachedToWindow()) {
view.requestApplyInsets();
} else {
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() { // from class: com.google.android.material.internal.ViewUtils.3
@Override // android.view.View.OnAttachStateChangeListener
public void onViewAttachedToWindow(@NonNull View view2) {
view2.removeOnAttachStateChangeListener(this);
view2.requestApplyInsets();
}
@Override // android.view.View.OnAttachStateChangeListener
public void onViewDetachedFromWindow(View view2) {
}
});
}
}
public static void requestFocusAndShowKeyboard(@NonNull View view, boolean z) {
view.requestFocus();
view.post(new LifecycleUtils$$ExternalSyntheticLambda2(view, z, 17));
}
public static void setBoundsFromRect(@NonNull View view, @NonNull Rect rect) {
view.setLeft(rect.left);
view.setTop(rect.top);
view.setRight(rect.right);
view.setBottom(rect.bottom);
}
public static void showKeyboard(@NonNull View view, boolean z) {
WindowInsetsControllerCompat windowInsetsController;
if (!z || (windowInsetsController = ViewCompat.getWindowInsetsController(view)) == null) {
getInputMethodManager(view).showSoftInput(view, 1);
} else {
windowInsetsController.show(WindowInsetsCompat.Type.ime());
}
}
public static void removeOnGlobalLayoutListener(@NonNull ViewTreeObserver viewTreeObserver, @NonNull ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener) {
viewTreeObserver.removeOnGlobalLayoutListener(onGlobalLayoutListener);
}
public static void requestFocusAndShowKeyboard(@NonNull View view) {
requestFocusAndShowKeyboard(view, true);
}
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
public static class RelativePadding {
public int bottom;
public int end;
public int start;
public int top;
public RelativePadding(@NonNull RelativePadding relativePadding) {
this.start = relativePadding.start;
this.top = relativePadding.top;
this.end = relativePadding.end;
this.bottom = relativePadding.bottom;
}
public void applyToView(View view) {
view.setPaddingRelative(this.start, this.top, this.end, this.bottom);
}
public RelativePadding(int i, int i2, int i3, int i4) {
this.start = i;
this.top = i2;
this.end = i3;
this.bottom = i4;
}
}
@NonNull
public static Rect calculateRectFromBounds(@NonNull View view) {
return calculateRectFromBounds(view, 0);
}
public static void showKeyboard(@NonNull View view) {
showKeyboard(view, true);
}
public static void hideKeyboard(@NonNull View view) {
hideKeyboard(view, true);
}
public static void doOnApplyWindowInsets(@NonNull View view, @Nullable AttributeSet attributeSet, int i, int i2) {
doOnApplyWindowInsets(view, attributeSet, i, i2, null);
}
public static void doOnApplyWindowInsets(@NonNull View view, @NonNull final OnApplyWindowInsetsListener onApplyWindowInsetsListener) {
final RelativePadding relativePadding = new RelativePadding(view.getPaddingStart(), view.getPaddingTop(), view.getPaddingEnd(), view.getPaddingBottom());
ViewCompat.setOnApplyWindowInsetsListener(view, new androidx.core.view.OnApplyWindowInsetsListener() { // from class: com.google.android.material.internal.ViewUtils.2
@Override // androidx.core.view.OnApplyWindowInsetsListener
public WindowInsetsCompat onApplyWindowInsets(View view2, WindowInsetsCompat windowInsetsCompat) {
return OnApplyWindowInsetsListener.this.onApplyWindowInsets(view2, windowInsetsCompat, new RelativePadding(relativePadding));
}
});
requestApplyInsetsWhenAttached(view);
}
}