Skip to content

Commit

Permalink
Make use of picture-in-picture (PIP) for the popup player on Android …
Browse files Browse the repository at this point in the history
…7.0 and higher.
  • Loading branch information
Isira-Seneviratne committed Aug 8, 2022
1 parent 74921d3 commit 707904f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="false" />

<application
android:name=".App"
Expand All @@ -27,8 +30,9 @@
tools:ignore="AllowBackup">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:launchMode="singleTask">
android:launchMode="singleTask"
android:supportsPictureInPicture="true"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import android.animation.ValueAnimator;
import android.app.Activity;
import android.app.PictureInPictureParams;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
Expand Down Expand Up @@ -434,6 +435,17 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
}
}

@Override
public void onPictureInPictureModeChanged(final boolean isInPictureInPictureMode) {
if (isInPictureInPictureMode) {
binding.overlayLayout.setVisibility(View.GONE);
binding.tabLayout.setVisibility(View.GONE);
} else {
binding.overlayLayout.setVisibility(View.VISIBLE);
binding.tabLayout.setVisibility(View.VISIBLE);
}
}

/*//////////////////////////////////////////////////////////////////////////
// OnClick
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -1128,6 +1140,18 @@ private void openBackgroundPlayer(final boolean append) {
}

private void openPopupPlayer(final boolean append) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final var pipParams = new PictureInPictureParams.Builder()
.build();
requireActivity().enterPictureInPictureMode(pipParams);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
requireActivity().enterPictureInPictureMode();
} else {
openPreNougatPopupPlayer(append);
}
}

private void openPreNougatPopupPlayer(final boolean append) {
if (!PermissionHelper.isPopupEnabled(activity)) {
PermissionHelper.showPopupEnablementToast(activity);
return;
Expand Down

0 comments on commit 707904f

Please sign in to comment.