-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feature: Offscreen pages caching functionality #4
Comments
FlipViewController.sideBufferSize is designed to control the number of preloaded pages. The default value is 1, which means 1 previous page, the current page and 1 next page are loaded after flipping to a page. Unfortunately in your scenario, the lazily loaded content may not be visible during animation as the screenshot of the page was took before they're ready. I think we may need an API to notify FlipViewController to update the screenshot on demand. |
Indeed. Do you think you can make it re-use Bitmaps? |
@murimons I implemented a rough solution. The key idea is to use FlipViewController.refreshPage(View pageView) to make the animation reload content of an updated page. The codes are developed in a new branch: feature/api-content-update Please let me know if it meets your requirement. I'll merge it back to the main branch later |
Two new methods are added to support refreshing a page manually: |
Excelent! This meets my requirement indeed! question: In the docs you say that for an active page this would be an expensive operation. Do you mean a page that is being viewed at that moment or flipped? So when i flip to a page which is still in the middle of lazy loading my image and when that finishes (and i'm still looking at it) , i refresh the screenshot, this would be a heavy operation? in terms of memory? thanks! |
An active page is the one of which content is involved in animation. You can treat the current page and its next one be the active pages as both of them are needed to render the animation. The refreshing routine is no more heavier than manually flipping page. It triggers the following operations for the active pages:
The first step is "heavy" as it asks the page to re-draw itself, which could be a bit slow for a very complex view hierarchy. My suggestion in the doc is a note for the potential cost. For example, if you are rendering a view animation in a page, then it better not to call refreshPage() for each frame of the animation. |
I understood that It doesn't store pixels in the heap but the Bitmap memory does get accounted against the heap. So if a refresh allocates a native Bitmap it also uses up the memory in the Java heap. But GC could still be fast because the Bitmap object in the heap is small. (Is GC speed related to object size?) I'm still having issues with Bitmaps in my app causing OOM exceptions because of this (Not related to android-flip). I'm now trying to find a way to re-use Bitmap objects. |
The native memory occupied by bitmap instances can lead to OOM as the VM budget is constrained by the sum of heap memory and native memory. Please check out gclog.py if you want to check the real memory usage of your app. |
Hi,
I think it would be a nice addition to add some sort of offscreen pages cache like the way a Android ViewPager/PagerAdapter work. Right now i have pages that contain an image that needs to be fetched from the internet so i need to be able to pre-instantiate those pages 1/more pages ahead and also keep 1/more previous pages to be able to flip back easily.
I have taken the liberty of trying something out and used some code from the ViewPager and PagerAdapter source but i cannot get it to work correctly yet but is more to illustrate what i mean.
Maybe you want to have a look at it. (It's not working correctly: after some flipping forward and backwards, the pages repeat and indexes are wrong. haven't figured out yet what the problem is.)
I forked your project here:
https://github.com/murimons/android-flip
thnx
The text was updated successfully, but these errors were encountered: