use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.
the class Iconics method init.
/**
* initializes the FONTS. This also tries to find all founds automatically via their font file
*
* @param ctx
*/
public static void init(Context ctx) {
if (!INIT_DONE) {
String[] fonts = GenericsUtil.getFields(ctx);
for (String fontsClassPath : fonts) {
try {
ITypeface typeface = (ITypeface) Class.forName(fontsClassPath).newInstance();
validateFont(typeface);
FONTS.put(typeface.getMappingPrefix(), typeface);
} catch (Exception e) {
Log.e("Android-Iconics", "Can't init: " + fontsClassPath);
}
}
INIT_DONE = true;
}
}
use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.
the class IconicsDrawable method icon.
/**
* Loads and draws given text
*
* @param icon
* @return The current IconExtDrawable for chaining.
*/
public IconicsDrawable icon(String icon) {
try {
ITypeface font = Iconics.findFont(mContext, icon.substring(0, 3));
icon = icon.replace("-", "_");
icon(font.getIcon(icon));
} catch (Exception ex) {
Log.e(Iconics.TAG, "Wrong icon name: " + icon);
}
return this;
}
use of com.mikepenz.iconics.typeface.ITypeface in project FastAdapter by mikepenz.
the class GenericItemActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.sample_generic_item);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter which will manage everything
fastAdapter = new FastAdapter();
fastAdapter.withSelectable(true);
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
//init our gridLayoutManager and configure RV
GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 3);
GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(GenericIconItem.class, IconModel.class);
final FastScrollIndicatorAdapter<GenericIconItem> fastScrollIndicatorAdapter = new FastScrollIndicatorAdapter<>();
rv.setAdapter(fastScrollIndicatorAdapter.wrap(itemAdapter.wrap(fastAdapter)));
DragScrollBar materialScrollBar = new DragScrollBar(this, rv, true);
materialScrollBar.setHandleColour(ContextCompat.getColor(this, R.color.colorAccent));
materialScrollBar.setHandleOffColour(ContextCompat.getColor(this, R.color.colorAccent));
materialScrollBar.addIndicator(new CustomIndicator(this), true);
rv.setLayoutManager(gridLayoutManager);
rv.setItemAnimator(new SlideDownAlphaAnimator());
//order fonts by their name
List<ITypeface> mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
Collections.sort(mFonts, new Comparator<ITypeface>() {
@Override
public int compare(final ITypeface object1, final ITypeface object2) {
return object1.getFontName().compareTo(object2.getFontName());
}
});
//add all icons of all registered Fonts to the list
ArrayList<IconModel> models = new ArrayList<>();
for (ITypeface font : mFonts) {
for (String icon : font.getIcons()) {
models.add(new IconModel(font.getIcon(icon)));
}
}
//fill with some sample data
itemAdapter.addModel(models);
//restore selections (this has to be done after the items were added
fastAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.
the class IconicsUtils method placeFontIcon.
/**
* @param spannedString
* @param tempIconString
* @param fonts
* @return
*/
private static StyleContainer placeFontIcon(SpannableStringBuilder spannedString, SpannableStringBuilder tempIconString, HashMap<String, ITypeface> fonts) {
//make sure to check only for possible icons
if (tempIconString.length() >= 6) {
//build the iconString
String iconString = tempIconString.subSequence(1, tempIconString.length() - 1).toString().replace("-", "_");
//find out the fontKey
String fontKey = tempIconString.subSequence(1, 4).toString();
try {
//get the correct character for this Font and Icon
ITypeface typeface = fonts.get(fontKey);
if (typeface != null) {
//get the icon for the iconString
IIcon icon = typeface.getIcon(iconString);
//we can only add an icon which is a font
if (icon != null) {
//get and add the mapped char to the string
char fontChar = icon.getCharacter();
spannedString.append(fontChar);
//add the current icon to the container
return new StyleContainer(spannedString.length() - 1, spannedString.length(), iconString, fonts.get(fontKey));
} else {
Log.e(Iconics.TAG, "Wrong icon name: " + iconString);
}
} else {
Log.e(Iconics.TAG, "Wrong fontId: " + iconString);
}
} catch (IllegalArgumentException e) {
Log.e(Iconics.TAG, "Wrong icon name: " + iconString);
}
}
//if this was no working icon we add the tempIconString and return null
spannedString.append(tempIconString);
return null;
}
use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Handle Toolbar
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
//order fonts by their name
mFonts = new ArrayList<>(Iconics.getRegisteredFonts(this));
Collections.sort(mFonts, new Comparator<ITypeface>() {
@Override
public int compare(final ITypeface object1, final ITypeface object2) {
return object1.getFontName().compareTo(object2.getFontName());
}
});
//add all icons of all registered Fonts to the list
ArrayList<IDrawerItem> items = new ArrayList<>(Iconics.getRegisteredFonts(this).size());
int count = 0;
for (ITypeface font : mFonts) {
PrimaryDrawerItem pdi = new PrimaryDrawerItem().withName(font.getFontName()).withBadge("" + font.getIcons().size()).withDescription(TextUtils.isEmpty(font.getAuthor()) ? font.getVersion() : font.getVersion() + " - " + font.getAuthor()).withBadgeStyle(new BadgeStyle().withColorRes(R.color.md_grey_200)).withIcon(getRandomIcon(font)).withIdentifier(count);
if (font.getMappingPrefix().equals("gmd")) {
mIdentifierGmd = count;
}
items.add(pdi);
count++;
}
mDrawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withDrawerItems(items).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(View view, int i, IDrawerItem iDrawerItem) {
loadIcons(mFonts.get(i).getFontName());
getSupportActionBar().setTitle(mFonts.get(i).getFontName());
return false;
}
}).withOnDrawerListener(new Drawer.OnDrawerListener() {
@Override
public void onDrawerOpened(View drawerView) {
KeyboardUtil.hideKeyboard(MainActivity.this);
}
@Override
public void onDrawerClosed(View drawerView) {
}
@Override
public void onDrawerSlide(View drawerView, float slideOffset) {
}
}).withFireOnInitialOnClick(true).withSelectedItem(mIdentifierGmd).build();
}
Aggregations