redirect the user to the device settings, if keyboard is not enabled

This commit is contained in:
tibbi 2022-01-05 10:46:37 +01:00
parent 2de1a89881
commit 37e40b935a
2 changed files with 30 additions and 0 deletions

View File

@ -2,13 +2,18 @@ package com.simplemobiletools.keyboard.activities
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.provider.Settings
import android.view.Menu import android.view.Menu
import android.view.MenuItem 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.extensions.appLaunched
import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.commons.models.FAQItem
import com.simplemobiletools.keyboard.BuildConfig import com.simplemobiletools.keyboard.BuildConfig
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
class MainActivity : SimpleActivity() { class MainActivity : SimpleActivity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -16,6 +21,22 @@ class MainActivity : SimpleActivity() {
appLaunched(BuildConfig.APPLICATION_ID) 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 { override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.menu_main, menu) menuInflater.inflate(R.menu.menu_main, menu)
return true return true
@ -40,4 +61,12 @@ class MainActivity : SimpleActivity() {
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) 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
}
}
} }

View File

@ -1,4 +1,5 @@
<resources> <resources>
<string name="app_name">Simple Keyboard</string> <string name="app_name">Simple Keyboard</string>
<string name="app_launcher_name">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> </resources>