Added safeStorageContext

This commit is contained in:
merkost
2023-05-29 17:01:23 +10:00
parent fc6bee9df7
commit 0b3bf0a750
3 changed files with 17 additions and 12 deletions

View File

@ -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
}

View File

@ -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!!)

View File

@ -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) {