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

Commit 297985ab authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

A brave new world for window insets (8/n)

WindowInsets now keeps track of all insets per type. Insets are
non-additive, i.e. every inset starts out relative to the window
edge, so the IME inset would include the navigation bar inset, but
not vice-versa.

We remove decorWindowInsets because it wasn't used at all.

For compatibility, we map the constructor where we pass in a Rect
to TOP_BAR. This is fine as every query to systemWindowInsets
stableInsets will include this type, so we don't need the
information where it came from.

Test: WindowInsetTest
Bug: 118118435
Change-Id: I1cb37d328060293f9a876e61d4a09e6675fa7197
parent 027ff086
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) {
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public class InsetsState implements Parcelable {
                        true /* ignoreVisibility */, null /* typeSideMap */);
            }
        }
        return new WindowInsets(new Rect(systemInsets), null, new Rect(maxInsets), isScreenRound,
        return new WindowInsets(new Rect(systemInsets), new Rect(maxInsets), isScreenRound,
                alwaysConsumeNavBar, cutout);
    }

+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);
            }
+201 −178

File changed.

Preview size limit exceeded, changes collapsed.

+17 −2
Original line number Diff line number Diff line
@@ -16,12 +16,19 @@

package android.view;

import static android.view.WindowInsets.Type.ime;
import static android.view.WindowInsets.Type.indexOf;
import static android.view.WindowInsets.Type.sideBars;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.graphics.Insets;
import android.graphics.Rect;
import android.platform.test.annotations.Presubmit;
import android.support.test.filters.SmallTest;
import android.support.test.runner.AndroidJUnit4;
import android.view.WindowInsets.Builder;
import android.view.WindowInsets.Type;

import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,13 +40,13 @@ public class WindowInsetsTest {

    @Test
    public void systemWindowInsets_afterConsuming_isConsumed() {
        assertTrue(new WindowInsets(new Rect(1, 2, 3, 4), null, null, false, false, null)
        assertTrue(new WindowInsets(new Rect(1, 2, 3, 4), null, false, false, null)
                .consumeSystemWindowInsets().isConsumed());
    }

    @Test
    public void multiNullConstructor_isConsumed() {
        assertTrue(new WindowInsets(null, null, null, false, false, null).isConsumed());
        assertTrue(new WindowInsets((Rect) null, null, false, false, null).isConsumed());
    }

    @Test
@@ -47,4 +54,12 @@ public class WindowInsetsTest {
        assertTrue(new WindowInsets((Rect) null).isConsumed());
    }

    @Test
    public void typeMap() {
        Builder b = new WindowInsets.Builder();
        b.setInsets(sideBars(), Insets.of(0, 0, 0, 100));
        b.setInsets(ime(), Insets.of(0, 0, 0, 300));
        WindowInsets insets = b.build();
        assertEquals(300, insets.getSystemWindowInsets().bottom);
    }
}
Loading