Search in sources :

Example 51 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project AboutLibraries by mikepenz.

the class LibraryItem method bindView.

/**
     * binds the data of this item onto the viewHolder
     *
     * @param holder the viewHolder of this item
     */
@Override
public void bindView(final ViewHolder holder, List<Object> payloads) {
    super.bindView(holder, payloads);
    //ctx
    final Context ctx = holder.itemView.getContext();
    //Set texts
    holder.libraryName.setText(library.getLibraryName());
    holder.libraryCreator.setText(library.getAuthor());
    if (TextUtils.isEmpty(library.getLibraryDescription())) {
        holder.libraryDescription.setText(library.getLibraryDescription());
    } else {
        holder.libraryDescription.setText(Html.fromHtml(library.getLibraryDescription()));
    }
    //Set License or Version Text
    if (TextUtils.isEmpty(library.getLibraryVersion()) && library.getLicense() != null && TextUtils.isEmpty(library.getLicense().getLicenseName()) || (!libsBuilder.showVersion && !libsBuilder.showLicense)) {
        holder.libraryBottomDivider.setVisibility(View.GONE);
        holder.libraryBottomContainer.setVisibility(View.GONE);
    } else {
        holder.libraryBottomDivider.setVisibility(View.VISIBLE);
        holder.libraryBottomContainer.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(library.getLibraryVersion()) && libsBuilder.showVersion) {
            holder.libraryVersion.setText(library.getLibraryVersion());
        } else {
            holder.libraryVersion.setText("");
        }
        if (library.getLicense() != null && !TextUtils.isEmpty(library.getLicense().getLicenseName()) && libsBuilder.showLicense) {
            holder.libraryLicense.setText(library.getLicense().getLicenseName());
        } else {
            holder.libraryLicense.setText("");
        }
    }
    //Define onClickListener
    if (!TextUtils.isEmpty(library.getAuthorWebsite())) {
        holder.libraryCreator.setOnTouchListener(rippleForegroundListener);
        holder.libraryCreator.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                boolean consumed = false;
                if (LibsConfiguration.getInstance().getListener() != null) {
                    consumed = LibsConfiguration.getInstance().getListener().onLibraryAuthorClicked(view, library);
                }
                if (!consumed) {
                    openAuthorWebsite(ctx, library.getAuthorWebsite());
                }
            }
        });
        holder.libraryCreator.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                boolean consumed = false;
                if (LibsConfiguration.getInstance().getListener() != null) {
                    consumed = LibsConfiguration.getInstance().getListener().onLibraryAuthorLongClicked(v, library);
                }
                if (!consumed) {
                    openAuthorWebsite(ctx, library.getAuthorWebsite());
                    consumed = true;
                }
                return consumed;
            }
        });
    } else {
        holder.libraryCreator.setOnTouchListener(null);
        holder.libraryCreator.setOnClickListener(null);
        holder.libraryCreator.setOnLongClickListener(null);
    }
    if (!TextUtils.isEmpty(library.getLibraryWebsite()) || !TextUtils.isEmpty(library.getRepositoryLink())) {
        holder.libraryDescription.setOnTouchListener(rippleForegroundListener);
        holder.libraryDescription.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean consumed = false;
                if (LibsConfiguration.getInstance().getListener() != null) {
                    consumed = LibsConfiguration.getInstance().getListener().onLibraryContentClicked(v, library);
                }
                if (!consumed) {
                    openLibraryWebsite(ctx, library.getLibraryWebsite() != null ? library.getLibraryWebsite() : library.getRepositoryLink());
                }
            }
        });
        holder.libraryDescription.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                boolean consumed = false;
                if (LibsConfiguration.getInstance().getListener() != null) {
                    consumed = LibsConfiguration.getInstance().getListener().onLibraryContentLongClicked(v, library);
                }
                if (!consumed) {
                    openLibraryWebsite(ctx, library.getLibraryWebsite() != null ? library.getLibraryWebsite() : library.getRepositoryLink());
                    consumed = true;
                }
                return consumed;
            }
        });
    } else {
        holder.libraryDescription.setOnTouchListener(null);
        holder.libraryDescription.setOnClickListener(null);
        holder.libraryDescription.setOnLongClickListener(null);
    }
    if (library.getLicense() != null && !TextUtils.isEmpty((library.getLicense().getLicenseWebsite()))) {
        holder.libraryBottomContainer.setOnTouchListener(rippleForegroundListener);
        holder.libraryBottomContainer.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                boolean consumed = false;
                if (LibsConfiguration.getInstance().getListener() != null) {
                    consumed = LibsConfiguration.getInstance().getListener().onLibraryBottomClicked(view, library);
                }
                if (!consumed) {
                    openLicense(ctx, libsBuilder, library);
                }
            }
        });
        holder.libraryBottomContainer.setOnLongClickListener(new View.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                boolean consumed = false;
                if (LibsConfiguration.getInstance().getListener() != null) {
                    consumed = LibsConfiguration.getInstance().getListener().onLibraryBottomLongClicked(v, library);
                }
                if (!consumed) {
                    openLicense(ctx, libsBuilder, library);
                    consumed = true;
                }
                return consumed;
            }
        });
    } else {
        holder.libraryBottomContainer.setOnTouchListener(null);
        holder.libraryBottomContainer.setOnClickListener(null);
        holder.libraryBottomContainer.setOnLongClickListener(null);
    }
    //notify the libsRecyclerViewListener to allow modifications
    if (LibsConfiguration.getInstance().getLibsRecyclerViewListener() != null) {
        LibsConfiguration.getInstance().getLibsRecyclerViewListener().onBindViewHolder(holder);
    }
}
Also used : Context(android.content.Context) CardView(android.support.v7.widget.CardView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 52 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project LollipopShowcase by mikepenz.

the class ReboundItemAnimator method runPendingAnimations.

@Override
public void runPendingAnimations() {
    if (!mViewHolders.isEmpty()) {
        for (final RecyclerView.ViewHolder viewHolder : mViewHolders) {
            SpringSystem springSystem = SpringSystem.create();
            SpringConfig springConfig = new SpringConfig(70, 10);
            final View target = viewHolder.itemView;
            // Add a spring to the system.
            Spring spring = springSystem.createSpring();
            spring.setSpringConfig(springConfig);
            spring.setCurrentValue(0.0f);
            // Add a listener to observe the motion of the spring.
            spring.addListener(new SimpleSpringListener() {

                @Override
                public void onSpringUpdate(Spring spring) {
                    // You can observe the updates in the spring
                    // state by asking its current value in onSpringUpdate.
                    float value = (float) spring.getCurrentValue();
                    target.setScaleX(value);
                    target.setScaleY(value);
                }
            });
            // Set the spring in motion; moving from 0 to 1
            spring.setEndValue(1.0f);
        }
    }
}
Also used : SimpleSpringListener(com.facebook.rebound.SimpleSpringListener) RecyclerView(android.support.v7.widget.RecyclerView) SpringConfig(com.facebook.rebound.SpringConfig) Spring(com.facebook.rebound.Spring) SpringSystem(com.facebook.rebound.SpringSystem) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 53 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project FastDev4Android by jiangqqlmj.

the class GalleryRecyclerAdapter method onCreateViewHolder.

/**
     * 创建Item View  然后使用ViewHolder来进行承载
     * @param parent
     * @param viewType
     * @return
     */
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View view = mInflater.inflate(R.layout.item_gallery_recycler, parent, false);
    ViewHolder viewHolder = new ViewHolder(view);
    view.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (onRecyclerViewItemClickListener != null) {
                onRecyclerViewItemClickListener.onItemClick(view, (int) view.getTag());
            }
        }
    });
    return viewHolder;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Example 54 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project XRecyclerView by jianghejie.

