Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f8d19af7 authored by Merissa Mitchell's avatar Merissa Mitchell
Browse files

[PiP on CD] Use DisplayIdListener to update PiP UI dimensions

when the display id changes in PipDisplayLayoutState.

Recall: http://recall/clips/82162650-bb7c-4cc1-9347-86889786f16e

Bug: 416788659
Bug: 417466276
Test: atest WMShellUnitTests:com.android.wm.shell.pip2
Test: atest WMShellUnitTests:com.android.wm.shell.pip
Test: atest WMShellUnitTests:com.android.wm.shell.common.pip
Test: Manual - verify on external display (2k monitor and Nexdock) that
PiP UI is scaled appropriately
Flag: com.android.window.flags.enable_connected_displays_pip

Change-Id: I1aa0c261dfce63542e8e628bf4843edaaf92e679
parent 24e52cc3
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ import android.util.Size
import com.android.wm.shell.R

class LegacySizeSpecSource(
        private val context: Context,
        private var context: Context,
        private val pipDisplayLayoutState: PipDisplayLayoutState
) : SizeSpecSource {
) : SizeSpecSource, PipDisplayLayoutState.DisplayIdListener {

    private var mDefaultMinSize = 0
    /** The absolute minimum an overridden size's edge can be */
@@ -39,6 +39,7 @@ class LegacySizeSpecSource(
    private var mMinAspectRatioForMinSize = 0f

    init {
        pipDisplayLayoutState.addDisplayIdListener(this)
        reloadResources()
    }

@@ -58,6 +59,11 @@ class LegacySizeSpecSource(
        mMinAspectRatioForMinSize = 1f / mMaxAspectRatioForMinSize
    }

    override fun onDisplayIdChanged(newContext: Context) {
        context = newContext
        reloadResources()
    }

    override fun onConfigurationChanged() {
        reloadResources()
    }
+12 −2
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.os.SystemProperties;
import android.util.ArraySet;
import android.view.Gravity;

import androidx.annotation.NonNull;

import com.android.wm.shell.R;

import java.util.Set;
@@ -30,7 +32,8 @@ import java.util.Set;
/**
 * Calculates the adjusted position that does not occlude keep clear areas.
 */
public class PhonePipKeepClearAlgorithm implements PipKeepClearAlgorithmInterface {
public class PhonePipKeepClearAlgorithm implements PipKeepClearAlgorithmInterface,
        PipDisplayLayoutState.DisplayIdListener {

    private boolean mKeepClearAreaGravityEnabled =
            SystemProperties.getBoolean(
@@ -39,8 +42,10 @@ public class PhonePipKeepClearAlgorithm implements PipKeepClearAlgorithmInterfac
    protected int mKeepClearAreasPadding;
    private int mImeOffset;

    public PhonePipKeepClearAlgorithm(Context context) {
    public PhonePipKeepClearAlgorithm(Context context,
            PipDisplayLayoutState pipDisplayLayoutState) {
        reloadResources(context);
        pipDisplayLayoutState.addDisplayIdListener(this);
    }

    private void reloadResources(Context context) {
@@ -49,6 +54,11 @@ public class PhonePipKeepClearAlgorithm implements PipKeepClearAlgorithmInterfac
        mImeOffset = res.getDimensionPixelSize(R.dimen.pip_ime_offset);
    }

    @Override
    public void onDisplayIdChanged(@NonNull Context context) {
        reloadResources(context);
    }

    /**
     * Adjusts the current position of PiP to avoid occluding keep clear areas. This will push PiP
     * towards the closest edge and then apply calculations to avoid occluding keep clear areas.
+8 −2
Original line number Diff line number Diff line
@@ -23,9 +23,9 @@ import com.android.wm.shell.R
import java.io.PrintWriter

class PhoneSizeSpecSource(
        private val context: Context,
        private var context: Context,
        private val pipDisplayLayoutState: PipDisplayLayoutState
) : SizeSpecSource {
) : SizeSpecSource, PipDisplayLayoutState.DisplayIdListener {
    private var DEFAULT_OPTIMIZED_ASPECT_RATIO = 9f / 16

    private var mDefaultMinSize = 0
@@ -87,6 +87,7 @@ class PhoneSizeSpecSource(
    private var mOptimizedAspectRatio = 0f

    init {
        pipDisplayLayoutState.addDisplayIdListener(this)
        reloadResources()
    }

@@ -119,6 +120,11 @@ class PhoneSizeSpecSource(
        }
    }

    override fun onDisplayIdChanged(newContext: Context) {
        context = newContext
        reloadResources()
    }

    override fun onConfigurationChanged() {
        reloadResources()
    }
+7 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import java.io.PrintWriter;
/**
 * Calculates the default, normal, entry, inset and movement bounds of the PIP.
 */
public class PipBoundsAlgorithm {
public class PipBoundsAlgorithm implements PipDisplayLayoutState.DisplayIdListener {

    private static final String TAG = PipBoundsAlgorithm.class.getSimpleName();
    private static final float INVALID_SNAP_FRACTION = -1f;
@@ -63,6 +63,7 @@ public class PipBoundsAlgorithm {
        mSnapAlgorithm = pipSnapAlgorithm;
        mPipKeepClearAlgorithm = pipKeepClearAlgorithm;
        mPipDisplayLayoutState = pipDisplayLayoutState;
        mPipDisplayLayoutState.addDisplayIdListener(this);
        mSizeSpecSource = sizeSpecSource;
        reloadResources(context);
        // Initialize the aspect ratio to the default aspect ratio.  Don't do this in reload
@@ -99,6 +100,11 @@ public class PipBoundsAlgorithm {
        reloadResources(context);
    }

    @Override
    public void onDisplayIdChanged(@NonNull Context context) {
        reloadResources(context);
    }

    /** Returns the normal bounds (i.e. the default entry bounds). */
    public Rect getNormalBounds() {
        // The normal bounds are the default bounds adjusted to the current aspect ratio.
+9 −2
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ import java.util.function.Consumer;
/**
 * Singleton source of truth for the current state of PIP bounds.
 */
public class PipBoundsState {
public class PipBoundsState implements PipDisplayLayoutState.DisplayIdListener {
    public static final int STASH_TYPE_NONE = 0;
    public static final int STASH_TYPE_LEFT = 1;
    public static final int STASH_TYPE_RIGHT = 2;
@@ -90,7 +90,7 @@ public class PipBoundsState {
    @NonNull private final PipDisplayLayoutState mPipDisplayLayoutState;
    private final Point mMaxSize = new Point();
    private final Point mMinSize = new Point();
    @NonNull private final Context mContext;
    @NonNull private Context mContext;
    private float mAspectRatio;
    private int mStashedState = STASH_TYPE_NONE;
    private int mStashOffset;
@@ -155,6 +155,7 @@ public class PipBoundsState {
        reloadResources();
        mSizeSpecSource = sizeSpecSource;
        mPipDisplayLayoutState = pipDisplayLayoutState;
        mPipDisplayLayoutState.addDisplayIdListener(this);

        // Update the relative proportion of the bounds compared to max possible size. Max size
        // spec takes the aspect ratio of the bounds into account, so both width and height
@@ -170,6 +171,12 @@ public class PipBoundsState {
        mSizeSpecSource.onConfigurationChanged();
    }

    @Override
    public void onDisplayIdChanged(@NonNull Context context) {
        mContext = context;
        reloadResources();
    }

    /** Update the bounds scale percentage value. */
    public void updateBoundsScale() {
        mBoundsScale = Math.min((float) mBounds.width() / mMaxSize.x, 1.0f);
Loading