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

Commit 78a5d3d0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Letterbox Reachability: Add a central stop for repositioning." into...

Merge "Letterbox Reachability: Add a central stop for repositioning." into sc-v2-dev am: 475584bd am: 9cf5a2d6

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15934230

Change-Id: I8c87742699cd8179510ffdd0d2c8482c12f9d9e6
parents 7c7383d9 9cf5a2d6
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -4925,16 +4925,15 @@
        device orientation. -->
    <bool name="config_letterboxIsReachabilityEnabled">false</bool>

    <!-- Default horizonal position of a center of the letterboxed app window when reachability is
        enabled and an app is fullscreen in landscape device orientation.
        0 corresponds to the left side of the screen and 1 to the right side. If given value < 0.0
        or > 1, it is ignored and right positionis used (1.0). The position multiplier is changed
        to a symmetrical value computed as (1 - current multiplier) after each double tap in the
        letterbox area. -->
    <item name="config_letterboxDefaultPositionMultiplierForReachability"
          format="float" type="dimen">
        0.9
    </item>
    <!-- Default horizonal position of the letterboxed app window when reachability is
        enabled and an app is fullscreen in landscape device orientation. When reachability is
        enabled, the position can change between left, center and right. This config defines the
        default one:
            - Option 0 - Left.
            - Option 1 - Center.
            - Option 2 - Right.
        If given value is outside of this range, the option 1 (center) is assummed. -->
    <integer name="config_letterboxDefaultPositionForReachability">1</integer>

    <!-- If true, hide the display cutout with display area -->
    <bool name="config_hideDisplayCutoutWithDisplayArea">false</bool>
+1 −1
Original line number Diff line number Diff line
@@ -4265,7 +4265,7 @@
  <java-symbol type="color" name="config_letterboxBackgroundColor" />
  <java-symbol type="dimen" name="config_letterboxHorizontalPositionMultiplier" />
  <java-symbol type="bool" name="config_letterboxIsReachabilityEnabled" />
  <java-symbol type="dimen" name="config_letterboxDefaultPositionMultiplierForReachability" />
  <java-symbol type="integer" name="config_letterboxDefaultPositionForReachability" />

  <java-symbol type="bool" name="config_hideDisplayCutoutWithDisplayArea" />

+4 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.view.WindowManager;

import com.android.server.UiThread;

import java.util.function.IntConsumer;
import java.util.function.Supplier;

/**
@@ -70,7 +71,7 @@ public class Letterbox {
    private final LetterboxSurface mFullWindowSurface = new LetterboxSurface("fullWindow");
    private final LetterboxSurface[] mSurfaces = { mLeft, mTop, mRight, mBottom };
    // Reachability gestures.
    private final Runnable mDoubleTapCallback;
    private final IntConsumer mDoubleTapCallback;

    /**
     * Constructs a Letterbox.
@@ -84,7 +85,7 @@ public class Letterbox {
            Supplier<Boolean> hasWallpaperBackgroundSupplier,
            Supplier<Integer> blurRadiusSupplier,
            Supplier<Float> darkScrimAlphaSupplier,
            Runnable doubleTapCallback) {
            IntConsumer doubleTapCallback) {
        mSurfaceControlFactory = surfaceControlFactory;
        mTransactionFactory = transactionFactory;
        mAreCornersRounded = areCornersRounded;
@@ -262,7 +263,7 @@ public class Letterbox {
        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            if (e.getAction() == MotionEvent.ACTION_UP) {
                mDoubleTapCallback.run();
                mDoubleTapCallback.accept((int) e.getX());
                return true;
            }
            return false;
+97 −45
Original line number Diff line number Diff line
@@ -54,6 +54,27 @@ final class LetterboxConfiguration {
    /** Using wallpaper as a background which can be blurred or dimmed with dark scrim. */
    static final int LETTERBOX_BACKGROUND_WALLPAPER = 3;

    /**
     * Enum for Letterbox reachability position types.
     *
     * <p>Order from left to right is important since it's used in {@link
     * #movePositionForReachabilityToNextRightStop} and {@link
     * #movePositionForReachabilityToNextLeftStop}.
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({LETTERBOX_REACHABILITY_POSITION_LEFT, LETTERBOX_REACHABILITY_POSITION_CENTER,
            LETTERBOX_REACHABILITY_POSITION_RIGHT})
    @interface LetterboxReachabilityPosition {};

    /** Letterboxed app window is aligned to the left side. */
    static final int LETTERBOX_REACHABILITY_POSITION_LEFT = 0;

    /** Letterboxed app window is positioned in the horizontal center. */
    static final int LETTERBOX_REACHABILITY_POSITION_CENTER = 1;

    /** Letterboxed app window is aligned to the right side. */
    static final int LETTERBOX_REACHABILITY_POSITION_RIGHT = 2;

    final Context mContext;

    // Aspect ratio of letterbox for fixed orientation, values <=
