Tuesday, July 23, 2013

Getting Size of control in BB10 Cascades API

I was working on update for my Audiobook Reader application for BB10. I wanted to create a custom control like shown below and I required to use AbsoluteLayout to create it.



In this case layouting needs to be done manually and to do that we need to consider width and height of the controls and position controls using those. But unlike Qt Quick, BB10 Cascades controls does not provide access to width, height and x,y properties.

However Cascades API offers LayoutUpdateHandler control, this control gets notification when layout is complete and with notification it offers actual location and size of control and it also store these values in it's layoutFrame property. I used that to find out size of control and did required layouting.

Following code shows how LayoutUpdateHandler can be used to find out size of control.
    Container {
        id: indicators
        layout: AbsoluteLayout {}
        
        touchPropagationMode: TouchPropagationMode.Full
        
        background: Color.DarkGray

        attachedObjects: [
            LayoutUpdateHandler {
                id: handler
            }
        ]

        property alias width: handler.layoutFrame.width;
        property alias height: handler.layoutFrame.height;
    }
Now you can use width and height property to know control's actual size.

3 comments:

  1. What formats does your Audio Book reader accept? I cannot get it to detect my files from Audible on my Blackberry Q10. When I navigate to the folder to "add a book" it sees nothing in the folder where the audio files are.

    ReplyDelete
    Replies
    1. By the way, if you can contact me about this, my email is Gaval2@aol.com

      My audible files have a .aa extension and I cannot use them because Audible no longer supports Blackberry devices.

      Thanks,

      Ben

      Delete
    2. Hi Ben,

      My application uses, Media API from BB10 OS, so it supports format, which are supported by OS. As I know BB10 supports (AAC, AMR, AWB, FLAC, M4A, MKA, MP3, OGG, WAV, WMA) these formats.
      ( http://forums.crackberry.com/blackberry-10-os-f269/blackberry-10-os-media-support-739511/ )

      Regarding not able to see files, Are you trying to browse SD card or Phone memory. There is problem browsing certain kind of SD card, API does not return files list, it may be same issue with you as well.

      Kunal

      Delete