floating-hearts-view icon indicating copy to clipboard operation
floating-hearts-view copied to clipboard

Some information

Open Angelk90 opened this issue 5 years ago • 13 comments

Hi @petersamokhin , Congratulations on the module, you could:

  1. Publish the example of the apk
  2. Would it be possible to use the module without where to use xml? example:
HeartsView icon = new HeartsView.Builder (context) .Config (
             5f, // The max amplitude of the flight along the X axis
             0.15f, // Duration of the flying animation will be multiplied by this value (lower - faster)
             2f // Heart size coefficient
) .model (
             0, // Unique ID of this image, used for Rajawali materials caching
             bitmap // Bitmap image
)
  1. It would be possible to improve the doc, I do not understand what it is: a) HeartsRenderer b) HeartsView

Angelk90 avatar Sep 25 '18 01:09 Angelk90

Hello! Thanks for your feedback.

  1. You can see demo.apk in readme! If it necessary, I can publish the source code of demo app.

  2. You can easily use the library without xml:

HeartView heartView = new HeartView(context);
heartView.applyConfig(new HeartsRenderer.Config(5f, 0.15f, 2f));
heartView.emitHeart(new HeartView.Model(0, bitmap));
  1. So, OK, I will simplify the API of the library :)

HeartsRenderer is wrapper for Rajawali's renderer. Rajawali is wrapper for OpenGL. You don't need to know something about this. Config not a part of the HeartsRenderer and it's my bad.

Simply try the example code above!

petersamokhin avatar Sep 25 '18 13:09 petersamokhin

@petersamokhin :

  1. I think it's better.
  2. And HeartView or HeartsView? In your example, you wrote HeartView.
  3. In the example in the readme to create the model use the word "val" that is used on kt. What if I wanted to do that part in java?
HeartsView heartView = new HeartsView(this);
heartView.applyConfig(new HeartsRenderer.Config(5f, 0.15f, 2f));
String image = "https://cdn.shopify.com/s/files/1/1061/1924/products/Thinking_Face_Emoji_large.png";
//val byteArray = URL(image).readBytes();
//Bitmap bitmap = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.size);
heartView.emitHeart(new HeartsView.Model(0, bitmap));

Or did you have the image inside the project?

 Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),
                R.drawable.ic_play_36dp);
        heartView.emitHeart(new HeartsView.Model(0, bitmap),1);
`java.lang.RuntimeException: Unable to start activity ComponentInfo{com.exoplayer/com.gg.MainActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bitmap`

Angelk90 avatar Sep 25 '18 14:09 Angelk90

  1. omg, sorry :D HeartsView

  2. Yes, there are kotlin-readme. A difference with the Java code is not so big (just replace val and add new). See my previous message with Java snippet.

For your exception: I think decodeResource method returning null. In demo app all images are in resources.

petersamokhin avatar Sep 26 '18 18:09 petersamokhin

@petersamokhin : I do not understand, can you post an example for java?

Angelk90 avatar Sep 26 '18 21:09 Angelk90

@Angelk90 See this message, please: https://github.com/petersamokhin/floating-hearts-view/issues/1#issuecomment-424353156

Quote:

HeartView heartView = new HeartView(context);
heartView.applyConfig(new HeartsRenderer.Config(5f, 0.15f, 2f));
heartView.emitHeart(new HeartView.Model(0, bitmap));

So you can simply create the instance of the HeartsView with Context, pass config to it and then emit hearts.

petersamokhin avatar Sep 29 '18 00:09 petersamokhin

@petersamokhin : I understand but take an example of a bitmap? Then emit Heart asks for a second parameter because there is no "?" Symbol in the function

Angelk90 avatar Sep 29 '18 00:09 Angelk90

@Angelk90 I'm sorry, I do not understand what you mean.

Then emit Heart asks for a second parameter

Yes, the second parameter is yMax, it's optional in Kotlin, but required in Java. I'm sorry, not it's fixed and you can try an example from my previous message.

See the latest release: https://github.com/petersamokhin/floating-hearts-view/releases/tag/0.0.3

Thanks!

petersamokhin avatar Sep 29 '18 23:09 petersamokhin

