show a number above the letters in the first row

This commit is contained in:
tibbi 2022-01-15 14:24:56 +01:00
parent e999e4900b
commit 3c4d2f0ee3
5 changed files with 49 additions and 12 deletions

View File

@ -212,6 +212,9 @@ 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 */
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 */
var icon: Drawable? = null var icon: Drawable? = null
@ -307,6 +310,7 @@ class MyKeyboard {
label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: "" label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: ""
text = a.getText(R.styleable.MyKeyboard_Key_keyOutputText) text = a.getText(R.styleable.MyKeyboard_Key_keyOutputText)
topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: ""
if (label.isNotEmpty()) { if (label.isNotEmpty()) {
codes = arrayListOf(label[0].toInt()) codes = arrayListOf(label[0].toInt())

View File

@ -17,6 +17,7 @@ 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.adjustAlpha
import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.R
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
@ -190,6 +191,9 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
private val mSwipeThreshold: Int private val mSwipeThreshold: Int
private val mDisambiguateSwipe: Boolean private val mDisambiguateSwipe: Boolean
private var mPopupMaxMoveDistance = 0f private var mPopupMaxMoveDistance = 0f
private var topSmallNumberSize = 0f
private var topSmallNumberMarginWidth = 0f
private var topSmallNumberMarginHeight = 0f
// Variables for dealing with multiple pointers // Variables for dealing with multiple pointers
private var mOldPointerCount = 1 private var mOldPointerCount = 1
@ -299,12 +303,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
mPaint.alpha = 255 mPaint.alpha = 255
mPadding = Rect(0, 0, 0, 0) mPadding = Rect(0, 0, 0, 0)
mMiniKeyboardCache = HashMap() mMiniKeyboardCache = HashMap()
mKeyBackground!!.getPadding(mPadding)
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 mAudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
mPopupMaxMoveDistance = context.resources.getDimension(R.dimen.popup_max_move_distance) mPopupMaxMoveDistance = resources.getDimension(R.dimen.popup_max_move_distance)
topSmallNumberSize = resources.getDimension(R.dimen.small_text_size)
topSmallNumberMarginWidth = resources.getDimension(R.dimen.top_small_number_margin_width)
topSmallNumberMarginHeight = resources.getDimension(R.dimen.top_small_number_margin_height)
resetMultiTap() resetMultiTap()
} }
@ -543,6 +549,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
val keys = mKeys val keys = mKeys
val invalidKey = mInvalidatedKey val invalidKey = mInvalidatedKey
paint.color = mKeyTextColor paint.color = mKeyTextColor
val smallLetterPaint = Paint()
smallLetterPaint.set(paint)
smallLetterPaint.apply {
color = paint.color.adjustAlpha(0.8f)
textSize = topSmallNumberSize
typeface = Typeface.DEFAULT
}
var drawSingleKey = false var drawSingleKey = false
if (invalidKey != null && canvas.getClipBounds(clipRegion)) { if (invalidKey != null && canvas.getClipBounds(clipRegion)) {
// Is clipRegion completely contained within the invalidated key? // Is clipRegion completely contained within the invalidated key?
@ -595,6 +609,11 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
label, ((key.width - padding.left - padding.right) / 2 + padding.left).toFloat(), label, ((key.width - padding.left - padding.right) / 2 + padding.left).toFloat(),
(key.height - padding.top - padding.bottom) / 2 + (paint.textSize - paint.descent()) / 2 + padding.top, paint (key.height - padding.top - padding.bottom) / 2 + (paint.textSize - paint.descent()) / 2 + padding.top, paint
) )
if (key.topSmallNumber.isNotEmpty()) {
canvas.drawText(key.topSmallNumber, key.width - topSmallNumberMarginWidth, topSmallNumberMarginHeight, smallLetterPaint)
}
// Turn off drop shadow // Turn off drop shadow
paint.setShadowLayer(0f, 0f, 0f, 0) paint.setShadowLayer(0f, 0f, 0f, 0)
} else if (key.icon != null && mKeyboard != null) { } else if (key.icon != null && mKeyboard != null) {

View File

@ -87,5 +87,7 @@
<attr name="keyIcon" format="reference" /> <attr name="keyIcon" format="reference" />
<!-- Mode of the keyboard. If the mode doesn't match the requested keyboard mode, the key will be skipped. --> <!-- Mode of the keyboard. If the mode doesn't match the requested keyboard mode, the key will be skipped. -->
<attr name="keyboardMode" /> <attr name="keyboardMode" />
<!-- Top small number shown above letters of the first row. -->
<attr name="topSmallNumber" format="string" />
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@ -1,3 +1,5 @@
<resources> <resources>
<dimen name="popup_max_move_distance">60dp</dimen> <dimen name="popup_max_move_distance">60dp</dimen>
<dimen name="top_small_number_margin_width">12dp</dimen>
<dimen name="top_small_number_margin_height">18dp</dimen>
</resources> </resources>

View File

@ -11,53 +11,63 @@
app:keyEdgeFlags="left" app:keyEdgeFlags="left"
app:keyLabel="q" app:keyLabel="q"
app:popupCharacters="1" app:popupCharacters="1"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="1" />
<Key <Key
app:codes="119" app:codes="119"
app:keyLabel="w" app:keyLabel="w"
app:popupCharacters="2" app:popupCharacters="2"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="2" />
<Key <Key
app:codes="101" app:codes="101"
app:keyLabel="e" app:keyLabel="e"
app:popupCharacters="3" app:popupCharacters="3"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="3" />
<Key <Key
app:codes="114" app:codes="114"
app:keyLabel="r" app:keyLabel="r"
app:popupCharacters="4" app:popupCharacters="4"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="4" />
<Key <Key
app:codes="116" app:codes="116"
app:keyLabel="t" app:keyLabel="t"
app:popupCharacters="5" app:popupCharacters="5"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="5" />
<Key <Key
app:codes="121" app:codes="121"
app:keyLabel="y" app:keyLabel="y"
app:popupCharacters="6" app:popupCharacters="6"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="6" />
<Key <Key
app:codes="117" app:codes="117"
app:keyLabel="u" app:keyLabel="u"
app:popupCharacters="7" app:popupCharacters="7"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="7" />
<Key <Key
app:codes="105" app:codes="105"
app:keyLabel="i" app:keyLabel="i"
app:popupCharacters="8" app:popupCharacters="8"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="8" />
<Key <Key
app:codes="111" app:codes="111"
app:keyLabel="o" app:keyLabel="o"
app:popupCharacters="9" app:popupCharacters="9"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="9" />
<Key <Key
app:codes="112" app:codes="112"
app:keyEdgeFlags="right" app:keyEdgeFlags="right"
app:keyLabel="p" app:keyLabel="p"
app:popupCharacters="0" app:popupCharacters="0"
app:popupKeyboard="@xml/keyboard_popup_template" /> app:popupKeyboard="@xml/keyboard_popup_template"
app:topSmallNumber="0" />
</Row> </Row>
<Row> <Row>
<Key <Key