✏️ Font Variation 2.0.0 – Change font weight programmatically

:pencil2: Font Variation

Starting with Android O, variable fonts were supported for Android. To this day, they continue to be. With no way to change font weight besides download separate files, it gets overwhelming. So overwhelming that your application can’t hold your font files anymore, you have too many!

As of June 2023, using Font Variation v2.0.0 is preferred. The likeliness of an out–of–memory error occurring is slim.

What’s needed

* Scroll down a bit to see an exmple!

  • A fallback font that is static, not variable. Read more about why!
  • A variable font, you can get one from fonts.google.com
    • Find your favorite font and use the Download family button in the top-right corner.
    • Unzip the downloaded file.
    • Find <𝚢𝚘𝚞𝚛-𝚏𝚘𝚗𝚝>-𝚅𝚊𝚛𝚒𝚊𝚋𝚕𝚎𝙵𝚘𝚗𝚝, it should appear in the root directory. Rename it if you’d like.
    • Upload it to your Kodular project!
    • Set the chosen font as the font parameter.
  • A component from those listed
    • Button
    • CheckBox
    • Label
    • Switch
  • The font weight you’d like your font to be displayed in
    • :1234: This value is normally between 100 and 900.

What font types are supported

  • An OTF file wasn’t tested
    • Most fonts from fonts.google.com only offer TTF variants.
    • OTF files are expected to work.
  • A TTF file was tested and worked fine
  • Others were not considered or don’t work with Android

Will this work with older Android versions

No, however, no minimum Android version is needed to use Font Variation. This was taken into consideration considering only about 61% of the Android population is running Android O. There is a check in place to make sure it only works on API 26 and onwards, the fallback font will be used otherwise or not at all if one isn’t specified.

image

com.github.flailingoctopus.fontvariation.aix

25 Likes

Amazing work! :+1:

4 Likes

This is going to be amazing for font lover like me. Good work! :+1:

2 Likes

Nice Work @Squishy… , Oh Sorry @hammerhai :sweat_smile: :+1:

1 Like

Awesome Work, Can’t Believe On My Eyes :eyes:

1 Like

@hammerhai Nice job but there is some query that can it work with Dynamic label’s also

1 Like

Another one… :+1:
A very amazing and unique extension :wink:
Great job @hammerhai aka squishy one :crazy_face:

2 Likes

It should work with labels created dynamically. In fact, extensions don’t have to add support for dynamic components.

2 Likes

great extension, that will help us a lot.

2 Likes

It will work with dynamic labels that is created by Dynamic Components extension as label(generated by extension) is a instance of a simple label. So it is same as a simple label component. However it would not work with in built dynamic label as the extension accepts Label datatype as a parameter(can’t say about this one), however in built dynamic label doesn’t return Label instance. Therefore if you use in built dynamic label then you’ll probably face an argument error by the extension.

1 Like

Thanks for confirmation

Thanks @iamwsumit I got the full confirmation now

:pencil2: Font Variation 0.2.0

Before I begin, I want to thank you all for the amazing support given for this extension! It felt great doing something new and knowing that I’m helping people do what they like most.

ADDED

  1. A new property named “Font” was added. Testing showed that this completely resolved OOMEs and greatly improved performance, however, it may vary by device.
  2. A new function named “SetFontSettings.” Read more below.

CHANGED

  1. Memory management has been revised to include checking if the applications allocated memory heap is low. As with the OOMEs, when allocated memory is running low, nothing will happen.

DEPRECATED

  1. “SetFontVariationSettings” has been deprecated and will no longer work as a result of the newly added property and revised memory management. Use “SetFontSettings” instead.

:file_cabinet: Files

I apologize to everyone who this may have been an inconvenience to.

  1. com.github.flailingoctopus.fontvariation.aix
2 Likes

Nice let’s try something new now :grin::grin::grin::grin: thanks @hammerhai

:pencil2: Font Variation 1.0.0

This release includes major and minor changes.

Added

  1. Added a new parameter to SetFontVariationSettings named fallback. Here’s how this parameter will handle use cases:

    Font Variation will first check if the font file exists in the applications external directory, then fallback to assets. It’s important to note that font files will only be retrieved from the “files” directory, no parent directory or sub-directory of "files."

    :zap: This parameter will not be consumed if it’s empty.



    There are two cases by which this parameter will be consumed:
  • The device isn’t at least API 26.
  • The Font property is not set.
  1. Added back SetFontVariationSettings after a long vacation! Read more about why below.

  2. Added the ability to use SetFontVariationSettings with more components!



    The allowed, and tested, component types are as follows:

    • Button
    • CheckBox
    • Label
    • Switch

Changed

  1. Due to the acceptance of more component types, the labelComponent parameter is now named component.

Deprecated

  1. Deprecated SetFontSettings, please use SetFontVariationSettings instead. It will continue to work properly, however without a fallback font.

Removed

  1. Removed the old SetFontVariationSettings from Font Variation 0.2.0. Use the new SetFontVariationSettings instead.


Files

:information_source: Font Variation doesn’t work in the companion.

com.github.flailingoctopus.fontvariation.aix

1 Like

:pencil2: Font Variation 2.0.0

This release includes major and minor changes.

Added

  1. Added caching for fonts.
  • This decision was based on Font Variation 0.2.0 which featured the removal of the font parameter from SetFontSettings due to performance issues when using the slider component to change the font variation settings frequently.
  • This has improved performance compared to Font Variation 0.1.0, which didn’t include font caching, however it was only tested with one variable font and performance may vary by device.
  1. Added FontVariationSettings as a new method for setting the font variation settings for supported components.

  • This change includes the addition of the font parameter, but comes with the removal of the width parameter due to its uselessness.

Deprecated

  1. Deprecated SetFontVariationSettings, use FontVariationSettings instead.
    • The Font property will continue to be supported until this is removed. Additionally, SetFontVariationSettings will continue working properly, however the width parameter will be ignored.

Removed

  1. Removed SetFontSettings, use FontVariationSettings instead.


Files

com.github.flailingoctopus.fontvariation.aix

7 Likes