Skip to content

Commit

Permalink
Version 3.3.0 of the Google Mobile Ads Unity Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
rampara committed Mar 6, 2017
1 parent d1b34d3 commit e8e9f8f
Show file tree
Hide file tree
Showing 41 changed files with 337 additions and 449 deletions.
15 changes: 15 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
Google Mobile Ads Unity Plugin Change Log

*************
Version 3.3.0
*************
- Removed support for in-app purchases.
- Fix positioning of ads in sticky-immersive mode.
- Fix issue were ads larger than 320dp could not be rendered.
- Fix incorrect positioning of ads in iOS for ad position BOTTOM.
- Add rewarded video test ad units to HelloWorld sample app.
- Suppress warnings for unsed dummy ad events.

Built and tested with:
- Google Play services 10.2.0
- Google Mobile Ads iOS SDK 7.18.0
- Unity Jar Resolver 1.2.12.0

*************
Version 3.2.0
*************
Expand Down
37 changes: 2 additions & 35 deletions samples/HelloWorld/Assets/Scripts/GoogleMobileAdsDemoScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,6 @@
using GoogleMobileAds;
using GoogleMobileAds.Api;

public class GoogleMobileAdsDemoHandler : IDefaultInAppPurchaseProcessor
{
private readonly string[] validSkus = { "android.test.purchased" };

// Will only be sent on a success.
public void ProcessCompletedInAppPurchase(IInAppPurchaseResult result)
{
result.FinishPurchase();
GoogleMobileAdsDemoScript.OutputMessage = "Purchase Succeeded! Credit user here.";
}

// Check SKU against valid SKUs.
public bool IsValidPurchase(string sku)
{
foreach (string validSku in this.validSkus)
{
if (sku == validSku)
{
return true;
}
}

return false;
}

// Return the app's public key.
public string AndroidPublicKey
{
// In a real app, return public key instead of null.
get { return null; }
}
}

// Example script showing how to invoke the Google Mobile Ads Unity plugin.
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
Expand Down Expand Up @@ -293,9 +260,9 @@ private void RequestRewardBasedVideo()
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "INSERT_AD_UNIT_HERE";
string adUnitId = "ca-app-pub-3940256099942544/5224354917";
#elif UNITY_IPHONE
string adUnitId = "INSERT_AD_UNIT_HERE";
string adUnitId = "ca-app-pub-3940256099942544/1712485313";
#else
string adUnitId = "unexpected_platform";
#endif
Expand Down
6 changes: 3 additions & 3 deletions source/android-library/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "22.0.1"

defaultConfig {
minSdkVersion 9
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
Expand All @@ -24,8 +24,8 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.google.android.gms:play-services-ads:10.2.0'
}

task clearJar(type: Delete) {
Expand Down
2 changes: 0 additions & 2 deletions source/android-library/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
<!-- Google Mobile Ads Permissions -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Uncomment to add billing for in-app purchase ads -->
<!--<uses-permission android:name="com.android.vending.BILLING" /> -->

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.google.unity.ads;

import android.os.Bundle;

import java.util.HashMap;

/**
* Mediation extras bundle class for the Google Mobile Ads Unity plugin.
*/
public interface AdNetworkExtras {

Bundle buildExtras(HashMap<String, String> extras);

Class getAdapterClass();
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,15 @@ public void onAdLeftApplication() {
public void createPopupWindow() {
// Workaround for issue where popUpWindow will not resize to the full width
// of the screen to accommodate a smart banner.
int popUpWindowWidthLayoutParam = mAdView.getAdSize().equals(AdSize.SMART_BANNER)
? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT;
mPopupWindow = new PopupWindow(mAdView, popUpWindowWidthLayoutParam,
ViewGroup.LayoutParams.WRAP_CONTENT);
int popUpWindowWidth = mAdView.getAdSize().equals(AdSize.SMART_BANNER)
? ViewGroup.LayoutParams.MATCH_PARENT
: mAdView.getAdSize().getWidthInPixels(mUnityPlayerActivity);
int popUpWindowHeight = mAdView.getAdSize().getHeightInPixels(mUnityPlayerActivity);
mPopupWindow = new PopupWindow(mAdView, popUpWindowWidth, popUpWindowHeight);

// Copy system UI visibility flags set on Unity player window to newly created PopUpWindow.
int visibilityFlags = mUnityPlayerActivity.getWindow().getAttributes().flags;
mPopupWindow.getContentView().setSystemUiVisibility(visibilityFlags);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.purchase.InAppPurchaseListener;
import com.google.android.gms.ads.purchase.PlayStorePurchaseListener;

/**
* Native interstitial implementation for the Google Mobile Ads Unity plugin.
Expand Down Expand Up @@ -134,38 +132,6 @@ public void run() {
});
}

/**
* Sets Play Store purchase parameters. The PlayStorePurchaseListener is implemented on the
* Unity side via {@code AndroidJavaProxy}.
*
* @param purchaseListener A PlayStorePurchaseListener for monitoring purchase events.
* @param publicKey The app's public key string.
*/
public void setPlayStorePurchaseParams(final PlayStorePurchaseListener purchaseListener,
final String publicKey) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
interstitial.setPlayStorePurchaseParams(purchaseListener, publicKey);
}
});
}