@petersamokhin : java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter bitmap

Code:

HeartsView heartView = new HeartsView(this);
heartView.applyConfig(new HeartsRenderer.Config(5f, 0.15f, 2f));
String image = "https://cdn.shopify.com/s/files/1/1061/1924/products/Thinking_Face_Emoji_large.png";
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_play_36dp);
heartView.emitHeart(new HeartsView.Model(0, bitmap));`

Angelk90 avatar Sep 30 '18 00:09 Angelk90

@Angelk90 BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_play_36dp) is returning null. Try to download the image by URL and convert byte array to bitmap, or try another method to get bitmap from drawable.

petersamokhin avatar Sep 30 '18 01:09 petersamokhin

@petersamokhin : Then, let's start again: The image I'm taking from the drawable, image is a png at the moment. So it should be easy to take the image because it exists and I do not have to download it and use it to convert it BitmapFactory.decodeResource But it does not work, because it comes back I'm wrong:

Attempt to invoke virtual method 'java.lang.String [] java.lang.String.split (java.lang.String)' on a null object reference

Are we sure it works for java, which runs on java?

have you ever tried to run it on java? Do you have an example?

Because I've tried them all, but sembre errors gives me.

Angelk90 avatar Sep 30 '18 01:09 Angelk90

@petersamokhin : https://stackoverflow.com/questions/52578976/module-in-kt-turn-on-java-error-attempt-to-invoke-virtual-method-java-lang-st

Angelk90 avatar Sep 30 '18 15:09 Angelk90

Yes, I've had the same issue and it's related to Android & OpenGL. You can try the example from my answer on stackoverflow.


Quote:

Working code:

public class IssueTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_issue_test);

        LinearLayout rootView = findViewById(R.id.rootView);

        final HeartsView heartView = new HeartsView(this);
        heartView.applyConfig(new HeartsRenderer.Config(5f, 2f, 2f));

        rootView.addView(heartView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

        final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_heart_white);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        heartView.emitHeart(new HeartsView.Model(0, bitmap), HeartsView.MAX_Y_FULL);
                    }
                });
            }
        }).start();
        
    }
}

res/layout/activity_issue_test.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/rootView"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#333333"
    tools:context=".fh.IssueTestActivity" />

And ic_heart_white.png is an image in res/drawable directory.

Tested on Google Nexus 5X emulator, API 28.

petersamokhin avatar Sep 30 '18 15:09 petersamokhin

@petersamokhin :

It seems that it works, these are my doubts and some requests:

  1. You can publish the example that you see in the image, it would be that of the apk, as I requested in previous posts. With its images and everything.
  2. If I wanted to make these images that rise continuously as I have to do, by force a while loop?
  3. If I wanted to make every image have to be created when the onclick comes up on a button, do I have to put the waiting on the thread too?
        LinearLayout layout = new LinearLayout(this);
        LinearLayout.LayoutParams match_parent = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setLayoutParams(match_parent);
        setContentView(layout);

        final HeartsView heartView = new HeartsView(this);
        heartView.applyConfig(new HeartsRenderer.Config(5f, 1f, 2f));
        //final Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.heart);
        final Bitmap bitmap = getBitmap(this,R.drawable.ic_favorite_black_24dp);//vector image
        layout.addView(heartView, match_parent);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        heartView.emitHeart(new HeartsView.Model(0, bitmap), HeartsView.MAX_Y_FULL);
                        heartView.emitHeart(new HeartsView.Model(0, bitmap), HeartsView.MAX_Y_FULL);
                    }
                });
            }
        }).start();

Function:

private static Bitmap getBitmap(Context context, int drawableId) {
        Drawable drawable = ContextCompat.getDrawable(context, drawableId);
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        } else if (drawable instanceof VectorDrawable) {
            return getBitmap((VectorDrawable) drawable);
        } else {
            throw new IllegalArgumentException("unsupported drawable type");
        }
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    private static Bitmap getBitmap(VectorDrawable vectorDrawable) {
        Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
                vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        vectorDrawable.draw(canvas);
        return bitmap;
    }

Angelk90 avatar Sep 30 '18 18:09 Angelk90