HoloEverywhere 1.6.8
- Tutorial

All uniformity, or good day!
Leafing through here Habr came across an article Connection fonts in your project author mcavalon , thought podcherpnut something interesting thread ... But seeing another TextView.setTypeface how-to, yawned, and went to read another article (@ rus1f1kat0r, hi by the way :)).
So, a few minutes ago (at the time of writing these lines it was still minutes, not hours, the girls pulled me out of control) I released HoloEverywhere 1.6.8, the main feature of this release is the advanced FontLoader, and a few more goodies, as always .
Let's first look at the old FontLoader and see what he knew (or rather did not).
// Regular font
myFontRegular = HoloFont.makeFont(R.raw.font_regular);
// Bold font
myFontBold = HoloFont.makeFont(R.raw.font_bold);
// Italic font
myFontItalic = HoloFont.makeFont(R.raw.font_italic);
// BoldItalic font
myFontBoldItalic = HoloFont.makeFont(R.raw.font_bold_italic);
// Super-puper merger
myFont = HoloFont.makeFont(myFontRegular, myFontBold, myFontItalic, myFontBoldItalic);
FontLoader.setDefaultFont(myFont);
… All. Absolutely no flexibility, no additional fonts, but nichrome, to be honest.
(No, there was still an option with FontLoader.apply (View, HoloFont), but it worked mediocre).
And now what features the new FontLoader provides:
- Normal separation of fonts by a family (font family)
- Normal font separation by style (bold / italic)
- The ability to add your own styles (default is normal, bold, italic, black, condensed, light, medium, thin) (no more than 31st styles, including those already built-in, i.e. for you there are 24 free styles (normal does not count as style )))
- The ability to combine styles in any combination (sorry for the tautology). No one bothers to make thin and bold style at the same time.
- Support for this with just one line in xml (including for your fonts, not the built-in roboto): android: fontFamily = "roboto-light"
- Fonts are downloaded on demand and only once.
- Very lazy fonts appeared. Or Schrodinger fonts, call it what you want. They seem to be there, but if they are not there, the application crash.
This is what I mean: before, creating a font required a direct font id from res / raw (R.raw.my_font). Now you can simply specify the string resource of this id ("my_font"). By the way, now all roboto fonts, except regular, bold, italic and bolditalic, are now lazy. Yes, they are in the core of the library, but they will only work if you put the corresponding file in res / raw. So you want to use Roboto Light, here you write android: fontFamily = "roboto-light", here we type from demo / res / raw / roboto_light.ttf and put it into your project - and everything works. - Support out of the box for (almost) all TextView-based widgets. That is: TextView itself, Button, CheckedTextView, EditText, AutoCompleteTextView, CheckBox, CompoundButton, MultiAutoCompleteTextView, RadioButton, Switch, ToggleButton. Exceptions to this list were very rare widgets: Chronometer, DigitalClock, TextClock, and ExtractEditText
- Support for textAppereance in all its manifestations.
- It works everywhere. Except Widget's App. ActionBar, any third-party libraries are generally shorter.
Add your font for a single element.
I will take the font Toscuchet CM by Alisson Depizol. Well, I’ll convert it to TrueType, because I don’t. Put it in res / raw / toscuchet.ttf.
We create MainApplication, which extends org.holoeverywhere.app.Application, create a static block of code (we add static {}, that is) (and in general, all library settings are best done in one place and here), meditate.
Sodzee RawFont object with a link to our ttf file:
public class MainApplication extends Application {
private static final Font sToscuchet;
static {
sToscuchet = new RawFont(R.raw.toscuchet);
}
}
Hmm, somehow a little code. But the KISS principle is not applicable in Java, so we slam a couple more unnecessary lines to anyone.
We need to create another object of the FontCollector type, which collects many scattered fonts into one large and obedient object.
Since we want to set our font for only one specific TextView, we need to add the Toscuchet font to our FontCollector and add the standard Roboto family. Well, at the same time we will provide meta-information about our new style. Voila:
public class MainApplication extends Application {
private static final Font sToscuchet;
private static final FontCollector sDefaultFont;
static {
sToscuchet = new RawFont(R.raw.toscuchet);
sToscuchet.setFontFamily("toscuchet");
sToscuchet.setFontStyle(FontLoader.TEXT_STYLE_NORMAL);
sDefaultFont = new FontCollector();
sDefaultFont.register(sToscuchet);
sDefaultFont.register(FontLoader.ROBOTO);
FontLoader.setDefaultFont(sDefaultFont);
}
}
Well, it’s already cultural, but where did you see such short blocks of code? ..
We go to our super markup, hang android on it: fontFamily = “toscuchet-normal”, start it, and we rejoice like children:

