winsontan520 / Android-WScratchView

[Deprecated] Provide a view which can be scratched
83 stars 35 forks source link

Slow preview when implementing onScratchCallback #13

Closed marcoforlin closed 9 years ago

marcoforlin commented 9 years ago

Hello,

thanks for your library. I added it to my project and it works fine as long as: mOnScratchCallback.onScratch(getScratchedRatio());

is not called.

I see that this is working fine in your demo project. The main difference is that in my case I am putting the view inside a fragment, but I don't know if that would be any different.

Do you have any suggestion?

thanks, kind regards Marco

my xml for this view: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/fragment" >

<LinearLayout
    android:id="@+id/linearlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical" >

    <Button
        android:id="@+id/mbutton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

<ImageView android:id="@+id/scratch_img" android:layout_width="450dp" android:layout_height="620dp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:scaleType="fitXY"/>

    <com.winsontan520.WScratchView
xmlns:wsv="http://schemas.android.com/apk/res-auto"
android:id="@+id/scratch_view"
android:layout_width="450dp"
android:layout_height="620dp"
android:layout_centerInParent="true"
wsv:antiAlias="true"
wsv:overlayColor="#0000ff"
wsv:revealSize="20dp"
wsv:scratchable="true" />

then i simply load an image in the imageview, and one in the scratchView. This works fine when not updating the percentage.

marcoforlin commented 9 years ago

Update: as predictable, the main issue was probably the size of the image, I could partially solve the issue by reducing the update speed by changing the reveal_size.

I say partially because the computation of the scratched percentage is still heavy and will probably behave worse on less powerful hardware.

bye, Marco

winsontan520 commented 9 years ago

Yes Marco, this library is just a quick hack for scratch view and not the proper way of drawing . There will be performance issue on less powerful device due to the heavy drawing loop. Meanwhile I don't have much free time to revamp it now...

marcoforlin commented 9 years ago

Hi, ok got it, thanks for the confirmation.

For now I will also stick with this code, if I do any useful updates to it in the future I will let you know.

bye, Marco