From c07dfc62962929eac644733260f7e15b4d44b656 Mon Sep 17 00:00:00 2001 From: Jackson Sui Date: Tue, 10 Sep 2024 12:04:48 -0700 Subject: [PATCH] Updates samples to v3.35.0. PiperOrigin-RevId: 673054076 --- AdvancedExample/app/build.gradle | 2 +- .../app/src/main/AndroidManifest.xml | 2 +- .../samplevideoplayer/SampleVideoPlayer.java | 43 ++++++++----------- .../samplevideoplayer/VideoPlayer.java | 2 +- .../v3/samples/videoplayerapp/MyActivity.java | 12 +++--- .../samples/videoplayerapp/VideoFragment.java | 23 +++------- .../videoplayerapp/VideoItemAdapter.java | 13 +++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- basicexample/app/build.gradle | 2 +- .../v3/samples/videoplayerapp/MyActivity.java | 11 +++-- .../videoplayerapp/VideoAdPlayerAdapter.java | 12 +++--- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 12 files changed, 56 insertions(+), 70 deletions(-) diff --git a/AdvancedExample/app/build.gradle b/AdvancedExample/app/build.gradle index 402de0e8..4f019164 100644 --- a/AdvancedExample/app/build.gradle +++ b/AdvancedExample/app/build.gradle @@ -40,5 +40,5 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.mediarouter:mediarouter:1.7.0' implementation 'com.android.support.constraint:constraint-layout:2.0.4' - implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.34.0' + implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.35.0' } diff --git a/AdvancedExample/app/src/main/AndroidManifest.xml b/AdvancedExample/app/src/main/AndroidManifest.xml index 50c919ef..1f748669 100644 --- a/AdvancedExample/app/src/main/AndroidManifest.xml +++ b/AdvancedExample/app/src/main/AndroidManifest.xml @@ -1,6 +1,6 @@ + > diff --git a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/SampleVideoPlayer.java b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/SampleVideoPlayer.java index 9835b1f4..f322d0e2 100644 --- a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/SampleVideoPlayer.java +++ b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/SampleVideoPlayer.java @@ -4,7 +4,6 @@ import android.content.Context; import android.media.AudioManager; -import android.media.MediaPlayer; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; import android.util.AttributeSet; @@ -24,7 +23,7 @@ private enum PlaybackState { private MediaController mediaController; private PlaybackState playbackState; - private final List videoPlayerCallbacks = new ArrayList(1); + private final List videoPlayerCallbacks = new ArrayList<>(1); public SampleVideoPlayer(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); @@ -49,36 +48,28 @@ private void init() { // Set OnCompletionListener to notify our callbacks when the video is completed. super.setOnCompletionListener( - new OnCompletionListener() { - - @Override - public void onCompletion(MediaPlayer mediaPlayer) { - // Reset the MediaPlayer. - playbackState = PlaybackState.STOPPED; - mediaPlayer.reset(); - mediaPlayer.setDisplay(getHolder()); - - for (PlayerCallback callback : videoPlayerCallbacks) { - callback.onComplete(); - } + mediaPlayer -> { + // Reset the MediaPlayer. + playbackState = PlaybackState.STOPPED; + mediaPlayer.reset(); + mediaPlayer.setDisplay(getHolder()); + + for (PlayerCallback callback : videoPlayerCallbacks) { + callback.onComplete(); } }); // Set OnErrorListener to notify our callbacks if the video errors. super.setOnErrorListener( - new OnErrorListener() { - - @Override - public boolean onError(MediaPlayer mp, int what, int extra) { - playbackState = PlaybackState.STOPPED; - for (PlayerCallback callback : videoPlayerCallbacks) { - callback.onError(); - } - - // Returning true signals to MediaPlayer that we handled the error. This will - // prevent the completion handler from being called. - return true; + (mp, what, extra) -> { + playbackState = PlaybackState.STOPPED; + for (PlayerCallback callback : videoPlayerCallbacks) { + callback.onError(); } + + // Returning true signals to MediaPlayer that we handled the error. This will + // prevent the completion handler from being called. + return true; }); } diff --git a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/VideoPlayer.java b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/VideoPlayer.java index dec4ca1a..170e7625 100644 --- a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/VideoPlayer.java +++ b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/samplevideoplayer/VideoPlayer.java @@ -6,7 +6,7 @@ public interface VideoPlayer { /** Interface for alerting caller of major video events. */ - public interface PlayerCallback { + interface PlayerCallback { /** Called when the current video starts playing from the beginning. */ void onPlay(); diff --git a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java index 495b2374..5c8751be 100644 --- a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java +++ b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java @@ -5,11 +5,13 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; import androidx.multidex.MultiDex; +import java.util.Objects; /** Main Activity. */ public class MyActivity extends AppCompatActivity @@ -61,16 +63,15 @@ public boolean onCreateOptionsMenu(Menu menu) { } @Override - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(@NonNull MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. - int id = item.getItemId(); return super.onOptionsItemSelected(item); } @Override - public void onConfigurationChanged(Configuration configuration) { + public void onConfigurationChanged(@NonNull Configuration configuration) { super.onConfigurationChanged(configuration); orientAppUi(); } @@ -123,6 +124,7 @@ public void onVideoSelected(VideoItem videoItem) { VideoListFragment videoListFragment = (VideoListFragment) getSupportFragmentManager().findFragmentByTag(VIDEO_PLAYLIST_FRAGMENT_TAG); + assert videoListFragment != null; int videoPlaylistFragmentId = videoListFragment.getId(); videoFragment = new VideoFragment(); @@ -154,11 +156,11 @@ private void hideStatusBar() { .getDecorView() .setSystemUiVisibility( View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN); - getSupportActionBar().hide(); + Objects.requireNonNull(getSupportActionBar()).hide(); } private void showStatusBar() { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); - getSupportActionBar().show(); + Objects.requireNonNull(getSupportActionBar()).show(); } } diff --git a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoFragment.java b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoFragment.java index f8064aed..b09e5853 100644 --- a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoFragment.java +++ b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoFragment.java @@ -23,7 +23,7 @@ public class VideoFragment extends Fragment { /** Listener called when the fragment's onCreateView is fired. */ public interface OnVideoFragmentViewCreatedListener { - public void onVideoFragmentViewCreated(); + void onVideoFragmentViewCreated(); } @Override @@ -61,7 +61,7 @@ private void initUi(View rootView) { // Make the dummyScrollContent height the size of the screen height. DisplayMetrics displayMetrics = new DisplayMetrics(); - getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + requireActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); ConstraintLayout constraintLayout = rootView.findViewById(R.id.constraintLayout); ConstraintSet forceHeight = new ConstraintSet(); forceHeight.clone(constraintLayout); @@ -72,13 +72,10 @@ private void initUi(View rootView) { // Provide an implementation of a logger so we can output SDK events to the UI. VideoPlayerController.Logger logger = - new VideoPlayerController.Logger() { - @Override - public void log(String message) { - Log.i("ImaExample", message); - if (logText != null) { - logText.append(message); - } + message -> { + Log.i("ImaExample", message); + if (logText != null) { + logText.append(message); } }; @@ -113,10 +110,6 @@ public void makeFullscreen(boolean isFullscreen) { } } - public VideoPlayerController getVideoPlayerController() { - return videoPlayerController; - } - @Override public void onPause() { if (videoPlayerController != null) { @@ -141,8 +134,4 @@ public void onDestroy() { } super.onDestroy(); } - - public boolean isVmap() { - return videoItem.getIsVmap(); - } } diff --git a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoItemAdapter.java b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoItemAdapter.java index ae0a5355..a07b0353 100644 --- a/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoItemAdapter.java +++ b/AdvancedExample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoItemAdapter.java @@ -7,20 +7,22 @@ import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; +import androidx.annotation.NonNull; import java.util.List; /** Renders VideoItems into a GridView for displaying videos in a playlist format. */ public class VideoItemAdapter extends ArrayAdapter { - private int layoutResourceId; + private final int layoutResourceId; public VideoItemAdapter(Context context, int layoutResourceId, List data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; } + @NonNull @Override - public View getView(int position, View convertView, ViewGroup parent) { + public View getView(int position, View convertView, @NonNull ViewGroup parent) { VideoItemHolder videoItemHolder; View row = convertView; @@ -29,8 +31,8 @@ public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(getContext()); row = inflater.inflate(layoutResourceId, parent, false); videoItemHolder = new VideoItemHolder(); - videoItemHolder.title = (TextView) row.findViewById(R.id.videoItemText); - videoItemHolder.image = (ImageView) row.findViewById(R.id.videoItemImage); + videoItemHolder.title = row.findViewById(R.id.videoItemText); + videoItemHolder.image = row.findViewById(R.id.videoItemImage); row.setTag(videoItemHolder); } else { videoItemHolder = (VideoItemHolder) row.getTag(); @@ -38,6 +40,7 @@ public View getView(int position, View convertView, ViewGroup parent) { VideoItem item = getItem(position); + assert item != null; videoItemHolder.title.setText(item.getTitle()); videoItemHolder.image.setImageResource(item.getImageResource()); @@ -45,7 +48,7 @@ public View getView(int position, View convertView, ViewGroup parent) { } /** Holds the UI element equivalents of a VideoItem. */ - private class VideoItemHolder { + private static class VideoItemHolder { TextView title; ImageView image; diff --git a/AdvancedExample/gradle/wrapper/gradle-wrapper.properties b/AdvancedExample/gradle/wrapper/gradle-wrapper.properties index de183985..82e606a5 100644 --- a/AdvancedExample/gradle/wrapper/gradle-wrapper.properties +++ b/AdvancedExample/gradle/wrapper/gradle-wrapper.properties @@ -2,5 +2,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip diff --git a/basicexample/app/build.gradle b/basicexample/app/build.gradle index 65294779..172d41ad 100644 --- a/basicexample/app/build.gradle +++ b/basicexample/app/build.gradle @@ -36,5 +36,5 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.7.0' implementation 'androidx.browser:browser:1.8.0' implementation 'androidx.media:media:1.7.0' - implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.34.0' + implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.35.0' } diff --git a/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java b/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java index f03dbdf9..7fa41304 100644 --- a/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java +++ b/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/MyActivity.java @@ -58,7 +58,6 @@ public class MyActivity extends AppCompatActivity { // the VideoView. private VideoView videoPlayer; private MediaController mediaController; - private View playButton; private VideoAdPlayerAdapter videoAdPlayerAdapter; @Override @@ -91,7 +90,7 @@ protected void onCreate(Bundle savedInstanceState) { new AdErrorEvent.AdErrorListener() { /** An event raised when there is an error loading or playing ads. */ @Override - public void onAdError(AdErrorEvent adErrorEvent) { + public void onAdError(@NonNull AdErrorEvent adErrorEvent) { Log.i(LOGTAG, "Ad Error: " + adErrorEvent.getError().getMessage()); resumeContent(); } @@ -99,7 +98,7 @@ public void onAdError(AdErrorEvent adErrorEvent) { adsLoader.addAdsLoadedListener( new AdsLoader.AdsLoadedListener() { @Override - public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) { + public void onAdsManagerLoaded(@NonNull AdsManagerLoadedEvent adsManagerLoadedEvent) { // Ads were successfully loaded, so get the AdsManager instance. AdsManager has // events for ad playback and errors. adsManager = adsManagerLoadedEvent.getAdsManager(); @@ -109,7 +108,7 @@ public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) { new AdErrorEvent.AdErrorListener() { /** An event raised when there is an error loading or playing ads. */ @Override - public void onAdError(AdErrorEvent adErrorEvent) { + public void onAdError(@NonNull AdErrorEvent adErrorEvent) { Log.e(LOGTAG, "Ad Error: " + adErrorEvent.getError().getMessage()); String universalAdIds = Arrays.toString(adsManager.getCurrentAd().getUniversalAdIds()); @@ -125,7 +124,7 @@ public void onAdError(AdErrorEvent adErrorEvent) { new AdEvent.AdEventListener() { /** Responds to AdEvents. */ @Override - public void onAdEvent(AdEvent adEvent) { + public void onAdEvent(@NonNull AdEvent adEvent) { if (adEvent.getType() != AdEvent.AdEventType.AD_PROGRESS) { Log.i(LOGTAG, "Event: " + adEvent.getType()); } @@ -182,7 +181,7 @@ public void onAdEvent(AdEvent adEvent) { }); // When the play button is clicked, request ads and hide the button. - playButton = findViewById(R.id.playButton); + View playButton = findViewById(R.id.playButton); playButton.setOnClickListener( view -> { videoPlayer.setVideoPath(SAMPLE_VIDEO_URL); diff --git a/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoAdPlayerAdapter.java b/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoAdPlayerAdapter.java index e916220a..8fa26438 100644 --- a/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoAdPlayerAdapter.java +++ b/basicexample/app/src/main/java/com/google/ads/interactivemedia/v3/samples/videoplayerapp/VideoAdPlayerAdapter.java @@ -7,6 +7,7 @@ import android.net.Uri; import android.util.Log; import android.widget.VideoView; +import androidx.annotation.NonNull; import com.google.ads.interactivemedia.v3.api.AdPodInfo; import com.google.ads.interactivemedia.v3.api.player.AdMediaInfo; import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer; @@ -40,12 +41,12 @@ public VideoAdPlayerAdapter(VideoView videoPlayer, AudioManager audioManager) { } @Override - public void addCallback(VideoAdPlayerCallback videoAdPlayerCallback) { + public void addCallback(@NonNull VideoAdPlayerCallback videoAdPlayerCallback) { videoAdPlayerCallbacks.add(videoAdPlayerCallback); } @Override - public void loadAd(AdMediaInfo adMediaInfo, AdPodInfo adPodInfo) { + public void loadAd(@NonNull AdMediaInfo adMediaInfo, @NonNull AdPodInfo adPodInfo) { // This simple ad loading logic works because preloading is disabled. To support // preloading ads your app must maintain state for the currently playing ad // while handling upcoming ad downloading and buffering at the same time. @@ -55,7 +56,7 @@ public void loadAd(AdMediaInfo adMediaInfo, AdPodInfo adPodInfo) { } @Override - public void pauseAd(AdMediaInfo adMediaInfo) { + public void pauseAd(@NonNull AdMediaInfo adMediaInfo) { Log.i(LOGTAG, "pauseAd"); savedAdPosition = videoPlayer.getCurrentPosition(); stopAdTracking(); @@ -89,12 +90,12 @@ public void release() { } @Override - public void removeCallback(VideoAdPlayerCallback videoAdPlayerCallback) { + public void removeCallback(@NonNull VideoAdPlayerCallback videoAdPlayerCallback) { videoAdPlayerCallbacks.remove(videoAdPlayerCallback); } @Override - public void stopAd(AdMediaInfo adMediaInfo) { + public void stopAd(@NonNull AdMediaInfo adMediaInfo) { Log.i(LOGTAG, "stopAd"); stopAdTracking(); } @@ -176,6 +177,7 @@ private void stopAdTracking() { } } + @NonNull @Override public VideoProgressUpdate getAdProgress() { long adPosition = videoPlayer.getCurrentPosition(); diff --git a/basicexample/gradle/wrapper/gradle-wrapper.properties b/basicexample/gradle/wrapper/gradle-wrapper.properties index 5d6560a4..348c409e 100644 --- a/basicexample/gradle/wrapper/gradle-wrapper.properties +++ b/basicexample/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-all.zip