datafield get position of the datafield on the screen (top half, top quadrant) on watch

so i am working on a datafield, and i need to know where the datafield is on the screen. on the round screen, to be precise. if it's on the bottom left quadrant, the drawing changes entirely. first i thought "hey. i'm going to use obscurity flags", but those don't do what i want. what is the right method?

  • Obscurity flags along with maybe looking at the DF height and width are really about all there is.  What's not working with the obscurity flags?  Understand they are bit flags so if the value is 5, it's both right and left. and 13, it's right, left and bottom.

  • but how would i know that it's in the top small portion for examle? ( the 4 piece layout on fenix 5, with one bottom piece, one top piece, and in the middle split up into two)

  • The one on top would have OBSCURITY_TOP, the one on the bottom, OBSCURITY_BOTTOM, and the two in the middle, neither,  You can't tell which of the middle two though.

  • when i use if (DataField.getObscurityFlags() == OBSCURE_TOP){

    //some code

    }

    and set the layout to that one, the code doesn't execyte (i change the layout in my code to a different layout). also, i use a variable that has the obscurityflags in the code, but that doesnt matter.

    yes, i did set the layout in the sim

  • You need to do something like 

     if (DataField.getObscurityFlags() & OBSCURE_TOP) {

    Like I said, they are bit flags so you want to check the OBSCURE_TOP bit, and not the full value

  • The one on top would have OBSCURITY_TOP, the one on the bottom, OBSCURITY_BOTTOM, and the two in the middle, neither,  You can't tell which of the middle two though.

    According to the User Experience Guide documentation (and confirmed in devices.xml) the fenix5 sets the left/right obscurity bits for the center fields in the 4 Fields A layout.

    ### 1 Field
    
    | Name    |   Left |   Top |   Width |   Height |   Obscurity Flags | Obscure Left   | Obscure Right   | Obscure Top   | Obscure Bottom   |
    |:--------|-------:|------:|--------:|---------:|------------------:|:---------------|:----------------|:--------------|:-----------------|
    | Field 1 |      0 |     0 |     240 |      240 |                15 | True           | True            | True          | True             |
    
    ### 2 Fields
    
    | Name    |   Left |   Top |   Width |   Height |   Obscurity Flags | Obscure Left   | Obscure Right   | Obscure Top   | Obscure Bottom   |
    |:--------|-------:|------:|--------:|---------:|------------------:|:---------------|:----------------|:--------------|:-----------------|
    | Field 1 |      0 |     0 |     240 |      119 |                 7 | True           | True            | True          | False            |
    | Field 2 |      0 |   121 |     240 |      119 |                13 | True           | True            | False         | True             |
    
    ### 3 Fields A
    
    | Name    |   Left |   Top |   Width |   Height |   Obscurity Flags | Obscure Left   | Obscure Right   | Obscure Top   | Obscure Bottom   |
    |:--------|-------:|------:|--------:|---------:|------------------:|:---------------|:----------------|:--------------|:-----------------|
    | Field 1 |      0 |     0 |     240 |       77 |                 7 | True           | True            | True          | False            |
    | Field 2 |      0 |    79 |     240 |       82 |                 5 | True           | True            | False         | False            |
    | Field 3 |      0 |   163 |     240 |       77 |                13 | True           | True            | False         | True             |
    
    ### 3 Fields B
    
    | Name    |   Left |   Top |   Width |   Height |   Obscurity Flags | Obscure Left   | Obscure Right   | Obscure Top   | Obscure Bottom   |
    |:--------|-------:|------:|--------:|---------:|------------------:|:---------------|:----------------|:--------------|:-----------------|
    | Field 1 |      0 |     0 |     240 |      119 |                 7 | True           | True            | True          | False            |
    | Field 2 |      0 |   121 |     119 |      119 |                 9 | True           | False           | False         | True             |
    | Field 3 |    121 |   121 |     119 |      119 |                12 | False          | True            | False         | True             |
    
    ### 4 Fields A
    
    | Name    |   Left |   Top |   Width |   Height |   Obscurity Flags | Obscure Left   | Obscure Right   | Obscure Top   | Obscure Bottom   |
    |:--------|-------:|------:|--------:|---------:|------------------:|:---------------|:----------------|:--------------|:-----------------|
    | Field 1 |      0 |     0 |     240 |       77 |                 7 | True           | True            | True          | False            |
    | Field 2 |      0 |    79 |     119 |       82 |                 1 | True           | False           | False         | False            |
    | Field 3 |    121 |    79 |     119 |       82 |                 4 | False          | True            | False         | False            |
    | Field 4 |      0 |   163 |     240 |       77 |                13 | True           | True            | False         | True             |
    
    ### 4 Fields B
    
    | Name    |   Left |   Top |   Width |   Height |   Obscurity Flags | Obscure Left   | Obscure Right   | Obscure Top   | Obscure Bottom   |
    |:--------|-------:|------:|--------:|---------:|------------------:|:---------------|:----------------|:--------------|:-----------------|
    | Field 1 |      0 |     0 |     119 |      119 |                 3 | True           | False           | True          | False            |
    | Field 2 |    121 |     0 |     119 |      119 |                 6 | False          | True            | True          | False            |
    | Field 3 |      0 |   121 |     119 |      119 |                 9 | True           | False           | False         | True             |
    | Field 4 |    121 |   121 |     119 |      119 |                12 | False          | True            | False         | True             |
    

  • True.  I was thinking the 4 field was

    top

    ----

    middle 1

    ----

    middle 2

    ---

    bottom

    Must have been thinking of another device..  Slight smile

  • that would mean that this code:

    if((obscurityflags & OBSCURE_TOP) && !(obscurityflags & OBSCURE_BOTTOM) && !(obscurityflags & OBSCURE_LEFT))&& !(obscurityflags & OBSCURE_RIGHT) )

    should only return true, when i use the 4 fields A layout, with the first datafield (the top one). while it does work with that exact version, it also returns true when i use the fullscreen layout, the 4 fields B on the top 2 fields, with 3 fields a and be, both on the top most ones. and with two fields, the top most one. do you know what i am doing wrong?

  • that would mean that this code:

    if((obscurityflags & OBSCURE_TOP) && !(obscurityflags & OBSCURE_BOTTOM) && !(obscurityflags & OBSCURE_LEFT))&& !(obscurityflags & OBSCURE_RIGHT) )

    should only return true, when i use the 4 fields A layout, with the first datafield (the top one). while it does work with that exact version, it also returns true when i use the fullscreen layout, the 4 fields B on the top 2 fields, with 3 fields a and be, both on the top most ones. and with two fields, the top most one. do you know what i am doing wrong?

  • Where do you have this code?  When you have a multi-field layout, onLayout is called for each one, then onUpdate is called.

    so in a 4 field layout, you'll see

    onLayout() then onUpdate() (field 1)

    onLayout() then onUpdate() (field 2)

    onLayout() then onUpdate() (field 3)

    onLayout() then onUpdate() (field 4)

    When debugging stuff like this, adding a few println calls can help, and maybe breakdown the if statement to see what each part is returning.