discord-jadx/app/src/main/java/androidx/core/widget/PopupWindowCompat.java

123 lines
4.6 KiB
Java

package androidx.core.widget;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.widget.PopupWindow;
import androidx.annotation.NonNull;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
public final class PopupWindowCompat {
private static final String TAG = "PopupWindowCompatApi21";
private static Method sGetWindowLayoutTypeMethod;
private static boolean sGetWindowLayoutTypeMethodAttempted;
private static Field sOverlapAnchorField;
private static boolean sOverlapAnchorFieldAttempted;
private static Method sSetWindowLayoutTypeMethod;
private static boolean sSetWindowLayoutTypeMethodAttempted;
private PopupWindowCompat() {
}
public static boolean getOverlapAnchor(@NonNull PopupWindow popupWindow) {
if (Build.VERSION.SDK_INT >= 23) {
return popupWindow.getOverlapAnchor();
}
if (!sOverlapAnchorFieldAttempted) {
try {
Field declaredField = PopupWindow.class.getDeclaredField("mOverlapAnchor");
sOverlapAnchorField = declaredField;
declaredField.setAccessible(true);
} catch (NoSuchFieldException e) {
Log.i("PopupWindowCompatApi21", "Could not fetch mOverlapAnchor field from PopupWindow", e);
}
sOverlapAnchorFieldAttempted = true;
}
Field field = sOverlapAnchorField;
if (field == null) {
return false;
}
try {
return ((Boolean) field.get(popupWindow)).booleanValue();
} catch (IllegalAccessException e2) {
Log.i("PopupWindowCompatApi21", "Could not get overlap anchor field in PopupWindow", e2);
return false;
}
}
public static int getWindowLayoutType(@NonNull PopupWindow popupWindow) {
if (Build.VERSION.SDK_INT >= 23) {
return popupWindow.getWindowLayoutType();
}
if (!sGetWindowLayoutTypeMethodAttempted) {
try {
Method declaredMethod = PopupWindow.class.getDeclaredMethod("getWindowLayoutType", new Class[0]);
sGetWindowLayoutTypeMethod = declaredMethod;
declaredMethod.setAccessible(true);
} catch (Exception unused) {
}
sGetWindowLayoutTypeMethodAttempted = true;
}
Method method = sGetWindowLayoutTypeMethod;
if (method != null) {
try {
return ((Integer) method.invoke(popupWindow, new Object[0])).intValue();
} catch (Exception unused2) {
}
}
return 0;
}
public static void setOverlapAnchor(@NonNull PopupWindow popupWindow, boolean z2) {
if (Build.VERSION.SDK_INT >= 23) {
popupWindow.setOverlapAnchor(z2);
return;
}
if (!sOverlapAnchorFieldAttempted) {
try {
Field declaredField = PopupWindow.class.getDeclaredField("mOverlapAnchor");
sOverlapAnchorField = declaredField;
declaredField.setAccessible(true);
} catch (NoSuchFieldException e) {
Log.i("PopupWindowCompatApi21", "Could not fetch mOverlapAnchor field from PopupWindow", e);
}
sOverlapAnchorFieldAttempted = true;
}
Field field = sOverlapAnchorField;
if (field != null) {
try {
field.set(popupWindow, Boolean.valueOf(z2));
} catch (IllegalAccessException e2) {
Log.i("PopupWindowCompatApi21", "Could not set overlap anchor field in PopupWindow", e2);
}
}
}
public static void setWindowLayoutType(@NonNull PopupWindow popupWindow, int i) {
if (Build.VERSION.SDK_INT >= 23) {
popupWindow.setWindowLayoutType(i);
return;
}
if (!sSetWindowLayoutTypeMethodAttempted) {
try {
Method declaredMethod = PopupWindow.class.getDeclaredMethod("setWindowLayoutType", Integer.TYPE);
sSetWindowLayoutTypeMethod = declaredMethod;
declaredMethod.setAccessible(true);
} catch (Exception unused) {
}
sSetWindowLayoutTypeMethodAttempted = true;
}
Method method = sSetWindowLayoutTypeMethod;
if (method != null) {
try {
method.invoke(popupWindow, Integer.valueOf(i));
} catch (Exception unused2) {
}
}
}
public static void showAsDropDown(@NonNull PopupWindow popupWindow, @NonNull View view, int i, int i2, int i3) {
popupWindow.showAsDropDown(view, i, i2, i3);
}
}