onLayout datafield

I've  read a few post and I'd like to confirm my observation.

On sim, then there is more then 1 df layout onLayout is called every second. But why? Is it an error? If I have 2 df it should call twice for 2 df not every second...

I tried to put 2 the same custom df and watch didn't  allow  for it, even if df was on different pages. First I had to remove df to can put it in another place. It means that it's impossible  to have 2 the same custom df.

So, can I assume that onLayout  is called once on device?

Second thing. I can obtain width and height of df but how to obtain locX and locY, especial for different devices. Should I calculate it based on OBSCURE_* flag?

  • I can obtain width and height of df but how to obtain locX and locY, especial for different devices.

    You cannot. This information is not available to the data field. Trying to infer it based on the size and obscurity values will not scale well either. Some devices have multiple fields with the same size and obscurity.

    On sim, then there is more then 1 df layout onLayout is called every second. But why? Is it an error? If I have 2 df it should call twice for 2 df not every second...

    This is not an error. The onLayout function is called by the system as needed. This typically happens when the size or obscurity of the data field changes. It is my understanding that some devices do (or at least did) allow you to specify the same data field more than once in the same activity profile, and this allows us to display the results in each field without having to keep two copies of your data field in memory or waste cpu cycles updating both of them if they would display the same data.

    It would be a bad idea to depend on the number of calls to onLayout (or onUpdate) during a given time interval. This is a bad idea for several reasons, but one example is that onLayout or onUpdate will not be called your the data field is on a data page that is not currently visible. It might also not get called if the view is obscured by a pop-up of some sort.

    It is safe to rely on the DataField.compute(info) method getting called once a second (on average).

  • dc.getHeight() and dc.getWidth() return correct values so I use it to measure df

    I decide to draw values in df centre so I don't need locX, locY Slight smile

    Ok, I agree you have to call onLayout if there is need (for example user change place for DF). But why every second if nothing change? It should be call once per df like in watch face...
    I somebody want to draw something different in each second he should draw it in onUpdate. I don't use layout.xml and it's wasting of processor to load resources and count everything what is constant and can be counted only once. But there is no choice...

  • If you have two DFs in the sim the obsurity will change if the top one is being displayed, or the bottom one

    So what's happening is

    onLayout() is called (for the top field)

    onUpdate() is called (for the top field)

    onLayout() is called (for the bottom field)

    on upDate is called (for the bottom field)

    -1 sec

    onLayout() is called (for the top field)

    onUpdate() is called (for the top field)

    onLayout() is called (for the bottom field)

    on upDate is called (for the bottom field)

    ....

    Where if you are only showing one field, it's

    onLayout() is called

    onUpdate() called

    -1sec

    onUpdate() called

    -1sec

    ...

  • as I supposed there is limitation or error on sim, as on sim after few second srceen looks like (number is incremented in onLayout()):

    on watch everywhere is 1.

    Of course, if user goes to option and change fields on page onLayout should call again.

    You don't have to call onLayout if nothing changed like in wf where is called once or if something changes layout (for example always on screen).

  • You don't call onLayout.  The system does.

  • of course, I mentioned that system should call onLayout only that it's needed.

    let's finish this thread, I think, sim should be correct.