Default font
The easiest way: call FontLoader.setDefaultFont (sToscuchet). But at the same time, the fonts will be the same everywhere in general, even where you need a bold or italic style. Not okay.
And here comes a small problem: FontCollector searches for the desired font based on a pair of fontFamily and fontStyle parameters. We already set the font family (sToscuchet.setFontFamily ("toscuchet");). You can of course redefine textViewStyle and specify the desired fontFamily there, but well, see. We just say FontCollector'y: her, or maybe you stop using fontFamily?
sDefaultFont = new FontCollector().allowAnyFontFamily();
Well ... You can remove android: fontFamily from our markup, build and run the project:

Now fontFamily is ignored for our font. Any TextView without additional modifiers (i.e. fontStyle = normal) will be pretty.
Styles
If you have several font styles (regular, bold, italic), then you can assemble it into one font. Like that:
public class MainApplication extends Application {
private static final Font sToscuchetRegular, sToscuchetBold, sToscuchetItalic;
private static final FontCollector sToscuchet, sDefaultFont;
static {
sToscuchetRegular = new RawFont(R.raw.toscuchet_regular).setFontStyle(FontLoader.TEXT_STYLE_NORMAL);
sToscuchetBold = new RawFont(R.raw.toscuchet_bold).setFontStyle(FontLoader.TEXT_STYLE_BOLD);
sToscuchetItalic = new RawFont(R.raw.toscuchet_italic).setFontStyle(FontLoader.TEXT_STYLE_ITALIC);
sToscuchet = new FontCollector().allowAnyFontFamily();
sToscuchet.setFontFamily("toscuchet");
sToscuchet.register(sToscuchetRegular).asDefaultFont();
sToscuchet.register(sToscuchetBold);
sToscuchet.register(sToscuchetItalic);
sDefaultFont = new FontCollector();
sDefaultFont.register(sToscuchet).asDefaultFont();
sDefaultFont.register(FontLoader.ROBOTO);
FontLoader.setDefaultFont(sDefaultFont);
}
}
Then an additional call to asDefaultFont () appeared, which means that the previous font must be made the default font. If nothing suitable is found, this font will be used.
Because There are no bold and italic faces for this font, we can do without an example :)
Well, something like this FontLoader came out for me. If you have questions, please contact. In a comment, in PM or by mail.
Oh, I almost forgot. You have whined so much about navigation in Slider from the demo that all navigation from the demo application has been moved to Slider addon as SliderMenu. And the code of the main activity of the demo application (slightly simplified) now looks like this:
@Addons(Activity.ADDON_SLIDER)
public class DemoActivity extends Activity {
public AddonSliderA addonSlider() {
return addon(AddonSlider.class);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final SliderMenu sliderMenu = addonSlider().obtainDefaultSliderMenu();
sliderMenu.add(R.string.demo, MainFragment.class, SliderMenu.BLUE);
sliderMenu.add(R.string.settings, SettingsFragment.class, SliderMenu.GREEN);
sliderMenu.add(R.string.other, OtherFragment.class, SliderMenu.ORANGE);
sliderMenu.add(R.string.about, AboutFragment.class, SliderMenu.PURPLE);
}
}
Cool, yeah? Doing almost nothing, we get an excellent implementation of Navigation Drawer, with tablet support and normal handling of Home / Back buttons. SliderMenu is also customizable, go for it :)

List of changes since version 1.5.0:
- Actually, Slider addon instead of SlidingMenu
- Reduced library size by optimizing png files
- Updated the background for the white theme, which has changed in API 16 (or 17, I do not remember)
- Colors fixed in options / overflow menu. To be honest, to be honest. Something wrong there, then it fell off after that ...
- Facebook SDK Addon
- TabSwipeFragment / TawSwipeActivity. Fragments and activities that implement Tabs + Swipe (or without swipe, if desired) navigation without unnecessary hassle. Saving states and all that jazz in place
- Fixed memory leaks in add-ons system and _SharedPreferencesImpl_XML
- The source files for generating themes were refracted, and then there was a small mess
- .DialogWhenLarge Themes
- IntentCompat.createChooser for holo-like dialogue with the choice of application to continue
- Fixed behavior when after registerForContextMenu it was necessary to call setLongClickable, otherwise
- More complete dialogue support
- Full support for choicemode / headerview / footerview for ListView / GridView.
- A bunch, just a bunch of bug fixes
Project Repository , APK Demo Applications