悦享送 v3.5.1版本的 MD5 值为:111dc8a16f422da8b2f1cf208abae9ea
以下内容为反编译后的 ActivityLifecycleImpl.java 源代码,内容仅作参考
package com.kongzue.dialogx.impl;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.util.ArrayMap;
import android.view.Window;
import com.kongzue.dialogx.DialogX;
import com.kongzue.dialogx.interfaces.BaseDialog;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
public class ActivityLifecycleImpl implements Application.ActivityLifecycleCallbacks {
private onActivityResumeCallBack onActivityResumeCallBack;
public interface onActivityResumeCallBack {
void getActivity(Activity activity);
}
@Override
public void onActivityPaused(Activity activity) {
}
@Override
public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
}
@Override
public void onActivityStarted(Activity activity) {
}
@Override
public void onActivityStopped(Activity activity) {
}
public ActivityLifecycleImpl(onActivityResumeCallBack onActivityResumeCallBack2) {
this.onActivityResumeCallBack = onActivityResumeCallBack2;
}
public static void init(Context context, onActivityResumeCallBack onActivityResumeCallBack2) {
Application applicationContext = getApplicationContext(context);
if (applicationContext == null) {
DialogX.error("DialogX 未初始化。\n请检查是否在启动对话框前进行初始化操作,使用以下代码进行初始化:\nDialogX.init(context);\n\n另外建议您前往查看 DialogX 的文档进行使用:https://github.com/kongzue/DialogX");
} else {
applicationContext.registerActivityLifecycleCallbacks(new ActivityLifecycleImpl(onActivityResumeCallBack2));
}
}
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) {
DialogX.error("DialogX.init: 初始化异常,请确保init方法内传入的Context是有效的。");
return null;
}
} catch (Exception unused2) {
return (Application) Class.forName("android.app.AppGlobals").getMethod("getInitialApplication", new Class[0]).invoke(null, null);
}
}
public static Activity getTopActivity() {
Map map;
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);
if (Build.VERSION.SDK_INT < 19) {
map = (HashMap) declaredField.get(invoke);
} else {
map = (ArrayMap) declaredField.get(invoke);
}
} catch (Exception e) {
e.printStackTrace();
}
if (map.size() < 1) {
return null;
}
for (Object obj : map.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;
}
@Override
public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
if (this.onActivityResumeCallBack != null) {
Window window = activity.getWindow();
if (window != null && DialogX.useActivityLayoutTranslationNavigationBar && (window.getDecorView().getSystemUiVisibility() & 512) != 512) {
window.getDecorView().setSystemUiVisibility(512);
}
this.onActivityResumeCallBack.getActivity(activity);
}
}
@Override
public void onActivityResumed(Activity activity) {
if (activity.isDestroyed() || activity.isFinishing()) {
return;
}
onActivityResumeCallBack onactivityresumecallback = this.onActivityResumeCallBack;
if (onactivityresumecallback != null) {
onactivityresumecallback.getActivity(activity);
}
BaseDialog.onActivityResume(activity);
}
@Override
public void onActivityDestroyed(Activity activity) {
if (BaseDialog.getContext() == activity) {
BaseDialog.cleanContext();
}
}
@Override
public void onActivityPreDestroyed(final Activity activity) {
BaseDialog.recycleDialog(activity);
}
}