By invoking the listener callback here, hooked into the draw loop, the AdViewHelper object + * can be sure that any movements of adView have been completed and the layout and screen position + * have been recalculated by the time the notification happens, preventing stale data from getting + * to the Listener. */ @Override public boolean onPreDraw() { - if (mNotifyBoundingBoxListenerOnNextDraw.compareAndSet(true, false)) { - if (mAdView != null && mAdViewInternalPtr != CPP_NULLPTR) { - notifyBoundingBoxChanged(mAdViewInternalPtr); + if (notifyBoundingBoxListenerOnNextDraw.compareAndSet(true, false)) { + if (adView != null && adViewInternalPtr != CPP_NULLPTR) { + notifyBoundingBoxChanged(adViewInternalPtr); } } // Returning true tells Android to continue the draw as normal. return true; } - /** - * Native callback to instruct the C++ wrapper to complete the corresponding future. - */ + /** Native callback to instruct the C++ wrapper to complete the corresponding future. */ public static native void completeAdViewFutureCallback( long nativeInternalPtr, int errorCode, String errorMessage); - /** - * Native callback to instruct the C++ wrapper to release its global reference on this - * object. - */ + /** Native callback to instruct the C++ wrapper to release its global reference on this object. */ public static native void releaseAdViewGlobalReferenceCallback(long nativeInternalPtr); - /** - * Native callback invoked upon successfully loading an ad. - */ + /** Native callback invoked upon successfully loading an ad. */ public static native void completeAdViewLoadedAd(long nativeInternalPtr, long mAdViewInternalPtr, int width, int height, ResponseInfo responseInfo); /** - * Native callback upon encountering an error loading an Ad Request. Returns - * Android Google Mobile Ads SDK error codes. - **/ + * Native callback upon encountering an error loading an Ad Request. Returns Android Google Mobile + * Ads SDK error codes. + */ public static native void completeAdViewLoadAdError( long nativeInternalPtr, LoadAdError error, int errorCode, String errorMessage); /** - * Native callback upon encountering a wrapper/internal error when - * processing a Load Ad Request. Returns an integer representing - * firebase::gma::AdError codes. + * Native callback upon encountering a wrapper/internal error when processing a Load Ad Request. + * Returns an integer representing firebase::gma::AdError codes. */ public static native void completeAdViewLoadAdInternalError( long nativeInternalPtr, int gmaErrorCode, String errorMessage); - /** - * Native callback to notify the C++ wrapper that the Ad's Bounding Box has changed. - */ + /** Native callback to notify the C++ wrapper that the Ad's Bounding Box has changed. */ public static native void notifyBoundingBoxChanged(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad clicked event - */ + /** Native callback to notify the C++ wrapper of an ad clicked event */ public static native void notifyAdClicked(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad closed event - */ + /** Native callback to notify the C++ wrapper of an ad closed event */ public static native void notifyAdClosed(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad impression event - */ + /** Native callback to notify the C++ wrapper of an ad impression event */ public static native void notifyAdImpression(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper of an ad opened event - */ + /** Native callback to notify the C++ wrapper of an ad opened event */ public static native void notifyAdOpened(long nativeInternalPtr); - /** - * Native callback to notify the C++ wrapper that a paid event has occurred. - */ + /** Native callback to notify the C++ wrapper that a paid event has occurred. */ public static native void notifyPaidEvent( long nativeInternalPtr, String currencyCode, int precisionType, long valueMicros); } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java index 2056275293..1abc0d4b1e 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/ConstantsHelper.java @@ -84,4 +84,6 @@ public final class ConstantsHelper { public static final int AD_VIEW_POSITION_BOTTOM_LEFT = 4; public static final int AD_VIEW_POSITION_BOTTOM_RIGHT = 5; + + private ConstantsHelper() {} } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java index 85aee3c383..f1cab85410 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/GmaInitializationHelper.java @@ -34,4 +34,6 @@ public void onInitializationComplete(InitializationStatus initializationStatus) public static native void initializationCompleteCallback( InitializationStatus initializationStatus); + + private GmaInitializationHelper() {} } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java index e08d82345a..c81ebc8dad 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/InterstitialAdHelper.java @@ -17,7 +17,6 @@ package com.google.firebase.gma.internal.cpp; import android.app.Activity; -import android.util.Log; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdValue; @@ -39,34 +38,32 @@ public class InterstitialAdHelper { // Pointer to the InterstitialAdInternalAndroid object that created this // object. - private long mInterstitialAdInternalPtr; + private long interstitialAdInternalPtr; // The GMA SDK {@link InterstitialAd} associated with this helper. - private InterstitialAd mInterstitial; + private InterstitialAd interstitial; // Synchronization object for thread safe access to: - // * mInterstitial - // * mInterstitialAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mInterstitialLock; + // * interstitial + // * interstitialAdInternalPtr + // * loadAdCallbackDataPtr + private final Object interstitialLock; // The {@link Activity} this helper uses to display its // {@link InterstitialAd}. - private Activity mActivity; + private Activity activity; // The ad unit ID to use for the {@link InterstitialAd}. - private String mAdUnitId; + private String adUnitId; // Pointer to a FutureCallbackData in the C++ wrapper that will be used to // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; + private long loadAdCallbackDataPtr; - /** - * Constructor. - */ + /** Constructor. */ public InterstitialAdHelper(long interstitialAdInternalPtr) { - mInterstitialAdInternalPtr = interstitialAdInternalPtr; - mInterstitialLock = new Object(); + this.interstitialAdInternalPtr = interstitialAdInternalPtr; + interstitialLock = new Object(); // Test the callbacks and fail quickly if something's wrong. completeInterstitialAdFutureCallback( @@ -78,19 +75,19 @@ public InterstitialAdHelper(long interstitialAdInternalPtr) { * InterstitialAd} object and sets it up. */ public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; + this.activity = activity; - mActivity.runOnUiThread(new Runnable() { + this.activity.runOnUiThread(new Runnable() { @Override public void run() { int errorCode; String errorMessage; - if (mInterstitial == null) { + if (interstitial == null) { try { errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; } catch (IllegalStateException e) { - mInterstitial = null; + interstitial = null; // This exception can be thrown if the ad unit ID was already set. errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; @@ -106,23 +103,23 @@ public void run() { /** Disconnect the helper from the interstital ad. */ public void disconnect() { - synchronized (mInterstitialLock) { - mInterstitialAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; + synchronized (interstitialLock) { + interstitialAdInternalPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } - if (mActivity == null) { + if (activity == null) { return; } - mActivity.runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - synchronized (mInterstitialLock) { - if (mInterstitial != null) { - mInterstitial.setFullScreenContentCallback(null); - mInterstitial.setOnPaidEventListener(null); - mInterstitial = null; + synchronized (interstitialLock) { + if (interstitial != null) { + interstitial.setFullScreenContentCallback(null); + interstitial.setOnPaidEventListener(null); + interstitial = null; } } } @@ -131,40 +128,41 @@ public void run() { /** Loads an ad for the underlying {@link InterstitialAd} object. */ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { + if (activity == null) { return; } - synchronized (mInterstitialLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { + synchronized (interstitialLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { completeInterstitialLoadAdInternalError(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; } - mLoadAdCallbackDataPtr = callbackDataPtr; + loadAdCallbackDataPtr = callbackDataPtr; } - mAdUnitId = adUnitId; + this.adUnitId = adUnitId; - mActivity.runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - if (mActivity == null) { - synchronized (mInterstitialLock) { - completeInterstitialLoadAdInternalError(mLoadAdCallbackDataPtr, + if (activity == null) { + synchronized (interstitialLock) { + completeInterstitialLoadAdInternalError(loadAdCallbackDataPtr, ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } } else { try { - InterstitialAd.load(mActivity, mAdUnitId, request, new InterstitialAdListener()); + InterstitialAd.load(activity, InterstitialAdHelper.this.adUnitId, request, + new InterstitialAdListener()); } catch (IllegalStateException e) { - synchronized (mInterstitialLock) { - completeInterstitialLoadAdInternalError(mLoadAdCallbackDataPtr, + synchronized (interstitialLock) { + completeInterstitialLoadAdInternalError(loadAdCallbackDataPtr, ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } } } @@ -174,22 +172,22 @@ public void run() { /** Shows a previously loaded ad. */ public void show(final long callbackDataPtr) { - mActivity.runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - synchronized (mInterstitialLock) { + synchronized (interstitialLock) { int errorCode; String errorMessage; - if (mAdUnitId == null) { + if (adUnitId == null) { errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mInterstitial == null) { + } else if (interstitial == null) { errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; } else { errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; - mInterstitial.show(mActivity); + interstitial.show(activity); } completeInterstitialAdFutureCallback(callbackDataPtr, errorCode, errorMessage); } @@ -201,52 +199,53 @@ private class InterstitialAdFullScreenContentListener extends FullScreenContentCallback implements OnPaidEventListener { @Override public void onAdClicked() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdClickedFullScreenContentEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdClickedFullScreenContentEvent(interstitialAdInternalPtr); } } } @Override public void onAdDismissedFullScreenContent() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdDismissedFullScreenContentEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdDismissedFullScreenContentEvent(interstitialAdInternalPtr); } } } @Override public void onAdFailedToShowFullScreenContent(AdError error) { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdFailedToShowFullScreenContentEvent(mInterstitialAdInternalPtr, error); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdFailedToShowFullScreenContentEvent(interstitialAdInternalPtr, error); } } } @Override public void onAdImpression() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdImpressionEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdImpressionEvent(interstitialAdInternalPtr); } } } @Override public void onAdShowedFullScreenContent() { - synchronized (mInterstitialLock) { - if (mInterstitialAdInternalPtr != CPP_NULLPTR) { - notifyAdShowedFullScreenContentEvent(mInterstitialAdInternalPtr); + synchronized (interstitialLock) { + if (interstitialAdInternalPtr != CPP_NULLPTR) { + notifyAdShowedFullScreenContentEvent(interstitialAdInternalPtr); } } } + @Override public void onPaidEvent(AdValue value) { - synchronized (mInterstitialLock) { - notifyPaidEvent(mInterstitialAdInternalPtr, value.getCurrencyCode(), + synchronized (interstitialLock) { + notifyPaidEvent(interstitialAdInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), value.getValueMicros()); } } @@ -255,26 +254,26 @@ public void onPaidEvent(AdValue value) { private class InterstitialAdListener extends InterstitialAdLoadCallback { @Override public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mInterstitialLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { + synchronized (interstitialLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { completeInterstitialLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } @Override public void onAdLoaded(InterstitialAd ad) { - synchronized (mInterstitialLock) { - mInterstitial = ad; + synchronized (interstitialLock) { + interstitial = ad; InterstitialAdFullScreenContentListener listener = new InterstitialAdFullScreenContentListener(); - mInterstitial.setFullScreenContentCallback(listener); - mInterstitial.setOnPaidEventListener(listener); - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - completeInterstitialLoadedAd(mLoadAdCallbackDataPtr, ad.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + interstitial.setFullScreenContentCallback(listener); + interstitial.setOnPaidEventListener(listener); + if (loadAdCallbackDataPtr != CPP_NULLPTR) { + completeInterstitialLoadedAd(loadAdCallbackDataPtr, ad.getResponseInfo()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } diff --git a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java index 3e78901d2f..038c2d5cfb 100644 --- a/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java +++ b/gma/src_java/com/google/firebase/gma/internal/cpp/RewardedAdHelper.java @@ -17,7 +17,6 @@ package com.google.firebase.gma.internal.cpp; import android.app.Activity; -import android.util.Log; import com.google.android.gms.ads.AdError; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdValue; @@ -42,32 +41,32 @@ public class RewardedAdHelper { // Pointer to the RewardedAdInternalAndroid object that created this // object. - private long mRewardedAdInternalPtr; + private long rewardedAdInternalPtr; // The GMA SDK {@link RewardedAd} associated with this helper. - private RewardedAd mRewarded; + private RewardedAd rewarded; // Synchronization object for thread safe access to: - // * mRewarded - // * mRewardedAdInternalPtr - // * mLoadAdCallbackDataPtr - private final Object mRewardedLock; + // * rewarded + // * rewardedAdInternalPtr + // * loadAdCallbackDataPtr + private final Object rewardedLock; // The {@link Activity} this helper uses to display its // {@link RewardedAd}. - private Activity mActivity; + private Activity activity; // The ad unit ID to use for the {@link RewardedAd}. - private String mAdUnitId; + private String adUnitId; // Pointer to a FutureCallbackData in the C++ wrapper that will be used to // complete the Future associated with the latest call to LoadAd. - private long mLoadAdCallbackDataPtr; + private long loadAdCallbackDataPtr; /** Constructor. */ public RewardedAdHelper(long rewardedAdInternalPtr) { - mRewardedAdInternalPtr = rewardedAdInternalPtr; - mRewardedLock = new Object(); + this.rewardedAdInternalPtr = rewardedAdInternalPtr; + rewardedLock = new Object(); // Test the callbacks and fail quickly if something's wrong. completeRewardedAdFutureCallback(CPP_NULLPTR, 0, ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE); @@ -78,20 +77,20 @@ public RewardedAdHelper(long rewardedAdInternalPtr) { * object and sets it up. */ public void initialize(final long callbackDataPtr, Activity activity) { - mActivity = activity; + this.activity = activity; - mActivity.runOnUiThread(new Runnable() { + this.activity.runOnUiThread(new Runnable() { @Override public void run() { int errorCode; String errorMessage; - synchronized (mRewardedLock) { - if (mRewarded == null) { + synchronized (rewardedLock) { + if (rewarded == null) { try { errorCode = ConstantsHelper.CALLBACK_ERROR_NONE; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_NONE; } catch (IllegalStateException e) { - mRewarded = null; + rewarded = null; // This exception can be thrown if the ad unit ID was already set. errorCode = ConstantsHelper.CALLBACK_ERROR_ALREADY_INITIALIZED; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_ALREADY_INITIALIZED; @@ -108,23 +107,23 @@ public void run() { /** Disconnect the helper from the interstital ad. */ public void disconnect() { - synchronized (mRewardedLock) { - mRewardedAdInternalPtr = CPP_NULLPTR; - mLoadAdCallbackDataPtr = CPP_NULLPTR; + synchronized (rewardedLock) { + rewardedAdInternalPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } - if (mActivity == null) { + if (activity == null) { return; } - mActivity.runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - synchronized (mRewardedLock) { - if (mRewarded != null) { - mRewarded.setFullScreenContentCallback(null); - mRewarded.setOnPaidEventListener(null); - mRewarded = null; + synchronized (rewardedLock) { + if (rewarded != null) { + rewarded.setFullScreenContentCallback(null); + rewarded.setOnPaidEventListener(null); + rewarded = null; } } } @@ -133,38 +132,39 @@ public void run() { /** Loads an ad for the underlying {@link RewardedAd} object. */ public void loadAd(long callbackDataPtr, String adUnitId, final AdRequest request) { - if (mActivity == null) { + if (activity == null) { return; } - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { + synchronized (rewardedLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { completeRewardedLoadAdInternalError(callbackDataPtr, ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS, ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS); return; } - mLoadAdCallbackDataPtr = callbackDataPtr; + loadAdCallbackDataPtr = callbackDataPtr; } - mAdUnitId = adUnitId; + this.adUnitId = adUnitId; - mActivity.runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - synchronized (mRewardedLock) { - if (mActivity == null) { - completeRewardedLoadAdInternalError(mLoadAdCallbackDataPtr, + synchronized (rewardedLock) { + if (activity == null) { + completeRewardedLoadAdInternalError(loadAdCallbackDataPtr, ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } else { try { - RewardedAd.load(mActivity, mAdUnitId, request, new RewardedAdListener()); + RewardedAd.load( + activity, RewardedAdHelper.this.adUnitId, request, new RewardedAdListener()); } catch (IllegalStateException e) { - completeRewardedLoadAdInternalError(mLoadAdCallbackDataPtr, + completeRewardedLoadAdInternalError(loadAdCallbackDataPtr, ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED, ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr = CPP_NULLPTR; } } } @@ -172,21 +172,19 @@ public void run() { }); } - /** - * Shows a previously loaded ad. - */ + /** Shows a previously loaded ad. */ public void show(final long callbackDataPtr, final String verificationCustomData, final String verificationUserId) { - mActivity.runOnUiThread(new Runnable() { + activity.runOnUiThread(new Runnable() { @Override public void run() { - synchronized (mRewardedLock) { + synchronized (rewardedLock) { int errorCode; String errorMessage; - if (mAdUnitId == null) { + if (adUnitId == null) { errorCode = ConstantsHelper.CALLBACK_ERROR_UNINITIALIZED; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_UNINITIALIZED; - } else if (mRewarded == null) { + } else if (rewarded == null) { errorCode = ConstantsHelper.CALLBACK_ERROR_LOAD_IN_PROGRESS; errorMessage = ConstantsHelper.CALLBACK_ERROR_MESSAGE_LOAD_IN_PROGRESS; } else { @@ -197,9 +195,9 @@ public void run() { .setCustomData(verificationCustomData) .setUserId(verificationUserId) .build(); - mRewarded.setServerSideVerificationOptions(options); + rewarded.setServerSideVerificationOptions(options); } - mRewarded.show(mActivity, new UserEarnedRewardListener()); + rewarded.show(activity, new UserEarnedRewardListener()); } completeRewardedAdFutureCallback(callbackDataPtr, errorCode, errorMessage); } @@ -210,10 +208,10 @@ public void run() { private class UserEarnedRewardListener implements OnUserEarnedRewardListener { @Override public void onUserEarnedReward(RewardItem rewardItem) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { notifyUserEarnedRewardEvent( - mRewardedAdInternalPtr, rewardItem.getType(), rewardItem.getAmount()); + rewardedAdInternalPtr, rewardItem.getType(), rewardItem.getAmount()); } } } @@ -223,53 +221,54 @@ private class RewardedAdFullScreenContentListener extends FullScreenContentCallback implements OnPaidEventListener { @Override public void onAdClicked() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdClickedFullScreenContentEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdClickedFullScreenContentEvent(rewardedAdInternalPtr); } } } @Override public void onAdDismissedFullScreenContent() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdDismissedFullScreenContentEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdDismissedFullScreenContentEvent(rewardedAdInternalPtr); } } } @Override public void onAdFailedToShowFullScreenContent(AdError error) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdFailedToShowFullScreenContentEvent(mRewardedAdInternalPtr, error); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdFailedToShowFullScreenContentEvent(rewardedAdInternalPtr, error); } } } @Override public void onAdImpression() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdImpressionEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdImpressionEvent(rewardedAdInternalPtr); } } } @Override public void onAdShowedFullScreenContent() { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyAdShowedFullScreenContentEvent(mRewardedAdInternalPtr); + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyAdShowedFullScreenContentEvent(rewardedAdInternalPtr); } } } + @Override public void onPaidEvent(AdValue value) { - synchronized (mRewardedLock) { - if (mRewardedAdInternalPtr != CPP_NULLPTR) { - notifyPaidEvent(mRewardedAdInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), + synchronized (rewardedLock) { + if (rewardedAdInternalPtr != CPP_NULLPTR) { + notifyPaidEvent(rewardedAdInternalPtr, value.getCurrencyCode(), value.getPrecisionType(), value.getValueMicros()); } } @@ -279,25 +278,25 @@ public void onPaidEvent(AdValue value) { private class RewardedAdListener extends RewardedAdLoadCallback { @Override public void onAdFailedToLoad(LoadAdError loadAdError) { - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { + synchronized (rewardedLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { completeRewardedLoadAdError( - mLoadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + loadAdCallbackDataPtr, loadAdError, loadAdError.getCode(), loadAdError.getMessage()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } } @Override public void onAdLoaded(RewardedAd ad) { - synchronized (mRewardedLock) { - if (mLoadAdCallbackDataPtr != CPP_NULLPTR) { - mRewarded = ad; + synchronized (rewardedLock) { + if (loadAdCallbackDataPtr != CPP_NULLPTR) { + rewarded = ad; RewardedAdFullScreenContentListener listener = new RewardedAdFullScreenContentListener(); - mRewarded.setFullScreenContentCallback(listener); - mRewarded.setOnPaidEventListener(listener); - completeRewardedLoadedAd(mLoadAdCallbackDataPtr, mRewarded.getResponseInfo()); - mLoadAdCallbackDataPtr = CPP_NULLPTR; + rewarded.setFullScreenContentCallback(listener); + rewarded.setOnPaidEventListener(listener); + completeRewardedLoadedAd(loadAdCallbackDataPtr, rewarded.getResponseInfo()); + loadAdCallbackDataPtr = CPP_NULLPTR; } } }