discord-jadx/app/src/main/java/androidx/transition/GhostViewPlatform.java

101 lines
3.5 KiB
Java

package androidx.transition;
import android.graphics.Matrix;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
@RequiresApi(21)
public class GhostViewPlatform implements GhostView {
private static final String TAG = "GhostViewApi21";
private static Method sAddGhostMethod;
private static boolean sAddGhostMethodFetched;
private static Class<?> sGhostViewClass;
private static boolean sGhostViewClassFetched;
private static Method sRemoveGhostMethod;
private static boolean sRemoveGhostMethodFetched;
private final View mGhostView;
private GhostViewPlatform(@NonNull View view) {
this.mGhostView = view;
}
public static GhostView addGhost(View view, ViewGroup viewGroup, Matrix matrix) {
fetchAddGhostMethod();
Method method = sAddGhostMethod;
if (method != null) {
try {
return new GhostViewPlatform((View) method.invoke(null, view, viewGroup, matrix));
} catch (IllegalAccessException unused) {
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getCause());
}
}
return null;
}
private static void fetchAddGhostMethod() {
if (!sAddGhostMethodFetched) {
try {
fetchGhostViewClass();
Method declaredMethod = sGhostViewClass.getDeclaredMethod("addGhost", View.class, ViewGroup.class, Matrix.class);
sAddGhostMethod = declaredMethod;
declaredMethod.setAccessible(true);
} catch (NoSuchMethodException e) {
Log.i("GhostViewApi21", "Failed to retrieve addGhost method", e);
}
sAddGhostMethodFetched = true;
}
}
private static void fetchGhostViewClass() {
if (!sGhostViewClassFetched) {
try {
sGhostViewClass = Class.forName("android.view.GhostView");
} catch (ClassNotFoundException e) {
Log.i("GhostViewApi21", "Failed to retrieve GhostView class", e);
}
sGhostViewClassFetched = true;
}
}
private static void fetchRemoveGhostMethod() {
if (!sRemoveGhostMethodFetched) {
try {
fetchGhostViewClass();
Method declaredMethod = sGhostViewClass.getDeclaredMethod("removeGhost", View.class);
sRemoveGhostMethod = declaredMethod;
declaredMethod.setAccessible(true);
} catch (NoSuchMethodException e) {
Log.i("GhostViewApi21", "Failed to retrieve removeGhost method", e);
}
sRemoveGhostMethodFetched = true;
}
}
public static void removeGhost(View view) {
fetchRemoveGhostMethod();
Method method = sRemoveGhostMethod;
if (method != null) {
try {
method.invoke(null, view);
} catch (IllegalAccessException unused) {
} catch (InvocationTargetException e) {
throw new RuntimeException(e.getCause());
}
}
}
@Override // androidx.transition.GhostView
public void reserveEndViewTransition(ViewGroup viewGroup, View view) {
}
@Override // androidx.transition.GhostView
public void setVisibility(int i) {
this.mGhostView.setVisibility(i);
}
}