migrate views to viewbinding
This commit is contained in:
parent
dccded4d72
commit
a1e6636159
|
@ -31,14 +31,13 @@ import androidx.core.graphics.drawable.toBitmap
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.isNougatPlus
|
import com.simplemobiletools.commons.helpers.isNougatPlus
|
||||||
import com.simplemobiletools.keyboard.R
|
import com.simplemobiletools.keyboard.R
|
||||||
|
import com.simplemobiletools.keyboard.databinding.KeyboardViewKeyboardBinding
|
||||||
import com.simplemobiletools.keyboard.extensions.config
|
import com.simplemobiletools.keyboard.extensions.config
|
||||||
import com.simplemobiletools.keyboard.extensions.getStrokeColor
|
import com.simplemobiletools.keyboard.extensions.getStrokeColor
|
||||||
import com.simplemobiletools.keyboard.extensions.safeStorageContext
|
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
|
||||||
import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.keyboard_holder
|
|
||||||
import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.keyboard_view
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
// based on https://www.androidauthority.com/lets-build-custom-keyboard-android-832362/
|
// based on https://www.androidauthority.com/lets-build-custom-keyboard-android-832362/
|
||||||
|
@ -60,19 +59,22 @@ class SimpleKeyboardIME : InputMethodService(), OnKeyboardActionListener, Shared
|
||||||
private var switchToLetters = false
|
private var switchToLetters = false
|
||||||
private var breakIterator: BreakIterator? = null
|
private var breakIterator: BreakIterator? = null
|
||||||
|
|
||||||
|
private lateinit var binding: KeyboardViewKeyboardBinding
|
||||||
|
|
||||||
override fun onInitializeInterface() {
|
override fun onInitializeInterface() {
|
||||||
super.onInitializeInterface()
|
super.onInitializeInterface()
|
||||||
safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
|
safeStorageContext.getSharedPrefs().registerOnSharedPreferenceChangeListener(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateInputView(): View {
|
override fun onCreateInputView(): View {
|
||||||
val keyboardHolder = layoutInflater.inflate(R.layout.keyboard_view_keyboard, null)
|
binding = KeyboardViewKeyboardBinding.inflate(layoutInflater)
|
||||||
keyboardView = keyboardHolder.keyboard_view as MyKeyboardView
|
keyboardView = binding.keyboardView.apply {
|
||||||
keyboardView!!.setKeyboardHolder(keyboardHolder.keyboard_holder)
|
setKeyboardHolder(binding)
|
||||||
keyboardView!!.setKeyboard(keyboard!!)
|
setKeyboard(keyboard!!)
|
||||||
keyboardView!!.setEditorInfo(currentInputEditorInfo)
|
setEditorInfo(currentInputEditorInfo)
|
||||||
keyboardView!!.mOnKeyboardActionListener = this
|
mOnKeyboardActionListener = this@SimpleKeyboardIME
|
||||||
return keyboardHolder!!
|
}
|
||||||
|
return binding.root
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPress(primaryCode: Int) {
|
override fun onPress(primaryCode: Int) {
|
||||||
|
|
|
@ -37,6 +37,8 @@ import com.simplemobiletools.keyboard.activities.ManageClipboardItemsActivity
|
||||||
import com.simplemobiletools.keyboard.activities.SettingsActivity
|
import com.simplemobiletools.keyboard.activities.SettingsActivity
|
||||||
import com.simplemobiletools.keyboard.adapters.ClipsKeyboardAdapter
|
import com.simplemobiletools.keyboard.adapters.ClipsKeyboardAdapter
|
||||||
import com.simplemobiletools.keyboard.adapters.EmojisAdapter
|
import com.simplemobiletools.keyboard.adapters.EmojisAdapter
|
||||||
|
import com.simplemobiletools.keyboard.databinding.KeyboardPopupKeyboardBinding
|
||||||
|
import com.simplemobiletools.keyboard.databinding.KeyboardViewKeyboardBinding
|
||||||
import com.simplemobiletools.keyboard.dialogs.ChangeLanguagePopup
|
import com.simplemobiletools.keyboard.dialogs.ChangeLanguagePopup
|
||||||
import com.simplemobiletools.keyboard.extensions.*
|
import com.simplemobiletools.keyboard.extensions.*
|
||||||
import com.simplemobiletools.keyboard.helpers.*
|
import com.simplemobiletools.keyboard.helpers.*
|
||||||
|
@ -51,8 +53,6 @@ import com.simplemobiletools.keyboard.interfaces.RefreshClipsListener
|
||||||
import com.simplemobiletools.keyboard.models.Clip
|
import com.simplemobiletools.keyboard.models.Clip
|
||||||
import com.simplemobiletools.keyboard.models.ClipsSectionLabel
|
import com.simplemobiletools.keyboard.models.ClipsSectionLabel
|
||||||
import com.simplemobiletools.keyboard.models.ListItem
|
import com.simplemobiletools.keyboard.models.ListItem
|
||||||
import kotlinx.android.synthetic.main.keyboard_popup_keyboard.view.*
|
|
||||||
import kotlinx.android.synthetic.main.keyboard_view_keyboard.view.*
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@SuppressLint("UseCompatLoadingForDrawables", "ClickableViewAccessibility")
|
@SuppressLint("UseCompatLoadingForDrawables", "ClickableViewAccessibility")
|
||||||
|
@ -66,6 +66,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var keyboardPopupBinding: KeyboardPopupKeyboardBinding? = null
|
||||||
|
private var keyboardViewBinding: KeyboardViewKeyboardBinding? = null
|
||||||
|
|
||||||
private var accessHelper: AccessHelper? = null
|
private var accessHelper: AccessHelper? = null
|
||||||
|
|
||||||
private var mKeyboard: MyKeyboard? = null
|
private var mKeyboard: MyKeyboard? = null
|
||||||
|
@ -285,14 +288,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets the top row above the keyboard containing a couple buttons and the clipboard **/
|
/** Sets the top row above the keyboard containing a couple buttons and the clipboard **/
|
||||||
fun setKeyboardHolder(keyboardHolder: View) {
|
fun setKeyboardHolder(binding: KeyboardViewKeyboardBinding) {
|
||||||
mToolbarHolder = keyboardHolder.toolbar_holder
|
keyboardViewBinding = binding.apply {
|
||||||
mClipboardManagerHolder = keyboardHolder.clipboard_manager_holder
|
mToolbarHolder = toolbarHolder
|
||||||
mEmojiPaletteHolder = keyboardHolder.emoji_palette_holder
|
mClipboardManagerHolder = clipboardManagerHolder
|
||||||
|
mEmojiPaletteHolder = emojiPaletteHolder
|
||||||
|
|
||||||
mToolbarHolder!!.apply {
|
settingsCog.setOnLongClickListener { context.toast(R.string.settings); true; }
|
||||||
settings_cog.setOnLongClickListener { context.toast(R.string.settings); true; }
|
settingsCog.setOnClickListener {
|
||||||
settings_cog.setOnClickListener {
|
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
Intent(context, SettingsActivity::class.java).apply {
|
Intent(context, SettingsActivity::class.java).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
|
@ -300,23 +303,23 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pinned_clipboard_items.setOnLongClickListener { context.toast(R.string.clipboard); true; }
|
pinnedClipboardItems.setOnLongClickListener { context.toast(R.string.clipboard); true; }
|
||||||
pinned_clipboard_items.setOnClickListener {
|
pinnedClipboardItems.setOnClickListener {
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
openClipboardManager()
|
openClipboardManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
clipboard_clear.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; }
|
clipboardClear.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; }
|
||||||
clipboard_clear.setOnClickListener {
|
clipboardClear.setOnClickListener {
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
clearClipboardContent()
|
clearClipboardContent()
|
||||||
toggleClipboardVisibility(false)
|
toggleClipboardVisibility(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestions_holder.addOnLayoutChangeListener(object : OnLayoutChangeListener {
|
suggestionsHolder.addOnLayoutChangeListener(object : OnLayoutChangeListener {
|
||||||
override fun onLayoutChange(v: View?, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
|
override fun onLayoutChange(v: View?, left: Int, top: Int, right: Int, bottom: Int, oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
|
||||||
updateSuggestionsToolbarLayout()
|
updateSuggestionsToolbarLayout()
|
||||||
suggestions_holder.removeOnLayoutChangeListener(this)
|
binding.suggestionsHolder.removeOnLayoutChangeListener(this)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -330,23 +333,21 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
setupStoredClips()
|
setupStoredClips()
|
||||||
}
|
}
|
||||||
|
|
||||||
mClipboardManagerHolder!!.apply {
|
binding.apply {
|
||||||
clipboard_manager_close.setOnClickListener {
|
clipboardManagerClose.setOnClickListener {
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
closeClipboardManager()
|
closeClipboardManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
clipboard_manager_manage.setOnLongClickListener { context.toast(R.string.manage_clipboard_items); true; }
|
clipboardManagerManage.setOnLongClickListener { context.toast(R.string.manage_clipboard_items); true; }
|
||||||
clipboard_manager_manage.setOnClickListener {
|
clipboardManagerManage.setOnClickListener {
|
||||||
Intent(context, ManageClipboardItemsActivity::class.java).apply {
|
Intent(context, ManageClipboardItemsActivity::class.java).apply {
|
||||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
context.startActivity(this)
|
context.startActivity(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
mEmojiPaletteHolder!!.apply {
|
emojiPaletteClose.setOnClickListener {
|
||||||
emoji_palette_close.setOnClickListener {
|
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
closeEmojiPalette()
|
closeEmojiPalette()
|
||||||
}
|
}
|
||||||
|
@ -367,7 +368,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
mUsingSystemTheme = config.isUsingSystemTheme
|
mUsingSystemTheme = config.isUsingSystemTheme
|
||||||
}
|
}
|
||||||
|
|
||||||
val isMainKeyboard = changedView == null || changedView != mini_keyboard_view
|
val isMainKeyboard = changedView == null || changedView != keyboardPopupBinding?.miniKeyboardView
|
||||||
mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {
|
mKeyBackground = if (mShowKeyBorders && isMainKeyboard) {
|
||||||
resources.getDrawable(R.drawable.keyboard_key_selector_outlined, context.theme)
|
resources.getDrawable(R.drawable.keyboard_key_selector_outlined, context.theme)
|
||||||
} else {
|
} else {
|
||||||
|
@ -397,35 +398,33 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
|
layerDrawable.findDrawableByLayerId(R.id.clipboard_background_shape).applyColorFilter(mBackgroundColor)
|
||||||
|
|
||||||
val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor()
|
val wasDarkened = mBackgroundColor != mBackgroundColor.darkenColor()
|
||||||
mToolbarHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
top_keyboard_divider.beGoneIf(wasDarkened)
|
topKeyboardDivider.beGoneIf(wasDarkened)
|
||||||
top_keyboard_divider.background = ColorDrawable(strokeColor)
|
topKeyboardDivider.background = ColorDrawable(strokeColor)
|
||||||
|
mToolbarHolder?.background = ColorDrawable(toolbarColor)
|
||||||
|
|
||||||
background = ColorDrawable(toolbarColor)
|
clipboardValue.apply {
|
||||||
clipboard_value.apply {
|
|
||||||
background = rippleBg
|
background = rippleBg
|
||||||
setTextColor(mTextColor)
|
setTextColor(mTextColor)
|
||||||
setLinkTextColor(mTextColor)
|
setLinkTextColor(mTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
settings_cog.applyColorFilter(mTextColor)
|
settingsCog.applyColorFilter(mTextColor)
|
||||||
pinned_clipboard_items.applyColorFilter(mTextColor)
|
pinnedClipboardItems.applyColorFilter(mTextColor)
|
||||||
clipboard_clear.applyColorFilter(mTextColor)
|
clipboardClear.applyColorFilter(mTextColor)
|
||||||
|
|
||||||
beInvisibleIf(context.isDeviceLocked)
|
mToolbarHolder?.beInvisibleIf(context.isDeviceLocked)
|
||||||
}
|
|
||||||
|
|
||||||
mClipboardManagerHolder?.apply {
|
topClipboardDivider.beGoneIf(wasDarkened)
|
||||||
top_clipboard_divider.beGoneIf(wasDarkened)
|
topClipboardDivider.background = ColorDrawable(strokeColor)
|
||||||
top_clipboard_divider.background = ColorDrawable(strokeColor)
|
clipboardManagerHolder.background = ColorDrawable(toolbarColor)
|
||||||
clipboard_manager_holder.background = ColorDrawable(toolbarColor)
|
|
||||||
|
|
||||||
clipboard_manager_close.applyColorFilter(mTextColor)
|
clipboardManagerClose.applyColorFilter(mTextColor)
|
||||||
clipboard_manager_manage.applyColorFilter(mTextColor)
|
clipboardManagerManage.applyColorFilter(mTextColor)
|
||||||
|
|
||||||
clipboard_manager_label.setTextColor(mTextColor)
|
clipboardManagerLabel.setTextColor(mTextColor)
|
||||||
clipboard_content_placeholder_1.setTextColor(mTextColor)
|
clipboardContentPlaceholder1.setTextColor(mTextColor)
|
||||||
clipboard_content_placeholder_2.setTextColor(mTextColor)
|
clipboardContentPlaceholder2.setTextColor(mTextColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor)
|
setupEmojiPalette(toolbarColor = toolbarColor, backgroundColor = mBackgroundColor, textColor = mTextColor)
|
||||||
|
@ -739,8 +738,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
if (mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view && context.config.showClipboardContent) {
|
if (mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view && context.config.showClipboardContent) {
|
||||||
val clipboardContent = context.getCurrentClip()
|
val clipboardContent = context.getCurrentClip()
|
||||||
if (clipboardContent?.isNotEmpty() == true) {
|
if (clipboardContent?.isNotEmpty() == true) {
|
||||||
mToolbarHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
clipboard_value.apply {
|
clipboardValue.apply {
|
||||||
text = clipboardContent
|
text = clipboardContent
|
||||||
removeUnderlines()
|
removeUnderlines()
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
|
@ -760,11 +759,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideClipboardViews() {
|
private fun hideClipboardViews() {
|
||||||
mToolbarHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
clipboard_value?.beGone()
|
clipboardValue.beGone()
|
||||||
clipboard_value?.alpha = 0f
|
clipboardValue.alpha = 0f
|
||||||
clipboard_clear?.beGone()
|
clipboardClear.beGone()
|
||||||
clipboard_clear?.alpha = 0f
|
clipboardClear.alpha = 0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,13 +778,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleClipboardVisibility(show: Boolean) {
|
private fun toggleClipboardVisibility(show: Boolean) {
|
||||||
if ((show && mToolbarHolder?.clipboard_value!!.alpha == 0f) || (!show && mToolbarHolder?.clipboard_value!!.alpha == 1f)) {
|
if ((show && keyboardViewBinding?.clipboardValue!!.alpha == 0f) || (!show && keyboardViewBinding?.clipboardValue!!.alpha == 1f)) {
|
||||||
val newAlpha = if (show) 1f else 0f
|
val newAlpha = if (show) 1f else 0f
|
||||||
val animations = ArrayList<ObjectAnimator>()
|
val animations = ArrayList<ObjectAnimator>()
|
||||||
val clipboardValueAnimation = ObjectAnimator.ofFloat(mToolbarHolder!!.clipboard_value!!, "alpha", newAlpha)
|
val clipboardValueAnimation = ObjectAnimator.ofFloat(keyboardViewBinding!!.clipboardValue, "alpha", newAlpha)
|
||||||
animations.add(clipboardValueAnimation)
|
animations.add(clipboardValueAnimation)
|
||||||
|
|
||||||
val clipboardClearAnimation = ObjectAnimator.ofFloat(mToolbarHolder!!.clipboard_clear!!, "alpha", newAlpha)
|
val clipboardClearAnimation = ObjectAnimator.ofFloat(keyboardViewBinding!!.clipboardClear, "alpha", newAlpha)
|
||||||
animations.add(clipboardClearAnimation)
|
animations.add(clipboardClearAnimation)
|
||||||
|
|
||||||
val animSet = AnimatorSet()
|
val animSet = AnimatorSet()
|
||||||
|
@ -794,14 +793,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
animSet.interpolator = AccelerateInterpolator()
|
animSet.interpolator = AccelerateInterpolator()
|
||||||
animSet.doOnStart {
|
animSet.doOnStart {
|
||||||
if (show) {
|
if (show) {
|
||||||
mToolbarHolder?.clipboard_value?.beVisible()
|
keyboardViewBinding?.clipboardValue?.beVisible()
|
||||||
mToolbarHolder?.clipboard_clear?.beVisible()
|
keyboardViewBinding?.clipboardClear?.beVisible()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
animSet.doOnEnd {
|
animSet.doOnEnd {
|
||||||
if (!show) {
|
if (!show) {
|
||||||
mToolbarHolder?.clipboard_value?.beGone()
|
keyboardViewBinding?.clipboardValue?.beGone()
|
||||||
mToolbarHolder?.clipboard_clear?.beGone()
|
keyboardViewBinding?.clipboardClear?.beGone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
animSet.start()
|
animSet.start()
|
||||||
|
@ -1001,8 +1000,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
mMiniKeyboardContainer = mMiniKeyboardCache[popupKey]
|
mMiniKeyboardContainer = mMiniKeyboardCache[popupKey]
|
||||||
if (mMiniKeyboardContainer == null) {
|
if (mMiniKeyboardContainer == null) {
|
||||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
mMiniKeyboardContainer = inflater.inflate(mPopupLayout, null)
|
keyboardPopupBinding = KeyboardPopupKeyboardBinding.inflate(inflater).apply {
|
||||||
mMiniKeyboard = mMiniKeyboardContainer!!.findViewById<View>(R.id.mini_keyboard_view) as MyKeyboardView
|
mMiniKeyboardContainer = root
|
||||||
|
mMiniKeyboard = miniKeyboardView
|
||||||
|
}
|
||||||
|
|
||||||
mMiniKeyboard!!.mOnKeyboardActionListener = object : OnKeyboardActionListener {
|
mMiniKeyboard!!.mOnKeyboardActionListener = object : OnKeyboardActionListener {
|
||||||
override fun onKey(code: Int) {
|
override fun onKey(code: Int) {
|
||||||
|
@ -1048,7 +1049,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
)
|
)
|
||||||
mMiniKeyboardCache[popupKey] = mMiniKeyboardContainer
|
mMiniKeyboardCache[popupKey] = mMiniKeyboardContainer
|
||||||
} else {
|
} else {
|
||||||
mMiniKeyboard = mMiniKeyboardContainer!!.findViewById<View>(R.id.mini_keyboard_view) as MyKeyboardView
|
mMiniKeyboard = keyboardPopupBinding!!.miniKeyboardView
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocationInWindow(mCoordinates)
|
getLocationInWindow(mCoordinates)
|
||||||
|
@ -1395,13 +1396,17 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
fun closeClipboardManager() {
|
fun closeClipboardManager() {
|
||||||
mClipboardManagerHolder?.clipboard_manager_holder?.beGone()
|
keyboardViewBinding?.apply {
|
||||||
mToolbarHolder?.suggestions_holder?.showAllInlineContentViews()
|
clipboardManagerHolder.beGone()
|
||||||
|
suggestionsHolder.showAllInlineContentViews()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun openClipboardManager() {
|
private fun openClipboardManager() {
|
||||||
mClipboardManagerHolder!!.clipboard_manager_holder.beVisible()
|
keyboardViewBinding?.apply {
|
||||||
mToolbarHolder?.suggestions_holder?.hideAllInlineContentViews()
|
clipboardManagerHolder.beVisible()
|
||||||
|
suggestionsHolder.hideAllInlineContentViews()
|
||||||
|
}
|
||||||
setupStoredClips()
|
setupStoredClips()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1434,10 +1439,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupClipsAdapter(clips: ArrayList<ListItem>) {
|
private fun setupClipsAdapter(clips: ArrayList<ListItem>) {
|
||||||
mClipboardManagerHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
clipboard_content_placeholder_1.beVisibleIf(clips.isEmpty())
|
clipboardContentPlaceholder1.beVisibleIf(clips.isEmpty())
|
||||||
clipboard_content_placeholder_2.beVisibleIf(clips.isEmpty())
|
clipboardContentPlaceholder2.beVisibleIf(clips.isEmpty())
|
||||||
clips_list.beVisibleIf(clips.isNotEmpty())
|
clipsList.beVisibleIf(clips.isNotEmpty())
|
||||||
}
|
}
|
||||||
|
|
||||||
val refreshClipsListener = object : RefreshClipsListener {
|
val refreshClipsListener = object : RefreshClipsListener {
|
||||||
|
@ -1451,26 +1456,27 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
mClipboardManagerHolder?.clips_list?.adapter = adapter
|
keyboardViewBinding?.clipsList?.adapter = adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEmojiPalette(toolbarColor: Int, backgroundColor: Int, textColor: Int) {
|
private fun setupEmojiPalette(toolbarColor: Int, backgroundColor: Int, textColor: Int) {
|
||||||
mEmojiPaletteHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
emoji_palette_top_bar.background = ColorDrawable(toolbarColor)
|
emojiPaletteTopBar.background = ColorDrawable(toolbarColor)
|
||||||
emoji_palette_holder.background = ColorDrawable(backgroundColor)
|
emojiPaletteHolder.background = ColorDrawable(backgroundColor)
|
||||||
emoji_palette_close.applyColorFilter(textColor)
|
emojiPaletteClose.applyColorFilter(textColor)
|
||||||
emoji_palette_label.setTextColor(textColor)
|
emojiPaletteLabel.setTextColor(textColor)
|
||||||
|
|
||||||
emoji_palette_bottom_bar.background = ColorDrawable(backgroundColor)
|
emojiPaletteBottomBar.background = ColorDrawable(backgroundColor)
|
||||||
val bottomTextColor = textColor.darkenColor()
|
val bottomTextColor = textColor.darkenColor()
|
||||||
emoji_palette_mode_change.apply {
|
emojiPaletteModeChange.apply {
|
||||||
setTextColor(bottomTextColor)
|
setTextColor(bottomTextColor)
|
||||||
setOnClickListener {
|
setOnClickListener {
|
||||||
vibrateIfNeeded()
|
vibrateIfNeeded()
|
||||||
closeEmojiPalette()
|
closeEmojiPalette()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emoji_palette_backspace.apply {
|
|
||||||
|
emojiPaletteBackspace.apply {
|
||||||
applyColorFilter(bottomTextColor)
|
applyColorFilter(bottomTextColor)
|
||||||
setOnTouchListener { _, event ->
|
setOnTouchListener { _, event ->
|
||||||
when (event.action) {
|
when (event.action) {
|
||||||
|
@ -1498,18 +1504,19 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setupEmojis()
|
setupEmojis()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun openEmojiPalette() {
|
fun openEmojiPalette() {
|
||||||
mEmojiPaletteHolder!!.emoji_palette_holder.beVisible()
|
keyboardViewBinding!!.emojiPaletteHolder.beVisible()
|
||||||
setupEmojis()
|
setupEmojis()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun closeEmojiPalette() {
|
private fun closeEmojiPalette() {
|
||||||
mEmojiPaletteHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
emoji_palette_holder?.beGone()
|
emojiPaletteHolder.beGone()
|
||||||
mEmojiPaletteHolder?.emojis_list?.scrollToPosition(0)
|
emojisList?.scrollToPosition(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1539,7 +1546,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupEmojiAdapter(emojis: List<String>) {
|
private fun setupEmojiAdapter(emojis: List<String>) {
|
||||||
mEmojiPaletteHolder?.emojis_list?.apply {
|
keyboardViewBinding?.emojisList?.apply {
|
||||||
val emojiItemWidth = context.resources.getDimensionPixelSize(R.dimen.emoji_item_size)
|
val emojiItemWidth = context.resources.getDimensionPixelSize(R.dimen.emoji_item_size)
|
||||||
val emojiTopBarElevation = context.resources.getDimensionPixelSize(R.dimen.emoji_top_bar_elevation).toFloat()
|
val emojiTopBarElevation = context.resources.getDimensionPixelSize(R.dimen.emoji_top_bar_elevation).toFloat()
|
||||||
|
|
||||||
|
@ -1550,7 +1557,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
}
|
}
|
||||||
|
|
||||||
onScroll {
|
onScroll {
|
||||||
mEmojiPaletteHolder!!.emoji_palette_top_bar.elevation = if (it > 4) emojiTopBarElevation else 0f
|
keyboardViewBinding!!.emojiPaletteTopBar.elevation = if (it > 4) emojiTopBarElevation else 0f
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1634,14 +1641,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
fun addToClipboardViews(it: InlineContentView, addToFront: Boolean = false) {
|
fun addToClipboardViews(it: InlineContentView, addToFront: Boolean = false) {
|
||||||
if (mToolbarHolder?.autofill_suggestions_holder != null) {
|
if (keyboardViewBinding?.autofillSuggestionsHolder != null) {
|
||||||
val newLayoutParams = LinearLayout.LayoutParams(it.layoutParams)
|
val newLayoutParams = LinearLayout.LayoutParams(it.layoutParams)
|
||||||
newLayoutParams.updateMarginsRelative(start = resources.getDimensionPixelSize(R.dimen.normal_margin))
|
newLayoutParams.updateMarginsRelative(start = resources.getDimensionPixelSize(R.dimen.normal_margin))
|
||||||
it.layoutParams = newLayoutParams
|
it.layoutParams = newLayoutParams
|
||||||
if (addToFront) {
|
if (addToFront) {
|
||||||
mToolbarHolder?.autofill_suggestions_holder?.addView(it, 0)
|
keyboardViewBinding?.autofillSuggestionsHolder?.addView(it, 0)
|
||||||
} else {
|
} else {
|
||||||
mToolbarHolder?.autofill_suggestions_holder?.addView(it)
|
keyboardViewBinding?.autofillSuggestionsHolder?.addView(it)
|
||||||
}
|
}
|
||||||
updateSuggestionsToolbarLayout()
|
updateSuggestionsToolbarLayout()
|
||||||
}
|
}
|
||||||
|
@ -1649,21 +1656,21 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
fun clearClipboardViews() {
|
fun clearClipboardViews() {
|
||||||
mToolbarHolder?.autofill_suggestions_holder?.removeAllViews()
|
keyboardViewBinding?.autofillSuggestionsHolder?.removeAllViews()
|
||||||
updateSuggestionsToolbarLayout()
|
updateSuggestionsToolbarLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateSuggestionsToolbarLayout() {
|
private fun updateSuggestionsToolbarLayout() {
|
||||||
mToolbarHolder?.apply {
|
keyboardViewBinding?.apply {
|
||||||
if (hasInlineViews()) {
|
if (hasInlineViews()) {
|
||||||
// make room on suggestion toolbar for inline views
|
// make room on suggestion toolbar for inline views
|
||||||
suggestions_items_holder?.gravity = Gravity.NO_GRAVITY
|
suggestionsItemsHolder.gravity = Gravity.NO_GRAVITY
|
||||||
clipboard_value?.maxWidth = resources.getDimensionPixelSize(R.dimen.suggestion_max_width)
|
clipboardValue.maxWidth = resources.getDimensionPixelSize(R.dimen.suggestion_max_width)
|
||||||
} else {
|
} else {
|
||||||
// restore original clipboard toolbar appearance
|
// restore original clipboard toolbar appearance
|
||||||
suggestions_items_holder?.gravity = Gravity.CENTER_HORIZONTAL
|
suggestionsItemsHolder.gravity = Gravity.CENTER_HORIZONTAL
|
||||||
suggestions_holder?.measuredWidth?.also { maxWidth ->
|
suggestionsHolder.measuredWidth.also { maxWidth ->
|
||||||
clipboard_value?.maxWidth = maxWidth
|
clipboardValue.maxWidth = maxWidth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1672,5 +1679,5 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
|
||||||
/**
|
/**
|
||||||
* Returns true if there are [InlineContentView]s in [autofill_suggestions_holder]
|
* Returns true if there are [InlineContentView]s in [autofill_suggestions_holder]
|
||||||
*/
|
*/
|
||||||
private fun hasInlineViews() = (mToolbarHolder?.autofill_suggestions_holder?.childCount ?: 0) > 0
|
private fun hasInlineViews() = (keyboardViewBinding?.autofillSuggestionsHolder?.childCount ?: 0) > 0
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue