22
33import android .content .Context ;
44import android .graphics .Rect ;
5- import android .os .Build ;
65import android .util .DisplayMetrics ;
7- import android .util .TypedValue ;
86import android .view .View ;
97import android .view .Window ;
108import android .view .inputmethod .InputMethodManager ;
1513import androidx .core .view .ViewCompat ;
1614import androidx .core .view .WindowInsetsAnimationCompat ;
1715import androidx .core .view .WindowInsetsCompat ;
18- import com .getcapacitor .Bridge ;
1916import java .util .List ;
2017
2118public class Keyboard {
@@ -24,7 +21,6 @@ interface KeyboardEventListener {
2421 void onKeyboardEvent (String event , int size );
2522 }
2623
27- private Bridge bridge ;
2824 private AppCompatActivity activity ;
2925 private View rootView ;
3026 private int usableHeightPrevious ;
@@ -43,9 +39,8 @@ public void setKeyboardEventListener(@Nullable KeyboardEventListener keyboardEve
4339 static final String EVENT_KB_WILL_HIDE = "keyboardWillHide" ;
4440 static final String EVENT_KB_DID_HIDE = "keyboardDidHide" ;
4541
46- public Keyboard (Bridge bridge , boolean resizeOnFullScreen ) {
47- this .bridge = bridge ;
48- this .activity = this .bridge .getActivity ();
42+ public Keyboard (AppCompatActivity activity , boolean resizeOnFullScreen ) {
43+ this .activity = activity ;
4944
5045 //http://stackoverflow.com/a/4737265/1091751 detect if keyboard is showing
5146 FrameLayout content = activity .getWindow ().getDecorView ().findViewById (android .R .id .content );
@@ -136,38 +131,9 @@ private void possiblyResizeChildOfContent(boolean keyboardShown) {
136131 private int computeUsableHeight () {
137132 Rect r = new Rect ();
138133 mChildOfContent .getWindowVisibleDisplayFrame (r );
139- if (shouldApplyEdgeToEdgeAdjustments ()) {
140- WindowInsetsCompat insets = ViewCompat .getRootWindowInsets (rootView );
141- if (insets != null ) {
142- int systemBars = insets .getInsets (WindowInsetsCompat .Type .systemBars ()).bottom ;
143- if (systemBars > 0 ) {
144- return r .bottom + systemBars ;
145- }
146- }
147- }
148-
149134 return isOverlays () ? r .bottom : r .height ();
150135 }
151136
152- private boolean shouldApplyEdgeToEdgeAdjustments () {
153- var adjustMarginsForEdgeToEdge = this .bridge .getConfig ().adjustMarginsForEdgeToEdge ();
154- if (adjustMarginsForEdgeToEdge .equals ("force" )) { // Force edge-to-edge adjustments regardless of app settings
155- return true ;
156- } else if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM && adjustMarginsForEdgeToEdge .equals ("auto" )) { // Auto means that we need to check the app's edge-to-edge preference
157- TypedValue value = new TypedValue ();
158- boolean optOutAttributeExists = activity
159- .getTheme ()
160- .resolveAttribute (android .R .attr .windowOptOutEdgeToEdgeEnforcement , value , true );
161-
162- if (!optOutAttributeExists ) { // Default is to apply edge to edge
163- return true ;
164- } else {
165- return value .data == 0 ;
166- }
167- }
168- return false ;
169- }
170-
171137 @ SuppressWarnings ("deprecation" )
172138 private boolean isOverlays () {
173139 final Window window = activity .getWindow ();
0 commit comments