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.*
/**
* Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard
* consists of rows of keys.
* Loads an XML description of a keyboard and stores the attributes of the keys. A keyboard consists of rows of keys.
* @attr ref android.R.styleable#Keyboard_keyWidth
* @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.
* Some of the key size defaults can be overridden per row from what the [MyKeyboard]
* defines.
* 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
* what the [MyKeyboard] defines.
* @attr ref android.R.styleable#Keyboard_keyWidth
* @attr ref android.R.styleable#Keyboard_horizontalGap
*/
@ -173,18 +171,17 @@ class MyKeyboard {
/** Focused state, used after long pressing a key and swiping to alternative keys */
var focused = false
/** Popup characters */
/** Popup characters showing after long pressing the key */
var popupCharacters: CharSequence? = null
/**
* Flags that specify the anchoring to edges of the keyboard for detecting touch events
* that are just out of the boundary of the key. This is a bit mask of
* [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and [MyKeyboard.EDGE_BOTTOM].
* Flags that specify the anchoring to edges of the keyboard for detecting touch events that are just out of the boundary of the key.
* This is a bit mask of [MyKeyboard.EDGE_LEFT], [MyKeyboard.EDGE_RIGHT], [MyKeyboard.EDGE_TOP] and [MyKeyboard.EDGE_BOTTOM].
*/
private var edgeFlags = 0
/** 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. */
var popupResId = 0
@ -192,8 +189,7 @@ class MyKeyboard {
/** Whether this key repeats itself when held down */
var repeatable = false
/** Create a key with the given top-left coordinate and extract its attributes from
* the XML parser.
/** Create a key with the given top-left coordinate and extract its attributes from the XML parser.
* @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 x the x coordinate of the top-left
@ -240,9 +236,8 @@ class MyKeyboard {
* Detects if a point falls inside this key.
* @param x the x-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,
* it will assume that all points between the key and the edge are considered to be inside
* the key.
* @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
* the edge are considered to be inside the key.
*/
fun isInside(x: Int, y: Int): Boolean {
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
* 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.
* 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.
* @param context the application or service context
* @param xmlLayoutResId the resource file that contains the keyboard layout and keys.
* @param enterKeyType determines what icon should we show on Enter key
*/
@JvmOverloads
constructor(context: Context, @XmlRes xmlLayoutResId: Int, enterKeyType: Int, modeId: Int = 0) {
val dm = context.resources.displayMetrics
mDisplayWidth = dm.widthPixels
constructor(context: Context, @XmlRes xmlLayoutResId: Int, enterKeyType: Int) {
mDisplayWidth = context.resources.displayMetrics.widthPixels
mDefaultHorizontalGap = 0
mDefaultWidth = mDisplayWidth / 10
mDefaultHeight = mDefaultWidth
@ -294,16 +282,11 @@ class MyKeyboard {
/**
*
* Creates a blank keyboard from the given resource file and populates it with the specified
* characters in left-to-right, top-to-bottom fashion, 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.
* Creates a blank keyboard from the given resource file and populates it with the specified characters in left-to-right, top-to-bottom fashion,
* 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.
* @param context the application or service context
* @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
* for each character.
* @param characters the list of characters to display on the keyboard. One key will be created for each character.
*/
constructor(context: Context, layoutTemplateResId: Int, characters: CharSequence) :
this(context, layoutTemplateResId, 0) {
@ -388,8 +371,7 @@ class MyKeyboard {
* Returns the indices of the keys that are closest to the given point.
* @param x the x-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
* point is out of range, then an array of size zero is returned.
* @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.
*/
fun getNearestKeys(x: Int, y: Int): IntArray {
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
* view will re-layout itself to accommodate the keyboard.
* @see MyKeyboard
*
* @see .getKeyboard
* 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.
* @param keyboard the keyboard to display in this view
*/
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.
* @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
* @see KeyboardView.isShifted
*/
private fun setShifted(shiftState: Int) {
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.
* @return true if the shift is in a pressed state, false otherwise. If there is
* no shift key on the keyboard or there is no keyboard attached, it returns false.
* @see KeyboardView.setShifted
* @return true if the shift is in a pressed state, false otherwise
*/
private fun isShifted(): Boolean {
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)
* and square it to get the proximity threshold. We use a square here and in computing
* the touch distance from a key's center to avoid taking a square root.
* Compute the average distance between adjacent keys (horizontally and vertically) and square it to get the proximity threshold. We use a square here and
* in computing the touch distance from a key's center to avoid taking a square root.
* @param keyboard
*/
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
* because the keyboard renders the keys to an off-screen buffer and an invalidate() only
* draws the cached buffer.
* @see .invalidateKey
* Requests a redraw of the entire keyboard. Calling [.invalidate] is not sufficient because the keyboard renders the keys to an off-screen buffer and
* an invalidate() only draws the cached buffer.
*/
fun invalidateAllKeys() {
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
* one key is changing it's content. Any changes that affect the position or size of the key
* may not be honored.
* 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
* affect the position or size of the key may not be honored.
* @param keyIndex the index of the key in the attached [MyKeyboard].
* @see .invalidateAllKeys
*/
private fun invalidateKey(keyIndex: Int) {
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
* with this key through the attributes popupLayout and popupCharacters.
* Called when a key is long pressed. By default this will open any popup keyboard associated with this key through the attributes
* popupLayout and popupCharacters.
* @param popupKey the key that was long pressed
* @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 handle the call.
* @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
* handle the call.
*/
private fun onLongPress(popupKey: MyKeyboard.Key, me: MotionEvent): Boolean {
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!!.mOnKeyboardActionListener = object : OnKeyboardActionListener {
override fun onKey(primaryCode: Int) {
mOnKeyboardActionListener!!.onKey(primaryCode)
override fun onKey(code: Int) {
mOnKeyboardActionListener!!.onKey(code)
dismissPopupKeyboard()
}