8

Using floating/translucent windows with Android PIP causes a 3 second delay plus scaling issues. I've put together a sample app to demo the problem. I'm thinking there is some combination of tags I am either using incorrectly or completely missing some tag or tags. I tried many different combinations and came up with a few combos to demo the problem. I'll add code portions to give you and idea of what I am doing. I'll add additional or full code as needed. I want to try and keep this question compact but it may become long as I add more of the sample app necessary for you to actually run the app on your development environment.

Here are the significant sections from styles.xml for the test app:

    <!--== ERROR CASE #1=================================-->
    <!-- Causes 3 second delay to get into PIP mode      -->
    <!-- Incorrect window scale during 3 second delay    -->
    <!-- Incorrect window size  after PIP exit           -->
    <!--=================================================-->
    <item name="android:windowIsFloating">true</item>
    <!--=================================================-->

    <!--== ERROR CASE #2=================================-->
    <!-- Causes 3 second delay to get into PIP mode-->
    <!-- Window is not transparent                 -->
    <!--=================================================-->
    <item name="android:windowIsTranslucent">true</item>
    <!--=================================================-->

    <!--== ERROR CASE #3=================================-->
    <!-- Causes 3 second delay to get into PIP mode      -->
    <!-- Incorrect window scale during 3 second delay    -->
    <!-- Incorrect window scale after PIP exit           -->
    <!--=================================================-->
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowIsFloating">true</item>
    <!--=================================================-->

The following image is the initial app screen (as expected):

Initial app screen.

Putting the app into PIP mode causes this screen for three seconds (unexpected delay and bad scale):

entering PIP mode.

After 3 seconds, PIP mode is enabled ( expected image )

PIP mode

Exiting PIP results in an unusable activity due to bad scaling:

PIP exit

I'll add additional code snippets as necessary. But for now, I'm thinking styles.xml file is incorrect.

Here is styles:

<resources>
<style name="StyleJava42" parent="Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:backgroundDimEnabled">true</item>
    <item name="android:windowFullscreen">false</item>

    <!--== ERROR CASE #1=================================-->
    <!-- Causes 3 second delay to get into PIP mode      -->
    <!-- Incorrect window scale during 3 second delay    -->
    <!-- Incorrect window size  after PIP exit           -->
    <!--=================================================-->
    <item name="android:windowIsFloating">true</item>
    <!--=================================================-->

    <!--== ERROR CASE #2=================================-->
    <!-- Causes 3 second delay to get into PIP mode-->
    <!-- Window is not transparent                 -->
    <!--=================================================-->
    <item name="android:windowIsTranslucent">true</item>
    <!--=================================================-->

    <!--== ERROR CASE #3=================================-->
    <!-- Causes 3 second delay to get into PIP mode      -->
    <!-- Incorrect window scale during 3 second delay    -->
    <!-- Incorrect window scale after PIP exit           -->
    <!--=================================================-->
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowIsFloating">true</item>
    <!--=================================================-->

</style>
</resources>

And here is the manifest:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat"
    >
    <activity
        android:theme="@style/StyleJava42"
        android:name=".MainActivity"
        android:supportsPictureInPicture="true"
        >
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

Bottom line, I need a usable transparent window going in to and out of PIP mode that does not cause scaling problems.

EDIT:2019_08_20 - As requested, here is the activity code:

public class MainActivity extends Java42LifeCycleTrace { //AppCompatActivity  {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        if (isInPictureInPictureMode()) {
            setContentView(R.layout.activity_main_pip);
        } else {
            setContentView(R.layout.activity_main);
        }
    }
}

public void pip(View v) {
    ((Button) v).setText("WORKING");
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
        PictureInPictureParams.Builder pipBuilder = null;
        pipBuilder = new PictureInPictureParams.Builder();
        PictureInPictureParams parms = pipBuilder.build();
        enterPictureInPictureMode(parms);
    }
}

public void exit(View v) {
    finish();
}
}

Here is layout activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity"
>
<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:background="@android:drawable/btn_default"
    android:onClick="pip"
    android:text="Press for PIP"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/button2"
    app:layout_constraintVertical_bias="0.100000024" />
<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:background="@android:drawable/btn_default"
    android:onClick="exit"
    android:text="Press to Exit"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.100000024" />

</androidx.constraintlayout.widget.ConstraintLayout>

Here is layout activity_main_pip.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".MainActivity">
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:drawable/btn_default"
    android:text="PIP Mode"
/>
</LinearLayout>
Java42
  • 7,628
  • 1
  • 32
  • 50

0 Answers0