/**
* Sets an InAppPurchaseListener for the interstitial. The InAppPurchaseListener is
* implemented on the Unity side via {@code AndroidJavaProxy}.
*
* @param purchaseListener An InAppPurchaseListener for monitoring purchase events.
*/
public void setInAppPurchaseListener(final InAppPurchaseListener purchaseListener) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
interstitial.setInAppPurchaseListener(purchaseListener);
}
});
}

/**
* Destroys the {@link InterstitialAd}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class NativeExpressAd {
* The {@code PopupWindow} that the banner ad be displayed in to ensure banner ads will be
* presented over a {@code SurfaceView}.
*/
private PopupWindow popupWindow;
private PopupWindow mPopupWindow;


/**
Expand Down Expand Up @@ -80,10 +80,8 @@ public void create(final String publisherId, final AdSize adSize, final int posi
public void run() {

createNativeExpressAdView(publisherId, adSize);
popupWindow = new PopupWindow(mAdView, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams
.WRAP_CONTENT);
popupWindow.showAtLocation(mUnityPlayerActivity.getWindow().getDecorView()
createPopupWindow();
mPopupWindow.showAtLocation(mUnityPlayerActivity.getWindow().getDecorView()
.getRootView(),
PluginUtils.getLayoutGravityForPositionCode(positionCode), 0, 0);
}
Expand All @@ -105,9 +103,8 @@ public void create(final String publisherId, final AdSize adSize, final int posi
public void run() {

createNativeExpressAdView(publisherId, adSize);
popupWindow = new PopupWindow(mAdView, ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.showAtLocation(mUnityPlayerActivity.getWindow().getDecorView()
createPopupWindow();
mPopupWindow.showAtLocation(mUnityPlayerActivity.getWindow().getDecorView()
.getRootView(),
Gravity.NO_GRAVITY, (int) PluginUtils.convertDpToPixel(positionX),
(int) PluginUtils.convertDpToPixel(positionY));
Expand Down Expand Up @@ -161,6 +158,16 @@ public void onAdLeftApplication() {

}

public void createPopupWindow() {
int popUpWindowWidth = mAdView.getAdSize().getWidthInPixels(mUnityPlayerActivity);
int popUpWindowHeight = mAdView.getAdSize().getHeightInPixels(mUnityPlayerActivity);
mPopupWindow = new PopupWindow(mAdView, popUpWindowWidth, popUpWindowHeight);

// Copy system UI visibility flags set on Unity player window to newly created PopUpWindow.
int visibilityFlags = mUnityPlayerActivity.getWindow().getAttributes().flags;
mPopupWindow.getContentView().setSystemUiVisibility(visibilityFlags);
}

/**
* Loads an ad on a background thread.
*
Expand Down Expand Up @@ -225,7 +232,7 @@ public void destroy() {
public void run() {
Log.d(PluginUtils.LOGTAG, "Calling destroy() on NativeExpressAdView");
mAdView.destroy();
popupWindow.dismiss();
mPopupWindow.dismiss();
ViewParent parentView = mAdView.getParent();
if (parentView != null && parentView instanceof ViewGroup) {
((ViewGroup) parentView).removeView(mAdView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
*/
package com.google.unity.ads;

