Skip to content

Commit

Permalink
Updates samples to v3.35.0.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 673054076
  • Loading branch information
google-ima-devrel-bot authored and IMA Developer Relations committed Sep 11, 2024
1 parent 9a98510 commit bc41078
Show file tree
Hide file tree
Showing 16 changed files with 126 additions and 161 deletions.
2 changes: 1 addition & 1 deletion AdvancedExample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
2 changes: 1 addition & 1 deletion AdvancedExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.ads.interactivemedia.v3.samples.videoplayerapp">
>
<!-- Required permissions for the IMA SDK -->
<uses-permission android:name="android.permission.INTERNET"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,7 +23,7 @@ private enum PlaybackState {

private MediaController mediaController;
private PlaybackState playbackState;
private final List<PlayerCallback> videoPlayerCallbacks = new ArrayList<PlayerCallback>(1);
private final List<PlayerCallback> videoPlayerCallbacks = new ArrayList<>(1);

public SampleVideoPlayer(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
Expand All @@ -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;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
};

Expand Down Expand Up @@ -113,10 +110,6 @@ public void makeFullscreen(boolean isFullscreen) {
}
}

public VideoPlayerController getVideoPlayerController() {
return videoPlayerController;
}

@Override
public void onPause() {
if (videoPlayerController != null) {
Expand All @@ -141,8 +134,4 @@ public void onDestroy() {
}
super.onDestroy();
}

public boolean isVmap() {
return videoItem.getIsVmap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<VideoItem> {

private int layoutResourceId;
private final int layoutResourceId;

public VideoItemAdapter(Context context, int layoutResourceId, List<VideoItem> 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;

Expand All @@ -29,23 +31,24 @@ 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();
}

VideoItem item = getItem(position);

assert item != null;
videoItemHolder.title.setText(item.getTitle());
videoItemHolder.image.setImageResource(item.getImageResource());

return row;
}

/** Holds the UI element equivalents of a VideoItem. */
private class VideoItemHolder {
private static class VideoItemHolder {

TextView title;
ImageView image;
Expand Down
Loading

0 comments on commit bc41078

Please sign in to comment.