plattysoft / Leonids

A Particle System for standard Android UI: http://plattysoft.github.io/Leonids/
Apache License 2.0
2.28k stars 398 forks source link

issues using this lib in Myadapter with RecyclerVIEW... #73

Open akshaylamba opened 7 years ago

akshaylamba commented 7 years ago

0 down vote favorite

I am trying to Using Particle system


                ParticleSystem ps = new ParticleSystem(holder.itemView.getContext(), 50, R.drawable.emoji_1f358, 1000);
                ps.setSpeedRange(0.1f, 0.25f);
                ps.setScaleRange(0.7f, 1.3f);
                ps.setSpeedRange(0.1f, 0.25f);
                ps.setAcceleration(0.0001f, 90);
                ps.setRotationSpeedRange(90, 180);
                ps.setFadeOut(200, new AccelerateInterpolator());
                ps.emit(v, 100)

I am Trying to Use it in a MyAdapter File in the below function :-


public void onBindViewHolder(final MyHolderCHAT holder, final int position) {
}

This is Giving me an Build error as Below :-

Error:(1824, 41) error: no suitable constructor found for ParticleSystem(Context,int,int,int) constructor ParticleSystem.ParticleSystem(ViewGroup,int,Drawable,long) is not applicable (argument mismatch; Context cannot be converted to ViewGroup) constructor ParticleSystem.ParticleSystem(Activity,int,int,long) is not applicable (argument mismatch; Context cannot be converted to Activity) constructor ParticleSystem.ParticleSystem(Activity,int,Drawable,long) is not applicable (argument mismatch; Context cannot be converted to Activity) constructor ParticleSystem.ParticleSystem(Activity,int,Bitmap,long) is not applicable (argument mismatch; Context cannot be converted to Activity) constructor ParticleSystem.ParticleSystem(Activity,int,AnimationDrawable,long) is not applicable (argument mismatch; Context cannot be converted to Activity)

I also tried using

ViewGroup vg = (ViewGroup) holder.itemView.getParent();
                        Drawable drawable = ContextCompat.getDrawable(c, R.drawable.emoji_1f358);
                        ParticleSystem ps = new ParticleSystem(vg, 50, drawable, 1000);
                        ps.setSpeedRange(0.1f, 0.25f);
                        ps.setScaleRange(0.7f, 1.3f);
                        ps.setSpeedRange(0.1f, 0.25f);
                        ps.setAcceleration(0.0001f, 90);
                        ps.setRotationSpeedRange(90, 180);
                        ps.setFadeOut(200, new AccelerateInterpolator());
                        ps.emit(v, 100);

But Got an error saying

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.support.v7.widget.RecyclerView$ViewHolder.shouldIgnore()' on a null object reference at android.support.v7.widget.RecyclerView.findMinMaxChildLayoutPositions(RecyclerView.java:3709) at android.support.v7.widget.RecyclerView.dispatchLayoutStep1(RecyclerView.java:3446) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3262)

plattysoft commented 7 years ago

A ViewGroup is something as simple as a FrameLayout or a RelativeLayout. If your list items have one of those as the top level element, it should be ok.

However I suggest giving the top level view an id and getting it by Id.

It may be confusing if the view moves and the particle system does not. There may be some side effects or unexpected behaviours. Putting particle effects on items on a ListView is not something I had tested or planned for. It may as well behave properly.

akshaylamba commented 7 years ago

I have Relative Layout in my Recycler View as My Recycler View is attached to a Custom Layout with Contains the Relative Layout representing each row in recycler view.... How should I call the Relative Layout in the Below code...

ParticleSystem ps = new ParticleSystem(holder.itemView.getContext(), 50, R.drawable.emoji_1f358, 1000);
                ps.setSpeedRange(0.1f, 0.25f);
                ps.setScaleRange(0.7f, 1.3f);
                ps.setSpeedRange(0.1f, 0.25f);
                ps.setAcceleration(0.0001f, 90);
                ps.setRotationSpeedRange(90, 180);
                ps.setFadeOut(200, new AccelerateInterpolator());
                ps.emit(v, 100)
fabads commented 6 years ago

Hi all, I wake up this old issue having the same issue as above. I'm trying to attach to top framelayout of my cardview but nothing is displayed:

(I do that in a click listener belonging to a button of my cardview)

ViewGroup mygroup = (ViewGroup) itemView.findViewById(R.id.background_hook);
                    new ParticleSystem(mygroup, 80, ContextCompat.getDrawable(itemView.getContext(), R.drawable.ic_raindrop_24dp), 10000)
                            .setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
                            .setAcceleration(0.00005f, 90)
                            .emitWithGravity(itemView.findViewById(R.id.button1), Gravity.BOTTOM, 8);

And what is the behaviour if we scroll the list? The particles stay in the item view?