@@ -59,11 +59,22 @@ public static final class BufferOffset {
5959 public static final int INSET_BOTTOM = 12 ;
6060 public static final int INSET_BOTTOM_IME = 32 ;
6161
62+ public static final int INSET_CUTOUT_LEFT = 40 ;
63+ public static final int INSET_CUTOUT_TOP = 44 ;
64+ public static final int INSET_CUTOUT_RIGHT = 48 ;
65+ public static final int INSET_CUTOUT_BOTTOM = 52 ;
66+
67+
6268 public static final int INSET_LEFT_CONSUMED = 16 ;
6369 public static final int INSET_TOP_CONSUMED = 20 ;
6470 public static final int INSET_RIGHT_CONSUMED = 24 ;
6571 public static final int INSET_BOTTOM_CONSUMED = 28 ;
6672 public static final int INSET_BOTTOM_IME_CONSUMED = 36 ;
73+
74+ public static final int INSET_CUTOUT_LEFT_CONSUMED = 56 ;
75+ public static final int INSET_CUTOUT_TOP_CONSUMED = 60 ;
76+ public static final int INSET_CUTOUT_RIGHT_CONSUMED = 64 ;
77+ public static final int INSET_CUTOUT_BOTTOM_CONSUMED = 68 ;
6778 }
6879
6980 int mPaddingLeft = 0 ;
@@ -72,13 +83,21 @@ public static final class BufferOffset {
7283 int mPaddingBottom = 0 ;
7384
7485 Insets edgeInsets = Insets .NONE ;
75- Insets appliedInsets = Insets .NONE ;
7686 Insets imeInsets = Insets .NONE ;
7787
78-
7988 int overflowEdge = OverflowEdgeIgnore ;
8089
81- private final ByteBuffer insetBuffer = ByteBuffer .allocateDirect (40 );
90+ private static final byte [] EMPTY_INSETS = new byte [72 ];
91+
92+ private ByteBuffer mInsetBuffer ;
93+
94+ private ByteBuffer getInsetBuffer () {
95+ if (mInsetBuffer == null ) {
96+ mInsetBuffer = ByteBuffer .allocateDirect (72 );
97+ mInsetBuffer .order (ByteOrder .nativeOrder ());
98+ }
99+ return mInsetBuffer ;
100+ }
82101
83102 private WindowInsetListener insetListener = null ;
84103 private androidx .core .view .OnApplyWindowInsetsListener windowInsetsListener = null ;
@@ -91,8 +110,6 @@ public interface WindowInsetListener {
91110 void onApplyWindowInsets (ByteBuffer inset );
92111 }
93112
94- private static final byte [] EMPTY_INSETS = new byte [40 ];
95-
96113
97114 private boolean pendingInsetApply = false ;
98115 private final OnAttachStateChangeListener onAttachStateChangeListener = new OnAttachStateChangeListener () {
@@ -112,7 +129,6 @@ public void onViewDetachedFromWindow(@NonNull View v) {
112129
113130 public LayoutBase (Context context , AttributeSet attrs , int defStyleAttr ) {
114131 super (context , attrs , defStyleAttr );
115- insetBuffer .order (ByteOrder .nativeOrder ());
116132 }
117133
118134 public LayoutBase (Context context ) {
@@ -222,16 +238,16 @@ public void setPadding(int left, int top, int right, int bottom) {
222238 }
223239
224240 private void putInset (int offset , int value ) {
225- insetBuffer .putInt (offset , value );
241+ getInsetBuffer () .putInt (offset , value );
226242 }
227243
228244 private int getInset (int offset ) {
229- return insetBuffer .getInt (offset );
245+ return getInsetBuffer () .getInt (offset );
230246 }
231247
232248 private void resetInset () {
233- insetBuffer .position (0 );
234- insetBuffer .put (EMPTY_INSETS , 0 , 40 );
249+ getInsetBuffer () .position (0 );
250+ getInsetBuffer () .put (EMPTY_INSETS , 0 , EMPTY_INSETS . length );
235251 }
236252
237253 public void setOverflowEdge (int value ) {
@@ -254,6 +270,7 @@ public WindowInsetsCompat onApplyWindowInsets(
254270
255271 Insets systemBars = insets .getInsets (WindowInsetsCompat .Type .systemBars ());
256272 Insets ime = insets .getInsets (WindowInsetsCompat .Type .ime ());
273+ Insets cutout = insets .getInsets (WindowInsetsCompat .Type .displayCutout ());
257274
258275 if (systemBars == Insets .NONE && ime == Insets .NONE ) {
259276 return WindowInsetsCompat .CONSUMED ;
@@ -357,14 +374,24 @@ public WindowInsetsCompat onApplyWindowInsets(
357374 putInset (BufferOffset .INSET_BOTTOM , insetNavBottom );
358375 putInset (BufferOffset .INSET_BOTTOM_IME , insetImeBottom );
359376
377+ putInset (BufferOffset .INSET_CUTOUT_LEFT , cutout .left );
378+ putInset (BufferOffset .INSET_CUTOUT_TOP , cutout .top );
379+ putInset (BufferOffset .INSET_CUTOUT_RIGHT , cutout .right );
380+ putInset (BufferOffset .INSET_CUTOUT_BOTTOM , cutout .bottom );
381+
360382 putInset (BufferOffset .INSET_LEFT_CONSUMED , 0 );
361383 putInset (BufferOffset .INSET_TOP_CONSUMED , 0 );
362384 putInset (BufferOffset .INSET_RIGHT_CONSUMED , 0 );
363385 putInset (BufferOffset .INSET_BOTTOM_CONSUMED , 0 );
364386 putInset (BufferOffset .INSET_BOTTOM_IME_CONSUMED , 0 );
365387
388+ putInset (BufferOffset .INSET_CUTOUT_LEFT_CONSUMED , 0 );
389+ putInset (BufferOffset .INSET_CUTOUT_TOP_CONSUMED , 0 );
390+ putInset (BufferOffset .INSET_CUTOUT_RIGHT_CONSUMED , 0 );
391+ putInset (BufferOffset .INSET_CUTOUT_BOTTOM_CONSUMED , 0 );
392+
366393 if (base .insetListener != null ) {
367- base .insetListener .onApplyWindowInsets (insetBuffer );
394+ base .insetListener .onApplyWindowInsets (getInsetBuffer () );
368395 }
369396
370397 defaultConsume [0 ] = defaultConsume [1 ] = defaultConsume [2 ] = defaultConsume [3 ] = false ;
0 commit comments