jackpocket/android-scratchoff

Issue showing view

sunil-singh-chaudhary opened this issue · 10 comments

I have add this view above edittext view but when i scatch all now cant write on edittext so any solution for this so after scatch full we can write to on below view (Edittext)

I haven't tried this, but you could probably just set the visibility of the ScratchableLayout (or whatever your scratch View is) when the finish callback is triggered:

.setCompletionCallback(() -> 
    view.postDelayed (() -> view.setVisibility(View.GONE), 300));

Where 'view' is your ScratchableLayout.

I did postDelayed there so that the clearing animation has time to run before hiding it.

how to reset the view? i try to use ScratchoffController 's reset method ,but the result is bad

Sorry, good catch. In it's current state, ScratchController.reset() should have been an internal private method on the controller as ScratchoffController.attach(View, View) needs to rebuild the ScratchLayoutDrawer in order to reset the scratchable View to an untouched state.

For now, calling attach(View, View) or creating a new ScratchController and attaching that will solve your problem. In the next revision, I'll fix that to expose the reset() functionality correctly.

I can't see log when i scratch above 90%;
This is my code:
mScratcCcontroller = new ScratchoffController(this)
.setThresholdPercent(0.50d)
.setTouchRadiusDip(this, 30)
.setFadeOnClear(true)
.setClearOnThresholdReached(true)
.setCompletionCallback(new Runnable() {
@OverRide
public void run() {
LogUtil.e("----setCompletionCallback--");
}
})
.attach(findViewById(R.id.scratchView), findViewById(R.id.llDiscNoteContent));

@yemamumu you have the threshold set to 50%, which would trigger the clear event after only 50% of the View has been scratched away. You should call .setThresholdPercent(0.90d) if you want it to clear after 90%.

Note: Keep in mind, 90% of the View can be a pretty large area for the user to scratch; especially with larger Views.

thanks, can you give me a demo?
My email : yema@lljz-inc.com

I want to set the scratch image and reset the controller to "scratch" again. I tried to reset and attach (even reset and call a new controller). But the view just seems to disappear.

       if(controller == null) { //call the first time
            scratch_img.setImageBitmap(bmap);
            controller = new ScratchoffController(context).attach(scratchView, frame_layout);
        }
        else{ //reset if it already has controller
            scratch_img.setImageBitmap(bmap);
            controller.reset();
            controller.attach(scratchView, frame_layout);
        }

Or can I set the scratched percent to 0 ?

Edit: I got an exception (the app doesn't crash, but the ScratchableLinearLayout disappears)


09-06 15:30:48.532 4752-4752/c W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Bitmap.recycle()' on a null object reference
09-06 15:30:48.532 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.processors.ThresholdProcessor.safelyReleaseCurrentBitmap(ThresholdProcessor.java:104)
09-06 15:30:48.532 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.processors.ThresholdProcessor.start(ThresholdProcessor.java:28)
09-06 15:30:48.532 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.processors.ScratchoffProcessor.start(ScratchoffProcessor.java:67)
09-06 15:30:48.532 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.ScratchoffController.safelyStartProcessors(ScratchoffController.java:227)
09-06 15:30:48.542 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.ScratchoffController.onScratchableLayoutAvailable(ScratchoffController.java:105)
09-06 15:30:48.542 4752-4752/W/System.err:     at com.jackpocket.scratchoff.ScratchableLayoutDrawer.initializePostDisplay(ScratchableLayoutDrawer.java:99)
09-06 15:30:48.542 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.ScratchableLayoutDrawer.access$200(ScratchableLayoutDrawer.java:18)
09-06 15:30:48.542 4752-4752/ W/System.err:     at com.jackpocket.scratchoff.ScratchableLayoutDrawer$2.run(ScratchableLayoutDrawer.java:81)

That exception is handled so you shouldn't need to worry (albeit it probably would have been better practice to have checked for it), but the issue you're experiencing is definitely strange, and I'm wondering if it might have something to do with setting the Bitmap.

Since I still haven't updated the reset() method, it probably won't work as expected... For the moment, just create and attach the controller each time and it should work correctly.

Not working

if(controller == null) { //call the first time
            scratch_img.setImageBitmap(bmap);
            controller = new ScratchoffController(context).attach(scratchView, frame_layout);
        }
        else{ //reset if it already has controller
            controller = null;
            scratch_img.setImageBitmap(bmap);
            controller = new ScratchoffController(context).attach(scratchView, frame_layout);
        }

Try this now, it should be fixed:

scratch_img.setImageBitmap(bmap);

if(controller == null)
    controller = new ScratchoffController(context)
            .attach(scratchView, frame_layout);
else
    controller.reset();