From 1b15a52fcbdcebc55ee3ffb4502995d6e9112560 Mon Sep 17 00:00:00 2001 From: merkost Date: Thu, 25 May 2023 21:45:10 +1000 Subject: [PATCH 01/13] Created Device Protected Storage Context --- app/src/main/AndroidManifest.xml | 2 ++ .../com/simplemobiletools/keyboard/databases/ClipsDatabase.kt | 3 ++- .../com/simplemobiletools/keyboard/extensions/Context.kt | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cd4a69d..4bcff12 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,6 +25,7 @@ @@ -42,6 +43,7 @@ diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt index 8b826e1..051fd9b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt @@ -4,6 +4,7 @@ import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase +import com.simplemobiletools.commons.extensions.safeStorageContext import com.simplemobiletools.keyboard.interfaces.ClipsDao import com.simplemobiletools.keyboard.models.Clip @@ -19,7 +20,7 @@ abstract class ClipsDatabase : RoomDatabase() { if (db == null) { synchronized(ClipsDatabase::class) { if (db == null) { - db = Room.databaseBuilder(context.applicationContext, ClipsDatabase::class.java, "clips.db").build() + db = Room.databaseBuilder(context.applicationContext.safeStorageContext, ClipsDatabase::class.java, "clips.db").build() db!!.openHelper.setWriteAheadLoggingEnabled(true) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 855438d..3e030a5 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -21,7 +21,7 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.ClipsDao -val Context.config: Config get() = Config.newInstance(applicationContext) +val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.clipsDB: ClipsDao get() = ClipsDatabase.getInstance(applicationContext).ClipsDao() From fc6bee9df7e898a03574ee36ab3db2691e649187 Mon Sep 17 00:00:00 2001 From: merkost Date: Fri, 26 May 2023 12:26:18 +1000 Subject: [PATCH 02/13] Configured storage for direct boot mode --- app/src/main/AndroidManifest.xml | 1 - .../keyboard/databases/ClipsDatabase.kt | 3 +-- .../keyboard/extensions/Context.kt | 17 +++++++++++++++-- .../keyboard/helpers/Config.kt | 3 ++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4bcff12..cfc5334 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -25,7 +25,6 @@ diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt index 051fd9b..04e64c8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/databases/ClipsDatabase.kt @@ -4,7 +4,6 @@ import android.content.Context import androidx.room.Database import androidx.room.Room import androidx.room.RoomDatabase -import com.simplemobiletools.commons.extensions.safeStorageContext import com.simplemobiletools.keyboard.interfaces.ClipsDao import com.simplemobiletools.keyboard.models.Clip @@ -20,7 +19,7 @@ abstract class ClipsDatabase : RoomDatabase() { if (db == null) { synchronized(ClipsDatabase::class) { if (db == null) { - db = Room.databaseBuilder(context.applicationContext.safeStorageContext, ClipsDatabase::class.java, "clips.db").build() + db = Room.databaseBuilder(context, ClipsDatabase::class.java, "clips.db").build() db!!.openHelper.setWriteAheadLoggingEnabled(true) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 3e030a5..4862531 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.keyboard.extensions import android.content.ClipboardManager import android.content.Context import android.graphics.Color +import android.os.Build import android.os.IBinder import android.view.LayoutInflater import android.view.View @@ -21,9 +22,21 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.ClipsDao -val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) +val Context.config: Config get() = Config.newInstance(applicationContext) -val Context.clipsDB: ClipsDao get() = ClipsDatabase.getInstance(applicationContext).ClipsDao() +val Context.safeStorageContext: Context + get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + createDeviceProtectedStorageContext() + } else { + this + } + +val Context.clipsDB: ClipsDao + get() = if (isDeviceLocked) { + ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao() + } else { + ClipsDatabase.getInstance(applicationContext).ClipsDao() + } fun Context.getCurrentClip(): String? { val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt index c612e27..3928b0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt @@ -2,11 +2,12 @@ package com.simplemobiletools.keyboard.helpers import android.content.Context import com.simplemobiletools.commons.helpers.BaseConfig +import com.simplemobiletools.keyboard.extensions.safeStorageContext import java.util.* class Config(context: Context) : BaseConfig(context) { companion object { - fun newInstance(context: Context) = Config(context) + fun newInstance(context: Context) = Config(context.safeStorageContext) } var vibrateOnKeypress: Boolean From 0b3bf0a750ffbf707619467693b68801901dbe06 Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 29 May 2023 17:01:23 +1000 Subject: [PATCH 03/13] Added safeStorageContext --- .../keyboard/extensions/Context.kt | 5 +++-- .../keyboard/services/SimpleKeyboardIME.kt | 5 +++-- .../keyboard/views/MyKeyboardView.kt | 19 +++++++++++-------- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 4862531..82b9eb2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -22,11 +22,12 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.interfaces.ClipsDao -val Context.config: Config get() = Config.newInstance(applicationContext) +val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - createDeviceProtectedStorageContext() + val deviceContext = createDeviceProtectedStorageContext() + deviceContext } else { this } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 8a08441..e8482de 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -13,8 +13,10 @@ import android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION import android.view.inputmethod.EditorInfo.IME_MASK_ACTION import android.view.inputmethod.ExtractedTextRequest import com.simplemobiletools.commons.extensions.getSharedPrefs +import com.simplemobiletools.commons.extensions.isDeviceLocked import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.extensions.config +import com.simplemobiletools.keyboard.extensions.safeStorageContext import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.views.MyKeyboardView import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.keyboard_holder @@ -40,7 +42,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL override fun onInitializeInterface() { super.onInitializeInterface() - getSharedPrefs().registerOnSharedPreferenceChangeListener(this) + safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this) } override fun onCreateInputView(): View { @@ -63,7 +65,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL super.onStartInput(attribute, restarting) inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS inputTypeClassVariation = attribute!!.inputType and TYPE_MASK_VARIATION - enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION) keyboard = createNewKeyboard() keyboardView?.setKeyboard(keyboard!!) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 76b4125..40f43fb 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -225,9 +225,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mLabelTextSize = resources.getDimension(R.dimen.label_text_size).toInt() mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt() mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt() - mTextColor = context.getProperTextColor() - mBackgroundColor = context.getProperBackgroundColor() - mPrimaryColor = context.getProperPrimaryColor() + mTextColor = context.safeStorageContext.getProperTextColor() + mBackgroundColor = context.safeStorageContext.getProperBackgroundColor() + mPrimaryColor = context.safeStorageContext.getProperPrimaryColor() mPreviewPopup = PopupWindow(context) mPreviewText = inflater.inflate(resources.getLayout(R.layout.keyboard_key_preview), null) as TextView @@ -374,12 +374,15 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } fun setupKeyboard(changedView: View? = null) { - mTextColor = context.getProperTextColor() - mBackgroundColor = context.getProperBackgroundColor() - mPrimaryColor = context.getProperPrimaryColor() + with(context.safeStorageContext) { + mTextColor = getProperTextColor() + mBackgroundColor = getProperBackgroundColor() + mPrimaryColor = getProperPrimaryColor() + + mShowKeyBorders = config.showKeyBorders + mUsingSystemTheme = config.isUsingSystemTheme + } - mShowKeyBorders = context.config.showKeyBorders - mUsingSystemTheme = context.config.isUsingSystemTheme val isMainKeyboard = changedView == null || changedView != mini_keyboard_view mKeyBackground = if (mShowKeyBorders && isMainKeyboard) { From 9fba02344387581bfa6b7282f88b510e545f11bc Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 29 May 2023 21:35:35 +1000 Subject: [PATCH 04/13] Added isDeviceLocked extension --- .../keyboard/extensions/Context.kt | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 82b9eb2..bc1c98c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -1,15 +1,12 @@ package com.simplemobiletools.keyboard.extensions +import android.app.KeyguardManager import android.content.ClipboardManager import android.content.Context import android.graphics.Color import android.os.Build import android.os.IBinder -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import android.view.Window -import android.view.WindowManager +import android.view.* import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.core.content.res.ResourcesCompat @@ -25,19 +22,18 @@ import com.simplemobiletools.keyboard.interfaces.ClipsDao val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - val deviceContext = createDeviceProtectedStorageContext() - deviceContext + get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isDeviceLocked) { + val deviceStorageContext = createDeviceProtectedStorageContext() + deviceStorageContext } else { this } +val Context.isDeviceLocked: Boolean + get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked + val Context.clipsDB: ClipsDao - get() = if (isDeviceLocked) { - ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao() - } else { - ClipsDatabase.getInstance(applicationContext).ClipsDao() - } + get() = ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao() fun Context.getCurrentClip(): String? { val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) From fa4e38e94ed7ee6bfcc17902a4c9044b018491ae Mon Sep 17 00:00:00 2001 From: merkost Date: Mon, 29 May 2023 22:27:03 +1000 Subject: [PATCH 05/13] Enabled numbers row based on shouldShowKeyboardToolbar value --- .../com/simplemobiletools/keyboard/extensions/Context.kt | 6 ++++-- .../com/simplemobiletools/keyboard/helpers/Config.kt | 7 ++++++- .../keyboard/services/SimpleKeyboardIME.kt | 1 - .../com/simplemobiletools/keyboard/views/MyKeyboardView.kt | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index bc1c98c..cd8c494 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -23,12 +23,14 @@ val Context.config: Config get() = Config.newInstance(applicationContext.safeSto val Context.safeStorageContext: Context get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isDeviceLocked) { - val deviceStorageContext = createDeviceProtectedStorageContext() - deviceStorageContext + createDeviceProtectedStorageContext() } else { this } +val Context.shouldShowKeyboardToolbar: Boolean + get() = !isDeviceLocked + val Context.isDeviceLocked: Boolean get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt index 3928b0c..42fd98f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/Config.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.keyboard.helpers import android.content.Context import com.simplemobiletools.commons.helpers.BaseConfig +import com.simplemobiletools.keyboard.extensions.isDeviceLocked import com.simplemobiletools.keyboard.extensions.safeStorageContext import java.util.* @@ -43,7 +44,11 @@ class Config(context: Context) : BaseConfig(context) { set(showClipboardContent) = prefs.edit().putBoolean(SHOW_CLIPBOARD_CONTENT, showClipboardContent).apply() var showNumbersRow: Boolean - get() = prefs.getBoolean(SHOW_NUMBERS_ROW, false) + get() = if (!context.isDeviceLocked) { + prefs.getBoolean(SHOW_NUMBERS_ROW, false) + } else { + true + } set(showNumbersRow) = prefs.edit().putBoolean(SHOW_NUMBERS_ROW, showNumbersRow).apply() private fun getDefaultLanguage(): Int { diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index e8482de..0fe6f82 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -13,7 +13,6 @@ import android.view.inputmethod.EditorInfo.IME_FLAG_NO_ENTER_ACTION import android.view.inputmethod.EditorInfo.IME_MASK_ACTION import android.view.inputmethod.ExtractedTextRequest import com.simplemobiletools.commons.extensions.getSharedPrefs -import com.simplemobiletools.commons.extensions.isDeviceLocked import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.extensions.safeStorageContext diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 40f43fb..db5ed46 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -428,6 +428,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut settings_cog.applyColorFilter(mTextColor) pinned_clipboard_items.applyColorFilter(mTextColor) clipboard_clear.applyColorFilter(mTextColor) + + toolbar_holder.beInvisibleIf(!context.shouldShowKeyboardToolbar) } mClipboardManagerHolder?.apply { From b14ad588d32239dd97b5a94a21dd08b8c2d91e0e Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 30 May 2023 16:17:22 +1000 Subject: [PATCH 06/13] Added if statement in application onCreate() --- app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt index 442c5f3..55c2d87 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/App.kt @@ -4,11 +4,14 @@ import android.app.Application import androidx.emoji2.bundled.BundledEmojiCompatConfig import androidx.emoji2.text.EmojiCompat import com.simplemobiletools.commons.extensions.checkUseEnglish +import com.simplemobiletools.keyboard.extensions.isDeviceLocked class App : Application() { override fun onCreate() { super.onCreate() - checkUseEnglish() + if (!isDeviceLocked) { + checkUseEnglish() + } setupEmojiCompat() } From c3c3ce09d2ad09bfbd13be55006b2a05d7c936f0 Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 30 May 2023 16:17:45 +1000 Subject: [PATCH 07/13] Using safeStorageContext in ClipsKeyboardAdapter.kt --- .../keyboard/adapters/ClipsKeyboardAdapter.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt index deaec35..462685a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt @@ -15,6 +15,7 @@ import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.extensions.getCurrentClip import com.simplemobiletools.keyboard.extensions.getStrokeColor +import com.simplemobiletools.keyboard.extensions.safeStorageContext import com.simplemobiletools.keyboard.helpers.ClipsHelper import com.simplemobiletools.keyboard.helpers.ITEM_CLIP import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL @@ -31,8 +32,9 @@ class ClipsKeyboardAdapter( ) : RecyclerView.Adapter() { private val layoutInflater = LayoutInflater.from(context) - private var textColor = context.getProperTextColor() - private var backgroundColor = context.getProperBackgroundColor() + + private var textColor = context.safeStorageContext.getProperTextColor() + private var backgroundColor = context.safeStorageContext.getProperBackgroundColor() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val layoutId = when (viewType) { From f46bc3652dc3728238f210199e6f99ad694b4713 Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 30 May 2023 16:46:28 +1000 Subject: [PATCH 08/13] Commentary fixes --- .../simplemobiletools/keyboard/services/SimpleKeyboardIME.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 0fe6f82..3054377 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -117,7 +117,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } } - // In other cases reset shift to OFF + // in other cases reset shift to OFF keyboard?.setShifted(ShiftState.OFF) keyboardView?.invalidateAllKeys() } @@ -128,8 +128,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL return } -// this.keyboardView.setEditorInfo(EditorInfo) - if (code != MyKeyboard.KEYCODE_SHIFT) { lastShiftPressTS = 0 } From 999c19cb7434e5bab091fa5c454d8e541be82d06 Mon Sep 17 00:00:00 2001 From: merkost Date: Thu, 8 Jun 2023 15:55:13 +1000 Subject: [PATCH 09/13] Refactoring --- .../keyboard/extensions/Context.kt | 3 ++- .../keyboard/helpers/ShiftState.kt | 19 +++++++++---------- .../keyboard/services/SimpleKeyboardIME.kt | 7 ++----- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index cd8c494..3091e45 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -12,6 +12,7 @@ import androidx.appcompat.app.AlertDialog import androidx.core.content.res.ResourcesCompat import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.views.MyTextView import com.simplemobiletools.keyboard.R @@ -22,7 +23,7 @@ import com.simplemobiletools.keyboard.interfaces.ClipsDao val Context.config: Config get() = Config.newInstance(applicationContext.safeStorageContext) val Context.safeStorageContext: Context - get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && isDeviceLocked) { + get() = if (isNougatPlus() && isDeviceLocked) { createDeviceProtectedStorageContext() } else { this diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt index 8b29258..b00b4bc 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/ShiftState.kt @@ -30,9 +30,11 @@ enum class ShiftState { if (isInputTypeAllowedCapitalizing(inputTypeClassVariation)) { return OFF } - return when (context.config.enableSentencesCapitalization) { - true -> ON_ONE_CHAR - else -> OFF + + return if (context.config.enableSentencesCapitalization) { + ON_ONE_CHAR + } else { + OFF } } @@ -40,14 +42,11 @@ enum class ShiftState { if (isInputTypeAllowedCapitalizing(inputTypeClassVariation)) { return OFF } - return when { - shouldCapitalize(context, text) -> { - ON_ONE_CHAR - } - else -> { - OFF - } + return if (shouldCapitalize(context, text)) { + ON_ONE_CHAR + } else { + OFF } } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 3054377..05752c8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -105,10 +105,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL return } else { // try capitalizing based on the editor info like google keep or google messenger apps - val editorInfo = currentInputEditorInfo - - if (editorInfo != null && editorInfo.inputType != InputType.TYPE_NULL) { - if (currentInputConnection.getCursorCapsMode(editorInfo.inputType) != 0) { + if (currentInputEditorInfo != null && currentInputEditorInfo.inputType != InputType.TYPE_NULL) { + if (currentInputConnection.getCursorCapsMode(currentInputEditorInfo.inputType) != 0) { keyboard?.setShifted(ShiftState.ON_ONE_CHAR) keyboardView?.invalidateAllKeys() return @@ -117,7 +115,6 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } } - // in other cases reset shift to OFF keyboard?.setShifted(ShiftState.OFF) keyboardView?.invalidateAllKeys() } From 33c278d686449f95132c611ca534050905917ff9 Mon Sep 17 00:00:00 2001 From: merkost Date: Fri, 9 Jun 2023 10:05:48 +1000 Subject: [PATCH 10/13] Removed spaces --- .../keyboard/services/SimpleKeyboardIME.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index 2148f08..2b6777d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -107,6 +107,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL inputConnection.commitText("", 1) } } + MyKeyboard.KEYCODE_SHIFT -> { if (keyboardMode == KEYBOARD_LETTERS) { when { @@ -130,6 +131,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } keyboardView!!.invalidateAllKeys() } + MyKeyboard.KEYCODE_ENTER -> { val imeOptionsActionId = getImeOptionsActionId() if (imeOptionsActionId != IME_ACTION_NONE) { @@ -139,6 +141,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER)) } } + MyKeyboard.KEYCODE_MODE_CHANGE -> { val keyboardXml = if (keyboardMode == KEYBOARD_LETTERS) { keyboardMode = KEYBOARD_SYMBOLS @@ -150,9 +153,11 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL keyboard = MyKeyboard(this, keyboardXml, enterKeyType) keyboardView!!.setKeyboard(keyboard!!) } + MyKeyboard.KEYCODE_EMOJI -> { keyboardView?.openEmojiPalette() } + else -> { var codeChar = code.toChar() val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0)?.text ?: return @@ -224,14 +229,17 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL keyboardMode = KEYBOARD_NUMBERS R.xml.keys_numbers } + TYPE_CLASS_PHONE -> { keyboardMode = KEYBOARD_PHONE R.xml.keys_phone } + TYPE_CLASS_DATETIME -> { keyboardMode = KEYBOARD_SYMBOLS R.xml.keys_symbols } + else -> { keyboardMode = KEYBOARD_LETTERS getKeyboardLayoutXML() From 5e23f27066ffb30e9a595332736d4be652355b8a Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 13 Jun 2023 13:03:13 +1000 Subject: [PATCH 11/13] safeStorageContext refactored --- .../keyboard/adapters/ClipsKeyboardAdapter.kt | 5 ++--- .../keyboard/extensions/Context.kt | 6 +----- .../keyboard/views/MyKeyboardView.kt | 14 ++++++++------ 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt index 462685a..2ffd34c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/adapters/ClipsKeyboardAdapter.kt @@ -15,7 +15,6 @@ import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.extensions.getCurrentClip import com.simplemobiletools.keyboard.extensions.getStrokeColor -import com.simplemobiletools.keyboard.extensions.safeStorageContext import com.simplemobiletools.keyboard.helpers.ClipsHelper import com.simplemobiletools.keyboard.helpers.ITEM_CLIP import com.simplemobiletools.keyboard.helpers.ITEM_SECTION_LABEL @@ -33,8 +32,8 @@ class ClipsKeyboardAdapter( private val layoutInflater = LayoutInflater.from(context) - private var textColor = context.safeStorageContext.getProperTextColor() - private var backgroundColor = context.safeStorageContext.getProperBackgroundColor() + private var textColor = context.getProperTextColor() + private var backgroundColor = context.getProperBackgroundColor() override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val layoutId = when (viewType) { diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 3091e45..1d6f44f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -4,7 +4,6 @@ import android.app.KeyguardManager import android.content.ClipboardManager import android.content.Context import android.graphics.Color -import android.os.Build import android.os.IBinder import android.view.* import android.widget.TextView @@ -29,9 +28,6 @@ val Context.safeStorageContext: Context this } -val Context.shouldShowKeyboardToolbar: Boolean - get() = !isDeviceLocked - val Context.isDeviceLocked: Boolean get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked @@ -60,7 +56,7 @@ fun Context.getStrokeColor(): Int { } } -fun Context.getKeyboardDialogBuilder() = if (baseConfig.isUsingSystemTheme) { +fun Context.getKeyboardDialogBuilder() = if (safeStorageContext.baseConfig.isUsingSystemTheme) { MaterialAlertDialogBuilder(this, R.style.MyKeyboard_Alert) } else { AlertDialog.Builder(this, R.style.MyKeyboard_Alert) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index db5ed46..d14051e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -225,9 +225,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mLabelTextSize = resources.getDimension(R.dimen.label_text_size).toInt() mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt() mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt() - mTextColor = context.safeStorageContext.getProperTextColor() - mBackgroundColor = context.safeStorageContext.getProperBackgroundColor() - mPrimaryColor = context.safeStorageContext.getProperPrimaryColor() + + with (context.safeStorageContext) { + mTextColor = getProperTextColor() + mBackgroundColor = getProperBackgroundColor() + mPrimaryColor = getProperPrimaryColor() + } mPreviewPopup = PopupWindow(context) mPreviewText = inflater.inflate(resources.getLayout(R.layout.keyboard_key_preview), null) as TextView @@ -383,7 +386,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mUsingSystemTheme = config.isUsingSystemTheme } - val isMainKeyboard = changedView == null || changedView != mini_keyboard_view mKeyBackground = if (mShowKeyBorders && isMainKeyboard) { resources.getDrawable(R.drawable.keyboard_key_selector_outlined, context.theme) @@ -429,7 +431,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut pinned_clipboard_items.applyColorFilter(mTextColor) clipboard_clear.applyColorFilter(mTextColor) - toolbar_holder.beInvisibleIf(!context.shouldShowKeyboardToolbar) + toolbar_holder.beInvisibleIf(context.isDeviceLocked) } mClipboardManagerHolder?.apply { @@ -1492,7 +1494,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut } } - val adapter = ClipsKeyboardAdapter(context, clips, refreshClipsListener) { clip -> + val adapter = ClipsKeyboardAdapter(context.safeStorageContext, clips, refreshClipsListener) { clip -> mOnKeyboardActionListener!!.onText(clip.value) vibrateIfNeeded() } From 3e9d8e6bb065e89ab1b5c1d8400fcc739b6860e0 Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 13 Jun 2023 13:17:24 +1000 Subject: [PATCH 12/13] SafeStorageContext added to Change Language dialog --- .../keyboard/dialogs/KeyboardRadioGroupDialog.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/dialogs/KeyboardRadioGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/dialogs/KeyboardRadioGroupDialog.kt index 578e501..fcf3c44 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/dialogs/KeyboardRadioGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/dialogs/KeyboardRadioGroupDialog.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.commons.extensions.onGlobalLayout import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.extensions.getKeyboardDialogBuilder +import com.simplemobiletools.keyboard.extensions.safeStorageContext import com.simplemobiletools.keyboard.extensions.setupKeyboardDialogStuff class KeyboardRadioGroupDialog( @@ -23,7 +24,7 @@ class KeyboardRadioGroupDialog( private val cancelCallback: (() -> Unit)? = null, private val callback: (newValue: Any) -> Unit ) { - private val context = ContextThemeWrapper(inputView.context, R.style.MyKeyboard_Alert) + private val context = ContextThemeWrapper(inputView.context.safeStorageContext, R.style.MyKeyboard_Alert) private var dialog: AlertDialog? = null private var wasInit = false private var selectedItemId = -1 From 14e761127d54c280942359ff93479a7397c24e7e Mon Sep 17 00:00:00 2001 From: merkost Date: Tue, 13 Jun 2023 18:09:45 +1000 Subject: [PATCH 13/13] Fixed safeStorageContext issue in getStrokeColor method --- .../kotlin/com/simplemobiletools/keyboard/extensions/Context.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt index 1d6f44f..9f2f28d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/extensions/Context.kt @@ -47,7 +47,7 @@ fun Context.getStrokeColor(): Int { resources.getColor(R.color.md_grey_400, theme) } } else { - val lighterColor = getProperBackgroundColor().lightenColor() + val lighterColor = safeStorageContext.getProperBackgroundColor().lightenColor() if (lighterColor == Color.WHITE || lighterColor == Color.BLACK) { resources.getColor(R.color.divider_grey, theme) } else {