Search in sources :

Example 1 with ITypeface

use of com.mikepenz.iconics.typeface.ITypeface in project FastAdapter by mikepenz.

the class IconGridActivity 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);
    //as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
    //https://github.com/mikepenz/Android-Iconics
    LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.sample_icon_grid);
    //style our ui
    new MaterializeBuilder().withActivity(this).build();
    //create our FastAdapter which will manage everything
    fastItemAdapter = new FastItemAdapter();
    //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);
    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            switch(fastItemAdapter.getItemViewType(position)) {
                case R.id.fastadapter_expandable_item_id:
                    return 3;
                case R.id.fastadapter_icon_item_id:
                    return 1;
                default:
                    return -1;
            }
        }
    });
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(fastItemAdapter);
    //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
    int count = 0;
    ArrayList<SimpleSubExpandableItem> items = new ArrayList<>(Iconics.getRegisteredFonts(this).size());
    for (ITypeface font : mFonts) {
        //we set the identifier from the count here, as I need a stable ID in the sample to showcase the state restore
        SimpleSubExpandableItem expandableItem = new SimpleSubExpandableItem();
        expandableItem.withName(font.getFontName()).withIdentifier(count);
        ArrayList<IItem> icons = new ArrayList<>();
        for (String icon : font.getIcons()) {
            IconItem iconItem = new IconItem();
            iconItem.withIcon(font.getIcon(icon));
            icons.add(iconItem);
        }
        expandableItem.withSubItems(icons);
        items.add(expandableItem);
        count++;
    }
    //fill with some sample data
    fastItemAdapter.add(items);
    //if first start we want to expand the item with ID 2
    if (savedInstanceState != null) {
        //restore selections (this has to be done after the items were added
        fastItemAdapter.withSavedInstanceState(savedInstanceState);
    } else {
        //expand one item to make sample look a bit more interesting
        fastItemAdapter.expand(2);
    }
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : SimpleSubExpandableItem(com.mikepenz.fastadapter.app.items.expandable.SimpleSubExpandableItem) FastItemAdapter(com.mikepenz.fastadapter.commons.adapters.FastItemAdapter) ArrayList(java.util.ArrayList) MaterializeBuilder(com.mikepenz.materialize.MaterializeBuilder) GridLayoutManager(android.support.v7.widget.GridLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) IconItem(com.mikepenz.fastadapter.app.items.IconItem) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) IItem(com.mikepenz.fastadapter.IItem) IconicsLayoutInflater(com.mikepenz.iconics.context.IconicsLayoutInflater) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with ITypeface

use of com.mikepenz.iconics.typeface.ITypeface in project FastAdapter by mikepenz.

the class MultiTypeGenericItemActivity 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_multi_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);
    //if you need multiple items for different models you can also do this be defining a Function which get's the model object and returns the item (extends IItem)
    GenericItemAdapter<IconModel, GenericIconItem> itemAdapter = new GenericItemAdapter<>(new Function<IconModel, GenericIconItem>() {

        @Override
        public GenericIconItem apply(IconModel o) {
            if (o instanceof RightIconModel) {
                return new RightGenericIconItem(o);
            } else {
                return new GenericIconItem(o);
            }
        }
    });
    rv.setLayoutManager(gridLayoutManager);
    rv.setItemAnimator(new SlideDownAlphaAnimator());
    rv.setAdapter(itemAdapter.wrap(fastAdapter));
    //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<>();
    int i = 0;
    for (ITypeface font : mFonts) {
        for (String icon : font.getIcons()) {
            if (i % 3 == 0) {
                models.add(new IconModel(font.getIcon(icon)));
            } else {
                models.add(new RightIconModel(font.getIcon(icon)));
            }
            i++;
        }
    }
    //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 : RightIconModel(com.mikepenz.fastadapter.app.generic.RightIconModel) IconModel(com.mikepenz.fastadapter.app.generic.IconModel) GenericIconItem(com.mikepenz.fastadapter.app.generic.GenericIconItem) RightGenericIconItem(com.mikepenz.fastadapter.app.generic.RightGenericIconItem) ArrayList(java.util.ArrayList) RightGenericIconItem(com.mikepenz.fastadapter.app.generic.RightGenericIconItem) 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) RightIconModel(com.mikepenz.fastadapter.app.generic.RightIconModel) RecyclerView(android.support.v7.widget.RecyclerView) FastAdapter(com.mikepenz.fastadapter.FastAdapter) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with ITypeface

