Merge pull request #183 from Merkost/direct_boot_aware
Direct boot aware
This commit is contained in:
commit
02bb8d6d99
|
@ -42,6 +42,7 @@
|
|||
|
||||
<service
|
||||
android:name=".services.SimpleKeyboardIME"
|
||||
android:directBootAware="true"
|
||||
android:exported="true"
|
||||
android:label="@string/app_name"
|
||||
android:permission="android.permission.BIND_INPUT_METHOD">
|
||||
|
|
|
@ -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()
|
||||
if (!isDeviceLocked) {
|
||||
checkUseEnglish()
|
||||
}
|
||||
setupEmojiCompat()
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ class ClipsKeyboardAdapter(
|
|||
) : RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolder>() {
|
||||
|
||||
private val layoutInflater = LayoutInflater.from(context)
|
||||
|
||||
private var textColor = context.getProperTextColor()
|
||||
private var backgroundColor = context.getProperBackgroundColor()
|
||||
|
||||
|
|
|
@ -19,7 +19,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, ClipsDatabase::class.java, "clips.db").build()
|
||||
db!!.openHelper.setWriteAheadLoggingEnabled(true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.simplemobiletools.keyboard.extensions
|
||||
|
||||
import android.app.KeyguardManager
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
|
@ -10,6 +11,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
|
||||
|
@ -17,9 +19,20 @@ 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()
|
||||
val Context.safeStorageContext: Context
|
||||
get() = if (isNougatPlus() && isDeviceLocked) {
|
||||
createDeviceProtectedStorageContext()
|
||||
} else {
|
||||
this
|
||||
}
|
||||
|
||||
val Context.isDeviceLocked: Boolean
|
||||
get() = (getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager).isDeviceLocked
|
||||
|
||||
val Context.clipsDB: ClipsDao
|
||||
get() = ClipsDatabase.getInstance(applicationContext.safeStorageContext).ClipsDao()
|
||||
|
||||
fun Context.getCurrentClip(): String? {
|
||||
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||
|
@ -34,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 {
|
||||
|
@ -43,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)
|
||||
|
|
|
@ -2,11 +2,13 @@ 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.*
|
||||
|
||||
class Config(context: Context) : BaseConfig(context) {
|
||||
companion object {
|
||||
fun newInstance(context: Context) = Config(context)
|
||||
fun newInstance(context: Context) = Config(context.safeStorageContext)
|
||||
}
|
||||
|
||||
var vibrateOnKeypress: Boolean
|
||||
|
@ -42,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 {
|
||||
|
|
|
@ -14,6 +14,7 @@ import android.view.inputmethod.ExtractedTextRequest
|
|||
import com.simplemobiletools.commons.extensions.getSharedPrefs
|
||||
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.interfaces.OnKeyboardActionListener
|
||||
import com.simplemobiletools.keyboard.views.MyKeyboardView
|
||||
|
@ -39,7 +40,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
|
||||
override fun onInitializeInterface() {
|
||||
super.onInitializeInterface()
|
||||
getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
|
||||
safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
|
||||
}
|
||||
|
||||
override fun onCreateInputView(): View {
|
||||
|
@ -62,7 +63,6 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
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!!)
|
||||
|
@ -108,6 +108,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
inputConnection.commitText("", 1)
|
||||
}
|
||||
}
|
||||
|
||||
MyKeyboard.KEYCODE_SHIFT -> {
|
||||
if (keyboardMode == KEYBOARD_LETTERS) {
|
||||
when {
|
||||
|
@ -131,6 +132,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
}
|
||||
keyboardView!!.invalidateAllKeys()
|
||||
}
|
||||
|
||||
MyKeyboard.KEYCODE_ENTER -> {
|
||||
val imeOptionsActionId = getImeOptionsActionId()
|
||||
if (imeOptionsActionId != IME_ACTION_NONE) {
|
||||
|
@ -140,6 +142,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER))
|
||||
}
|
||||
}
|
||||
|
||||
MyKeyboard.KEYCODE_MODE_CHANGE -> {
|
||||
val keyboardXml = if (keyboardMode == KEYBOARD_LETTERS) {
|
||||
keyboardMode = KEYBOARD_SYMBOLS
|
||||
|
@ -151,9 +154,11 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
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
|
||||
|
@ -225,14 +230,17 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
|||
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()
|
||||
|
|
|
@ -191,9 +191,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.getProperTextColor()
|
||||
mBackgroundColor = context.getProperBackgroundColor()
|
||||
mPrimaryColor = context.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
|
||||
|
@ -343,12 +346,14 @@ 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 = context.config.showKeyBorders
|
||||
mUsingSystemTheme = context.config.isUsingSystemTheme
|
||||
mShowKeyBorders = config.showKeyBorders
|
||||
mUsingSystemTheme = config.isUsingSystemTheme
|
||||
}
|
||||
|
||||
val isMainKeyboard = changedView == null || changedView != mini_keyboard_view
|
||||
mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {
|
||||
|
@ -394,6 +399,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.isDeviceLocked)
|
||||
}
|
||||
|
||||
mClipboardManagerHolder?.apply {
|
||||
|
@ -1413,7 +1420,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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue