无痛单词 v1.8.1版本的 MD5 值为:7ae56c6858542fe70230b6be4f1a4b5a
以下内容为反编译后的 ActivityLifecycleImpl.java 源代码,内容仅作参考
package com.kongzue.dialogx.impl;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.util.ArrayMap;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.kongzue.dialogx.DialogX;
import com.kongzue.dialogx.interfaces.BaseDialog;
import com.kongzue.dialogx.util.DialogXFloatingWindowActivity;
import java.lang.reflect.Field;
public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallbacks {
private static ActivityLifecycleImpl activityLifecycle;
private static Application application;
private onActivityResumeCallBack onActivityResumeCallBack;
public interface onActivityResumeCallBack {
void getActivity(Activity activity);
}
public ActivityLifecycleImpl(onActivityResumeCallBack onactivityresumecallback) {
this.onActivityResumeCallBack = onactivityresumecallback;
}
public static Application getApplicationContext() {
Application application2 = application;
if (application2 != null) {
return application2;
}
try {
try {
return (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication", new Class[0]).invoke(null, null);
} catch (Exception unused) {
return (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", new Class[0]).invoke(null, null);
}
} catch (Exception unused2) {
return null;
}
}
public static Application getApplicationContext(Context context) {
if (context != null) {
return (Application) context.getApplicationContext();
}
try {
try {
return (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication", new Class[0]).invoke(null, null);
} catch (Exception unused) {
return (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", new Class[0]).invoke(null, null);
}
} catch (Exception unused2) {
DialogX.error("DialogX.init: 初始化异常,请确保init方法内传入的Context是有效的。");
return null;
}
}
public static Activity getTopActivity() {
ArrayMap arrayMap;
try {
Class<?> cls = Class.forName("android.app.ActivityThread");
Object invoke = cls.getMethod("currentActivityThread", new Class[0]).invoke(null, new Object[0]);
Field declaredField = cls.getDeclaredField("mActivities");
declaredField.setAccessible(true);
arrayMap = (ArrayMap) declaredField.get(invoke);
} catch (Exception e2) {
e2.printStackTrace();
}
if (arrayMap.size() < 1) {
return null;
}
for (Object obj : arrayMap.values()) {
Class<?> cls2 = obj.getClass();
Field declaredField2 = cls2.getDeclaredField("paused");
declaredField2.setAccessible(true);
if (!declaredField2.getBoolean(obj)) {
Field declaredField3 = cls2.getDeclaredField("activity");
declaredField3.setAccessible(true);
return (Activity) declaredField3.get(obj);
}
}
return null;
}
public static void init(Context context, onActivityResumeCallBack onactivityresumecallback) {
if (context == null) {
Application application2 = application;
if (application2 != null) {
init(application2, onactivityresumecallback);
return;
}
return;
}
Application applicationContext = getApplicationContext(context);
if (applicationContext == null) {
DialogX.error("DialogX 未初始化(E1)。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
return;
}
application = applicationContext;
ActivityLifecycleImpl activityLifecycleImpl = activityLifecycle;
if (activityLifecycleImpl != null) {
applicationContext.unregisterActivityLifecycleCallbacks(activityLifecycleImpl);
}
ActivityLifecycleImpl activityLifecycleImpl2 = new ActivityLifecycleImpl(onactivityresumecallback);
activityLifecycle = activityLifecycleImpl2;
applicationContext.registerActivityLifecycleCallbacks(activityLifecycleImpl2);
}
public static boolean isExemptActivities(Activity activity) {
if (activity == null) {
return true;
}
for (String str : DialogX.unsupportedActivitiesPackageNames) {
if (activity.getClass().getName().contains(str)) {
return true;
}
}
return false;
}
@Override
public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle bundle) {
onActivityResumeCallBack onactivityresumecallback = this.onActivityResumeCallBack;
if (onactivityresumecallback == null || (activity instanceof DialogXFloatingWindowActivity)) {
return;
}
onactivityresumecallback.getActivity(activity);
}
@Override
public void onActivityDestroyed(@NonNull Activity activity) {
if (BaseDialog.getTopActivity() == activity) {
BaseDialog.cleanContext();
}
}
@Override
public void onActivityPaused(@NonNull Activity activity) {
}
@Override
public void onActivityPreDestroyed(@NonNull Activity activity) {
BaseDialog.recycleDialog(activity);
}
@Override
public void onActivityResumed(@NonNull Activity activity) {
if (activity.isDestroyed() || activity.isFinishing() || (activity instanceof DialogXFloatingWindowActivity)) {
return;
}
onActivityResumeCallBack onactivityresumecallback = this.onActivityResumeCallBack;
if (onactivityresumecallback != null) {
onactivityresumecallback.getActivity(activity);
}
BaseDialog.onActivityResume(activity);
}
@Override
public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle bundle) {
}
@Override
public void onActivityStarted(@NonNull Activity activity) {
if (application == null) {
BaseDialog.init(activity);
}
}
@Override
public void onActivityStopped(@NonNull Activity activity) {
}
}