Smart Fonts


Source link: https://github.com/smart-fun/SmartFonts

Smart Fonts for Android

Smart Fonts is an Android Studio Library which makes it easy to use Custom Fonts (TTF or OTF) in your apps. It handles the Android text widgets ( TextView, EditText, CheckBox, RadioButton...). You can add any other widgets easily, including your own classes!

You can use Styles, and see the result directly in the Layout Editor!

A manager handles the caching of the fonts so that they are loaded only once. If a font is not used it is not loaded.

It is easy to integrate with gradle.

Usage

Before starting to code, you must copy your font files (.TTF or .ODT) in the "assets" folder of your application. This folder may not exist so you'll probably have to create it (usually app/scr/main/assets).

This is a best practice to create a subfolder "fonts" inside the assets folder. Copy your files in that "assets/fonts" folder.

In your string.xml file (or in a custom xml file), define names for these fonts. It is not mandatory, but it is a good practice so that it will be then easier to use (shorter names, no typing mistakes), and it will be faster to change the font without having to change all your layouts.

<resources>
  <string translatable="false" name="fontTitle">fonts/Souses.otf</string>
  <string translatable="false" name="fontNotice">fonts/LinLibertine_R.ttf</string> </resources>

Now you can use the widgets from the library in your layouts.

The Class names are composed with "Font" + the usual Android class name: FontTextView, FontCheckBox, FontButton, ...

To use the new "font" attribute, you'll have to add this in top of your layout:

xmlns:app=" http://schemas.android.com/apk/res-auto"

<?xml version="1.0" encoding="utf-8"?> <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical">

 <fr.arnaudguyon.smartfontslib.FontTextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Hello World"

app:font="@string/fontNotice" />

  ...

Thanks to the autocompletion it is fast to add a view:

Use with styles

I recommend to always use styles in your projects (with or without this library). It is a little bit more work to do once, but so much time saved after!

To use the custom fonts in your style, simply add the "font" attribute.

<style name="MyTitleStyle" parent="@android:style/Widget.TextView">
  <item name="font">@string/fontTitle</item>
  <item name="android:textSize">16sp</item> </style>

Then use it everywhere, no more need to define the "font" attribute directly.

<fr.arnaudguyon.smartfontslib.FontTextView
  style="@style/MyTitleStyle"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="Hello Title Style"/>

Use with your own custom classes

You may have created you own components and you want to use the fonts and the caching system of the library. It is really easy to do if your class inherit from TextView (or its subclasses). Just add a call to the Manager like this:

public class MyCrazyRadioButton extends RadioButton {

public MyCrazyRadioButton(Context context, AttributeSet attrs) {

super(context, attrs);

FontManager.getInstance().applyFont(this, attrs);

// add this call
  
}

public MyCrazyRadioButton(Context context, AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

FontManager.getInstance().applyFont(this, attrs);

// add this call
  
}
 
}
 

If your class does not inherit from any Android TextView class, then you can retrieve the Typeface from the FontManager and apply it by yourself:

 Typeface typeface = FontManager.getInstance().getTypeface(context, R.string.fontNotice);

  if (typeface != null) {

mTextView.setTypeface(typeface);

  
}

Installation with gradle

Add the following maven{ } line to your PROJECT build.gradle file

allprojects {

  repositories {

jcenter()

maven {
 url "https://jitpack.io" 
}

 // add this line
  
}
 
}
 

Add the libary dependency to your APP build.gradle file

dependencies {

  compile 'com.github.smart-fun:SmartFonts:1.0.2'
 // add this line 
}
 

Library License

Copyright 2016 Arnaud Guyon

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Resources

ListView in Android supports header and footer views - views that do not belong to the underlying adapter but otherwise show up in the list and scroll along with the contents. However, they only work if you have not yet set your own adapter and are therefore not terribly flexible.

The SackOfViewsAdapter is another way of approaching this. Here, you provide the Views that make up the rows, and the adapter feeds them to Android as if they were newly created.

The SackOfViewsAdapter is designed to be sub-classed, mostly to determine how isEnabled() behaves, so you can control which of those views are selectable and which simply scroll with the list.

StrictMode is a handy feature in API Level 9 and higher, telling you where your Android application is doing things it probably should not on the main application thread.

In the spirit of StrictMode, the StrictModeEx project offers classes to help you diagnose similar sorts of problems beyond what StrictMode itself offers.

Right now, that consists of one class: StrictAdapter. This ListAdapter wrapper will log slow-running getView() calls, plus optionally give you an overall performance view on how your Adapter is doing in the code you control.

geo

Java utility methods for geohashing.

A very, very compact library that enables you to create on-demand singletons within your application and easily store them to disk. Utilizing a dead-simple API, this library makes creating singletons and persisting data much more fun!

This app is built during the free time of the developer for fun. It provides with a tool to test some Intent behavior while building and testing other apps or just for fun playing with the framework. ;) This app would not work and feel the same way if it weren't for some great Android open-source projects that were used during the development.

Material Design Example is a sample application for the new design concept made by Google, Material Design. Besides the design, we have the new APIs introduced in Android SDK Lollipop:

  • Custom theme colors
  • Circular reveal
  • Activity transitions
  • Toolbar
  • Recycler View
  • Card View

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