diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt index e125f6d..6426111 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/services/SimpleKeyboardIME.kt @@ -8,9 +8,7 @@ import android.view.View import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo.IME_ACTION_NONE import android.view.inputmethod.ExtractedTextRequest -import com.simplemobiletools.commons.extensions.performHapticFeedback import com.simplemobiletools.keyboard.R -import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.helpers.MyKeyboard import com.simplemobiletools.keyboard.helpers.SHIFT_OFF import com.simplemobiletools.keyboard.helpers.SHIFT_ON_ONE_CHAR @@ -48,8 +46,8 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL } override fun onPress(primaryCode: Int) { - if (primaryCode != 0 && baseContext.config.vibrateOnKeypress) { - keyboardView?.performHapticFeedback() + if (primaryCode != 0) { + keyboardView?.vibrateIfNeeded() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 6485f89..334b56a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -323,6 +323,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mToolbarHolder!!.apply { settings_cog.setOnLongClickListener { context.toast(R.string.settings); true; } settings_cog.setOnClickListener { + vibrateIfNeeded() Intent(context, SettingsActivity::class.java).apply { addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) context.startActivity(this) @@ -331,11 +332,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut pinned_clipboard_items.setOnLongClickListener { context.toast(R.string.clipboard); true; } pinned_clipboard_items.setOnClickListener { + vibrateIfNeeded() mClipboardManagerHolder!!.clipboard_manager_holder.beVisible() } clipboard_clear.setOnLongClickListener { context.toast(R.string.clear_clipboard_data); true; } clipboard_clear.setOnClickListener { + vibrateIfNeeded() clearClipboardContent() toggleClipboardVisibility(false) } @@ -351,11 +354,18 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mClipboardManagerHolder!!.apply { clipboard_manager_close.setOnClickListener { + vibrateIfNeeded() mClipboardManagerHolder!!.clipboard_manager_holder.beGone() } } } + fun vibrateIfNeeded() { + if (context.config.vibrateOnKeypress) { + performHapticFeedback() + } + } + /** * Sets the state of the shift key of the keyboard, if any. * @param shifted whether or not to enable the state of the shift key @@ -575,10 +585,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut removeUnderlines() setOnClickListener { mOnKeyboardActionListener!!.onText(clipboardContent.toString()) - - if (context.config.vibrateOnKeypress) { - performHapticFeedback() - } + vibrateIfNeeded() } } @@ -1277,8 +1284,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut private fun repeatKey(initialCall: Boolean): Boolean { val key = mKeys[mRepeatKeyIndex] if (!initialCall && key.code == KEYCODE_SPACE) { - if (!mIsLongPressingSpace && context.config.vibrateOnKeypress) { - performHapticFeedback() + if (!mIsLongPressingSpace) { + vibrateIfNeeded() } mIsLongPressingSpace = true