Skip to content

Commit dd44380

Browse files
jkdsnot-fl3
authored andcommitted
android: add MainActivity.java hooks for ResizingLayout
1 parent c9cef83 commit dd44380

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

java/MainActivity.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,21 +199,38 @@ class ResizingLayout
199199
LinearLayout
200200
implements
201201
View.OnApplyWindowInsetsListener {
202+
//% RESIZING_LAYOUT_BODY
202203

203-
public ResizingLayout(Context context){
204-
super(context);
204+
public ResizingLayout(MainActivity activity){
205+
super(activity);
205206
// When viewing in landscape mode with keyboard shown, there are
206207
// gaps on both sides so we fill the negative space with black.
207208
setBackgroundColor(Color.BLACK);
208209
setOnApplyWindowInsetsListener(this);
210+
211+
//% RESIZING_LAYOUT_CONSTRUCTOR
209212
}
210213

211214
@Override
212215
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
216+
// This handler provides a default impl which resizes content when the
217+
// IME is shown or hidden.
218+
//
219+
// However this will lead to flickers in your app as the content is
220+
// resized before you have a chance to redraw it.
221+
//
222+
// The workaround for now is:
223+
// * Get IME and system insets and send them to your app.
224+
// * Notify your app to draw and apply the insets to fit.
225+
// * Disable this function by returning early.
226+
227+
//% RESIZING_LAYOUT_ON_APPLY_WINDOW_INSETS
228+
213229
if (Build.VERSION.SDK_INT >= 30) {
214230
Insets imeInsets = insets.getInsets(WindowInsets.Type.ime());
215231
Insets sysInsets = insets.getInsets(WindowInsets.Type.systemBars());
216232

233+
// When IME is visible then we dont need bottom inset
217234
int bottomPadding = sysInsets.bottom;
218235
if (imeInsets.bottom > 0) {
219236
bottomPadding = imeInsets.bottom;

0 commit comments

Comments
 (0)