diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt index b72cc69..106101c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/helpers/MyKeyboard.kt @@ -212,6 +212,9 @@ class MyKeyboard { /** Label to display */ 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 */ var icon: Drawable? = null @@ -307,6 +310,7 @@ class MyKeyboard { label = a.getText(R.styleable.MyKeyboard_Key_keyLabel) ?: "" text = a.getText(R.styleable.MyKeyboard_Key_keyOutputText) + topSmallNumber = a.getString(R.styleable.MyKeyboard_Key_topSmallNumber) ?: "" if (label.isNotEmpty()) { codes = arrayListOf(label[0].toInt()) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 84fd57c..0e74c74 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -17,6 +17,7 @@ import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityManager import android.widget.PopupWindow import android.widget.TextView +import com.simplemobiletools.commons.extensions.adjustAlpha import com.simplemobiletools.keyboard.R import com.simplemobiletools.keyboard.helpers.MyKeyboard 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 mDisambiguateSwipe: Boolean private var mPopupMaxMoveDistance = 0f + private var topSmallNumberSize = 0f + private var topSmallNumberMarginWidth = 0f + private var topSmallNumberMarginHeight = 0f // Variables for dealing with multiple pointers private var mOldPointerCount = 1 @@ -299,12 +303,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut mPaint.alpha = 255 mPadding = Rect(0, 0, 0, 0) mMiniKeyboardCache = HashMap() - mKeyBackground!!.getPadding(mPadding) mSwipeThreshold = (500 * resources.displayMetrics.density).toInt() mDisambiguateSwipe = false//resources.getBoolean(R.bool.config_swipeDisambiguation) mAccessibilityManager = (context.getSystemService(Context.ACCESSIBILITY_SERVICE) as AccessibilityManager) 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() } @@ -543,6 +549,14 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut val keys = mKeys val invalidKey = mInvalidatedKey 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 if (invalidKey != null && canvas.getClipBounds(clipRegion)) { // 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(), (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 paint.setShadowLayer(0f, 0f, 0f, 0) } else if (key.icon != null && mKeyboard != null) { diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 46a9b71..319fd36 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -87,5 +87,7 @@ + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index cfeb359..c04500f 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -1,3 +1,5 @@ 60dp + 12dp + 18dp diff --git a/app/src/main/res/xml/keys_layout.xml b/app/src/main/res/xml/keys_layout.xml index 0ec4abe..207bc79 100644 --- a/app/src/main/res/xml/keys_layout.xml +++ b/app/src/main/res/xml/keys_layout.xml @@ -11,53 +11,63 @@ app:keyEdgeFlags="left" app:keyLabel="q" app:popupCharacters="1" - app:popupKeyboard="@xml/keyboard_popup_template" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="1" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="2" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="3" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="4" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="5" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="6" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="7" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="8" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="9" /> + app:popupKeyboard="@xml/keyboard_popup_template" + app:topSmallNumber="0" />