// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
package com.unity3d.player;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Handler;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.Window;
import android.os.Process;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import com.google.android.gms.ads.AdError;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.FullScreenContentCallback;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.OnUserEarnedRewardListener;
import com.google.android.gms.ads.interstitial.InterstitialAd;
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
import com.google.android.gms.ads.rewarded.RewardItem;
import com.google.android.gms.ads.rewarded.RewardedAd;
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;
import com.unity3d.player.IUnityPlayerLifecycleEvents;
import com.unity3d.player.UnityPlayer;
public class UnityPlayerActivity extends Activity implements IUnityPlayerLifecycleEvents
{
protected UnityPlayer mUnityPlayer; // don't change the name of this variable; referenced from native code
// Override this in your custom UnityPlayerActivity to tweak the command line arguments passed to the Unity Android Player
// The command line arguments are passed as a string, separated by spaces
// UnityPlayerActivity calls this from 'onCreate'
// Supported: -force-gles20, -force-gles30, -force-gles31, -force-gles31aep, -force-gles32, -force-gles, -force-vulkan
// See https://docs.unity3d.com/Manual/CommandLineArguments.html
// @param cmdLine the current command line arguments, may be null
// @return the modified command line string or null
protected String updateUnityCommandLineArguments(String cmdLine)
{
return cmdLine;
}
AdView mAdView;
//当前是否显示着退出弹框,弹出弹框页面不能显示banner
boolean isShowViewExit = false;
FrameLayout.LayoutParams layoutParamsBanner;
InterstitialAd mInterstitialAd;
RewardedAd rewardedAd0, rewardedAd1, rewardedAd2, rewardedAd3,rewardedAd4,rewardedAd5,rewardedAd6,rewardedAd7,rewardedAd8;
boolean isLoadR0=false,isLoadR1=false,isLoadR2=false,isLoadR3=false,isLoadR4=false,isLoadR5=false,isLoadR6=false,isLoadR7=false,isLoadR8=false;
boolean isLoading;
// Setup activity layout
@Override protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
String cmdLine = updateUnityCommandLineArguments(getIntent().getStringExtra("unity"));
getIntent().putExtra("unity", cmdLine);
mUnityPlayer = new UnityPlayer(this, this);
setContentView(mUnityPlayer);
mUnityPlayer.requestFocus();
// DelayShowBannerAd();
LoadInterstitialAd();
LoadRewardAd0();
LoadRewardAd1();
// LoadRewardAd2();
// LoadRewardAd3();
// LoadRewardAd4();
// LoadRewardAd5();
// LoadRewardAd6();
// LoadRewardAd7();
// LoadRewardAd8();
isShowViewExit = false;
}
private void DelayShowBannerAd(){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
ShowBannerAd();
}
},5000);
}
public void ShowBannerAd() {
ShowLog("lload banner");
try{
runOnUiThread(new Runnable() {
@SuppressLint("MissingPermission")
@Override
public void run() {
mAdView = new AdView(UnityPlayerActivity.this);
mAdView.setAdSize(AdSize.BANNER);
mAdView.setAdUnitId(SdkData.BannerID);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
ShowLog("banner ad loaded");
}
@Override
public void onAdFailedToLoad(LoadAdError adError) {
// Code to be executed when an ad request fails.
ShowLog("banner ad load failed");
}
@Override
public void onAdOpened() {
// Code to be executed when an ad opens an overlay that
// covers the screen.
ShowLog("banner ad opened");
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
ShowLog("banner ad clicked");
}
@Override
public void onAdClosed() {
// Code to be executed when the user is about to return
// to the app after tapping on an ad.
ShowLog("banner ad closed");
}
});
int width = 728;
//广告高度由宽度进行自适应
int height = FrameLayout.LayoutParams.WRAP_CONTENT;
layoutParamsBanner = new FrameLayout.LayoutParams(width, height);
layoutParamsBanner.gravity = Gravity.TOP | Gravity.CENTER;
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
layoutParamsBanner.bottomMargin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP
, 0, displayMetrics);
int dp16 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 0, displayMetrics);
layoutParamsBanner.setMarginStart(dp16);
addContentView(mAdView, layoutParamsBanner);
// scrollViewNative.addView(mAdView);
}
});
} catch (Exception e) {
ShowLog(e.toString());
}
}
public void ShowViewExit(){
// ShowLog("show view exit and hide banner ");
// isShowViewExit = true;
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if(mAdView!=null) {
//// mAdView.clearAnimation();
// mAdView.setVisibility(View.INVISIBLE);
//// mAdView.requestLayout();
// }
// }
// });
}
public void HideViewExit(){
// ShowLog("hide view exit and show banner ");
// isShowViewExit = false;
// runOnUiThread(new Runnable() {
// @Override
// public void run() {
// if(mAdView!=null) {
// mAdView.setVisibility(View.VISIBLE);
//// mAdView.requestLayout();
// }
// }
// });
}
boolean isLoadInAd=false;
评论5