Search in sources :

Example 6 with ITypeface

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;
    }
}
Also used : ITypeface(com.mikepenz.iconics.typeface.ITypeface) SpannableString(android.text.SpannableString)

Example 7 with ITypeface

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;
}
Also used : ITypeface(com.mikepenz.iconics.typeface.ITypeface)

Example 8 with ITypeface

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);
}
Also used : FastScrollIndicatorAdapter(com.mikepenz.fastadapter.app.adapters.FastScrollIndicatorAdapter) IconModel(com.mikepenz.fastadapter.app.generic.IconModel) DragScrollBar(com.turingtechnologies.materialscrollbar.DragScrollBar) GenericIconItem(com.mikepenz.fastadapter.app.generic.GenericIconItem) ArrayList(java.util.ArrayList) CustomIndicator(com.turingtechnologies.materialscrollbar.CustomIndicator) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) GenericItemAdapter(com.mikepenz.fastadapter.adapters.GenericItemAdapter) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with ITypeface

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;
}
Also used : IIcon(com.mikepenz.iconics.typeface.IIcon) ITypeface(com.mikepenz.iconics.typeface.ITypeface)

Example 10 with ITypeface

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();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) ArrayList(java.util.ArrayList) Drawer(com.mikepenz.materialdrawer.Drawer) SearchView(android.support.v7.widget.SearchView) View(android.view.View) ITypeface(com.mikepenz.iconics.typeface.ITypeface) BadgeStyle(com.mikepenz.materialdrawer.holder.BadgeStyle) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

ITypeface (com.mikepenz.iconics.typeface.ITypeface)12 GridLayoutManager (android.support.v7.widget.GridLayoutManager)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Toolbar (android.support.v7.widget.Toolbar)4 ArrayList (java.util.ArrayList)4 SlideDownAlphaAnimator (com.mikepenz.itemanimators.SlideDownAlphaAnimator)3 MaterializeBuilder (com.mikepenz.materialize.MaterializeBuilder)3 SearchView (android.support.v7.widget.SearchView)2 FastAdapter (com.mikepenz.fastadapter.FastAdapter)2 GenericItemAdapter (com.mikepenz.fastadapter.adapters.GenericItemAdapter)2 GenericIconItem (com.mikepenz.fastadapter.app.generic.GenericIconItem)2 IconModel (com.mikepenz.fastadapter.app.generic.IconModel)2 IIcon (com.mikepenz.iconics.typeface.IIcon)2 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 SpannableString (android.text.SpannableString)1 MenuInflater (android.view.MenuInflater)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 IItem (com.mikepenz.fastadapter.IItem)1 FastScrollIndicatorAdapter (com.mikepenz.fastadapter.app.adapters.FastScrollIndicatorAdapter)1