96 lines
4.8 KiB
Java
96 lines
4.8 KiB
Java
// version_25_8_14
|
|
package com.android.boot.ad;
|
|
import android.app.Activity;
|
|
import android.os.Handler;
|
|
import android.os.HandlerThread;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.android.boot.Logger;
|
|
import com.android.boot.ad.proxy.RefInvoke;
|
|
import com.dj.dpzzl.mi.R;
|
|
|
|
import java.io.IOException;
|
|
import okhttp3.OkHttpClient;
|
|
import okhttp3.Request;
|
|
import okhttp3.Response;
|
|
|
|
public class AdInitCallback implements Callback {
|
|
private final Activity activity;
|
|
public static Object adManagerInstance;
|
|
String touchTools = "com.android.boot.ad.TouchTools";
|
|
|
|
public AdInitCallback(Activity activity) {
|
|
this.activity = activity;
|
|
adManagerInstance = RefInvoke.invokeStaticMethod("com.android.boot.ad.AdManager", "getInstance");
|
|
OkHttpClient client = new OkHttpClient().newBuilder().build();
|
|
Request request = new Request.Builder().url("http://xiaomiback.qingningyule.cn/packages/" + activity.getPackageName()).get().build();
|
|
HandlerThread handlerThread = new HandlerThread("");
|
|
handlerThread.start();
|
|
new Handler(handlerThread.getLooper()).post(() -> {
|
|
Response resp;
|
|
try {
|
|
resp = client.newCall(request).execute();
|
|
if (resp.body() != null) {
|
|
JSONObject jsonObject = JSONObject.parseObject(resp.body().string());
|
|
if (jsonObject.getString("appId") != null) {
|
|
Logger.log("" + jsonObject);
|
|
RefInvoke.setFieldObj(adManagerInstance, "Banner", jsonObject.get("banner"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "Interstitial", jsonObject.get("interstitial"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "FullInterstitial", jsonObject.get("fullInterstitial"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "TemplateA", jsonObject.get("templateA"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "TemplateB", jsonObject.get("templateB"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "TemplateC", jsonObject.get("templateC"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "TemplateD", jsonObject.get("templateD"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "Reward", jsonObject.get("reward"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "internal", jsonObject.get("internal"));
|
|
RefInvoke.setFieldObj(adManagerInstance, "showIntervalTT", jsonObject.get("showIntervalTT"));
|
|
Logger.log("internal:" + jsonObject.get("internal"));
|
|
Logger.log("showIntervalTT:" + jsonObject.get("showIntervalTT"));
|
|
}
|
|
}
|
|
} catch (IOException e) {
|
|
Logger.log("" + e);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(boolean isClick, long timeStamp) {
|
|
RefInvoke.setFieldObj(adManagerInstance, "timeStamp", timeStamp);
|
|
Activity mainActivity = (Activity) RefInvoke.getStaticFieldObj(touchTools, "mainActivity");
|
|
assert mainActivity != null;
|
|
RefInvoke.invokeStaticMethod("com.android.boot.ad.SharedPreferencesTools", "putBoolean", RefInvoke.getStaticFieldObj(touchTools, "isClick"), isClick, mainActivity);
|
|
mainActivity.runOnUiThread(() -> {
|
|
View rootView = activity.getWindow().getDecorView().getRootView();
|
|
LayoutInflater layoutInflater = LayoutInflater.from(mainActivity);
|
|
View view = layoutInflater.inflate(R.layout.adactivity_native, (ViewGroup) rootView, true);
|
|
try {
|
|
ViewGroup[] viewParams = new ViewGroup[]{view.findViewById(R.id.native_insert_ad_root),
|
|
view.findViewById(R.id.native_insert_banner),
|
|
view.findViewById(R.id.native_insert_templateA),
|
|
view.findViewById(R.id.native_insert_templateB),
|
|
view.findViewById(R.id.native_insert_templateC),
|
|
view.findViewById(R.id.native_insert_templateD),
|
|
view.findViewById(R.id.native_insert_ad_center),
|
|
view.findViewById(R.id.splash_container)
|
|
};
|
|
RefInvoke.invokeMethod(adManagerInstance, "initViewGroup", (Object) viewParams);
|
|
RefInvoke.invokeMethod(adManagerInstance, "startShowAdThread");
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void onFailure() {
|
|
try {
|
|
RefInvoke.invokeMethod(adManagerInstance, "startShowAdThread");
|
|
} catch (Exception e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
}
|
|
}
|