removing some unused code

This commit is contained in:
tibbi
2022-01-20 11:00:19 +01:00
parent 6fdf41f753
commit 4bfb6042cf
2 changed files with 3 additions and 150 deletions

View File

@ -206,16 +206,4 @@ class SimpleKeyboardIME : InputMethodService(), MyKeyboardView.OnKeyboardActionL
currentInputConnection?.setSelection(newCursorPosition, newCursorPosition) currentInputConnection?.setSelection(newCursorPosition, newCursorPosition)
} }
override fun onText(text: CharSequence?) {}
override fun swipeLeft() {}
override fun swipeRight() {}
override fun swipeDown() {}
override fun swipeUp() {}
override fun onRelease(primaryCode: Int) {}
} }

View File

@ -6,18 +6,17 @@ import android.graphics.*
import android.graphics.Paint.Align import android.graphics.Paint.Align
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.inputmethodservice.KeyboardView import android.inputmethodservice.KeyboardView
import android.media.AudioManager
import android.os.Handler import android.os.Handler
import android.os.Message import android.os.Message
import android.util.AttributeSet import android.util.AttributeSet
import android.util.TypedValue import android.util.TypedValue
import android.view.* import android.view.*
import android.view.GestureDetector.SimpleOnGestureListener
import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityManager import android.view.accessibility.AccessibilityManager
import android.widget.PopupWindow import android.widget.PopupWindow
import android.widget.TextView import android.widget.TextView
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.mydebug
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
import com.simplemobiletools.keyboard.extensions.config import com.simplemobiletools.keyboard.extensions.config
import com.simplemobiletools.keyboard.helpers.* import com.simplemobiletools.keyboard.helpers.*
@ -34,12 +33,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
*/ */
fun onPress(primaryCode: Int) fun onPress(primaryCode: Int)
/**
* Called when the user releases a key. This is sent after the [.onKey] is called. For keys that repeat, this is only called once.
* @param primaryCode the code of the key that was released
*/
fun onRelease(primaryCode: Int)
/** /**
* Send a key press to the listener. * Send a key press to the listener.
* @param primaryCode this is the key that was pressed * @param primaryCode this is the key that was pressed
@ -49,32 +42,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
*/ */
fun onKey(primaryCode: Int, keyCodes: IntArray?) fun onKey(primaryCode: Int, keyCodes: IntArray?)
/**
* Sends a sequence of characters to the listener.
* @param text the sequence of characters to be displayed.
*/
fun onText(text: CharSequence?)
/**
* Called when the user quickly moves the finger from right to left.
*/
fun swipeLeft()
/**
* Called when the user quickly moves the finger from left to right.
*/
fun swipeRight()
/**
* Called when the user quickly moves the finger from up to down.
*/
fun swipeDown()
/**
* Called when the user quickly moves the finger from down to up.
*/
fun swipeUp()
/** /**
* Called when the finger has been lifted after pressing a key * Called when the finger has been lifted after pressing a key
*/ */
@ -222,9 +189,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
/** The accessibility manager for accessibility support */ /** The accessibility manager for accessibility support */
private val mAccessibilityManager: AccessibilityManager private val mAccessibilityManager: AccessibilityManager
/** The audio manager for accessibility support */
private val mAudioManager: AudioManager
private var mHandler: Handler? = null private var mHandler: Handler? = null
companion object { companion object {
@ -304,7 +268,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mSwipeThreshold = (500 * resources.displayMetrics.density).toInt() mSwipeThreshold = (500 * resources.displayMetrics.density).toInt()
mDisambiguateSwipe = false//resources.getBoolean(R.bool.config_swipeDisambiguation) mDisambiguateSwipe = false//resources.getBoolean(R.bool.config_swipeDisambiguation)
mAccessibilityManager = (context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager) mAccessibilityManager = (context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager)
mAudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
mPopupMaxMoveDistance = resources.getDimension(R.dimen.popup_max_move_distance) mPopupMaxMoveDistance = resources.getDimension(R.dimen.popup_max_move_distance)
mTopSmallNumberSize = resources.getDimension(R.dimen.small_text_size) mTopSmallNumberSize = resources.getDimension(R.dimen.small_text_size)
mTopSmallNumberMarginWidth = resources.getDimension(R.dimen.top_small_number_margin_width) mTopSmallNumberMarginWidth = resources.getDimension(R.dimen.top_small_number_margin_width)
@ -315,7 +278,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
@SuppressLint("HandlerLeak") @SuppressLint("HandlerLeak")
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
initGestureDetector()
if (mHandler == null) { if (mHandler == null) {
mHandler = object : Handler() { mHandler = object : Handler() {
override fun handleMessage(msg: Message) { override fun handleMessage(msg: Message) {
@ -349,63 +311,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
} }
private fun initGestureDetector() {
if (mGestureDetector == null) {
mGestureDetector = GestureDetector(context, object : SimpleOnGestureListener() {
override fun onFling(me1: MotionEvent, me2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
if (mPossiblePoly) {
return false
}
val absX = Math.abs(velocityX)
val absY = Math.abs(velocityY)
val deltaX = me2.x - me1.x
val deltaY = me2.y - me1.y
val travelX = width / 2 // Half the keyboard width
val travelY = height / 2 // Half the keyboard height
mSwipeTracker.computeCurrentVelocity(1000)
val endingVelocityX: Float = mSwipeTracker.xVelocity
val endingVelocityY: Float = mSwipeTracker.yVelocity
var sendDownKey = false
if (velocityX > mSwipeThreshold && absY < absX && deltaX > travelX) {
sendDownKey = if (mDisambiguateSwipe && endingVelocityX < velocityX / 4) {
true
} else {
swipeRight()
return true
}
} else if (velocityX < -mSwipeThreshold && absY < absX && deltaX < -travelX) {
sendDownKey = if (mDisambiguateSwipe && endingVelocityX > velocityX / 4) {
true
} else {
swipeLeft()
return true
}
} else if (velocityY < -mSwipeThreshold && absX < absY && deltaY < -travelY) {
sendDownKey = if (mDisambiguateSwipe && endingVelocityY > velocityY / 4) {
true
} else {
swipeUp()
return true
}
} else if (velocityY > mSwipeThreshold && absX < absY / 2 && deltaY > travelY) {
sendDownKey = if (mDisambiguateSwipe && endingVelocityY < velocityY / 4) {
true
} else {
swipeDown()
return true
}
}
if (sendDownKey) {
detectAndSendKey(mDownKey, mStartX, mStartY, me1.eventTime)
}
return false
}
})
mGestureDetector!!.setIsLongpressEnabled(false)
}
}
/** /**
* Attaches a keyboard to this view. The keyboard can be switched at any time and the * Attaches a keyboard to this view. The keyboard can be switched at any time and the
* view will re-layout itself to accommodate the keyboard. * view will re-layout itself to accommodate the keyboard.
@ -744,10 +649,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
private fun detectAndSendKey(index: Int, x: Int, y: Int, eventTime: Long) { private fun detectAndSendKey(index: Int, x: Int, y: Int, eventTime: Long) {
if (index != NOT_A_KEY && index < mKeys.size) { if (index != NOT_A_KEY && index < mKeys.size) {
val key = mKeys[index] val key = mKeys[index]
if (key.text != null) { if (key.text == null) {
onKeyboardActionListener!!.onText(key.text)
onKeyboardActionListener!!.onRelease(NOT_A_KEY)
} else {
var code = key.codes[0] var code = key.codes[0]
// TextEntryState.keyPressedAt(key, x, y); // TextEntryState.keyPressedAt(key, x, y);
val codes = IntArray(MAX_NEARBY_KEYS) val codes = IntArray(MAX_NEARBY_KEYS)
@ -763,7 +665,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
code = key.codes[mTapCount] code = key.codes[mTapCount]
} }
onKeyboardActionListener!!.onKey(code, codes) onKeyboardActionListener!!.onKey(code, codes)
onKeyboardActionListener!!.onRelease(code)
} }
mLastSentIndex = index mLastSentIndex = index
mLastTapTime = eventTime mLastTapTime = eventTime
@ -1033,25 +934,13 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
override fun onKey(primaryCode: Int, keyCodes: IntArray?) { override fun onKey(primaryCode: Int, keyCodes: IntArray?) {
onKeyboardActionListener!!.onKey(primaryCode, keyCodes) onKeyboardActionListener!!.onKey(primaryCode, keyCodes)
dismissPopupKeyboard() dismissPopupKeyboard()
mydebug("onkey")
} }
override fun onText(text: CharSequence?) {
onKeyboardActionListener!!.onText(text)
dismissPopupKeyboard()
}
override fun swipeLeft() {}
override fun swipeRight() {}
override fun swipeUp() {}
override fun swipeDown() {}
override fun onPress(primaryCode: Int) { override fun onPress(primaryCode: Int) {
onKeyboardActionListener!!.onPress(primaryCode) onKeyboardActionListener!!.onPress(primaryCode)
} }
override fun onRelease(primaryCode: Int) {
onKeyboardActionListener!!.onRelease(primaryCode)
}
override fun onActionUp() { override fun onActionUp() {
onKeyboardActionListener!!.onActionUp() onKeyboardActionListener!!.onActionUp()
} }
@ -1065,7 +954,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
} }
//mInputView.setSuggest(mSuggest);
val keyboard = if (popupKey.popupCharacters != null) { val keyboard = if (popupKey.popupCharacters != null) {
MyKeyboard(context, popupKeyboardId, popupKey.popupCharacters!!) MyKeyboard(context, popupKeyboardId, popupKey.popupCharacters!!)
} else { } else {
@ -1257,13 +1145,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
return true return true
} }
if (mGestureDetector!!.onTouchEvent(me)) {
showPreview(NOT_A_KEY)
mHandler!!.removeMessages(MSG_REPEAT)
mHandler!!.removeMessages(MSG_LONGPRESS)
return true
}
// Needs to be called after the gesture detector gets a turn, as it may have // Needs to be called after the gesture detector gets a turn, as it may have
// displayed the mini keyboard // displayed the mini keyboard
if (mMiniKeyboardOnScreen && action != MotionEvent.ACTION_CANCEL) { if (mMiniKeyboardOnScreen && action != MotionEvent.ACTION_CANCEL) {
@ -1429,22 +1310,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
return true return true
} }
protected fun swipeRight() {
onKeyboardActionListener!!.swipeRight()
}
protected fun swipeLeft() {
onKeyboardActionListener!!.swipeLeft()
}
protected fun swipeUp() {
onKeyboardActionListener!!.swipeUp()
}
protected fun swipeDown() {
onKeyboardActionListener!!.swipeDown()
}
fun closing() { fun closing() {
if (mPreviewPopup.isShowing) { if (mPreviewPopup.isShowing) {
mPreviewPopup.dismiss() mPreviewPopup.dismiss()