From 92b25d50603b46f80d04e135ca1a898db6c8f75c Mon Sep 17 00:00:00 2001 From: Naveen Singh <36371707+naveensingh@users.noreply.github.com> Date: Mon, 26 Jan 2026 00:07:58 +0530 Subject: [PATCH] feat: add font customization (#380) --- CHANGELOG.md | 3 +++ .../org/fossify/keyboard/views/MyKeyboardView.kt | 15 +++++++++------ app/src/main/res/layout/activity_main.xml | 2 +- .../main/res/layout/keyboard_view_keyboard.xml | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e65f1adc..ed95d70d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added +- Added support for custom fonts + ### Fixed - Fixed an issue where sound/vibration preferences were ignored after reboot ([#372]) diff --git a/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt index cf79d6f6..3126313f 100644 --- a/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/org/fossify/keyboard/views/MyKeyboardView.kt @@ -62,6 +62,7 @@ import org.fossify.commons.extensions.isDynamicTheme import org.fossify.commons.extensions.lightenColor import org.fossify.commons.extensions.removeUnderlines import org.fossify.commons.extensions.toast +import org.fossify.commons.helpers.FontHelper import org.fossify.commons.helpers.HIGHER_ALPHA import org.fossify.commons.helpers.ensureBackgroundThread import org.fossify.commons.helpers.isPiePlus @@ -670,11 +671,12 @@ class MyKeyboardView @JvmOverloads constructor( val paint = mPaint val keys = mKeys paint.color = mTextColor + val customTypeface = FontHelper.getTypeface(context) val smallLetterPaint = Paint().apply { set(paint) color = paint.color.adjustAlpha(0.8f) textSize = mTopSmallNumberSize - typeface = Typeface.DEFAULT + typeface = customTypeface } canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR) @@ -699,13 +701,13 @@ class MyKeyboardView @JvmOverloads constructor( if (code == KEYCODE_SPACE && key.label.length > 1) { // Use smaller font size for current language label on space bar paint.textSize = mSpaceBarTextSize.toFloat() - paint.typeface = Typeface.DEFAULT + paint.typeface = customTypeface } else if (label.length > 1) { paint.textSize = mLabelTextSize.toFloat() - paint.typeface = Typeface.DEFAULT_BOLD + paint.typeface = Typeface.create(customTypeface, Typeface.BOLD) } else { paint.textSize = mKeyTextSize.toFloat() - paint.typeface = Typeface.DEFAULT + paint.typeface = customTypeface } paint.color = textColor @@ -1042,15 +1044,16 @@ class MyKeyboardView @JvmOverloads constructor( if (key.icon != null) { mPreviewText!!.setCompoundDrawables(null, null, null, key.icon) } else { + val customTypeface = FontHelper.getTypeface(context) if (key.label.length > 1) { mPreviewText!!.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize.toFloat()) - mPreviewText!!.typeface = Typeface.DEFAULT_BOLD + mPreviewText!!.typeface = Typeface.create(customTypeface, Typeface.BOLD) } else { mPreviewText!!.setTextSize( TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge.toFloat() ) - mPreviewText!!.typeface = Typeface.DEFAULT + mPreviewText!!.typeface = customTypeface } mPreviewText!!.setCompoundDrawables(null, null, null, null) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 6d2de619..a35d5cc6 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -39,7 +39,7 @@ android:layout_height="wrap_content" android:layout_margin="@dimen/normal_margin"> - - - -