font-utils


Source link: https://github.com/mattsilber/font-utils

font-utils

The goal of this library is to allow your app to support multiple FontFamilies (e.g. lato, roboto, etc.) with their own styles (e.g. normal, bold, italic) in an easily-configurable way.

Installation

repositories {

  jcenter() 
}
  dependencies {

  compile('com.guardanis:font-utils:1.0.2') 
}

Usage

First, make sure your fonts are located in your assets folder (in a /fonts/ subdirectory to be organized). Let's assume you have a roboto normal/bold font called robo.ttf and robo_bold.ttf, respectively. Now you need to override the R.array.fu__font_family_resources string-array resource to include your fonts:

<string-array name="fu__font_family_resources">
  <item>roboto--normal=fonts/robo.ttf,bold=fonts/robo_bold.ttf</item> </string-array>

The format here is:

<item>FONT_FAMILY_NAME--STYLE_1=FONT1_PATH,STYLE_2=FONT2_PATH</item>

With the supported styles being

  • NORMAL
  • BOLD
  • ITALICS
  • BOLD_ITALICS

Values in the resources are not case-sensitive, and their comparing integers are static in the Typeface class (e.g. Typeface.BOLD or Typeface.ITALICS).

Now, we need to ensure we have a default FontFamily correctly set by overring R.string.fu__default_font_family:

<string name="fu__default_font_family">roboto</string>

Next, we have 3 choices for how to use this font. We can either

Use the already-overridden classes for you
<com.guardanis.fontutils.TextView

xmlns:app="http://schemas.android.com/apk/res-auto"
  app:textFontFamily="roboto"
  android:textStyle="bold" /> 

These convenience helper classes include

  • com.guardanis.fontutils.TextView
  • com.guardanis.fontutils.Button
  • com.guardanis.fontutils.EditText

Check them out if you want to implement them for other types of TextViews.

Use the FontUtils attribute in your own custom classes so they support your fonts by default

Call the following from your custom TextView (or TextView subclass)'s constructor.

FontUtils.getInstance(getContext())

  .load(this, attrs, defStyle);
 
Manually call one of the FontUntils' helper methods to set the font programmatically
TextView view = (TextView) findViewById(R.id.some_id);
 FontUtils.getInstance(getContext())

  .setTypeface(view, fontFamily, style);

ToDos and Notes

  • A NORMAL font is required for a typeface to be loaded. If the FontFamily is loaded without a normal font, it will throw a RuntimeException letting you know what went wrong.
  • Trying to load any non-normal font style that doesn't exist will default to the normal style.

Resources

AndroidResizer is a simple Java desktop app for automatically re-sizing android assets.

AR will downscale your assets and copy them into an android-style folder structure.

Android & Pure Java library to shape a voice with an instrument.

NaturalLenguageProcessor is an Android library that wraps text-processing.com API and gives you the possibility to stem, to tag and to analyze sentimentally the text you want.

Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed).

NodeFlow is an Android library that provides a simple way to visualize hierarchical content. Perfect for displaying items that are organized in categories / subcategories.

Android library for boilerplate destruction - "Just code what is worth coding"

  • Generates boilerplate code based on used annotations and lets you focus on what matters.
  • Generated code is fully traceable.
  • Everything is generated during compile time.
  • No reflection used!
  • Consists of modules.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes