Create a gist now

Instantly share code, notes, and snippets.

@shareme /GWSApp.java
Last active Dec 25, 2015

GWSApp class, shows how to use HoloEverywhere FontLoader and other stuff
package gws.grottworkshop.fourandroid;
import gws.grottworkshop.fourandroid.FontLoader.Font;
import gws.grottworkshop.fourandroid.FontLoader.FontCollector;
import gws.grottworkshop.fourandroid.FontLoader.RawFont;
import gws.grottworkshop.fourandroid.util.ImageCacheManager;
import gws.grottworkshop.fourandroid.util.ImageCacheManager.CacheType;
import gws.grottworkshop.fourandroid.util.RequestManager;
import android.app.Application;
import android.graphics.Bitmap.CompressFormat;
/**
* GWSAPP class, is an example of how you should
* extend the application class to get all the features of
* the FourAndroid UI library.
*
* @author fredgrott
*
*/
public class GWSApp extends Application {
private static int DISK_IMAGECACHE_SIZE = 1024*1024*10;
private static CompressFormat DISK_IMAGECACHE_COMPRESS_FORMAT = CompressFormat.PNG;
private static int DISK_IMAGECACHE_QUALITY = 100; //PNG is lossless so quality is ignored but must be provided
private static final Font sDroidSansBold,sDroidSansRegular, sDroidSansMonoRegular,
sDroidSerifBold,sDroidSerifBoldItalic,sDroidSerifItalic,sDroidSerifRegular,
sRobotoSlabBold, sRobotoSlabLight, sRobotoSlabRegular, sRobotoSlabThin;
private static final FontCollector sDroidSans, sDroidSansMono, sDroidSerif, sRobotoSlab, sDefaultFont;
static {
sDroidSansBold = new RawFont(R.raw.droidsans_bold).setFontStyle(FontLoader.TEXT_STYLE_BOLD);
sDroidSansRegular = new RawFont(R.raw.droidsans_regular).setFontStyle(FontLoader.TEXT_STYLE_NORMAL);
sDroidSansMonoRegular = new RawFont(R.raw.droidsansmono_regular).setFontStyle(FontLoader.TEXT_STYLE_NORMAL);
sDroidSerifBold = new RawFont(R.raw.droidserif_bold).setFontStyle(FontLoader.TEXT_STYLE_BOLD);
sDroidSerifBoldItalic= new RawFont(R.raw.droidserif_bolditalic).setFontStyle(FontLoader.TEXT_STYLE_BOLD | FontLoader.TEXT_STYLE_ITALIC);
sDroidSerifItalic = new RawFont(R.raw.droidserif_italic).setFontStyle(FontLoader.TEXT_STYLE_ITALIC);
sDroidSerifRegular = new RawFont(R.raw.droidserif_regular).setFontStyle(FontLoader.TEXT_STYLE_NORMAL);
sRobotoSlabBold = new RawFont(R.raw.robotoslab_bold).setFontStyle(FontLoader.TEXT_STYLE_BOLD);
sRobotoSlabLight = new RawFont(R.raw.robotoslab_light).setFontStyle(FontLoader.TEXT_STYLE_LIGHT);
sRobotoSlabRegular = new RawFont(R.raw.robotoslab_regular).setFontStyle(FontLoader.TEXT_STYLE_NORMAL);
sRobotoSlabThin = new RawFont(R.raw.robotoslab_thin).setFontStyle(FontLoader.TEXT_STYLE_THIN);
sDroidSans = new FontCollector().allowAnyFontFamily();
sDroidSans.setFontFamily("droidsans");
sDroidSans.register(sDroidSansRegular).asDefaultFont();
sDroidSans.register(sDroidSansBold);
sDroidSansMono = new FontCollector().allowAnyFontFamily();
sDroidSansMono.setFontFamily("droidsansmono");
sDroidSansMono.register(sDroidSansMonoRegular).asDefaultFont();
sDroidSerif = new FontCollector().allowAnyFontFamily();
sDroidSerif.setFontFamily("droidserif");
sDroidSerif.register(sDroidSerifRegular).asDefaultFont();
sDroidSerif.register(sDroidSerifBold);
sDroidSerif.register(sDroidSerifBoldItalic);
sDroidSerif.register(sDroidSerifItalic);
sRobotoSlab = new FontCollector().allowAnyFontFamily();
sRobotoSlab.setFontFamily("robotoslab");
sRobotoSlab.register(sRobotoSlabRegular).asDefaultFont();
sRobotoSlab.register(sRobotoSlabBold);
sRobotoSlab.register(sRobotoSlabLight);
sRobotoSlab.register(sRobotoSlabThin);
sDefaultFont = new FontCollector();
sDefaultFont.register(sDroidSans).asDefaultFont();
sDefaultFont.register(sDroidSansMono);
sDefaultFont.register(sDroidSerif);
sDefaultFont.register(sRobotoSlab);
sDefaultFont.register (FontLoader.ROBOTO);
FontLoader.setDefaultFont (sDefaultFont);
}
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
// initialize caches
init();
//load shared prefs
}
/**
* Initialize the request manager and the image cache
*/
private void init() {
RequestManager.init(this);
createImageCache();
}
/**
* Create the image cache. Uses Memory Cache by default. Change to Disk for a Disk based LRU implementation.
*/
private void createImageCache(){
ImageCacheManager.getInstance().init(this,
this.getPackageCodePath()
, DISK_IMAGECACHE_SIZE
, DISK_IMAGECACHE_COMPRESS_FORMAT
, DISK_IMAGECACHE_QUALITY
, CacheType.MEMORY);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment