2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-02 03:40:16 +00:00

Fixes #1632: Hides keyboard on exit, shows on entry

This commit is contained in:
Sawyer Blatz 2019-04-16 08:09:19 -07:00 committed by Jeff Boek
parent 493bab42a4
commit d9bc4bf502

View File

@ -4,6 +4,7 @@
package org.mozilla.fenix package org.mozilla.fenix
import android.app.Activity
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Build import android.os.Build
@ -11,6 +12,7 @@ import android.os.Bundle
import android.preference.PreferenceManager import android.preference.PreferenceManager
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar import androidx.appcompat.widget.Toolbar
import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.NavHostFragment
@ -105,6 +107,8 @@ open class HomeActivity : AppCompatActivity() {
navHost.navController.popBackStack(R.id.browserFragment, true) navHost.navController.popBackStack(R.id.browserFragment, true)
allSessionsRemoved = false allSessionsRemoved = false
} }
showSoftwareKeyboardIfNecessary()
} }
override fun onDestroy() { override fun onDestroy() {
@ -140,6 +144,27 @@ open class HomeActivity : AppCompatActivity() {
super.onBackPressed() super.onBackPressed()
} }
override fun onPause() {
super.onPause()
hideSoftwareKeyboardIfNecessary()
}
private fun showSoftwareKeyboardIfNecessary() {
(getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply {
currentFocus?.also {
this.showSoftInput(it, 0)
}
}
}
private fun hideSoftwareKeyboardIfNecessary() {
(getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply {
currentFocus?.also {
this.hideSoftInputFromWindow(it.windowToken, 0)
}
}
}
private fun handleCrashIfNecessary(intent: Intent?) { private fun handleCrashIfNecessary(intent: Intent?) {
if (intent == null) { return } if (intent == null) { return }
if (!Crash.isCrashIntent(intent)) { return } if (!Crash.isCrashIntent(intent)) { return }