formatting some comments

This commit is contained in:
tibbi 2022-01-22 10:15:34 +01:00
parent be30b19380
commit 74dea45afe
2 changed files with 34 additions and 64 deletions

View File

@ -16,8 +16,7 @@ import com.simplemobiletools.keyboard.R
import java.util.* import java.util.*
/** /**
* Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard * Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard consists of rows of keys.
* consists of rows of keys.
* @attr ref android.R.styleable#Keyboard_keyWidth * @attr ref android.R.styleable#Keyboard_keyWidth
* @attr ref android.R.styleable#Keyboard_horizontalGap * @attr ref android.R.styleable#Keyboard_horizontalGap
*/ */
@ -91,9 +90,8 @@ class MyKeyboard {
} }
/** /**
* Container for keys in the keyboard. All keys in a row are at the same Y-coordinate. * Container for keys in the keyboard. All keys in a row are at the same Y-coordinate. Some of the key size defaults can be overridden per row from
* Some of the key size defaults can be overridden per row from what the [MyKeyboard] * what the [MyKeyboard] defines.
* defines.
* @attr ref android.R.styleable#Keyboard_keyWidth * @attr ref android.R.styleable#Keyboard_keyWidth
* @attr ref android.R.styleable#Keyboard_horizontalGap * @attr ref android.R.styleable#Keyboard_horizontalGap
*/ */
@ -146,7 +144,7 @@ class MyKeyboard {
/** Label to display */ /** Label to display */
var label: CharSequence = "" var label: CharSequence = ""
/** First row of letters can also be used for inserting numbers by long pressing them, show those numbers */ /** First row of letters can also be used for inserting numbers by long pressing them, show those numbers */
var topSmallNumber: String = "" var topSmallNumber: String = ""
/** Icon to display instead of a label. Icon takes precedence over a label */ /** Icon to display instead of a label. Icon takes precedence over a label */
@ -170,21 +168,20 @@ class MyKeyboard {
/** The current pressed state of this key */ /** The current pressed state of this key */
var pressed = false var pressed = false
/** Focused state, used after long pressing a key and swiping to alternative keys */ /** Focused state, used after long pressing a key and swiping to alternative keys */
var focused = false var focused = false
/** Popup characters */ /** Popup characters showing after long pressing the key */
var popupCharacters: CharSequence? = null var popupCharacters: CharSequence? = null
/** /**
* Flags that specify the anchoring to edges of the keyboard for detecting touch events * Flags that specify the anchoring to edges of the keyboard for detecting touch events that are just out of the boundary of the key.
* that are just out of the boundary of the key. This is a bit mask of * This is a bit mask of [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and [MyKeyboard.EDGE_BOTTOM].
* [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and [MyKeyboard.EDGE_BOTTOM].
*/ */
private var edgeFlags = 0 private var edgeFlags = 0
/** The keyboard that this key belongs to */ /** The keyboard that this key belongs to */
private val keyboard: MyKeyboard = parent.parent private val keyboard = parent.parent
/** If this key pops up a mini keyboard, this is the resource id for the XML layout for that keyboard. */ /** If this key pops up a mini keyboard, this is the resource id for the XML layout for that keyboard. */
var popupResId = 0 var popupResId = 0
@ -192,8 +189,7 @@ class MyKeyboard {
/** Whether this key repeats itself when held down */ /** Whether this key repeats itself when held down */
var repeatable = false var repeatable = false
/** Create a key with the given top-left coordinate and extract its attributes from /** Create a key with the given top-left coordinate and extract its attributes from the XML parser.
* the XML parser.
* @param res resources associated with the caller's context * @param res resources associated with the caller's context
* @param parent the row that this key belongs to. The row must already be attached to a [MyKeyboard]. * @param parent the row that this key belongs to. The row must already be attached to a [MyKeyboard].
* @param x the x coordinate of the top-left * @param x the x coordinate of the top-left
@ -240,9 +236,8 @@ class MyKeyboard {
* Detects if a point falls inside this key. * Detects if a point falls inside this key.
* @param x the x-coordinate of the point * @param x the x-coordinate of the point
* @param y the y-coordinate of the point * @param y the y-coordinate of the point
* @return whether or not the point falls inside the key. If the key is attached to an edge, * @return whether or not the point falls inside the key. If the key is attached to an edge, it will assume that all points between the key and
* it will assume that all points between the key and the edge are considered to be inside * the edge are considered to be inside the key.
* the key.
*/ */
fun isInside(x: Int, y: Int): Boolean { fun isInside(x: Int, y: Int): Boolean {
val leftEdge = edgeFlags and EDGE_LEFT > 0 val leftEdge = edgeFlags and EDGE_LEFT > 0
@ -269,21 +264,14 @@ class MyKeyboard {
} }
/** /**
* Creates a keyboard from the given xml key layout file. Weeds out rows * Creates a keyboard from the given xml key layout file. Weeds out rows that have a keyboard mode defined but don't match the specified mode.
* that have a keyboard mode defined but don't match the specified mode.
* @param context the application or service context
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
* @param modeId keyboard mode identifier
*/
/**
* Creates a keyboard from the given xml key layout file.
* @param context the application or service context * @param context the application or service context
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys. * @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
* @param enterKeyType determines what icon should we show on Enter key
*/ */
@JvmOverloads @JvmOverloads
constructor(context: Context, @XmlRes xmlLayoutResId: Int, enterKeyType: Int, modeId: Int = 0) { constructor(context: Context, @XmlRes xmlLayoutResId: Int, enterKeyType: Int) {
val dm = context.resources.displayMetrics mDisplayWidth = context.resources.displayMetrics.widthPixels
mDisplayWidth = dm.widthPixels
mDefaultHorizontalGap = 0 mDefaultHorizontalGap = 0
mDefaultWidth = mDisplayWidth / 10 mDefaultWidth = mDisplayWidth / 10
mDefaultHeight = mDefaultWidth mDefaultHeight = mDefaultWidth
@ -294,16 +282,11 @@ class MyKeyboard {
/** /**
* *
* Creates a blank keyboard from the given resource file and populates it with the specified * Creates a blank keyboard from the given resource file and populates it with the specified characters in left-to-right, top-to-bottom fashion,
* characters in left-to-right, top-to-bottom fashion, using the specified number of columns. * using the specified number of columns. If the specified number of columns is -1, then the keyboard will fit as many keys as possible in each row.
*
*
* If the specified number of columns is -1, then the keyboard will fit as many keys as
* possible in each row.
* @param context the application or service context * @param context the application or service context
* @param layoutTemplateResId the layout template file, containing no keys. * @param layoutTemplateResId the layout template file, containing no keys.
* @param characters the list of characters to display on the keyboard. One key will be created * @param characters the list of characters to display on the keyboard. One key will be created for each character.
* for each character.
*/ */
constructor(context: Context, layoutTemplateResId: Int, characters: CharSequence) : constructor(context: Context, layoutTemplateResId: Int, characters: CharSequence) :
this(context, layoutTemplateResId, 0) { this(context, layoutTemplateResId, 0) {
@ -388,8 +371,7 @@ class MyKeyboard {
* Returns the indices of the keys that are closest to the given point. * Returns the indices of the keys that are closest to the given point.
* @param x the x-coordinate of the point * @param x the x-coordinate of the point
* @param y the y-coordinate of the point * @param y the y-coordinate of the point
* @return the array of integer indices for the nearest keys to the given point. If the given * @return the array of integer indices for the nearest keys to the given point. If the given point is out of range, then an array of size zero is returned.
* point is out of range, then an array of size zero is returned.
*/ */
fun getNearestKeys(x: Int, y: Int): IntArray { fun getNearestKeys(x: Int, y: Int): IntArray {
if (mGridNeighbors == null) { if (mGridNeighbors == null) {

View File

@ -252,11 +252,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
/** /**
* 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.
* @see MyKeyboard
*
* @see .getKeyboard
* @param keyboard the keyboard to display in this view * @param keyboard the keyboard to display in this view
*/ */
fun setKeyboard(keyboard: MyKeyboard) { fun setKeyboard(keyboard: MyKeyboard) {
@ -283,7 +279,6 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
* Sets the state of the shift key of the keyboard, if any. * 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 * @param shifted whether or not to enable the state of the shift key
* @return true if the shift key state changed, false if there was no change * @return true if the shift key state changed, false if there was no change
* @see KeyboardView.isShifted
*/ */
private fun setShifted(shiftState: Int) { private fun setShifted(shiftState: Int) {
if (mKeyboard?.setShifted(shiftState) == true) { if (mKeyboard?.setShifted(shiftState) == true) {
@ -293,9 +288,7 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
/** /**
* Returns the state of the shift key of the keyboard, if any. * Returns the state of the shift key of the keyboard, if any.
* @return true if the shift is in a pressed state, false otherwise. If there is * @return true if the shift is in a pressed state, false otherwise
* no shift key on the keyboard or there is no keyboard attached, it returns false.
* @see KeyboardView.setShifted
*/ */
private fun isShifted(): Boolean { private fun isShifted(): Boolean {
return mKeyboard?.mShiftState ?: SHIFT_OFF > SHIFT_OFF return mKeyboard?.mShiftState ?: SHIFT_OFF > SHIFT_OFF
@ -330,9 +323,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
/** /**
* Compute the average distance between adjacent keys (horizontally and vertically) * Compute the average distance between adjacent keys (horizontally and vertically) and square it to get the proximity threshold. We use a square here and
* and square it to get the proximity threshold. We use a square here and in computing * in computing the touch distance from a key's center to avoid taking a square root.
* the touch distance from a key's center to avoid taking a square root.
* @param keyboard * @param keyboard
*/ */
private fun computeProximityThreshold(keyboard: MyKeyboard?) { private fun computeProximityThreshold(keyboard: MyKeyboard?) {
@ -710,10 +702,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
/** /**
* Requests a redraw of the entire keyboard. Calling [.invalidate] is not sufficient * Requests a redraw of the entire keyboard. Calling [.invalidate] is not sufficient because the keyboard renders the keys to an off-screen buffer and
* because the keyboard renders the keys to an off-screen buffer and an invalidate() only * an invalidate() only draws the cached buffer.
* draws the cached buffer.
* @see .invalidateKey
*/ */
fun invalidateAllKeys() { fun invalidateAllKeys() {
mDirtyRect.union(0, 0, width, height) mDirtyRect.union(0, 0, width, height)
@ -722,11 +712,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
/** /**
* Invalidates a key so that it will be redrawn on the next repaint. Use this method if only * Invalidates a key so that it will be redrawn on the next repaint. Use this method if only one key is changing it's content. Any changes that
* one key is changing it's content. Any changes that affect the position or size of the key * affect the position or size of the key may not be honored.
* may not be honored.
* @param keyIndex the index of the key in the attached [MyKeyboard]. * @param keyIndex the index of the key in the attached [MyKeyboard].
* @see .invalidateAllKeys
*/ */
private fun invalidateKey(keyIndex: Int) { private fun invalidateKey(keyIndex: Int) {
if (keyIndex < 0 || keyIndex >= mKeys.size) { if (keyIndex < 0 || keyIndex >= mKeys.size) {
@ -766,11 +754,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
} }
/** /**
* Called when a key is long pressed. By default this will open any popup keyboard associated * Called when a key is long pressed. By default this will open any popup keyboard associated with this key through the attributes
* with this key through the attributes popupLayout and popupCharacters. * popupLayout and popupCharacters.
* @param popupKey the key that was long pressed * @param popupKey the key that was long pressed
* @return true if the long press is handled, false otherwise. Subclasses should call the * @return true if the long press is handled, false otherwise. Subclasses should call the method on the base class if the subclass doesn't wish to
* method on the base class if the subclass doesn't wish to handle the call. * handle the call.
*/ */
private fun onLongPress(popupKey: MyKeyboard.Key, me: MotionEvent): Boolean { private fun onLongPress(popupKey: MyKeyboard.Key, me: MotionEvent): Boolean {
val popupKeyboardId = popupKey.popupResId val popupKeyboardId = popupKey.popupResId
@ -782,8 +770,8 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mMiniKeyboard = mMiniKeyboardContainer!!.findViewById<View>(R.id.mini_keyboard_view) as MyKeyboardView mMiniKeyboard = mMiniKeyboardContainer!!.findViewById<View>(R.id.mini_keyboard_view) as MyKeyboardView
mMiniKeyboard!!.mOnKeyboardActionListener = object : OnKeyboardActionListener { mMiniKeyboard!!.mOnKeyboardActionListener = object : OnKeyboardActionListener {
override fun onKey(primaryCode: Int) { override fun onKey(code: Int) {
mOnKeyboardActionListener!!.onKey(primaryCode) mOnKeyboardActionListener!!.onKey(code)
dismissPopupKeyboard() dismissPopupKeyboard()
} }