redirect the user to the device settings, if keyboard is not enabled
This commit is contained in:
parent
2de1a89881
commit
37e40b935a
2 changed files with 30 additions and 0 deletions
|
@ -2,13 +2,18 @@ package com.simplemobiletools.keyboard.activities
|
|||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.inputmethod.InputMethodManager
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationAdvancedDialog
|
||||
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
|
||||
import com.simplemobiletools.commons.extensions.appLaunched
|
||||
import com.simplemobiletools.commons.models.FAQItem
|
||||
import com.simplemobiletools.keyboard.BuildConfig
|
||||
import com.simplemobiletools.keyboard.R
|
||||
|
||||
|
||||
class MainActivity : SimpleActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -16,6 +21,22 @@ class MainActivity : SimpleActivity() {
|
|||
appLaunched(BuildConfig.APPLICATION_ID)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
if (!isKeyboardEnabled()) {
|
||||
ConfirmationAdvancedDialog(this, messageId = R.string.redirection_note, positive = R.string.ok, negative = 0) { success ->
|
||||
if (success) {
|
||||
Intent(Settings.ACTION_INPUT_METHOD_SETTINGS).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
startActivity(this)
|
||||
}
|
||||
} else {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_main, menu)
|
||||
return true
|
||||
|
@ -40,4 +61,12 @@ class MainActivity : SimpleActivity() {
|
|||
|
||||
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true)
|
||||
}
|
||||
|
||||
private fun isKeyboardEnabled(): Boolean {
|
||||
val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
|
||||
val enabledKeyboards = inputMethodManager.enabledInputMethodList
|
||||
return enabledKeyboards.any {
|
||||
it.settingsActivity == SettingsActivity::class.java.canonicalName
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<resources>
|
||||
<string name="app_name">Simple Keyboard</string>
|
||||
<string name="app_launcher_name">Keyboard</string>
|
||||
<string name="redirection_note">Please enable Simple Keyboard on the next screen, to make it an available keyboard. Press \'Back\' once enabled.</string>
|
||||
</resources>
|
||||
|
|
Loading…
Reference in a new issue