Merge pull request #183 from Merkost/direct_boot_aware
Direct boot aware
This commit is contained in:
commit
02bb8d6d99
|
@ -42,6 +42,7 @@
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.SimpleKeyboardIME"
|
android:name=".services.SimpleKeyboardIME"
|
||||||
|
android:directBootAware="true"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:permission="android.permission.BIND_INPUT_METHOD">
|
android:permission="android.permission.BIND_INPUT_METHOD">
|
||||||
|
|
|
@ -4,11 +4,14 @@ import android.app.Application
|
||||||
import androidx.emoji2.bundled.BundledEmojiCompatConfig
|
import androidx.emoji2.bundled.BundledEmojiCompatConfig
|
||||||
import androidx.emoji2.text.EmojiCompat
|
import androidx.emoji2.text.EmojiCompat
|
||||||
import com.simplemobiletools.commons.extensions.checkUseEnglish
|
import com.simplemobiletools.commons.extensions.checkUseEnglish
|
||||||
|
import com.simplemobiletools.keyboard.extensions.isDeviceLocked
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
checkUseEnglish()
|
if (!isDeviceLocked) {
|
||||||
|
checkUseEnglish()
|
||||||
|
}
|
||||||
setupEmojiCompat()
|
setupEmojiCompat()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ class ClipsKeyboardAdapter(
|
||||||
) : RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolder>() {
|
) : RecyclerView.Adapter<ClipsKeyboardAdapter.ViewHolder>() {
|
||||||
|
|
||||||
private val layoutInflater = LayoutInflater.from(context)
|
private val layoutInflater = LayoutInflater.from(context)
|
||||||
|
|
||||||
private var textColor = context.getProperTextColor()
|
private var textColor = context.getProperTextColor()
|
||||||
private var backgroundColor = context.getProperBackgroundColor()
|
private var backgroundColor = context.getProperBackgroundColor()
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ abstract class ClipsDatabase : RoomDatabase() {
|
||||||
if (db == null) {
|
if (db == null) {
|
||||||
synchronized(ClipsDatabase::class) {
|
synchronized(ClipsDatabase::class) {
|
||||||
if (db == null) {
|
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)
|
db!!.openHelper.setWriteAheadLoggingEnabled(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.simplemobiletools.commons.extensions.onGlobalLayout
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
import com.simplemobiletools.keyboard.extensions.getKeyboardDialogBuilder
|
import com.simplemobiletools.keyboard.extensions.getKeyboardDialogBuilder
|
||||||
|
import com.simplemobiletools.keyboard.extensions.safeStorageContext
|
||||||
import com.simplemobiletools.keyboard.extensions.setupKeyboardDialogStuff
|
import com.simplemobiletools.keyboard.extensions.setupKeyboardDialogStuff
|
||||||
|
|
||||||
class KeyboardRadioGroupDialog(
|
class KeyboardRadioGroupDialog(
|
||||||
|
@ -23,7 +24,7 @@ class KeyboardRadioGroupDialog(
|
||||||
private val cancelCallback: (() -> Unit)? = null,
|
private val cancelCallback: (() -> Unit)? = null,
|
||||||
private val callback: (newValue: Any) -> Unit
|
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 dialog: AlertDialog? = null
|
||||||
private var wasInit = false
|
private var wasInit = false
|
||||||
private var selectedItemId = -1
|
private var selectedItemId = -1
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.simplemobiletools.keyboard.extensions
|
package com.simplemobiletools.keyboard.extensions
|
||||||
|
|
||||||
|
import android.app.KeyguardManager
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
@ -10,6 +11,7 @@ import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
import com.simplemobiletools.commons.models.RadioItem
|
import com.simplemobiletools.commons.models.RadioItem
|
||||||
import com.simplemobiletools.commons.views.MyTextView
|
import com.simplemobiletools.commons.views.MyTextView
|
||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
|
@ -17,9 +19,20 @@ import com.simplemobiletools.keyboard.databases.ClipsDatabase
|
||||||
import com.simplemobiletools.keyboard.helpers.*
|
import com.simplemobiletools.keyboard.helpers.*
|
||||||
import com.simplemobiletools.keyboard.interfaces.ClipsDao
|
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? {
|
fun Context.getCurrentClip(): String? {
|
||||||
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
val clipboardManager = (getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
|
||||||
|
@ -34,7 +47,7 @@ fun Context.getStrokeColor(): Int {
|
||||||
resources.getColor(R.color.md_grey_400, theme)
|
resources.getColor(R.color.md_grey_400, theme)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val lighterColor = getProperBackgroundColor().lightenColor()
|
val lighterColor = safeStorageContext.getProperBackgroundColor().lightenColor()
|
||||||
if (lighterColor == Color.WHITE || lighterColor == Color.BLACK) {
|
if (lighterColor == Color.WHITE || lighterColor == Color.BLACK) {
|
||||||
resources.getColor(R.color.divider_grey, theme)
|
resources.getColor(R.color.divider_grey, theme)
|
||||||
} else {
|
} 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)
|
MaterialAlertDialogBuilder(this, R.style.MyKeyboard_Alert)
|
||||||
} else {
|
} else {
|
||||||
AlertDialog.Builder(this, R.style.MyKeyboard_Alert)
|
AlertDialog.Builder(this, R.style.MyKeyboard_Alert)
|
||||||
|
|
|
@ -2,11 +2,13 @@ package com.simplemobiletools.keyboard.helpers
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import com.simplemobiletools.commons.helpers.BaseConfig
|
import com.simplemobiletools.commons.helpers.BaseConfig
|
||||||
|
import com.simplemobiletools.keyboard.extensions.isDeviceLocked
|
||||||
|
import com.simplemobiletools.keyboard.extensions.safeStorageContext
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class Config(context: Context) : BaseConfig(context) {
|
class Config(context: Context) : BaseConfig(context) {
|
||||||
companion object {
|
companion object {
|
||||||
fun newInstance(context: Context) = Config(context)
|
fun newInstance(context: Context) = Config(context.safeStorageContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
var vibrateOnKeypress: Boolean
|
var vibrateOnKeypress: Boolean
|
||||||
|
@ -42,7 +44,11 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
set(showClipboardContent) = prefs.edit().putBoolean(SHOW_CLIPBOARD_CONTENT, showClipboardContent).apply()
|
set(showClipboardContent) = prefs.edit().putBoolean(SHOW_CLIPBOARD_CONTENT, showClipboardContent).apply()
|
||||||
|
|
||||||
var showNumbersRow: Boolean
|
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()
|
set(showNumbersRow) = prefs.edit().putBoolean(SHOW_NUMBERS_ROW, showNumbersRow).apply()
|
||||||
|
|
||||||
private fun getDefaultLanguage(): Int {
|
private fun getDefaultLanguage(): Int {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.view.inputmethod.ExtractedTextRequest
|
||||||
import com.simplemobiletools.commons.extensions.getSharedPrefs
|
import com.simplemobiletools.commons.extensions.getSharedPrefs
|
||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
import com.simplemobiletools.keyboard.extensions.config
|
import com.simplemobiletools.keyboard.extensions.config
|
||||||
|
import com.simplemobiletools.keyboard.extensions.safeStorageContext
|
||||||
import com.simplemobiletools.keyboard.helpers.*
|
import com.simplemobiletools.keyboard.helpers.*
|
||||||
import com.simplemobiletools.keyboard.interfaces.OnKeyboardActionListener
|
import com.simplemobiletools.keyboard.interfaces.OnKeyboardActionListener
|
||||||
import com.simplemobiletools.keyboard.views.MyKeyboardView
|
import com.simplemobiletools.keyboard.views.MyKeyboardView
|
||||||
|
@ -39,7 +40,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
|
|
||||||
override fun onInitializeInterface() {
|
override fun onInitializeInterface() {
|
||||||
super.onInitializeInterface()
|
super.onInitializeInterface()
|
||||||
getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
|
safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateInputView(): View {
|
override fun onCreateInputView(): View {
|
||||||
|
@ -62,7 +63,6 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
super.onStartInput(attribute, restarting)
|
super.onStartInput(attribute, restarting)
|
||||||
inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS
|
inputTypeClass = attribute!!.inputType and TYPE_MASK_CLASS
|
||||||
inputTypeClassVariation = attribute.inputType and TYPE_MASK_VARIATION
|
inputTypeClassVariation = attribute.inputType and TYPE_MASK_VARIATION
|
||||||
|
|
||||||
enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION)
|
enterKeyType = attribute.imeOptions and (IME_MASK_ACTION or IME_FLAG_NO_ENTER_ACTION)
|
||||||
keyboard = createNewKeyboard()
|
keyboard = createNewKeyboard()
|
||||||
keyboardView?.setKeyboard(keyboard!!)
|
keyboardView?.setKeyboard(keyboard!!)
|
||||||
|
@ -108,6 +108,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
inputConnection.commitText("", 1)
|
inputConnection.commitText("", 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyKeyboard.KEYCODE_SHIFT -> {
|
MyKeyboard.KEYCODE_SHIFT -> {
|
||||||
if (keyboardMode == KEYBOARD_LETTERS) {
|
if (keyboardMode == KEYBOARD_LETTERS) {
|
||||||
when {
|
when {
|
||||||
|
@ -131,6 +132,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
}
|
}
|
||||||
keyboardView!!.invalidateAllKeys()
|
keyboardView!!.invalidateAllKeys()
|
||||||
}
|
}
|
||||||
|
|
||||||
MyKeyboard.KEYCODE_ENTER -> {
|
MyKeyboard.KEYCODE_ENTER -> {
|
||||||
val imeOptionsActionId = getImeOptionsActionId()
|
val imeOptionsActionId = getImeOptionsActionId()
|
||||||
if (imeOptionsActionId != IME_ACTION_NONE) {
|
if (imeOptionsActionId != IME_ACTION_NONE) {
|
||||||
|
@ -140,6 +142,7 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER))
|
inputConnection.sendKeyEvent(KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MyKeyboard.KEYCODE_MODE_CHANGE -> {
|
MyKeyboard.KEYCODE_MODE_CHANGE -> {
|
||||||
val keyboardXml = if (keyboardMode == KEYBOARD_LETTERS) {
|
val keyboardXml = if (keyboardMode == KEYBOARD_LETTERS) {
|
||||||
keyboardMode = KEYBOARD_SYMBOLS
|
keyboardMode = KEYBOARD_SYMBOLS
|
||||||
|
@ -151,9 +154,11 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
keyboard = MyKeyboard(this, keyboardXml, enterKeyType)
|
keyboard = MyKeyboard(this, keyboardXml, enterKeyType)
|
||||||
keyboardView!!.setKeyboard(keyboard!!)
|
keyboardView!!.setKeyboard(keyboard!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
MyKeyboard.KEYCODE_EMOJI -> {
|
MyKeyboard.KEYCODE_EMOJI -> {
|
||||||
keyboardView?.openEmojiPalette()
|
keyboardView?.openEmojiPalette()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
var codeChar = code.toChar()
|
var codeChar = code.toChar()
|
||||||
val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0)?.text ?: return
|
val originalText = inputConnection.getExtractedText(ExtractedTextRequest(), 0)?.text ?: return
|
||||||
|
@ -225,14 +230,17 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
keyboardMode = KEYBOARD_NUMBERS
|
keyboardMode = KEYBOARD_NUMBERS
|
||||||
R.xml.keys_numbers
|
R.xml.keys_numbers
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPE_CLASS_PHONE -> {
|
TYPE_CLASS_PHONE -> {
|
||||||
keyboardMode = KEYBOARD_PHONE
|
keyboardMode = KEYBOARD_PHONE
|
||||||
R.xml.keys_phone
|
R.xml.keys_phone
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPE_CLASS_DATETIME -> {
|
TYPE_CLASS_DATETIME -> {
|
||||||
keyboardMode = KEYBOARD_SYMBOLS
|
keyboardMode = KEYBOARD_SYMBOLS
|
||||||
R.xml.keys_symbols
|
R.xml.keys_symbols
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
keyboardMode = KEYBOARD_LETTERS
|
keyboardMode = KEYBOARD_LETTERS
|
||||||
getKeyboardLayoutXML()
|
getKeyboardLayoutXML()
|
||||||
|
|
|
@ -191,9 +191,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
mLabelTextSize = resources.getDimension(R.dimen.label_text_size).toInt()
|
mLabelTextSize = resources.getDimension(R.dimen.label_text_size).toInt()
|
||||||
mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt()
|
mPreviewHeight = resources.getDimension(R.dimen.key_height).toInt()
|
||||||
mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt()
|
mSpaceMoveThreshold = resources.getDimension(R.dimen.medium_margin).toInt()
|
||||||
mTextColor = context.getProperTextColor()
|
|
||||||
mBackgroundColor = context.getProperBackgroundColor()
|
with (context.safeStorageContext) {
|
||||||
mPrimaryColor = context.getProperPrimaryColor()
|
mTextColor = getProperTextColor()
|
||||||
|
mBackgroundColor = getProperBackgroundColor()
|
||||||
|
mPrimaryColor = getProperPrimaryColor()
|
||||||
|
}
|
||||||
|
|
||||||
mPreviewPopup = PopupWindow(context)
|
mPreviewPopup = PopupWindow(context)
|
||||||
mPreviewText = inflater.inflate(resources.getLayout(R.layout.keyboard_key_preview), null) as TextView
|
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) {
|
fun setupKeyboard(changedView: View? = null) {
|
||||||
mTextColor = context.getProperTextColor()
|
with(context.safeStorageContext) {
|
||||||
mBackgroundColor = context.getProperBackgroundColor()
|
mTextColor = getProperTextColor()
|
||||||
mPrimaryColor = context.getProperPrimaryColor()
|
mBackgroundColor = getProperBackgroundColor()
|
||||||
|
mPrimaryColor = getProperPrimaryColor()
|
||||||
|
|
||||||
mShowKeyBorders = context.config.showKeyBorders
|
mShowKeyBorders = config.showKeyBorders
|
||||||
mUsingSystemTheme = context.config.isUsingSystemTheme
|
mUsingSystemTheme = config.isUsingSystemTheme
|
||||||
|
}
|
||||||
|
|
||||||
val isMainKeyboard = changedView == null || changedView != mini_keyboard_view
|
val isMainKeyboard = changedView == null || changedView != mini_keyboard_view
|
||||||
mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {
|
mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {
|
||||||
|
@ -394,6 +399,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
settings_cog.applyColorFilter(mTextColor)
|
settings_cog.applyColorFilter(mTextColor)
|
||||||
pinned_clipboard_items.applyColorFilter(mTextColor)
|
pinned_clipboard_items.applyColorFilter(mTextColor)
|
||||||
clipboard_clear.applyColorFilter(mTextColor)
|
clipboard_clear.applyColorFilter(mTextColor)
|
||||||
|
|
||||||
|
toolbar_holder.beInvisibleIf(context.isDeviceLocked)
|
||||||
}
|
}
|
||||||
|
|
||||||
mClipboardManagerHolder?.apply {
|
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)
|
mOnKeyboardActionListener!!.onText(clip.value)
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue