From 37e40b935aba7ca1c325075412a6d2d6b6eafbf6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Wed, 5 Jan 2022 10:46:37 +0100 Subject: [PATCH] redirect the user to the device settings, if keyboard is not enabled --- .../keyboard/activities/MainActivity.kt | 29 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 2 files changed, 30 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/activities/MainActivity.kt index 03ad36a..2015678 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/activities/MainActivity.kt @@ -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 + } + } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1c93f8f..5f2a36b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,4 +1,5 @@ Simple Keyboard Keyboard + Please enable Simple Keyboard on the next screen, to make it an available keyboard. Press \'Back\' once enabled.