Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.google.ads.interactivemedia.v3.samples.videoplayerapp;

import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
Expand All @@ -18,14 +19,34 @@ public class VideoFragment extends Fragment {
private VideoPlayerController videoPlayerController;
private VideoItem videoItem;
private TextView videoTitle;
private ScrollView videoExampleLayout;
private ConstraintLayout constraintLayout;
private OnVideoFragmentViewCreatedListener viewCreatedCallback;

/** Listener called when the fragment's onCreateView is fired. */
public interface OnVideoFragmentViewCreatedListener {
void onVideoFragmentViewCreated();
}

@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
viewCreatedCallback = (OnVideoFragmentViewCreatedListener) context;
} catch (ClassCastException e) {
ClassCastException exception =
new ClassCastException(
context + " must implement " + OnVideoFragmentViewCreatedListener.class.getName());
exception.initCause(e);
throw exception;
}
}

@Override
public void onDetach() {
viewCreatedCallback = null;
super.onDetach();
}

@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Expand Down Expand Up @@ -55,14 +76,14 @@ private void initUi(View rootView) {
View playPauseToggle = rootView.findViewById(R.id.videoContainer);
ViewGroup companionAdSlot = rootView.findViewById(R.id.companionAdSlot);
videoTitle = rootView.findViewById(R.id.video_title);
videoExampleLayout = rootView.findViewById(R.id.videoExampleLayout);
ScrollView videoExampleLayout = rootView.findViewById(R.id.videoExampleLayout);
videoExampleLayout.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
videoExampleLayout.setSmoothScrollingEnabled(true);

// Make the dummyScrollContent height the size of the screen height.
DisplayMetrics displayMetrics = new DisplayMetrics();
requireActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
ConstraintLayout constraintLayout = rootView.findViewById(R.id.constraintLayout);
constraintLayout = rootView.findViewById(R.id.constraintLayout);
ConstraintSet forceHeight = new ConstraintSet();
forceHeight.clone(constraintLayout);
forceHeight.constrainHeight(R.id.dummyScrollContent, displayMetrics.heightPixels);
Expand Down Expand Up @@ -97,8 +118,12 @@ private void initUi(View rootView) {

/** Shows or hides all non-video UI elements to make the video as large as possible. */
public void makeFullscreen(boolean isFullscreen) {
for (int i = 0; i < videoExampleLayout.getChildCount(); i++) {
View view = videoExampleLayout.getChildAt(i);
if (constraintLayout == null) {
return;
}

for (int i = 0; i < constraintLayout.getChildCount(); i++) {
View view = constraintLayout.getChildAt(i);
// If it's not the video element, hide or show it, depending on fullscreen status.
if (view.getId() != R.id.videoContainer) {
if (isFullscreen) {
Expand Down
Loading