Skip to content

Commit 4c8040d

Browse files
Merge pull request #2702 from nextcloud/backport/2701/stable-4.4
[stable-4.4] BugFix - Add IME Insets In EditNoteActivity
2 parents 5c319f4 + 88acac0 commit 4c8040d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

app/src/main/java/it/niedermann/owncloud/notes/edit/EditNoteActivity.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
import androidx.annotation.NonNull;
2222
import androidx.annotation.Nullable;
23+
import androidx.core.graphics.Insets;
24+
import androidx.core.view.ViewCompat;
25+
import androidx.core.view.WindowCompat;
26+
import androidx.core.view.WindowInsetsCompat;
2327
import androidx.fragment.app.Fragment;
2428
import androidx.preference.PreferenceManager;
2529

@@ -101,6 +105,34 @@ protected void onCreate(final Bundle savedInstanceState) {
101105

102106
setSupportActionBar(binding.toolbar);
103107
binding.toolbar.setOnClickListener((v) -> fragment.showEditTitleDialog());
108+
setImeInsets();
109+
}
110+
111+
private void setImeInsets() {
112+
final var window = getWindow();
113+
if (window == null) {
114+
return;
115+
}
116+
117+
WindowCompat.setDecorFitsSystemWindows(window, false);
118+
119+
final var decorView = window.getDecorView();
120+
ViewCompat.setOnApplyWindowInsetsListener(decorView, (v, insets) -> {
121+
Insets imeInsets = insets.getInsets(WindowInsetsCompat.Type.ime());
122+
Insets navBarInsets = insets.getInsets(WindowInsetsCompat.Type.navigationBars());
123+
124+
// Apply bottom padding when keyboard is shown
125+
int bottomPadding = Math.max(imeInsets.bottom, navBarInsets.bottom);
126+
127+
v.setPadding(
128+
v.getPaddingLeft(),
129+
v.getPaddingTop(),
130+
v.getPaddingRight(),
131+
bottomPadding
132+
);
133+
134+
return insets;
135+
});
104136
}
105137

106138
@Override

0 commit comments

Comments
 (0)