use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.

the class IconicsUtils method placeFontIcon.

/**
     * @param editable
     * @param iconStart
     * @param iconEnd
     * @param fonts
     * @return
     */
private static StyleContainer placeFontIcon(Editable editable, int iconStart, int iconEnd, HashMap<String, ITypeface> fonts) {
    //make sure to check only for possible icons
    if (iconEnd - iconStart >= 6) {
        //build the iconString
        String iconString = editable.subSequence(iconStart + 1, iconEnd).toString().replace("-", "_");
        //find out the fontKey
        String fontKey = editable.subSequence(iconStart + 1, iconStart + 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();
                    editable.replace(iconStart, iconEnd + 1, String.valueOf(fontChar));
                    //add the current icon to the container
                    return new StyleContainer(iconStart, iconStart + 1, 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);
        }
    }
    return null;
}
Also used : IIcon(com.mikepenz.iconics.typeface.IIcon) ITypeface(com.mikepenz.iconics.typeface.ITypeface)

Example 4 with ITypeface

use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.

the class IconsFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    // Init and Setup RecyclerView
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    recyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 2));
    //animator not yet working
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    mAdapter = new FastItemAdapter<>();
    configAdapter();
    recyclerView.setAdapter(mAdapter);
    if (getArguments() != null) {
        String fontName = getArguments().getString(FONT_NAME);
        for (ITypeface iTypeface : Iconics.getRegisteredFonts(getActivity())) {
            if (iTypeface.getFontName().equalsIgnoreCase(fontName)) {
                if (iTypeface.getIcons() != null) {
                    for (String icon : iTypeface.getIcons()) {
                        icons.add(new IconItem(icon));
                    }
                    mAdapter.set(icons);
                    break;
                }
            }
        }
    }
    //filter if a search param was provided
    onSearch(search);
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager) IconItem(com.mikepenz.iconics.sample.item.IconItem) ITypeface(com.mikepenz.iconics.typeface.ITypeface) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 5 with ITypeface

use of com.mikepenz.iconics.typeface.ITypeface in project Android-Iconics by mikepenz.

the class MainActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    //
    menu.findItem(R.id.search).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_search).color(Color.WHITE).sizeDp(24).respectFontBounds(true));
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String s) {
                search(s);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                search(s);
                return true;
            }

            private void search(String s) {
                mCurrentSearch = s;
                if (mDrawer != null) {
                    int count = 0;
                    for (ITypeface font : mFonts) {
                        int foundCount = 0;
                        if (font.getIcons() != null) {
                            for (String icon : font.getIcons()) {
                                if (icon.toLowerCase().contains(s.toLowerCase())) {
                                    foundCount++;
                                }
                            }
                        }
                        mDrawer.updateBadge(count, new StringHolder(foundCount + ""));
                        count++;
                    }
                }
                //filter out the current fragment
                if (mIconsFragment != null)
                    mIconsFragment.onSearch(s);
            }
        });
    } else {
        menu.findItem(R.id.search).setVisible(false);
    }
    MenuItem menuItem = menu.findItem(R.id.action_opensource);
    menuItem.setIcon(new IconicsDrawable(this, FontAwesome.Icon.faw_github).actionBar().color(Color.WHITE));
    return super.onCreateOptionsMenu(menu);
}
Also used : StringHolder(com.mikepenz.materialdrawer.holder.StringHolder) SearchView(android.support.v7.widget.SearchView) MenuInflater(android.view.MenuInflater) ITypeface(com.mikepenz.iconics.typeface.ITypeface) MenuItem(android.view.MenuItem) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable)

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