allow toggling vibrations and popups on key presses

This commit is contained in:
tibbi 2022-01-26 22:21:50 +01:00
parent 247ed0607d
commit 31ea72638c
6 changed files with 61 additions and 18 deletions

View File

@ -22,7 +22,8 @@ class SettingsActivity : SimpleActivity() {
setupPurchaseThankYou()
setupCustomizeColors()
setupUseEnglish()
setupClipboard()
setupVibrateOnKeypress()
setupShowPopupOnKeypress()
updateTextColors(settings_scrollview)
@ -65,7 +66,7 @@ class SettingsActivity : SimpleActivity() {
settings_use_english.isChecked = config.useEnglish
if (settings_use_english_holder.isGone() && settings_purchase_thank_you_holder.isGone()) {
settings_show_clipboard_holder.background = resources.getDrawable(R.drawable.ripple_all_corners, theme)
settings_vibrate_on_keypress_holder.background = resources.getDrawable(R.drawable.ripple_top_corners, theme)
}
settings_use_english_holder.setOnClickListener {
@ -75,11 +76,19 @@ class SettingsActivity : SimpleActivity() {
}
}
private fun setupClipboard() {
settings_show_clipboard.isChecked = config.showClipboard
settings_show_clipboard_holder.setOnClickListener {
settings_show_clipboard.toggle()
config.showClipboard = settings_show_clipboard.isChecked
private fun setupVibrateOnKeypress() {
settings_vibrate_on_keypress.isChecked = config.vibrateOnKeypress
settings_vibrate_on_keypress_holder.setOnClickListener {
settings_vibrate_on_keypress.toggle()
config.vibrateOnKeypress = settings_vibrate_on_keypress.isChecked
}
}
private fun setupShowPopupOnKeypress() {
settings_show_popup_on_keypress.isChecked = config.showPopupOnKeypress
settings_show_popup_on_keypress_holder.setOnClickListener {
settings_show_popup_on_keypress.toggle()
config.showPopupOnKeypress = settings_show_popup_on_keypress.isChecked
}
}
}

View File

@ -8,7 +8,11 @@ class Config(context: Context) : BaseConfig(context) {
fun newInstance(context: Context) = Config(context)
}
var showClipboard: Boolean
get() = prefs.getBoolean(SHOW_CLIPBOARD, true)
set(showClipboard) = prefs.edit().putBoolean(SHOW_CLIPBOARD, showClipboard).apply()
var vibrateOnKeypress: Boolean
get() = prefs.getBoolean(VIBRATE_ON_KEYPRESS, true)
set(vibrateOnKeypress) = prefs.edit().putBoolean(VIBRATE_ON_KEYPRESS, vibrateOnKeypress).apply()
var showPopupOnKeypress: Boolean
get() = prefs.getBoolean(SHOW_POPUP_ON_KEYPRESS, true)
set(showPopupOnKeypress) = prefs.edit().putBoolean(SHOW_POPUP_ON_KEYPRESS, showPopupOnKeypress).apply()
}

View File

@ -8,4 +8,5 @@ const val SHIFT_ON_PERMANENT = 2
const val MAX_KEYS_PER_MINI_ROW = 5
// shared prefs
const val SHOW_CLIPBOARD = "show_clipboard"
const val VIBRATE_ON_KEYPRESS = "vibrate_on_keypress"
const val SHOW_POPUP_ON_KEYPRESS = "show_popup_on_keypress"

View File

@ -10,6 +10,7 @@ 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
@ -47,7 +48,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
}
override fun onPress(primaryCode: Int) {
if (primaryCode != 0) {
if (primaryCode != 0 && baseContext.config.vibrateOnKeypress) {
keyboardView?.performHapticFeedback()
}
}

View File

@ -551,8 +551,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
private fun handleClipboard() {
if (context.config.showClipboard && mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view) {
val clipboardContent = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip?.getItemAt(0)?.text?.trim()
if (mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view) {
val clipboardManager = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
val clipboardContent = clipboardManager.primaryClip?.getItemAt(0)?.text?.trim()
if (clipboardContent?.isNotEmpty() == true) {
mToolbarHolder?.apply {
clipboard_value.apply {
@ -560,9 +561,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
removeUnderlines()
setOnClickListener {
mOnKeyboardActionListener!!.onText(clipboardContent.toString())
if (context.config.vibrateOnKeypress) {
performHapticFeedback()
}
}
}
toggleClipboardVisibility(true)
}
@ -692,6 +696,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
}
private fun showPreview(keyIndex: Int) {
if (!context.config.showPopupOnKeypress) {
return
}
val oldKeyIndex = mCurrentKeyIndex
val previewPopup = mPreviewPopup
mCurrentKeyIndex = keyIndex
@ -1255,6 +1263,10 @@ 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()
}
mIsLongPressingSpace = true
} else {
detectAndSendKey(mCurrentKey, key.x, key.y, mLastTapTime)

View File

@ -90,18 +90,34 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_clipboard_holder"
android:id="@+id/settings_vibrate_on_keypress_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_background">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_vibrate_on_keypress"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/vibrate_on_keypress" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_show_popup_on_keypress_holder"
style="@style/SettingsHolderCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ripple_bottom_corners">
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_show_clipboard"
android:id="@+id/settings_show_popup_on_keypress"
style="@style/SettingsCheckboxStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/show_clipboard_content" />
android:text="@string/show_popup" />
</RelativeLayout>
</LinearLayout>