jimu-decompiled/sources/androidx/core/view/ViewCompat.java
2025-05-13 19:24:51 +02:00

796 lines
24 KiB
Java

package androidx.core.view;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.SparseArray;
import android.view.Display;
import android.view.KeyEvent;
import android.view.PointerIcon;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.WindowInsets;
import android.view.WindowManager;
import androidx.core.R$id;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes.dex */
public class ViewCompat {
private static Field a;
private static boolean b;
private static Field c;
private static boolean d;
private static WeakHashMap<View, String> e;
private static WeakHashMap<View, ViewPropertyAnimatorCompat> f;
private static Field g;
private static boolean h;
private static ThreadLocal<Rect> i;
public interface OnUnhandledKeyEventListenerCompat {
boolean a(View view, KeyEvent keyEvent);
}
static {
new AtomicInteger(1);
f = null;
h = false;
}
public static void A(View view) {
if (Build.VERSION.SDK_INT >= 16) {
view.postInvalidateOnAnimation();
} else {
view.postInvalidate();
}
}
public static void B(View view) {
int i2 = Build.VERSION.SDK_INT;
if (i2 >= 20) {
view.requestApplyInsets();
} else if (i2 >= 16) {
view.requestFitSystemWindows();
}
}
/* JADX WARN: Multi-variable type inference failed */
public static void C(View view) {
if (Build.VERSION.SDK_INT >= 21) {
view.stopNestedScroll();
} else if (view instanceof NestedScrollingChild) {
((NestedScrollingChild) view).stopNestedScroll();
}
}
private static void D(View view) {
float translationY = view.getTranslationY();
view.setTranslationY(1.0f + translationY);
view.setTranslationY(translationY);
}
private static Rect a() {
if (i == null) {
i = new ThreadLocal<>();
}
Rect rect = i.get();
if (rect == null) {
rect = new Rect();
i.set(rect);
}
rect.setEmpty();
return rect;
}
public static void b(View view, boolean z) {
if (Build.VERSION.SDK_INT >= 16) {
view.setHasTransientState(z);
}
}
@Deprecated
public static void c(View view, float f2) {
view.setPivotX(f2);
}
@Deprecated
public static void d(View view, float f2) {
view.setPivotY(f2);
}
public static void e(View view, int i2) {
if (Build.VERSION.SDK_INT >= 19) {
view.setAccessibilityLiveRegion(i2);
}
}
public static void f(View view, int i2) {
int i3 = Build.VERSION.SDK_INT;
if (i3 >= 19) {
view.setImportantForAccessibility(i2);
} else if (i3 >= 16) {
if (i2 == 4) {
i2 = 2;
}
view.setImportantForAccessibility(i2);
}
}
public static void g(View view, int i2) {
if (Build.VERSION.SDK_INT >= 26) {
view.setImportantForAutofill(i2);
}
}
@Deprecated
public static void h(View view, float f2) {
view.setScaleX(f2);
}
public static int i(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.getImportantForAccessibility();
}
return 0;
}
@SuppressLint({"InlinedApi"})
public static int j(View view) {
if (Build.VERSION.SDK_INT >= 26) {
return view.getImportantForAutofill();
}
return 0;
}
public static int k(View view) {
if (Build.VERSION.SDK_INT >= 17) {
return view.getLayoutDirection();
}
return 0;
}
public static int l(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.getMinimumHeight();
}
if (!d) {
try {
c = View.class.getDeclaredField("mMinHeight");
c.setAccessible(true);
} catch (NoSuchFieldException unused) {
}
d = true;
}
Field field = c;
if (field == null) {
return 0;
}
try {
return ((Integer) field.get(view)).intValue();
} catch (Exception unused2) {
return 0;
}
}
public static int m(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.getMinimumWidth();
}
if (!b) {
try {
a = View.class.getDeclaredField("mMinWidth");
a.setAccessible(true);
} catch (NoSuchFieldException unused) {
}
b = true;
}
Field field = a;
if (field == null) {
return 0;
}
try {
return ((Integer) field.get(view)).intValue();
} catch (Exception unused2) {
return 0;
}
}
public static int n(View view) {
return Build.VERSION.SDK_INT >= 17 ? view.getPaddingEnd() : view.getPaddingRight();
}
public static int o(View view) {
return Build.VERSION.SDK_INT >= 17 ? view.getPaddingStart() : view.getPaddingLeft();
}
public static String p(View view) {
if (Build.VERSION.SDK_INT >= 21) {
return view.getTransitionName();
}
WeakHashMap<View, String> weakHashMap = e;
if (weakHashMap == null) {
return null;
}
return weakHashMap.get(view);
}
public static int q(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.getWindowSystemUiVisibility();
}
return 0;
}
public static float r(View view) {
if (Build.VERSION.SDK_INT >= 21) {
return view.getZ();
}
return 0.0f;
}
public static boolean s(View view) {
if (h) {
return false;
}
if (g == null) {
try {
g = View.class.getDeclaredField("mAccessibilityDelegate");
g.setAccessible(true);
} catch (Throwable unused) {
h = true;
return false;
}
}
try {
return g.get(view) != null;
} catch (Throwable unused2) {
h = true;
return false;
}
}
public static boolean t(View view) {
if (Build.VERSION.SDK_INT >= 15) {
return view.hasOnClickListeners();
}
return false;
}
public static boolean u(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.hasOverlappingRendering();
}
return true;
}
public static boolean v(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.hasTransientState();
}
return false;
}
public static boolean w(View view) {
return Build.VERSION.SDK_INT >= 19 ? view.isAttachedToWindow() : view.getWindowToken() != null;
}
public static boolean x(View view) {
return Build.VERSION.SDK_INT >= 19 ? view.isLaidOut() : view.getWidth() > 0 && view.getHeight() > 0;
}
/* JADX WARN: Multi-variable type inference failed */
public static boolean y(View view) {
if (Build.VERSION.SDK_INT >= 21) {
return view.isNestedScrollingEnabled();
}
if (view instanceof NestedScrollingChild) {
return ((NestedScrollingChild) view).isNestedScrollingEnabled();
}
return false;
}
public static boolean z(View view) {
if (Build.VERSION.SDK_INT >= 17) {
return view.isPaddingRelative();
}
return false;
}
/* JADX WARN: Multi-variable type inference failed */
public static ColorStateList c(View view) {
if (Build.VERSION.SDK_INT >= 21) {
return view.getBackgroundTintList();
}
if (view instanceof TintableBackgroundView) {
return ((TintableBackgroundView) view).getSupportBackgroundTintList();
}
return null;
}
/* JADX WARN: Multi-variable type inference failed */
public static PorterDuff.Mode d(View view) {
if (Build.VERSION.SDK_INT >= 21) {
return view.getBackgroundTintMode();
}
if (view instanceof TintableBackgroundView) {
return ((TintableBackgroundView) view).getSupportBackgroundTintMode();
}
return null;
}
public static boolean h(View view) {
if (Build.VERSION.SDK_INT >= 16) {
return view.getFitsSystemWindows();
}
return false;
}
static class UnhandledKeyEventManager {
private static final ArrayList<WeakReference<View>> d = new ArrayList<>();
private WeakHashMap<View, Boolean> a = null;
private SparseArray<WeakReference<View>> b = null;
private WeakReference<KeyEvent> c = null;
UnhandledKeyEventManager() {
}
private SparseArray<WeakReference<View>> a() {
if (this.b == null) {
this.b = new SparseArray<>();
}
return this.b;
}
private View b(View view, KeyEvent keyEvent) {
WeakHashMap<View, Boolean> weakHashMap = this.a;
if (weakHashMap != null && weakHashMap.containsKey(view)) {
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
for (int childCount = viewGroup.getChildCount() - 1; childCount >= 0; childCount--) {
View b = b(viewGroup.getChildAt(childCount), keyEvent);
if (b != null) {
return b;
}
}
}
if (c(view, keyEvent)) {
return view;
}
}
return null;
}
private boolean c(View view, KeyEvent keyEvent) {
ArrayList arrayList = (ArrayList) view.getTag(R$id.tag_unhandled_key_listeners);
if (arrayList == null) {
return false;
}
for (int size = arrayList.size() - 1; size >= 0; size--) {
if (((OnUnhandledKeyEventListenerCompat) arrayList.get(size)).a(view, keyEvent)) {
return true;
}
}
return false;
}
static UnhandledKeyEventManager a(View view) {
UnhandledKeyEventManager unhandledKeyEventManager = (UnhandledKeyEventManager) view.getTag(R$id.tag_unhandled_key_event_manager);
if (unhandledKeyEventManager != null) {
return unhandledKeyEventManager;
}
UnhandledKeyEventManager unhandledKeyEventManager2 = new UnhandledKeyEventManager();
view.setTag(R$id.tag_unhandled_key_event_manager, unhandledKeyEventManager2);
return unhandledKeyEventManager2;
}
private void b() {
WeakHashMap<View, Boolean> weakHashMap = this.a;
if (weakHashMap != null) {
weakHashMap.clear();
}
if (d.isEmpty()) {
return;
}
synchronized (d) {
if (this.a == null) {
this.a = new WeakHashMap<>();
}
for (int size = d.size() - 1; size >= 0; size--) {
View view = d.get(size).get();
if (view == null) {
d.remove(size);
} else {
this.a.put(view, Boolean.TRUE);
for (ViewParent parent = view.getParent(); parent instanceof View; parent = parent.getParent()) {
this.a.put((View) parent, Boolean.TRUE);
}
}
}
}
}
boolean a(View view, KeyEvent keyEvent) {
if (keyEvent.getAction() == 0) {
b();
}
View b = b(view, keyEvent);
if (keyEvent.getAction() == 0) {
int keyCode = keyEvent.getKeyCode();
if (b != null && !KeyEvent.isModifierKey(keyCode)) {
a().put(keyCode, new WeakReference<>(b));
}
}
return b != null;
}
boolean a(KeyEvent keyEvent) {
int indexOfKey;
WeakReference<KeyEvent> weakReference = this.c;
if (weakReference != null && weakReference.get() == keyEvent) {
return false;
}
this.c = new WeakReference<>(keyEvent);
WeakReference<View> weakReference2 = null;
SparseArray<WeakReference<View>> a = a();
if (keyEvent.getAction() == 1 && (indexOfKey = a.indexOfKey(keyEvent.getKeyCode())) >= 0) {
weakReference2 = a.valueAt(indexOfKey);
a.removeAt(indexOfKey);
}
if (weakReference2 == null) {
weakReference2 = a.get(keyEvent.getKeyCode());
}
if (weakReference2 == null) {
return false;
}
View view = weakReference2.get();
if (view != null && ViewCompat.w(view)) {
c(view, keyEvent);
}
return true;
}
}
public static int b(View view) {
if (Build.VERSION.SDK_INT >= 19) {
return view.getAccessibilityLiveRegion();
}
return 0;
}
@Deprecated
public static void e(View view, float f2) {
view.setRotation(f2);
}
@Deprecated
public static void g(View view, float f2) {
view.setRotationY(f2);
}
@Deprecated
public static void i(View view, float f2) {
view.setScaleY(f2);
}
@Deprecated
public static void j(View view, float f2) {
view.setTranslationX(f2);
}
@Deprecated
public static void k(View view, float f2) {
view.setTranslationY(f2);
}
public static Rect e(View view) {
if (Build.VERSION.SDK_INT >= 18) {
return view.getClipBounds();
}
return null;
}
@Deprecated
public static void f(View view, float f2) {
view.setRotationX(f2);
}
public static float g(View view) {
if (Build.VERSION.SDK_INT >= 21) {
return view.getElevation();
}
return 0.0f;
}
/* JADX WARN: Multi-variable type inference failed */
public static void h(View view, int i2) {
if (view instanceof NestedScrollingChild2) {
((NestedScrollingChild2) view).a(i2);
} else if (i2 == 0) {
C(view);
}
}
public static void b(View view, float f2) {
if (Build.VERSION.SDK_INT >= 21) {
view.setElevation(f2);
}
}
public static Display f(View view) {
if (Build.VERSION.SDK_INT >= 17) {
return view.getDisplay();
}
if (w(view)) {
return ((WindowManager) view.getContext().getSystemService("window")).getDefaultDisplay();
}
return null;
}
public static void c(View view, int i2) {
int i3 = Build.VERSION.SDK_INT;
if (i3 >= 23) {
view.offsetLeftAndRight(i2);
return;
}
if (i3 >= 21) {
Rect a2 = a();
boolean z = false;
Object parent = view.getParent();
if (parent instanceof View) {
View view2 = (View) parent;
a2.set(view2.getLeft(), view2.getTop(), view2.getRight(), view2.getBottom());
z = !a2.intersects(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
a(view, i2);
if (z && a2.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
((View) parent).invalidate(a2);
return;
}
return;
}
a(view, i2);
}
public static void d(View view, int i2) {
int i3 = Build.VERSION.SDK_INT;
if (i3 >= 23) {
view.offsetTopAndBottom(i2);
return;
}
if (i3 >= 21) {
Rect a2 = a();
boolean z = false;
Object parent = view.getParent();
if (parent instanceof View) {
View view2 = (View) parent;
a2.set(view2.getLeft(), view2.getTop(), view2.getRight(), view2.getBottom());
z = !a2.intersects(view.getLeft(), view.getTop(), view.getRight(), view.getBottom());
}
b(view, i2);
if (z && a2.intersect(view.getLeft(), view.getTop(), view.getRight(), view.getBottom())) {
((View) parent).invalidate(a2);
return;
}
return;
}
b(view, i2);
}
public static void a(View view, AccessibilityDelegateCompat accessibilityDelegateCompat) {
view.setAccessibilityDelegate(accessibilityDelegateCompat == null ? null : accessibilityDelegateCompat.a());
}
public static WindowInsetsCompat b(View view, WindowInsetsCompat windowInsetsCompat) {
if (Build.VERSION.SDK_INT < 21) {
return windowInsetsCompat;
}
WindowInsets windowInsets = (WindowInsets) WindowInsetsCompat.a(windowInsetsCompat);
WindowInsets onApplyWindowInsets = view.onApplyWindowInsets(windowInsets);
if (onApplyWindowInsets != windowInsets) {
windowInsets = new WindowInsets(onApplyWindowInsets);
}
return WindowInsetsCompat.a(windowInsets);
}
public static void a(View view, Runnable runnable) {
if (Build.VERSION.SDK_INT >= 16) {
view.postOnAnimation(runnable);
} else {
view.postDelayed(runnable, ValueAnimator.getFrameDelay());
}
}
public static void a(View view, Runnable runnable, long j) {
if (Build.VERSION.SDK_INT >= 16) {
view.postOnAnimationDelayed(runnable, j);
} else {
view.postDelayed(runnable, ValueAnimator.getFrameDelay() + j);
}
}
private static void b(View view, int i2) {
view.offsetTopAndBottom(i2);
if (view.getVisibility() == 0) {
D(view);
Object parent = view.getParent();
if (parent instanceof View) {
D((View) parent);
}
}
}
public static void a(View view, int i2, int i3, int i4, int i5) {
if (Build.VERSION.SDK_INT >= 17) {
view.setPaddingRelative(i2, i3, i4, i5);
} else {
view.setPadding(i2, i3, i4, i5);
}
}
public static ViewPropertyAnimatorCompat a(View view) {
if (f == null) {
f = new WeakHashMap<>();
}
ViewPropertyAnimatorCompat viewPropertyAnimatorCompat = f.get(view);
if (viewPropertyAnimatorCompat != null) {
return viewPropertyAnimatorCompat;
}
ViewPropertyAnimatorCompat viewPropertyAnimatorCompat2 = new ViewPropertyAnimatorCompat(view);
f.put(view, viewPropertyAnimatorCompat2);
return viewPropertyAnimatorCompat2;
}
static boolean b(View view, KeyEvent keyEvent) {
if (Build.VERSION.SDK_INT >= 28) {
return false;
}
return UnhandledKeyEventManager.a(view).a(keyEvent);
}
@Deprecated
public static void a(View view, float f2) {
view.setAlpha(f2);
}
public static void a(View view, String str) {
if (Build.VERSION.SDK_INT >= 21) {
view.setTransitionName(str);
return;
}
if (e == null) {
e = new WeakHashMap<>();
}
e.put(view, str);
}
@Deprecated
public static void a(View view, boolean z) {
view.setFitsSystemWindows(z);
}
public static void a(View view, final OnApplyWindowInsetsListener onApplyWindowInsetsListener) {
if (Build.VERSION.SDK_INT >= 21) {
if (onApplyWindowInsetsListener == null) {
view.setOnApplyWindowInsetsListener(null);
} else {
view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() { // from class: androidx.core.view.ViewCompat.1
@Override // android.view.View.OnApplyWindowInsetsListener
public WindowInsets onApplyWindowInsets(View view2, WindowInsets windowInsets) {
return (WindowInsets) WindowInsetsCompat.a(OnApplyWindowInsetsListener.this.a(view2, WindowInsetsCompat.a(windowInsets)));
}
});
}
}
}
public static WindowInsetsCompat a(View view, WindowInsetsCompat windowInsetsCompat) {
if (Build.VERSION.SDK_INT < 21) {
return windowInsetsCompat;
}
WindowInsets windowInsets = (WindowInsets) WindowInsetsCompat.a(windowInsetsCompat);
WindowInsets dispatchApplyWindowInsets = view.dispatchApplyWindowInsets(windowInsets);
if (dispatchApplyWindowInsets != windowInsets) {
windowInsets = new WindowInsets(dispatchApplyWindowInsets);
}
return WindowInsetsCompat.a(windowInsets);
}
public static void a(View view, Drawable drawable) {
if (Build.VERSION.SDK_INT >= 16) {
view.setBackground(drawable);
} else {
view.setBackgroundDrawable(drawable);
}
}
/* JADX WARN: Multi-variable type inference failed */
public static void a(View view, ColorStateList colorStateList) {
if (Build.VERSION.SDK_INT >= 21) {
view.setBackgroundTintList(colorStateList);
if (Build.VERSION.SDK_INT == 21) {
Drawable background = view.getBackground();
boolean z = (view.getBackgroundTintList() == null && view.getBackgroundTintMode() == null) ? false : true;
if (background == null || !z) {
return;
}
if (background.isStateful()) {
background.setState(view.getDrawableState());
}
view.setBackground(background);
return;
}
return;
}
if (view instanceof TintableBackgroundView) {
((TintableBackgroundView) view).setSupportBackgroundTintList(colorStateList);
}
}
/* JADX WARN: Multi-variable type inference failed */
public static void a(View view, PorterDuff.Mode mode) {
if (Build.VERSION.SDK_INT >= 21) {
view.setBackgroundTintMode(mode);
if (Build.VERSION.SDK_INT == 21) {
Drawable background = view.getBackground();
boolean z = (view.getBackgroundTintList() == null && view.getBackgroundTintMode() == null) ? false : true;
if (background == null || !z) {
return;
}
if (background.isStateful()) {
background.setState(view.getDrawableState());
}
view.setBackground(background);
return;
}
return;
}
if (view instanceof TintableBackgroundView) {
((TintableBackgroundView) view).setSupportBackgroundTintMode(mode);
}
}
private static void a(View view, int i2) {
view.offsetLeftAndRight(i2);
if (view.getVisibility() == 0) {
D(view);
Object parent = view.getParent();
if (parent instanceof View) {
D((View) parent);
}
}
}
public static void a(View view, Rect rect) {
if (Build.VERSION.SDK_INT >= 18) {
view.setClipBounds(rect);
}
}
public static void a(View view, int i2, int i3) {
if (Build.VERSION.SDK_INT >= 23) {
view.setScrollIndicators(i2, i3);
}
}
public static void a(View view, PointerIconCompat pointerIconCompat) {
if (Build.VERSION.SDK_INT >= 24) {
view.setPointerIcon((PointerIcon) (pointerIconCompat != null ? pointerIconCompat.a() : null));
}
}
static boolean a(View view, KeyEvent keyEvent) {
if (Build.VERSION.SDK_INT >= 28) {
return false;
}
return UnhandledKeyEventManager.a(view).a(view, keyEvent);
}
}