| 
															
														 | 
														
															 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															1
														 | 
														
															 package com.th3rdwave.safeareacontext; 
														 | 
														
															1
														 | 
														
															 package com.th3rdwave.safeareacontext; 
														 | 
													
												
													
														| 
															2
														 | 
														
															  
														 | 
														
															2
														 | 
														
															  
														 | 
													
												
													
														| 
															3
														 | 
														
															 import android.content.Context; 
														 | 
														
															3
														 | 
														
															 import android.content.Context; 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															4
														 | 
														
															+import android.graphics.Rect; 
														 | 
													
												
													
														| 
															4
														 | 
														
															 import android.os.Build; 
														 | 
														
															5
														 | 
														
															 import android.os.Build; 
														 | 
													
												
													
														| 
															5
														 | 
														
															 import android.view.Surface; 
														 | 
														
															6
														 | 
														
															 import android.view.Surface; 
														 | 
													
												
													
														| 
															6
														 | 
														
															 import android.view.View; 
														 | 
														
															7
														 | 
														
															 import android.view.View; 
														 | 
													
												
											
												
													
														| 
															
														 | 
														
															 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															65
														 | 
														
															     View contentView = rootView.findViewById(android.R.id.content); 
														 | 
														
															66
														 | 
														
															     View contentView = rootView.findViewById(android.R.id.content); 
														 | 
													
												
													
														| 
															66
														 | 
														
															     float windowWidth = rootView.getWidth(); 
														 | 
														
															67
														 | 
														
															     float windowWidth = rootView.getWidth(); 
														 | 
													
												
													
														| 
															67
														 | 
														
															     float windowHeight = rootView.getHeight(); 
														 | 
														
															68
														 | 
														
															     float windowHeight = rootView.getHeight(); 
														 | 
													
												
													
														| 
															68
														 | 
														
															-    int[] windowLocation = new int[2]; 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															69
														 | 
														
															-    contentView.getLocationInWindow(windowLocation); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															70
														 | 
														
															-    windowInsets.top = Math.max(windowInsets.top - windowLocation[1], 0); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															71
														 | 
														
															-    windowInsets.left = Math.max(windowInsets.left - windowLocation[0], 0); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															72
														 | 
														
															-    windowInsets.bottom = Math.max(windowLocation[1] + contentView.getHeight() + windowInsets.bottom - windowHeight, 0); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															73
														 | 
														
															-    windowInsets.right = Math.max(windowLocation[0] + contentView.getWidth() + windowInsets.right - windowWidth, 0); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															69
														 | 
														
															+    Rect visibleRect = new Rect(); 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															70
														 | 
														
															+    contentView.getGlobalVisibleRect(visibleRect); 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															71
														 | 
														
															+ 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															72
														 | 
														
															+    windowInsets.top = Math.max(windowInsets.top - visibleRect.top, 0); 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															73
														 | 
														
															+    windowInsets.left = Math.max(windowInsets.left - visibleRect.left, 0); 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															74
														 | 
														
															+    windowInsets.bottom = Math.max(visibleRect.top + contentView.getHeight() + windowInsets.bottom - windowHeight, 0); 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															75
														 | 
														
															+    windowInsets.right = Math.max(visibleRect.left + contentView.getWidth() + windowInsets.right - windowWidth, 0); 
														 | 
													
												
													
														| 
															74
														 | 
														
															     return windowInsets; 
														 | 
														
															76
														 | 
														
															     return windowInsets; 
														 | 
													
												
													
														| 
															75
														 | 
														
															   } 
														 | 
														
															77
														 | 
														
															   } 
														 | 
													
												
													
														| 
															76
														 | 
														
															  
														 | 
														
															78
														 | 
														
															  
														 | 
													
												
													
														| 
															77
														 | 
														
															   private void maybeUpdateInsets() { 
														 | 
														
															79
														 | 
														
															   private void maybeUpdateInsets() { 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															80
														 | 
														
															+    if (!isAttachedToWindow()) { 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															81
														 | 
														
															+      return; 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															82
														 | 
														
															+    } 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															83
														 | 
														
															+ 
														 | 
													
												
													
														| 
															78
														 | 
														
															     EdgeInsets edgeInsets = getSafeAreaInsets(); 
														 | 
														
															84
														 | 
														
															     EdgeInsets edgeInsets = getSafeAreaInsets(); 
														 | 
													
												
													
														| 
															79
														 | 
														
															     if (mLastInsets == null || !mLastInsets.equalsToEdgeInsets(edgeInsets)) { 
														 | 
														
															85
														 | 
														
															     if (mLastInsets == null || !mLastInsets.equalsToEdgeInsets(edgeInsets)) { 
														 | 
													
												
													
														| 
															80
														 | 
														
															       Assertions.assertNotNull(mInsetsChangeListener).onInsetsChange(this, edgeInsets); 
														 | 
														
															86
														 | 
														
															       Assertions.assertNotNull(mInsetsChangeListener).onInsetsChange(this, edgeInsets); 
														 | 
													
												
											
												
													
														| 
															
														 | 
														
															 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															86
														 | 
														
															   protected void onAttachedToWindow() { 
														 | 
														
															92
														 | 
														
															   protected void onAttachedToWindow() { 
														 | 
													
												
													
														| 
															87
														 | 
														
															     super.onAttachedToWindow(); 
														 | 
														
															93
														 | 
														
															     super.onAttachedToWindow(); 
														 | 
													
												
													
														| 
															88
														 | 
														
															  
														 | 
														
															94
														 | 
														
															  
														 | 
													
												
													
														| 
															89
														 | 
														
															-    getRootView().getViewTreeObserver().addOnGlobalLayoutListener(this); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															95
														 | 
														
															+    getViewTreeObserver().addOnGlobalLayoutListener(this); 
														 | 
													
												
													
														| 
															90
														 | 
														
															     maybeUpdateInsets(); 
														 | 
														
															96
														 | 
														
															     maybeUpdateInsets(); 
														 | 
													
												
													
														| 
															91
														 | 
														
															   } 
														 | 
														
															97
														 | 
														
															   } 
														 | 
													
												
													
														| 
															92
														 | 
														
															  
														 | 
														
															98
														 | 
														
															  
														 | 
													
												
											
												
													
														| 
															
														 | 
														
															 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															94
														 | 
														
															   protected void onDetachedFromWindow() { 
														 | 
														
															100
														 | 
														
															   protected void onDetachedFromWindow() { 
														 | 
													
												
													
														| 
															95
														 | 
														
															     super.onDetachedFromWindow(); 
														 | 
														
															101
														 | 
														
															     super.onDetachedFromWindow(); 
														 | 
													
												
													
														| 
															96
														 | 
														
															  
														 | 
														
															102
														 | 
														
															  
														 | 
													
												
													
														| 
															97
														 | 
														
															-    getRootView().getViewTreeObserver().removeOnGlobalLayoutListener(this); 
														 | 
														
															
														 | 
														
															 
														 | 
													
												
													
														| 
															
														 | 
														
															 
														 | 
														
															103
														 | 
														
															+    getViewTreeObserver().removeOnGlobalLayoutListener(this); 
														 | 
													
												
													
														| 
															98
														 | 
														
															   } 
														 | 
														
															104
														 | 
														
															   } 
														 | 
													
												
													
														| 
															99
														 | 
														
															  
														 | 
														
															105
														 | 
														
															  
														 | 
													
												
													
														| 
															100
														 | 
														
															   @Override 
														 | 
														
															106
														 | 
														
															   @Override 
														 |