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);
}
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);
}
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;
}
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);
}
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);
}
Aggregations