Search in sources :

Example 1 with IconItem

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);
}
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 2 with IconItem

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);
        }
    }
}
Also used : IconItem(com.mikepenz.iconics.sample.item.IconItem) ArrayList(java.util.ArrayList)

Example 3 with IconItem

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);
            }
        }
    });
}
Also used : PopupWindow(android.widget.PopupWindow) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) MotionEvent(android.view.MotionEvent) IconItem(com.mikepenz.iconics.sample.item.IconItem) RecyclerView(android.support.v7.widget.RecyclerView) AbstractList(java.util.AbstractList) ArrayList(java.util.ArrayList) List(java.util.List) FastAdapter(com.mikepenz.fastadapter.FastAdapter) ImageView(android.widget.ImageView) Context(android.content.Context) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable)

Aggregations

IconItem (com.mikepenz.iconics.sample.item.IconItem)3 RecyclerView (android.support.v7.widget.RecyclerView)2 ArrayList (java.util.ArrayList)2 Context (android.content.Context)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 MotionEvent (android.view.MotionEvent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 PopupWindow (android.widget.PopupWindow)1 FastAdapter (com.mikepenz.fastadapter.FastAdapter)1 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)1 ITypeface (com.mikepenz.iconics.typeface.ITypeface)1 AbstractList (java.util.AbstractList)1 List (java.util.List)1