MatteoBattilana / WeatherView

WeatherView is an Android Library let you make cool weather animations for your app
Apache License 2.0
506 stars 81 forks source link

Animation stops abruptly #18

Closed aboutgaurav closed 4 years ago

aboutgaurav commented 6 years ago

@MatteoBattilana I have successfully implemented this library in my app. And its working flawlessly. But animation of 'WeatherView' stops abruptly when i try to take the screenshot.

Layout file:

               <FrameLayout
                android:id="@+id/containerImagePreview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:background="@color/yellow_light">

                <!--Preview imageView-->
                <android.support.v7.widget.AppCompatImageView
                    android:id="@+id/image_preview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:adjustViewBounds="true"
                    android:scaleType="fitXY"
                    tools:src="@tools:sample/avatars" />

                <!--Snowfall and rain filter-->
                <com.github.matteobattilana.weather.WeatherView
                    android:id="@+id/whether_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone" />

            </FrameLayout>`

do you know this is happening? Any guide and direction will be helpful. Thanks

MatteoBattilana commented 6 years ago

@aboutgaurav Thank you for being interested in WeatherView library. I will investigate about this strange bug. Can you provide me your code?

aboutgaurav commented 6 years ago

@MatteoBattilana Thank you for quick response.

Snippet for screenshot:

      for(int i = 0; i < 12; i++) {

        frameLayout.setDrawingCacheEnabled(true)
        Bitmap bm = frameLayout.getDrawingCache();
        try {
            File file = new File(Environment.getExternalStorageDirectory().getPath() + 
            "/Cread/Short/short_pic" + i + ".jpg");
            file.getParentFile().mkdirs();

            if (!file.exists()) {
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            FileOutputStream out = new FileOutputStream(file);
            bm.compress(Bitmap.CompressFormat.JPEG, 85, out);
            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //Disable drawing cache
        frameLayout.setDrawingCacheEnabled(false);
    }

Code for Snow and Rain animation:

                    //snow animation
                    whetherView.setWeatherData(PrecipType.SNOW);

                    //rain aniamtion
                    whetherView.setWeatherData(PrecipType.RAIN);
AvneeshKhanna commented 6 years ago

Facing the same bug. Especially, in rain mode, the rain doesn't appear in screenshots. Works fine in snow mode.

@MatteoBattilana

magneticflux- commented 6 years ago

@aboutgaurav @AvneeshKhanna Could you provide the versions of Android, Android Support libraries, and WeatherView you are using?

aboutgaurav commented 6 years ago

Android version: Jelly Bean (4.3.1) Support Library: 26.1.0 WeatherView : 2.0.3

magneticflux- commented 6 years ago

I'm unable to reproduce this on an Android 4.3.1 emulator. What model of phone are you using to test?

aboutgaurav commented 6 years ago

Tested on following devices: -HM 1s xiaomi -OnePlus 3t -OnePlus 5

And i am using above mentioned code to take the screenshot.

magneticflux- commented 6 years ago

I am able to reproduce this behavior. It appears that the motion blur effect is responsible. Because the motion blur effect is based on the previous onDraw call, having it redraw instantly after a previous draw makes the raindrops have 0 length.

I'm working on a better method of rendering the particles with motion information.

aboutgaurav commented 6 years ago

@magneticflux- Thanks for the effort. Let me know when you fix this.

magneticflux- commented 6 years ago

https://github.com/jinatonic/confetti/pull/41 has been merged, so I'll update WeatherView with this fix as soon as they release a version that includes my contributions.

aboutgaurav commented 5 years ago

Thanks

MatteoBattilana commented 4 years ago

@magneticflux- The 1.1.2 confetti library release contains the pull request you opened time ago. Can you merge it and add the missing code?