the class SimpleItemTouchHelperCallback method onChildDraw.

@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
    super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
    // Fade out the view as it is swiped out of the parent's bounds
    if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE) {
        View itemView = viewHolder.itemView;
        final float alpha = ALPHA_FULL - Math.abs(dX) / (float) itemView.getWidth();
        itemView.setAlpha(alpha);
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 55 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project archi by ivacf.

the class RepositoryAdapter method onCreateViewHolder.

@Override
public RepositoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    final View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_repo, parent, false);
    final RepositoryViewHolder viewHolder = new RepositoryViewHolder(itemView);
    viewHolder.contentLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (callback != null) {
                callback.onItemClick(viewHolder.repository);
            }
        }
    });
    return viewHolder;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)265 View (android.view.View)248 TextView (android.widget.TextView)129 ImageView (android.widget.ImageView)95 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)47 LayoutInflater (android.view.LayoutInflater)34 ViewGroup (android.view.ViewGroup)32 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)28 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)25 Context (android.content.Context)21 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)17 BindView (butterknife.BindView)17 CardView (android.support.v7.widget.CardView)15 Paint (android.graphics.Paint)11 ParallaxRecyclerAdapter (com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter)8 ExampleData (de.madcyph3r.example.data.ExampleData)8 Drawable (android.graphics.drawable.Drawable)7 Test (org.junit.Test)7