@@ -85,25 +106,25 @@ final class LetterboxConfiguration {
    // side of the screen and 1.0 to the right side.
    private float mLetterboxHorizontalPositionMultiplier;

    // Default horizontal position of a center of the letterboxed app window when reachability is
    // enabled and an app is fullscreen in landscape device orientatio. 0 corresponds to the left
    // side of the screen and 1.0 to the right side.
    // It is used as a starting point for mLetterboxHorizontalMultiplierForReachability.
    private float mDefaultPositionMultiplierForReachability;
    // Default horizontal position the letterboxed app window when reachability is enabled and
    // an app is fullscreen in landscape device orientatio.
    // It is used as a starting point for mLetterboxPositionForReachability.
    @LetterboxReachabilityPosition
    private int mDefaultPositionForReachability;

    // Whether reachability repositioning is allowed for letterboxed fullscreen apps in landscape
    // device orientation.
    private boolean mIsReachabilityEnabled;

    // Horizontal position of a center of the letterboxed app window. 0 corresponds to
    // the left side of the screen and 1 to the right side. Keep it global to prevent
    // "jumps" when switching between letterboxed apps. It's updated to reposition the app
    // window in response to a double tap gesture (see LetterboxUiController#handleDoubleTap).
    // Used in LetterboxUiController#getHorizontalPositionMultiplier which is called from
    // Horizontal position of a center of the letterboxed app window which is global to prevent
    // "jumps" when switching between letterboxed apps. It's updated to reposition the app window
    // in response to a double tap gesture (see LetterboxUiController#handleDoubleTap). Used in
    // LetterboxUiController#getHorizontalPositionMultiplier which is called from
    // ActivityRecord#updateResolvedBoundsHorizontalPosition.
    // TODO(b/199426138): Global reachability setting causes a jump when resuming an app from
    // Overview after changing position in another app.
    private volatile float mLetterboxHorizontalMultiplierForReachability;
    @LetterboxReachabilityPosition
    private volatile int mLetterboxPositionForReachability;

    LetterboxConfiguration(Context systemUiContext) {
        mContext = systemUiContext;
@@ -120,9 +141,8 @@ final class LetterboxConfiguration {
                R.dimen.config_letterboxHorizontalPositionMultiplier);
        mIsReachabilityEnabled = mContext.getResources().getBoolean(
                R.bool.config_letterboxIsReachabilityEnabled);
        mDefaultPositionMultiplierForReachability = mContext.getResources().getFloat(
                R.dimen.config_letterboxDefaultPositionMultiplierForReachability);
        mLetterboxHorizontalMultiplierForReachability = mDefaultPositionMultiplierForReachability;
        mDefaultPositionForReachability = readLetterboxReachabilityPositionFromConfig(mContext);
        mLetterboxPositionForReachability = mDefaultPositionForReachability;
    }

    /**
@@ -395,58 +415,90 @@ final class LetterboxConfiguration {
    }

    /*
     * Gets default horizontal position of a center of the letterboxed app window when reachability
     * is enabled specified in {@link
     * R.dimen.config_letterboxDefaultPositionMultiplierForReachability} or via an ADB command.
     * 0 corresponds to the left side of the screen and 1 to the right side. The returned value is
     * >= 0.0 and <= 1.0.
     * Gets default horizontal position of the letterboxed app window when reachability is enabled.
     * Specified in {@link R.integer.config_letterboxDefaultPositionForReachability} or via an ADB
     * command.
     */
    float getDefaultPositionMultiplierForReachability() {
        return (mDefaultPositionMultiplierForReachability < 0.0f
                || mDefaultPositionMultiplierForReachability > 1.0f)
                        // Default to a right position if invalid value is provided.
                        ? 1.0f : mDefaultPositionMultiplierForReachability;
    @LetterboxReachabilityPosition
    int getDefaultPositionForReachability() {
        return mDefaultPositionForReachability;
    }

    /**
     * Overrides default horizontal position of a center of the letterboxed app window when
     * reachability is enabled. If given value < 0.0 or > 1.0, then it and a value of {@link
     * R.dimen.config_letterboxDefaultPositionMultiplierForReachability} are ignored and the right
     * position (1.0) is used.
     * Overrides default horizonal position of the letterboxed app window when reachability
     * is enabled.
     */
    void setDefaultPositionMultiplierForReachability(float multiplier) {
        mDefaultPositionMultiplierForReachability = multiplier;
    void setDefaultPositionForReachability(@LetterboxReachabilityPosition int position) {
        mDefaultPositionForReachability = position;
    }

    /**
     * Resets default horizontal position of a center of the letterboxed app window when
     * reachability is enabled to {@link
     * R.dimen.config_letterboxDefaultPositionMultiplierForReachability}.
     * Resets default horizontal position of the letterboxed app window when reachability is
     * enabled to {@link R.integer.config_letterboxDefaultPositionForReachability}.
     */
    void resetDefaultPositionMultiplierForReachability() {
        mDefaultPositionMultiplierForReachability = mContext.getResources().getFloat(
                R.dimen.config_letterboxDefaultPositionMultiplierForReachability);
    void resetDefaultPositionForReachability() {
        mDefaultPositionForReachability = readLetterboxReachabilityPositionFromConfig(mContext);
    }

    @LetterboxReachabilityPosition
    private static int readLetterboxReachabilityPositionFromConfig(Context context) {
        int position = context.getResources().getInteger(
                R.integer.config_letterboxDefaultPositionForReachability);
        return position == LETTERBOX_REACHABILITY_POSITION_LEFT
                    || position == LETTERBOX_REACHABILITY_POSITION_CENTER
                    || position == LETTERBOX_REACHABILITY_POSITION_RIGHT
                    ? position : LETTERBOX_REACHABILITY_POSITION_CENTER;
    }

    /*
     * Gets horizontal position of a center of the letterboxed app window when reachability
     * is enabled specified. 0 corresponds to the left side of the screen and 1 to the right side.
     *
     * <p>The position multiplier is changed to a symmetrical value computed as (1 - current
     * multiplier) after each double tap in the letterbox area.
     * <p>The position multiplier is changed after each double tap in the letterbox area.
     */
    float getHorizontalMultiplierForReachability() {
        return mLetterboxHorizontalMultiplierForReachability;
        switch (mLetterboxPositionForReachability) {
            case LETTERBOX_REACHABILITY_POSITION_LEFT:
                return 0.0f;
            case LETTERBOX_REACHABILITY_POSITION_CENTER:
                return 0.5f;
            case LETTERBOX_REACHABILITY_POSITION_RIGHT:
                return 1.0f;
            default:
                throw new AssertionError(
                    "Unexpected letterbox position type: " + mLetterboxPositionForReachability);
        }
    }

    /** Returns a string representing the given {@link LetterboxReachabilityPosition}. */
    static String letterboxReachabilityPositionToString(
            @LetterboxReachabilityPosition int position) {
        switch (position) {
            case LETTERBOX_REACHABILITY_POSITION_LEFT:
                return "LETTERBOX_REACHABILITY_POSITION_LEFT";
            case LETTERBOX_REACHABILITY_POSITION_CENTER:
                return "LETTERBOX_REACHABILITY_POSITION_CENTER";
            case LETTERBOX_REACHABILITY_POSITION_RIGHT:
                return "LETTERBOX_REACHABILITY_POSITION_RIGHT";
            default:
                throw new AssertionError(
                    "Unexpected letterbox position type: " + position);
        }
    }

    /**
     * Changes letterbox position for reachability to the next available one on the right side.
     */
    void movePositionForReachabilityToNextRightStop() {
        mLetterboxPositionForReachability = Math.min(
                mLetterboxPositionForReachability + 1, LETTERBOX_REACHABILITY_POSITION_RIGHT);
    }

    /**
     * Changes horizontal position of a center of the letterboxed app window to the opposite
     * (1 - current multiplier) when reachability is enabled specified. 0 corresponds to the left
     * side of the screen and 1 to the right side.
     * Changes letterbox position for reachability to the next available one on the left side.
     */
    void flipHorizontalMultiplierForReachability() {
        mLetterboxHorizontalMultiplierForReachability =
                1.0f - mLetterboxHorizontalMultiplierForReachability;
    void movePositionForReachabilityToNextLeftStop() {
        mLetterboxPositionForReachability = Math.max(mLetterboxPositionForReachability - 1, 0);
    }

}
+13 −2
Original line number Diff line number Diff line
@@ -210,12 +210,23 @@ final class LetterboxUiController {
        return mActivityRecord.mWmService.mContext.getResources();
    }

    private void handleDoubleTap() {
    private void handleDoubleTap(int x) {
        if (!isReachabilityEnabled() || mActivityRecord.isInTransition()) {
            return;
        }

        mLetterboxConfiguration.flipHorizontalMultiplierForReachability();
        if (mLetterbox.getInnerFrame().left <= x && mLetterbox.getInnerFrame().right >= x) {
            // Only react to clicks at the sides of the letterboxed app window.
            return;
        }

        if (mLetterbox.getInnerFrame().left > x) {
            // Moving to the next stop on the left side of the app window: right > center > left.
            mLetterboxConfiguration.movePositionForReachabilityToNextLeftStop();
        } else if (mLetterbox.getInnerFrame().right < x) {
            // Moving to the next stop on the right side of the app window: left > center > right.
            mLetterboxConfiguration.movePositionForReachabilityToNextRightStop();
        }

        // TODO(197549949): Add animation for transition.
        mActivityRecord.recomputeConfiguration();
Loading