Download File
Download Project
Settings
Line Wrap
Themes
default
ambiance
bespin
dracula
eclipse
material
mbo
mdn-like
neat
solarized dark
ttcn
zenburn
MainActivity.java
/* * Copyright (C) 2016 Google, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.example.gms.ads.nativeexpressexample; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; import com.google.android.gms.ads.AdListener; import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.NativeExpressAdView; import com.google.android.gms.ads.VideoController; import com.google.android.gms.ads.VideoOptions; /** * A simple activity showing the use of a {@link NativeExpressAdView}. */ public class MainActivity extends AppCompatActivity { private static String LOG_TAG = "EXAMPLE"; NativeExpressAdView mAdView; VideoController mVideoController; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Locate the NativeExpressAdView. mAdView = findViewById(R.id.adView); // Set its video options. mAdView.setVideoOptions(new VideoOptions.Builder() .setStartMuted(true) .build()); // The VideoController can be used to get lifecycle events and info about an ad's video // asset. One will always be returned by getVideoController, even if the ad has no video // asset. mVideoController = mAdView.getVideoController(); mVideoController.setVideoLifecycleCallbacks(new VideoController.VideoLifecycleCallbacks() { @Override public void onVideoEnd() { Log.d(LOG_TAG, "Video playback is finished."); super.onVideoEnd(); } }); // Set an AdListener for the AdView, so the Activity can take action when an ad has finished // loading. mAdView.setAdListener(new AdListener() { @Override public void onAdLoaded() { if (mVideoController.hasVideoContent()) { Log.d(LOG_TAG, "Received an ad that contains a video asset."); } else { Log.d(LOG_TAG, "Received an ad that does not contain a video asset."); } } }); mAdView.loadAd(new AdRequest.Builder().build()); } }