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

Commit 64e9cd30 authored by Jorim Jaggi's avatar Jorim Jaggi Committed by Android (Google) Code Review
Browse files

Merge changes from topic "inset_dispatch"

* changes:
  A brave new world for window insets (10/n)
  A brave new world for window insets (9/n)
  A brave new world for window insets (8/n)
parents 298c2698 15637fdd
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -970,7 +970,7 @@ public abstract class WallpaperService extends Service {
                            mFinalSystemInsets.set(mDispatchedOverscanInsets);
                            mFinalStableInsets.set(mDispatchedStableInsets);
                            WindowInsets insets = new WindowInsets(mFinalSystemInsets,
                                    null, mFinalStableInsets,
                                    mFinalStableInsets,
                                    getResources().getConfiguration().isScreenRound(), false,
                                    mDispatchedDisplayCutout);
                            if (DEBUG) {
+39 −16
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.view;

import static android.view.WindowInsets.Type.indexOf;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.graphics.Insets;
@@ -114,8 +116,8 @@ public class InsetsState implements Parcelable {
    public WindowInsets calculateInsets(Rect frame, boolean isScreenRound,
            boolean alwaysConsumeNavBar, DisplayCutout cutout,
            @Nullable @InsetSide SparseIntArray typeSideMap) {
        Insets systemInsets = Insets.NONE;
        Insets maxInsets = Insets.NONE;
        Insets[] typeInsetsMap = new Insets[Type.SIZE];
        Insets[] typeMaxInsetsMap = new Insets[Type.SIZE];
        final Rect relativeFrame = new Rect(frame);
        final Rect relativeFrameMax = new Rect(frame);
        for (int type = FIRST_TYPE; type <= LAST_TYPE; type++) {
@@ -123,32 +125,38 @@ public class InsetsState implements Parcelable {
            if (source == null) {
                continue;
            }
            systemInsets = processSource(source, systemInsets, relativeFrame,
                    false /* ignoreVisibility */, typeSideMap);
            processSource(source, relativeFrame, false /* ignoreVisibility */, typeInsetsMap,
                    typeSideMap);

            // IME won't be reported in max insets as the size depends on the EditorInfo of the IME
            // target.
            if (source.getType() != TYPE_IME) {
                maxInsets = processSource(source, maxInsets, relativeFrameMax,
                        true /* ignoreVisibility */, null /* typeSideMap */);
                processSource(source, relativeFrameMax, true /* ignoreVisibility */,
                        typeMaxInsetsMap, null /* typeSideMap */);
            }
        }
        return new WindowInsets(new Rect(systemInsets), null, new Rect(maxInsets), isScreenRound,
        return new WindowInsets(typeInsetsMap, typeMaxInsetsMap, isScreenRound,
                alwaysConsumeNavBar, cutout);
    }

    private Insets processSource(InsetsSource source, Insets insets, Rect relativeFrame,
            boolean ignoreVisibility, @Nullable @InsetSide SparseIntArray typeSideMap) {
        Insets currentInsets = source.calculateInsets(relativeFrame, ignoreVisibility);
        insets = Insets.add(currentInsets, insets);
        relativeFrame.inset(insets);
        if (typeSideMap != null && !Insets.NONE.equals(currentInsets)) {
            @InsetSide int insetSide = getInsetSide(currentInsets);
    private void processSource(InsetsSource source, Rect relativeFrame, boolean ignoreVisibility,
            Insets[] typeInsetsMap, @Nullable @InsetSide SparseIntArray typeSideMap) {
        Insets insets = source.calculateInsets(relativeFrame, ignoreVisibility);

        int index = indexOf(toPublicType(source.getType()));
        Insets existing = typeInsetsMap[index];
        if (existing == null) {
            typeInsetsMap[index] = insets;
        } else {
            typeInsetsMap[index] = Insets.max(existing, insets);
        }

        if (typeSideMap != null && !Insets.NONE.equals(insets)) {
            @InsetSide int insetSide = getInsetSide(insets);
            if (insetSide != INSET_SIDE_UNKNWON) {
                typeSideMap.put(source.getType(), getInsetSide(currentInsets));
                typeSideMap.put(source.getType(), getInsetSide(insets));
            }
        }
        return insets;
    }

    /**
@@ -229,6 +237,21 @@ public class InsetsState implements Parcelable {
        return result;
    }

    static @InsetType int toPublicType(@InternalInsetType int type) {
        switch (type) {
            case TYPE_TOP_BAR:
                return Type.TOP_BAR;
            case TYPE_SIDE_BAR_1:
            case TYPE_SIDE_BAR_2:
            case TYPE_SIDE_BAR_3:
                return Type.SIDE_BARS;
            case TYPE_IME:
                return Type.IME;
            default:
                throw new IllegalArgumentException("Unknown type: " + type);
        }
    }

    public static boolean getDefaultVisibly(@InsetType int type) {
        switch (type) {
            case TYPE_TOP_BAR:
+23 −0
Original line number Diff line number Diff line
@@ -939,6 +939,26 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
     */
    private static boolean sAcceptZeroSizeDragShadow;
    /**
     * Prior to Q, {@link #dispatchApplyWindowInsets} had some issues:
     * <ul>
     *     <li>The modified insets changed by {@link #onApplyWindowInsets} were passed to the
     *     entire view hierarchy in prefix order, including siblings as well as siblings of parents
     *     further down the hierarchy. This violates the basic concepts of the view hierarchy, and
     *     thus, the hierarchical dispatching mechanism was hard to use for apps.</li>
     *
     *     <li>Dispatch was stopped after the insets were fully consumed. This is somewhat confusing
     *     for developers, but more importantly, by adding more granular information to
     *     {@link WindowInsets} it becomes really cumbersome to define what consumed actually means
     *     </li>
     * </ul>
     *
     * In order to make window inset dispatching work properly, we dispatch window insets
     * in the view hierarchy in a proper hierarchical manner and don't stop dispatching if the
     * insets are consumed if this flag is set to {@code false}.
     */
    static boolean sBrokenInsetsDispatch;
    /** @hide */
    @IntDef({NOT_FOCUSABLE, FOCUSABLE, FOCUSABLE_AUTO})
    @Retention(RetentionPolicy.SOURCE)
@@ -5108,6 +5128,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            sAcceptZeroSizeDragShadow = targetSdkVersion < Build.VERSION_CODES.P;
            sBrokenInsetsDispatch = !ViewRootImpl.USE_NEW_INSETS
                    || targetSdkVersion < Build.VERSION_CODES.Q;
            sCompatibilityDone = true;
        }
    }
+16 −0
Original line number Diff line number Diff line
@@ -7111,6 +7111,14 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
    @Override
    public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
        insets = super.dispatchApplyWindowInsets(insets);
        if (View.sBrokenInsetsDispatch) {
            return brokenDispatchApplyWindowInsets(insets);
        } else {
            return newDispatchApplyWindowInsets(insets);
        }
    }

    private WindowInsets brokenDispatchApplyWindowInsets(WindowInsets insets) {
        if (!insets.isConsumed()) {
            final int count = getChildCount();
            for (int i = 0; i < count; i++) {
@@ -7123,6 +7131,14 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
        return insets;
    }

    private WindowInsets newDispatchApplyWindowInsets(WindowInsets insets) {
        final int count = getChildCount();
        for (int i = 0; i < count; i++) {
            getChildAt(i).dispatchApplyWindowInsets(insets);
        }
        return insets;
    }

    /**
     * Returns the animation listener to which layout animation events are
     * sent.
+1 −2
Original line number Diff line number Diff line
@@ -1859,8 +1859,7 @@ public final class ViewRootImpl implements ViewParent,
                        mContext.getResources().getConfiguration().isScreenRound(),
                        mAttachInfo.mAlwaysConsumeNavBar, displayCutout);
            } else {
                mLastWindowInsets = new WindowInsets(contentInsets,
                        null /* windowDecorInsets */, stableInsets,
                mLastWindowInsets = new WindowInsets(contentInsets, stableInsets,
                        mContext.getResources().getConfiguration().isScreenRound(),
                        mAttachInfo.mAlwaysConsumeNavBar, displayCutout);
            }
Loading