-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Squished dialogs when opening keyboard programmatically
Signed-off-by: Álvaro Brey <[email protected]>
- Loading branch information
1 parent
178ea45
commit 5bc78f5
Showing
3 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/it/niedermann/owncloud/notes/shared/util/KeyboardUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Nextcloud Android client application | ||
* | ||
* @author Álvaro Brey | ||
* Copyright (C) 2022 Álvaro Brey | ||
* Copyright (C) 2022 Nextcloud GmbH | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU AFFERO GENERAL PUBLIC LICENSE for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public | ||
* License along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
package it.niedermann.owncloud.notes.shared.util | ||
|
||
import android.content.Context | ||
import android.view.inputmethod.InputMethodManager | ||
import android.widget.EditText | ||
|
||
object KeyboardUtils { | ||
private const val SHOW_INPUT_DELAY_MILLIS = 100L | ||
|
||
@JvmStatic | ||
fun showKeyboardForEditText(editText: EditText) { | ||
editText.requestFocus() | ||
// needs 100ms delay to account for focus animations | ||
editText.postDelayed({ | ||
val context = editText.context | ||
if (context != null) { | ||
val inputMethodManager = | ||
context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT) | ||
} | ||
}, SHOW_INPUT_DELAY_MILLIS) | ||
} | ||
} |