Use EmojiCompat library for backward compatibility
This commit is contained in:
parent
ecce3793ca
commit
11460028ff
6 changed files with 23 additions and 3 deletions
|
@ -66,6 +66,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
implementation 'com.github.SimpleMobileTools:Simple-Commons:c05de1687e'
|
||||
implementation 'androidx.emoji2:emoji2-bundled:1.1.0'
|
||||
|
||||
kapt 'androidx.room:room-compiler:2.4.2'
|
||||
implementation 'androidx.room:room-runtime:2.4.2'
|
||||
|
|
|
@ -1,11 +1,19 @@
|
|||
package com.simplemobiletools.keyboard
|
||||
|
||||
import android.app.Application
|
||||
import androidx.emoji2.bundled.BundledEmojiCompatConfig
|
||||
import androidx.emoji2.text.EmojiCompat
|
||||
import com.simplemobiletools.commons.extensions.checkUseEnglish
|
||||
|
||||
class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
checkUseEnglish()
|
||||
setupEmojiCompat()
|
||||
}
|
||||
|
||||
private fun setupEmojiCompat() {
|
||||
val config = BundledEmojiCompatConfig(this)
|
||||
EmojiCompat.init(config)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.emoji2.text.EmojiCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.simplemobiletools.keyboard.R
|
||||
import kotlinx.android.synthetic.main.item_emoji.view.*
|
||||
|
@ -32,7 +33,8 @@ class EmojisAdapter(
|
|||
}
|
||||
|
||||
private fun setupEmoji(view: View, emoji: String) {
|
||||
view.emoji_value.text = emoji
|
||||
val processed = EmojiCompat.get().process(emoji)
|
||||
view.emoji_value.text = processed
|
||||
}
|
||||
|
||||
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
|
|
@ -45,6 +45,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
|
|||
keyboardView = keyboardHolder.keyboard_view as MyKeyboardView
|
||||
keyboardView!!.setKeyboard(keyboard!!)
|
||||
keyboardView!!.setKeyboardHolder(keyboardHolder.keyboard_holder)
|
||||
keyboardView!!.setEditorInfo(currentInputEditorInfo)
|
||||
keyboardView!!.mOnKeyboardActionListener = this
|
||||
return keyboardHolder!!
|
||||
}
|
||||
|
|
|
@ -22,10 +22,13 @@ import android.view.*
|
|||
import android.view.accessibility.AccessibilityEvent
|
||||
import android.view.accessibility.AccessibilityManager
|
||||
import android.view.animation.AccelerateInterpolator
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.PopupWindow
|
||||
import android.widget.TextView
|
||||
import androidx.core.animation.doOnEnd
|
||||
import androidx.core.animation.doOnStart
|
||||
import androidx.emoji2.text.EmojiCompat
|
||||
import androidx.emoji2.text.EmojiCompat.EMOJI_SUPPORTED
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||
import com.simplemobiletools.commons.helpers.isPiePlus
|
||||
|
@ -153,6 +156,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
private var mToolbarHolder: View? = null
|
||||
private var mClipboardManagerHolder: View? = null
|
||||
private var mEmojiPaletteHolder: View? = null
|
||||
private var emojiCompatMetadataVersion = 0
|
||||
|
||||
// For multi-tap
|
||||
private var mLastTapTime = 0L
|
||||
|
@ -423,6 +427,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
}
|
||||
}
|
||||
|
||||
fun setEditorInfo(editorInfo: EditorInfo) {
|
||||
emojiCompatMetadataVersion = editorInfo.extras?.getInt(EmojiCompat.EDITOR_INFO_METAVERSION_KEY, 0) ?: 0
|
||||
}
|
||||
|
||||
fun vibrateIfNeeded() {
|
||||
if (context.config.vibrateOnKeypress) {
|
||||
performHapticFeedback()
|
||||
|
@ -1443,7 +1451,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
|||
typeface = Typeface.DEFAULT
|
||||
}
|
||||
val emojis = fullEmojiList.filter { emoji ->
|
||||
systemFontPaint.hasGlyph(emoji)
|
||||
systemFontPaint.hasGlyph(emoji) || EmojiCompat.get().getEmojiMatch(emoji, emojiCompatMetadataVersion) == EMOJI_SUPPORTED
|
||||
}
|
||||
Handler(Looper.getMainLooper()).post {
|
||||
setupEmojiAdapter(emojis)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<com.simplemobiletools.commons.views.MyTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.appcompat.widget.AppCompatTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/emoji_value"
|
||||
android:layout_width="@dimen/emoji_item_size"
|
||||
|
|
Loading…
Reference in a new issue