Skip to content

Commit

Permalink
Perform fullscreen action on configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
simoarpe committed Dec 16, 2024
1 parent 7cd9559 commit b66f4dc
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions android/java/org/chromium/chrome/browser/app/BraveActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

Expand Down Expand Up @@ -63,6 +64,7 @@
import com.wireguard.android.backend.GoBackend;

import org.chromium.chrome.browser.util.TabUtils;
import org.chromium.chrome.browser.youtube.YouTubeFeaturesLayout;
import org.jni_zero.JNINamespace;
import org.jni_zero.NativeMethods;

Expand Down Expand Up @@ -234,7 +236,6 @@
import org.chromium.mojo.system.MojoException;
import org.chromium.ui.KeyboardUtils;
import org.chromium.ui.widget.Toast;
import org.chromium.url.GURL;

import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -518,28 +519,16 @@ protected void onDestroyInternal() {
cleanUpWalletNativeServices();
cleanUpMiscAndroidMetrics();
}

@Override
public void onUserLeaveHint() {
super.onUserLeaveHint();
if (isActivityFinishingOrDestroyed()) return;
Tab currentTab = getActivityTab();
if (TabUtils.isYouTubeVideo(currentTab)
&& !isInPictureInPictureMode()
&& BackgroundVideoPlaybackTabHelper.isPlayingMedia(currentTab.getWebContents())) {
BackgroundVideoPlaybackTabHelper.setFullscreen(currentTab.getWebContents());
try {
enterPictureInPictureMode(new PictureInPictureParams.Builder().build());
} catch (IllegalStateException | IllegalArgumentException e) {
Log.e(TAG, "Error while entering picture in picture mode", e);
}
}
}

@Override
public void performOnConfigurationChanged(Configuration newConfig) {
super.performOnConfigurationChanged(newConfig);

YouTubeFeaturesLayout youtubeFeaturesLayout = findViewById(R.id.youtube_features_layout);
if (youtubeFeaturesLayout != null && youtubeFeaturesLayout.getLayoutParams() instanceof FrameLayout.LayoutParams params) {
params.bottomMargin = (int) getResources().getDimension(R.dimen.youtube_features_layout_margin_bottom);
params.leftMargin = (int) getResources().getDimension(R.dimen.youtube_features_layout_margin_left);
}

Tab currentTab = getActivityTab();
if (TabUtils.isYouTubeVideo(currentTab)
&& !isInPictureInPictureMode()
Expand All @@ -548,6 +537,13 @@ public void performOnConfigurationChanged(Configuration newConfig) {
}
}

public void showYouTubeFeaturesLayout(final boolean show) {
YouTubeFeaturesLayout youtubeFeaturesLayout = findViewById(R.id.youtube_features_layout);
if (youtubeFeaturesLayout != null) {
youtubeFeaturesLayout.setVisibility(show ? View.VISIBLE : View.GONE);
}
}

/**
* Gets Wallet model for Brave activity. It may be {@code null} if native initialization has not
* completed yet.
Expand Down

0 comments on commit b66f4dc

Please sign in to comment.