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

Commit c4f571a2 authored by Robert Horvath's avatar Robert Horvath
Browse files

Move TV PiP away from keep clear areas

The PiP is placed in a way to avoid keep clear areas.
If no areas overlapping the default PiP anchor position are defined,
the PiP will stay at its anchor position.
Otherwise, it will try to move to a free location closest to its anchor
position. Unrestricted areas can cause the PiP to move across the entire
screen, but restricted areas have limited influence and can only move
the PiP a short distance.
If no free position is found, the PiP will be stashed for some time.
To find the position to move to once the PiP unstashes, a relaxed search
is performed, excluding a restricted keep clear area. If this still does
not yield a position to move to, only unrestricted areas will be taken
into account. The PiP is stashed along the edge closest to the unstash
position.

Bug: 218416347
Bug: 218494300
Test: atest TvPipKeepClearAlgorithmTest
Change-Id: I76c6527320fc403bb604b188f38eed505eeaab89
parent 22c3bb0c
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -33,4 +33,10 @@
    <!-- The default gravity for the picture-in-picture window.
         Currently, this maps to Gravity.BOTTOM | Gravity.RIGHT -->
    <integer name="config_defaultPictureInPictureGravity">0x55</integer>

    <!-- Fraction of screen width/height restricted keep clear areas can move the PiP. -->
    <fraction name="config_pipMaxRestrictedMoveDistance">15%</fraction>

    <!-- Duration (in milliseconds) the PiP stays stashed before automatically unstashing. -->
    <integer name="config_pipStashDuration">5000</integer>
</resources>
+24 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2022 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!-- These resources are around just to allow their values to be customized
     for TV products.  Do not translate. -->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">

    <!-- Padding between PIP and keep clear areas that caused it to move. -->
    <dimen name="pip_keep_clear_area_padding">16dp</dimen>
</resources>
+4 −2
Original line number Diff line number Diff line
@@ -70,7 +70,8 @@ public abstract class TvPipModule {
            TaskStackListenerImpl taskStackListener,
            DisplayController displayController,
            WindowManagerShellWrapper windowManagerShellWrapper,
            @ShellMainThread ShellExecutor mainExecutor) {
            @ShellMainThread ShellExecutor mainExecutor,
            @ShellMainThread Handler mainHandler) {
        return Optional.of(
                TvPipController.create(
                        context,
@@ -84,7 +85,8 @@ public abstract class TvPipModule {
                        taskStackListener,
                        displayController,
                        windowManagerShellWrapper,
                        mainExecutor));
                        mainExecutor,
                        mainHandler));
    }

    @WMSingleton
+1 −1
Original line number Diff line number Diff line
@@ -74,7 +74,7 @@ public class PipBoundsAlgorithm {
    /**
     * TODO: move the resources to SysUI package.
     */
    protected void reloadResources(Context context) {
    private void reloadResources(Context context) {
        final Resources res = context.getResources();
        mDefaultAspectRatio = res.getFloat(
                R.dimen.config_pictureInPictureDefaultAspectRatio);
+5 −1
Original line number Diff line number Diff line
@@ -54,11 +54,15 @@ public class PipBoundsState {
    public static final int STASH_TYPE_NONE = 0;
    public static final int STASH_TYPE_LEFT = 1;
    public static final int STASH_TYPE_RIGHT = 2;
    public static final int STASH_TYPE_BOTTOM = 3;
    public static final int STASH_TYPE_TOP = 4;

    @IntDef(prefix = { "STASH_TYPE_" }, value =  {
            STASH_TYPE_NONE,
            STASH_TYPE_LEFT,
            STASH_TYPE_RIGHT
            STASH_TYPE_RIGHT,
            STASH_TYPE_BOTTOM,
            STASH_TYPE_TOP
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface StashType {}
Loading