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

Commit f4284638 authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Update how PIP size is determined"

parents 6c83d230 a7f69740
Loading
Loading
Loading
Loading
+47 −1
Original line number Diff line number Diff line
@@ -18,9 +18,11 @@ package com.android.internal.policy;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.util.Size;
import android.view.Gravity;
import android.view.ViewConfiguration;
import android.widget.Scroller;
@@ -56,6 +58,10 @@ public class PipSnapAlgorithm {
    private final int mDefaultSnapMode = SNAP_MODE_CORNERS_AND_EDGES;
    private int mSnapMode = mDefaultSnapMode;

    private final float mDefaultSizePercent;
    private final float mMinAspectRatioForMinSize;
    private final float mMaxAspectRatioForMinSize;

    private Scroller mScroller;
    private int mOrientation = Configuration.ORIENTATION_UNDEFINED;

@@ -63,9 +69,15 @@ public class PipSnapAlgorithm {
    private boolean mIsMinimized;

    public PipSnapAlgorithm(Context context) {
        Resources res = context.getResources();
        mContext = context;
        mMinimizedVisibleSize = context.getResources().getDimensionPixelSize(
        mMinimizedVisibleSize = res.getDimensionPixelSize(
                com.android.internal.R.dimen.pip_minimized_visible_size);
        mDefaultSizePercent = res.getFloat(
                com.android.internal.R.dimen.config_pictureInPictureDefaultSizePercent);
        mMaxAspectRatioForMinSize = res.getFloat(
                com.android.internal.R.dimen.config_pictureInPictureAspectRatioLimitForMinSize);
        mMinAspectRatioForMinSize = 1f / mMaxAspectRatioForMinSize;
        onConfigurationChanged();
    }

@@ -241,6 +253,40 @@ public class PipSnapAlgorithm {
        movementBoundsOut.bottom -= imeHeight;
    }

    /**
     * @return the size of the PiP at the given {@param aspectRatio}, ensuring that the minimum edge
     * is at least {@param minEdgeSize}.
     */
    public Size getSizeForAspectRatio(float aspectRatio, float minEdgeSize, int displayWidth,
            int displayHeight) {
        final int smallestDisplaySize = Math.min(displayWidth, displayHeight);
        final int minSize = (int) Math.max(minEdgeSize, smallestDisplaySize * mDefaultSizePercent);

        final int width;
        final int height;
        if (aspectRatio <= mMinAspectRatioForMinSize || aspectRatio > mMaxAspectRatioForMinSize) {
            // Beyond these points, we can just use the min size as the shorter edge
            if (aspectRatio <= 1) {
                // Portrait, width is the minimum size
                width = minSize;
                height = Math.round(width / aspectRatio);
            } else {
                // Landscape, height is the minimum size
                height = minSize;
                width = Math.round(height * aspectRatio);
            }
        } else {
            // Within these points, we ensure that the bounds fit within the radius of the limits
            // at the points
            final float widthAtMaxAspectRatioForMinSize = mMaxAspectRatioForMinSize * minSize;
            final float radius = PointF.length(widthAtMaxAspectRatioForMinSize, minSize);
            height = (int) Math.round(Math.sqrt((radius * radius) /
                    (aspectRatio * aspectRatio + 1)));
            width = Math.round(height * aspectRatio);
        }
        return new Size(width, height);
    }

    /**
     * @return the closest point in {@param points} to the given {@param x} and {@param y}.
     */
+4 −3
Original line number Diff line number Diff line
@@ -24,9 +24,10 @@
    <!-- Flags enabling default window features. See Window.java -->
    <bool name="config_defaultWindowFeatureOptionsPanel">false</bool>

    <!-- Max default size [WIDTHxHEIGHT] on screen for picture-in-picture windows to fit inside.
         These values are in DPs and will be converted to pixel sizes internally. -->
    <string translatable="false" name="config_defaultPictureInPictureSize">240x135</string>
    <!-- The percentage of the screen width to use for the default width or height of
         picture-in-picture windows. Regardless of the percent set here, calculated size will never
         be smaller than @dimen/default_minimal_size_pip_resizable_task. -->
    <item name="config_pictureInPictureDefaultSizePercent" format="float" type="dimen">0.14</item>

    <!-- Default insets [LEFT/RIGHTxTOP/BOTTOM] from the screen edge for picture-in-picture windows.
         These values are in DPs and will be converted to pixel sizes internally. -->
+11 −3
Original line number Diff line number Diff line
@@ -2545,9 +2545,17 @@
         These values are in DPs and will be converted to pixel sizes internally. -->
    <string translatable="false" name="config_defaultPictureInPictureScreenEdgeInsets">16x16</string>

    <!-- Max default size [WIDTHxHEIGHT] on screen for picture-in-picture windows to fit inside.
         These values are in DPs and will be converted to pixel sizes internally. -->
    <string translatable="false" name="config_defaultPictureInPictureSize">192x120</string>
    <!-- The percentage of the screen width to use for the default width or height of
         picture-in-picture windows. Regardless of the percent set here, calculated size will never
         be smaller than @dimen/default_minimal_size_pip_resizable_task. -->
    <item name="config_pictureInPictureDefaultSizePercent" format="float" type="dimen">0.23</item>

    <!-- The default aspect ratio for picture-in-picture windows. -->
    <item name="config_pictureInPictureDefaultAspectRatio" format="float" type="dimen">1.777778</item>

    <!-- This is the limit for the max and min aspect ratio (1 / this value) at which the min size
         will be used instead of an adaptive size based loosely on area. -->
    <item name="config_pictureInPictureAspectRatioLimitForMinSize" format="float" type="dimen">1.777778</item>

    <!-- The default gravity for the picture-in-picture window.
         Currently, this maps to Gravity.BOTTOM | Gravity.RIGHT -->
+3 −0
Original line number Diff line number Diff line
@@ -486,6 +486,9 @@
    <!-- The default minimal size of a resizable task, in both dimensions. -->
    <dimen name="default_minimal_size_resizable_task">220dp</dimen>

    <!-- The default minimal size of a PiP task, in both dimensions. -->
    <dimen name="default_minimal_size_pip_resizable_task">108dp</dimen>

    <!-- Height of a task when in minimized mode from the top when launcher is resizable. -->
    <dimen name="task_height_of_minimized_mode">80dp</dimen>

+4 −1
Original line number Diff line number Diff line
@@ -318,7 +318,9 @@
  <java-symbol type="integer" name="config_defaultDisplayDefaultColorMode" />
  <java-symbol type="bool" name="config_enableAppWidgetService" />
  <java-symbol type="string" name="config_defaultPictureInPictureScreenEdgeInsets" />
  <java-symbol type="string" name="config_defaultPictureInPictureSize" />
  <java-symbol type="dimen" name="config_pictureInPictureDefaultSizePercent" />
  <java-symbol type="dimen" name="config_pictureInPictureDefaultAspectRatio" />
  <java-symbol type="dimen" name="config_pictureInPictureAspectRatioLimitForMinSize" />
  <java-symbol type="integer" name="config_defaultPictureInPictureGravity" />
  <java-symbol type="dimen" name="config_pictureInPictureMinAspectRatio" />
  <java-symbol type="dimen" name="config_pictureInPictureMaxAspectRatio" />
@@ -1777,6 +1779,7 @@
  <java-symbol type="id" name="replace_message" />
  <java-symbol type="fraction" name="config_dimBehindFadeDuration" />
  <java-symbol type="dimen" name="default_minimal_size_resizable_task" />
  <java-symbol type="dimen" name="default_minimal_size_pip_resizable_task" />
  <java-symbol type="dimen" name="task_height_of_minimized_mode" />
  <java-symbol type="fraction" name="config_screenAutoBrightnessDozeScaleFactor" />
  <java-symbol type="fraction" name="config_autoBrightnessAdjustmentMaxGamma" />
Loading