use of com.mikepenz.iconics.sample.item.IconItem 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.sample.item.IconItem in project Android-Iconics by mikepenz.
the class IconsFragment method onSearch.
void onSearch(String s) {
search = s;
if (mAdapter != null) {
if (TextUtils.isEmpty(s)) {
mAdapter.clear();
mAdapter.setNewList(icons);
} else {
AbstractList<IconItem> tmpList = new ArrayList<>();
for (IconItem icon : icons) {
if (icon.getIcon().toLowerCase().contains(s.toLowerCase())) {
tmpList.add(icon);
}
}
mAdapter.setNewList(tmpList);
}
}
}
use of com.mikepenz.iconics.sample.item.IconItem in project Android-Iconics by mikepenz.
the class IconsFragment method configAdapter.
private void configAdapter() {
//our popup on touch
mAdapter.withOnTouchListener(new FastAdapter.OnTouchListener<IconItem>() {
@Override
public boolean onTouch(View v, MotionEvent motionEvent, IAdapter<IconItem> adapter, IconItem item, int position) {
int a = motionEvent.getAction();
if (a == MotionEvent.ACTION_DOWN) {
if (popup != null && popup.isShowing()) {
popup.dismiss();
}
IconicsDrawable icon = new IconicsDrawable(v.getContext()).icon(item.getIcon()).sizeDp(144).paddingDp(8).backgroundColor(Color.parseColor("#DDFFFFFF")).roundedCornersDp(12);
ImageView imageView = new ImageView(v.getContext());
imageView.setImageDrawable(icon);
int size = (int) UIUtils.convertDpToPixel(144, v.getContext());
popup = new PopupWindow(imageView, size, size);
popup.showAsDropDown(v);
//copy to clipboard
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(icon.getIcon().getFormattedName());
} else {
android.content.ClipboardManager clipboard = (android.content.ClipboardManager) v.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
android.content.ClipData clip = android.content.ClipData.newPlainText("Android-Iconics icon", icon.getIcon().getFormattedName());
clipboard.setPrimaryClip(clip);
}
} else if (a == MotionEvent.ACTION_UP || a == MotionEvent.ACTION_CANCEL || a == MotionEvent.ACTION_OUTSIDE) {
if (popup != null && popup.isShowing()) {
popup.dismiss();
}
}
return false;
}
});
mAdapter.withOnBindViewHolderListener(new FastAdapter.OnBindViewHolderListener() {
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position, List payloads) {
IconItem.ViewHolder holder = (IconItem.ViewHolder) viewHolder;
//as we overwrite the default listener
mAdapter.getItem(position).bindView(holder, payloads);
if (randomize) {
holder.image.setColorRes(getRandomColor(position));
holder.image.setPaddingDp(random.nextInt(12));
holder.image.setContourWidthDp(random.nextInt(2));
holder.image.setContourColor(getRandomColor(position - 2));
int y = random.nextInt(10);
if (y % 4 == 0) {
holder.image.setBackgroundColorRes(getRandomColor(position - 4));
holder.image.setRoundedCornersDp(2 + random.nextInt(10));
}
}
}
@Override
public void unBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
IconItem item = mAdapter.getItem(position);
if (item != null) {
item.unbindView((IconItem.ViewHolder) viewHolder);
}
}
});
}
Aggregations