import android.app.Activity;
import android.content.res.Resources;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.purchase.InAppPurchaseResult;

/**
* Utilities for the Google Mobile Ads Unity plugin.
Expand Down Expand Up @@ -139,15 +137,4 @@ public static float convertDpToPixel(float dp) {
float px = dp * metrics.density;
return px;
}


/**
* Returns whether the InAppPurchaseResult was successful.
*
* @param result The InAppPurchaseResult to check.
* @return true on success, otherwise false.
*/
public static boolean isResultSuccess(InAppPurchaseResult result) {
return result.getResultCode() == Activity.RESULT_OK;
}
}
74 changes: 49 additions & 25 deletions source/plugin/Assets/GoogleMobileAds/Api/AdRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,42 @@
using System.Collections;
using System.Collections.Generic;

using GoogleMobileAds.Api.Mediation;

namespace GoogleMobileAds.Api
{
public class AdRequest
{
public const string Version = "3.2.0";
public const string Version = "3.3.0";
public const string TestDeviceSimulator = "SIMULATOR";

public class Builder
private AdRequest(Builder builder)
{
internal List<string> TestDevices { get; private set; }
internal HashSet<string> Keywords { get; private set; }
internal DateTime? Birthday { get; private set; }
internal Gender? Gender { get; private set; }
internal bool? ChildDirectedTreatmentTag { get; private set; }
internal Dictionary<string, string> Extras { get; private set; }
this.TestDevices = new List<string>(builder.TestDevices);
this.Keywords = new HashSet<string>(builder.Keywords);
this.Birthday = builder.Birthday;
this.Gender = builder.Gender;
this.TagForChildDirectedTreatment = builder.ChildDirectedTreatmentTag;
this.Extras = new Dictionary<string, string>(builder.Extras);
this.MediationExtras = builder.MediationExtras;
}

public List<string> TestDevices { get; private set; }

public HashSet<string> Keywords { get; private set; }

public DateTime? Birthday { get; private set; }

public Gender? Gender { get; private set; }

public bool? TagForChildDirectedTreatment { get; private set; }

public Dictionary<string, string> Extras { get; private set; }

public List<MediationExtras> MediationExtras { get; private set; }

public class Builder
{
public Builder()
{
this.TestDevices = new List<string>();
Expand All @@ -40,8 +60,23 @@ public Builder()
this.Gender = null;
this.ChildDirectedTreatmentTag = null;
this.Extras = new Dictionary<string, string>();
this.MediationExtras = new List<MediationExtras>();
}

internal List<string> TestDevices { get; private set; }

internal HashSet<string> Keywords { get; private set; }

internal DateTime? Birthday { get; private set; }

internal Gender? Gender { get; private set; }

internal bool? ChildDirectedTreatmentTag { get; private set; }

internal Dictionary<string, string> Extras { get; private set; }

internal List<MediationExtras> MediationExtras { get; private set; }

public Builder AddKeyword(string keyword)
{
this.Keywords.Add(keyword);
Expand Down Expand Up @@ -71,6 +106,12 @@ public Builder SetGender(Gender gender)
return this;
}

public Builder AddMediationExtras(MediationExtras extras)
{
this.MediationExtras.Add(extras);
return this;
}

public Builder TagForChildDirectedTreatment(bool tagForChildDirectedTreatment)
{
this.ChildDirectedTreatmentTag = tagForChildDirectedTreatment;
Expand All @@ -83,22 +124,5 @@ public Builder AddExtra(string key, string value)
return this;
}
}

public List<string> TestDevices { get; private set; }
public HashSet<string> Keywords { get; private set; }
public DateTime? Birthday { get; private set; }
public Gender? Gender { get; private set; }
public bool? TagForChildDirectedTreatment { get; private set; }
public Dictionary<string, string> Extras { get; private set; }

private AdRequest(Builder builder)
{
this.TestDevices = new List<string>(builder.TestDevices);
this.Keywords = new HashSet<string>(builder.Keywords);
this.Birthday = builder.Birthday;
this.Gender = builder.Gender;
this.TagForChildDirectedTreatment = builder.ChildDirectedTreatmentTag;
this.Extras = new Dictionary<string, string>(builder.Extras);
}
}
}
Loading

0 comments on commit e8e9f8f

Please sign in to comment.