com.google.android.gms.ads.VideoOptions Java Examples

The following examples show how to use com.google.android.gms.ads.VideoOptions. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeVideoAdLoader.java    From googleads-mobile-android-mediation with Apache License 2.0 6 votes vote down vote up
NativeVideoAdLoader(
    NendNativeAdForwarder forwarder,
    AdUnitMapper mapper,
    NativeMediationAdRequest nativeMediationAdRequest,
    Bundle mediationExtras) {
  Context context = forwarder.getContextFromWeakReference();
  if (context == null) {
    Log.e(TAG, "Your context may be released...");
    forwarder.failedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
    return;
  }
  this.forwarder = forwarder;

  NendAdNativeVideo.VideoClickOption clickOption = NendAdNativeVideo.VideoClickOption.LP;
  VideoOptions nativeVideoOptions =
      nativeMediationAdRequest.getNativeAdOptions().getVideoOptions();
  if (nativeVideoOptions != null && nativeVideoOptions.getClickToExpandRequested()) {
    clickOption = NendAdNativeVideo.VideoClickOption.FullScreen;
  }
  videoAdLoader = new NendAdNativeVideoLoader(context, mapper.spotId, mapper.apiKey, clickOption);
  videoAdLoader.setMediationName(MEDIATION_NAME_ADMOB);
  if (mediationExtras != null) {
    videoAdLoader.setUserId(mediationExtras.getString(NendMediationAdapter.KEY_USER_ID, ""));
  }
}
 
Example #2
Source File: AdPreset.java    From admobadapter with Apache License 2.0 4 votes vote down vote up
public VideoOptions getVideoOptions() {
    return videoOptions;
}
 
Example #3
Source File: AdPreset.java    From admobadapter with Apache License 2.0 4 votes vote down vote up
public void setVideoOptions(VideoOptions videoOptions) {
    this.videoOptions = videoOptions;
}
 
Example #4
Source File: MainActivity.java    From android-ads with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a request for a new native ad based on the boolean parameters and calls the
 * corresponding "populate" method when one is successfully returned.
 *
 */
private void refreshAd() {
    refresh.setEnabled(false);

    AdLoader.Builder builder = new AdLoader.Builder(this, ADMOB_AD_UNIT_ID);

    builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
        // OnUnifiedNativeAdLoadedListener implementation.
        @Override
        public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
            // You must call destroy on old ads when you are done with them,
            // otherwise you will have a memory leak.
            if (nativeAd != null) {
                nativeAd.destroy();
            }
            nativeAd = unifiedNativeAd;
            FrameLayout frameLayout =
                    findViewById(R.id.fl_adplaceholder);
            UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
                    .inflate(R.layout.ad_unified, null);
            populateUnifiedNativeAdView(unifiedNativeAd, adView);
            frameLayout.removeAllViews();
            frameLayout.addView(adView);
        }

    });

    VideoOptions videoOptions = new VideoOptions.Builder()
            .setStartMuted(startVideoAdsMuted.isChecked())
            .build();

    NativeAdOptions adOptions = new NativeAdOptions.Builder()
            .setVideoOptions(videoOptions)
            .build();

    builder.withNativeAdOptions(adOptions);

    AdLoader adLoader = builder.withAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            refresh.setEnabled(true);
            Toast.makeText(MainActivity.this, "Failed to load native ad: "
                    + errorCode, Toast.LENGTH_SHORT).show();
        }
    }).build();

    adLoader.loadAd(new AdRequest.Builder().build());

    videoStatus.setText("");
}
 
Example #5
Source File: MainActivity.java    From googleads-mobile-android-examples with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a request for a new native ad based on the boolean parameters and calls the
 * corresponding "populate" method when one is successfully returned.
 *
 */
private void refreshAd() {
    refresh.setEnabled(false);

    AdLoader.Builder builder = new AdLoader.Builder(this, ADMOB_AD_UNIT_ID);

    builder.forUnifiedNativeAd(new UnifiedNativeAd.OnUnifiedNativeAdLoadedListener() {
        // OnUnifiedNativeAdLoadedListener implementation.
        @Override
        public void onUnifiedNativeAdLoaded(UnifiedNativeAd unifiedNativeAd) {
            // If this callback occurs after the activity is destroyed, you must call
            // destroy and return or you may get a memory leak.
            if (isDestroyed()) {
                unifiedNativeAd.destroy();
                return;
            }
            // You must call destroy on old ads when you are done with them,
            // otherwise you will have a memory leak.
            if (nativeAd != null) {
                nativeAd.destroy();
            }
            nativeAd = unifiedNativeAd;
            FrameLayout frameLayout =
                    findViewById(R.id.fl_adplaceholder);
            UnifiedNativeAdView adView = (UnifiedNativeAdView) getLayoutInflater()
                    .inflate(R.layout.ad_unified, null);
            populateUnifiedNativeAdView(unifiedNativeAd, adView);
            frameLayout.removeAllViews();
            frameLayout.addView(adView);
        }

    });

    VideoOptions videoOptions = new VideoOptions.Builder()
            .setStartMuted(startVideoAdsMuted.isChecked())
            .build();

    NativeAdOptions adOptions = new NativeAdOptions.Builder()
            .setVideoOptions(videoOptions)
            .build();

    builder.withNativeAdOptions(adOptions);

    AdLoader adLoader = builder.withAdListener(new AdListener() {
        @Override
        public void onAdFailedToLoad(int errorCode) {
            refresh.setEnabled(true);
            Toast.makeText(MainActivity.this, "Failed to load native ad: "
                    + errorCode, Toast.LENGTH_SHORT).show();
        }
    }).build();

    adLoader.loadAd(new AdRequest.Builder().build());

    videoStatus.setText("");
}
 
Example #6
Source File: AdMobNativeSettings.java    From mobile-sdk-android with Apache License 2.0 2 votes vote down vote up
/**
 * Set the VideoOptions to be set on the NativeAdOptions when construction AdLoader.
 * @param videoOptions an instance of com.google.android.gms.ads.VideoOptions
 */
public static void setVideoOptions(VideoOptions videoOptions) {
    AdMobNativeSettings.videoOptions = videoOptions;
}