Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA
Accepted Solution

UI freezing

In relation to my previous post, I'm trying to create a picture viewing UI that has a swipe gesture for going to the next/prev photo.

 

When the UI loads, it creates 5 image views and calls setImageSource on each of them to load their photo. Only one of them is visible on the screen. When the user goes to the next photo, I slide in the image view that was to the right.

 

The problem is, when the UI first loads and the first image appears, UI events don't seem to get processed -- perhaps until all 5 image views have finished loading their image?  You can slide your finger across the screen and nothing happens. Then, a second or two later, the swipe gesture plays itself out.

 

Is this behavior expected?  Do the image loads lock up the UI and cause it to stop processing events?

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: UI freezing

The image size itself may also be a factor, do you do any preprocessing of the image to reduce the size or precache?


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: UI freezing

Yes, the images are large -- ones taken by the Z10 camera. (so, 8 megapixels?)

 

I realize the UI will need time to load the images, that's not really what my question is about... I'm more alarmed that the UI is locking up.  I would think / hope that the UI would continue to run at 60 fps even if images were being loaded... and that the image views would simply remain non-visible until the images load and are ready to be displayed.

 

How does the threading work there?  Possibly I need to look into asynchronous image loading? There's an "imageloader" example app that loads images (over the network I think) and then sends the image data to an ImageView. I suppose I'll have to try that as a next step...

Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: UI freezing

Ok, so there's another clue.  Even if I wait for several seconds after loading the UI to swipe to the next photo, there's still a lag of about 0.5 seconds before the images will start to slide. A guess is that the ImageView is somehow deferring some loading / rendering steps until the first time that image appears on the screen?

 

The reason I say that is that once the image to the right has slid onto the screen, you scan slide it back off the screen and then back onto the screen without any lock ups. I don't know whether explicit asychronous image loading code would help with that or not.

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: UI freezing

For big images, you should use an imagetracker https://developer.blackberry.com/native/reference/cascades/bb__cascades__ImageTracker.html
Like all of my posts
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: UI freezing

Hi Kyle, Interesting class, thanks. But I'm not sure how it applies to my problem.

Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: UI freezing

Just in that you dont have to set the image and do the loading directly with the ImageView until it is fully loaded. In theory you wont have any lag in this case while the ImageView is displaying the content.

Another option is to resize the image with QImage before you set it on the imageview
Like all of my posts
Developer
Posts: 587
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: UI freezing

The way I got around this was to use a bit of hackery. I tried the ImageTracker, but it didn't have any affect. My guess is that the lag isn't from the actual loading of the image from the SD card, as that happens prior to the swipe. Rather, it's when the image view first becomes visible on the screen.

 

To work around this, I display 1 horizontal pixel of the image on the screen, even if it's not supposed to be on the screen, and I set its opacity to 0.1 so that it's not perceptible. When I do this, the swipe event happens as one would expect without any lag prior to the next image appearing on the screen.