mirror of
				https://github.com/SimpleMobileTools/Simple-Keyboard.git
				synced 2025-06-05 21:49:26 +02:00 
			
		
		
		
	allow toggling vibrations and popups on key presses
This commit is contained in:
		| @@ -22,7 +22,8 @@ class SettingsActivity : SimpleActivity() { | |||||||
|         setupPurchaseThankYou() |         setupPurchaseThankYou() | ||||||
|         setupCustomizeColors() |         setupCustomizeColors() | ||||||
|         setupUseEnglish() |         setupUseEnglish() | ||||||
|         setupClipboard() |         setupVibrateOnKeypress() | ||||||
|  |         setupShowPopupOnKeypress() | ||||||
|  |  | ||||||
|         updateTextColors(settings_scrollview) |         updateTextColors(settings_scrollview) | ||||||
|  |  | ||||||
| @@ -65,7 +66,7 @@ class SettingsActivity : SimpleActivity() { | |||||||
|         settings_use_english.isChecked = config.useEnglish |         settings_use_english.isChecked = config.useEnglish | ||||||
|  |  | ||||||
|         if (settings_use_english_holder.isGone() && settings_purchase_thank_you_holder.isGone()) { |         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 { |         settings_use_english_holder.setOnClickListener { | ||||||
| @@ -75,11 +76,19 @@ class SettingsActivity : SimpleActivity() { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun setupClipboard() { |     private fun setupVibrateOnKeypress() { | ||||||
|         settings_show_clipboard.isChecked = config.showClipboard |         settings_vibrate_on_keypress.isChecked = config.vibrateOnKeypress | ||||||
|         settings_show_clipboard_holder.setOnClickListener { |         settings_vibrate_on_keypress_holder.setOnClickListener { | ||||||
|             settings_show_clipboard.toggle() |             settings_vibrate_on_keypress.toggle() | ||||||
|             config.showClipboard = settings_show_clipboard.isChecked |             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 | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,11 @@ class Config(context: Context) : BaseConfig(context) { | |||||||
|         fun newInstance(context: Context) = Config(context) |         fun newInstance(context: Context) = Config(context) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     var showClipboard: Boolean |     var vibrateOnKeypress: Boolean | ||||||
|         get() = prefs.getBoolean(SHOW_CLIPBOARD, true) |         get() = prefs.getBoolean(VIBRATE_ON_KEYPRESS, true) | ||||||
|         set(showClipboard) = prefs.edit().putBoolean(SHOW_CLIPBOARD, showClipboard).apply() |         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() | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,4 +8,5 @@ const val SHIFT_ON_PERMANENT = 2 | |||||||
| const val MAX_KEYS_PER_MINI_ROW = 5 | const val MAX_KEYS_PER_MINI_ROW = 5 | ||||||
|  |  | ||||||
| // shared prefs | // 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" | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import android.view.inputmethod.EditorInfo.IME_ACTION_NONE | |||||||
| import android.view.inputmethod.ExtractedTextRequest | import android.view.inputmethod.ExtractedTextRequest | ||||||
| import com.simplemobiletools.commons.extensions.performHapticFeedback | import com.simplemobiletools.commons.extensions.performHapticFeedback | ||||||
| import com.simplemobiletools.keyboard.R | import com.simplemobiletools.keyboard.R | ||||||
|  | import com.simplemobiletools.keyboard.extensions.config | ||||||
| import com.simplemobiletools.keyboard.helpers.MyKeyboard | import com.simplemobiletools.keyboard.helpers.MyKeyboard | ||||||
| import com.simplemobiletools.keyboard.helpers.SHIFT_OFF | import com.simplemobiletools.keyboard.helpers.SHIFT_OFF | ||||||
| import com.simplemobiletools.keyboard.helpers.SHIFT_ON_ONE_CHAR | import com.simplemobiletools.keyboard.helpers.SHIFT_ON_ONE_CHAR | ||||||
| @@ -47,7 +48,7 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     override fun onPress(primaryCode: Int) { |     override fun onPress(primaryCode: Int) { | ||||||
|         if (primaryCode != 0) { |         if (primaryCode != 0 && baseContext.config.vibrateOnKeypress) { | ||||||
|             keyboardView?.performHapticFeedback() |             keyboardView?.performHapticFeedback() | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -551,8 +551,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun handleClipboard() { |     private fun handleClipboard() { | ||||||
|         if (context.config.showClipboard && mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view) { |         if (mToolbarHolder != null && mPopupParent.id != R.id.mini_keyboard_view) { | ||||||
|             val clipboardContent = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager).primaryClip?.getItemAt(0)?.text?.trim() |             val clipboardManager = (context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager) | ||||||
|  |             val clipboardContent = clipboardManager.primaryClip?.getItemAt(0)?.text?.trim() | ||||||
|             if (clipboardContent?.isNotEmpty() == true) { |             if (clipboardContent?.isNotEmpty() == true) { | ||||||
|                 mToolbarHolder?.apply { |                 mToolbarHolder?.apply { | ||||||
|                     clipboard_value.apply { |                     clipboard_value.apply { | ||||||
| @@ -560,7 +561,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | |||||||
|                         removeUnderlines() |                         removeUnderlines() | ||||||
|                         setOnClickListener { |                         setOnClickListener { | ||||||
|                             mOnKeyboardActionListener!!.onText(clipboardContent.toString()) |                             mOnKeyboardActionListener!!.onText(clipboardContent.toString()) | ||||||
|                             performHapticFeedback() |  | ||||||
|  |                             if (context.config.vibrateOnKeypress) { | ||||||
|  |                                 performHapticFeedback() | ||||||
|  |                             } | ||||||
|                         } |                         } | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
| @@ -692,6 +696,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private fun showPreview(keyIndex: Int) { |     private fun showPreview(keyIndex: Int) { | ||||||
|  |         if (!context.config.showPopupOnKeypress) { | ||||||
|  |             return | ||||||
|  |         } | ||||||
|  |  | ||||||
|         val oldKeyIndex = mCurrentKeyIndex |         val oldKeyIndex = mCurrentKeyIndex | ||||||
|         val previewPopup = mPreviewPopup |         val previewPopup = mPreviewPopup | ||||||
|         mCurrentKeyIndex = keyIndex |         mCurrentKeyIndex = keyIndex | ||||||
| @@ -1255,6 +1263,10 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut | |||||||
|     private fun repeatKey(initialCall: Boolean): Boolean { |     private fun repeatKey(initialCall: Boolean): Boolean { | ||||||
|         val key = mKeys[mRepeatKeyIndex] |         val key = mKeys[mRepeatKeyIndex] | ||||||
|         if (!initialCall && key.code == KEYCODE_SPACE) { |         if (!initialCall && key.code == KEYCODE_SPACE) { | ||||||
|  |             if (!mIsLongPressingSpace && context.config.vibrateOnKeypress) { | ||||||
|  |                 performHapticFeedback() | ||||||
|  |             } | ||||||
|  |  | ||||||
|             mIsLongPressingSpace = true |             mIsLongPressingSpace = true | ||||||
|         } else { |         } else { | ||||||
|             detectAndSendKey(mCurrentKey, key.x, key.y, mLastTapTime) |             detectAndSendKey(mCurrentKey, key.x, key.y, mLastTapTime) | ||||||
|   | |||||||
| @@ -90,18 +90,34 @@ | |||||||
|             </RelativeLayout> |             </RelativeLayout> | ||||||
|  |  | ||||||
|             <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" |                 style="@style/SettingsHolderCheckboxStyle" | ||||||
|                 android:layout_width="match_parent" |                 android:layout_width="match_parent" | ||||||
|                 android:layout_height="wrap_content" |                 android:layout_height="wrap_content" | ||||||
|                 android:background="@drawable/ripple_bottom_corners"> |                 android:background="@drawable/ripple_bottom_corners"> | ||||||
|  |  | ||||||
|                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox |                 <com.simplemobiletools.commons.views.MyAppCompatCheckbox | ||||||
|                     android:id="@+id/settings_show_clipboard" |                     android:id="@+id/settings_show_popup_on_keypress" | ||||||
|                     style="@style/SettingsCheckboxStyle" |                     style="@style/SettingsCheckboxStyle" | ||||||
|                     android:layout_width="match_parent" |                     android:layout_width="match_parent" | ||||||
|                     android:layout_height="wrap_content" |                     android:layout_height="wrap_content" | ||||||
|                     android:text="@string/show_clipboard_content" /> |                     android:text="@string/show_popup" /> | ||||||
|  |  | ||||||
|             </RelativeLayout> |             </RelativeLayout> | ||||||
|         </LinearLayout> |         </LinearLayout> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user