×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    ContainerList: How to detect/skip initial calls to getCellRendererComponent

    I am using LWUIT for Series 40. I have a ContainerList in which each cell contains an image. In the renderer, for a given cell, a background thread is created to download the image.

    My problem has to do with the way ContainerList calls getCellRendererComponent() for all cells upon list creation. I do not want to immediately start downloading hundreds of images.

    So my question: is there some way to detect whether getCellRendererComponent() is being called as a part of this initial run through, as opposed to being called because the cell is about to be visible, and only start the download in the latter case?

    My first thought is to not allow any image downloads (past the first few cells) if the list has not been scrolled yet. Is there some way to detect scrolls?

    I'd love to hear any suggestions on how to achieve this.
    Last edited by james.harpe; 2013-09-25 at 21:37.

  2. #2
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    265

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    There is an interesting blog by Eric Coolman about Lazy Loading in Codename one.Since LWUIT and codename one are pretty similar, you can easily apply the same concept here.

    http://gadgets.coolman.ca/lazy-loadi...-codename-one/

    The trick lies here,the fetchMore() function.It is called as soon as the end of the list is reached!

    Code:
    .....
    public Component getListCellRendererComponent(List list,Object value, int index, boolean isSelected) {
                if ((index + 1) >= list.size()) {
                    fetchMore(list);
                }
    .....

  3. #3
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Thanks for your response! I'll check this out.

  4. #4
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Quote Originally Posted by arunkam View Post
    There is an interesting blog by Eric Coolman about Lazy Loading in Codename one.Since LWUIT and codename one are pretty similar, you can easily apply the same concept here.

    http://gadgets.coolman.ca/lazy-loadi...-codename-one/

    The trick lies here,the fetchMore() function.It is called as soon as the end of the list is reached!

    Code:
    .....
    public Component getListCellRendererComponent(List list,Object value, int index, boolean isSelected) {
                if ((index + 1) >= list.size()) {
                    fetchMore(list);
                }
    .....
    This will not work for my case.

    This will only work for List, not ContainerList.

    ContainerList calls getListCellRendererComponent for each cell immediately when the list is created. So the fetchMore() method would not be called when the end of the list is reached, it would be called immediately.

    If I was able to use List, I wouldn't have this problem anyway.

    Any other ideas?

  5. #5
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Even if you have to provide all Component-s, you probably do not have to actually draw them immediately. If that is the case, first you can fill your image array with a single placeholder, and start downloading the real images, one at a time. When a cell has to be drawn, it checks what is in the array. If it is the real image, draws it and everything is done. If it is the placeholder image, draws the placeholder, but also initiates the download of the real image (of course here you want to apply some flag to avoid downloading a single image multiple times, perhaps do not actually start downloading here, just move the given image to the start of the list-of-images-to-download). And when the real image is available, request a repaint on the list (here you may want to use some repaint-the-list-when-I-am-ready flag for the images).

  6. #6
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    265

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Populate your List Model in such a way that it has only 20 or so entries first.When u reach the bottom of the list, add next 20 entries.Like wizard says, use a placeholder image till the original Image is downloaded.Image Downloader Service will be useful for you.

  7. #7
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Quote Originally Posted by arunkam View Post
    Populate your List Model in such a way that it has only 20 or so entries first.When u reach the bottom of the list, add next 20 entries.Like wizard says, use a placeholder image till the original Image is downloaded.Image Downloader Service will be useful for you.
    Again, how would you know when you "reach the bottom of the list"? Certainly not by getCellRendererComponent(), because that will be called for all 20 cells immediately.

  8. #8
    Registered User
    Join Date
    Sep 2013
    Posts
    50

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Quote Originally Posted by wizard_hu_ View Post
    Even if you have to provide all Component-s, you probably do not have to actually draw them immediately. If that is the case, first you can fill your image array with a single placeholder, and start downloading the real images, one at a time. When a cell has to be drawn, it checks what is in the array. If it is the real image, draws it and everything is done. If it is the placeholder image, draws the placeholder, but also initiates the download of the real image (of course here you want to apply some flag to avoid downloading a single image multiple times, perhaps do not actually start downloading here, just move the given image to the start of the list-of-images-to-download). And when the real image is available, request a repaint on the list (here you may want to use some repaint-the-list-when-I-am-ready flag for the images).
    This would would still start all x number of image downloads immediately, because ContainerList calls getCellRendererComponent for all cells when the list is created.

    It looks like it calls that method twice for each cell upon list creation. So what I'm doing now is only starting the image download if getCellRendererComponent has been called >2 times for that particular index. This keeps the images from downloading right away, but seems kinda sloppy.

    However, even after preventing these image downloads, on a list of ~450 items, it's taking ~10 seconds just to get through those initial two run throughs of getCellRendererComponent(). There has to be a way to make this faster!

  9. #9
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    getCellRendererComponent does not draw anything. My suggestion was about defering download until an item really gets displayed.

  10. #10
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    265

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    Quote Originally Posted by james.harpe View Post
    Again, how would you know when you "reach the bottom of the list"? Certainly not by getCellRendererComponent(), because that will be called for all 20 cells immediately.
    Hi

    Yes you are right.It didnt work as I thought it would.I looked into the source code of List and Container List, I was not able to understand it fully, but based on what I did manage to understand, I think when a pointer dragged event occurs, animate is called which effectively scrolls the list. The index of the list item which will come to focus is also determined.Try messing with that code, it may help you create a custom list with desired effect.

    I read a discussion about scrolling by Shai, in which he suggested that one way would be to override animate of a list and call super().If it returns false, the list has stopped animating, an indicator that the list has probably stopped scrolling.However,apparently this is not the best approach and is not guaranteed to be accurate.

  11. #11
    Registered User
    Join Date
    Feb 2013
    Posts
    41

    Re: ContainerList: How to detect/skip initial calls to getCellRendererComponent

    I too had the same problem. My approach was to basically create an image downloader with fixed-size queue that holds requests. Older requests get discarded to make way for new requests - this way, you only request for images that gets displayed on the screen. The downloader would then get a request from the request queue, and if it is not yet downloaded (i.e. not saved to disk), it returns a placeholder image and then fires off a network request to fetch the image - or if it has been downloaded already (e.g. saved to disk), it returns that image right away.

Similar Threads

  1. ContainerList problems
    By james.harpe in forum Mobile Java UI and User Experience
    Replies: 13
    Last Post: 2013-10-10, 16:05
  2. How to skip makmake
    By Roose in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2009-04-24, 07:44
  3. How to skip video on n95??
    By KlaarMobileEntertainment in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2007-12-19, 06:03
  4. How to detect incoming & outgoing calls?
    By deval in forum Symbian
    Replies: 2
    Last Post: 2007-08-25, 11:49
  5. Skip Traverse
    By mariodipaolo in forum Mobile Java General
    Replies: 0
    Last Post: 2004-07-19, 15:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •