Android Question Int To DIP

Discussion in 'Android Questions' started by LordZenzo, Jun 5, 2019.

  1. LordZenzo

    LordZenzo Well-Known Member Licensed User

    this simple operation generates an error in the compilation
    Code:
    LS1.Padding=Array (6.7%x ,0dip,0dip,0dip) [\CODE]

    in the forum I found this solution
    [CODE]
    Sub IntToDIP(Integer As Int) As Int 
       
    Dim DIP As Int
       DIP = Integer * 
    1dip
       
    Return DIP
    End Sub
    [\CODE]
     
  2. Star-Dust

    Star-Dust Expert Licensed User

    To have greater precision and avoid the rounding of 1Dip, Erel suggested to work 100dip / 100.
    The error is perhaps generated by the fact that you use reserved KeyWords

    Code:
    Sub IntToDIP(Value As Int) As float
        
    Return Value*(100dip/100)
    End Sub
     
  3. LordZenzo

    LordZenzo Well-Known Member Licensed User

    no
    this is error in the compilation

    LS1.Padding=Array(IntToDIP(4%x),0dip,0dip,0dip)
    javac 1.8.0_131
    src\com\iliad\gilo\main.java:493: error: incompatible types: Object[] cannot be converted to int[]
    parent.mostCurrent._ls1.setPadding((int[])(new Object[]{(Object)(_inttodip(anywheresoftware.b4a.keywords.Common.PerXToCurrent((float) (4),mostCurrent.activityBA))),(Object)(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0))),(Object)(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0))),(Object)(anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (0)))}));
     
  4. Star-Dust

    Star-Dust Expert Licensed User

    Try it
    Code:
    Dim V as Int =IntToDIP(4%x)
    LS1.Padding=
    Array(V,0dip,0dip,0dip)
     
    jimmyF likes this.
  5. LucaMs

    LucaMs Expert Licensed User

    LS1.Padding = Array As Int (6.7%x ,0dip,0dip,0dip)
     
    Erel, Jorge M A, jimmyF and 1 other person like this.
  6. LordZenzo

    LordZenzo Well-Known Member Licensed User

    what a shame, a beginner's mistake
     
  7. emexes

    emexes Well-Known Member Licensed User

    Super-minor point, but... I think this function converts DIPs to P(ixel)s, ie, the opposite of its name.

    Perhaps rename it to DIPToPixel() or PixelFromDIP().
     
  8. emexes

    emexes Well-Known Member Licensed User

    Whilst down in the mud of pedant detail here...

    Since DIP's are defined as 160 per inch, I've been using 160DIP / 160 as the conversion factor, which likely cancels out an integer rounding based on the DIP suffix probably being equivalent to the integer operations: * DevicePPI / 160.

    On the one hand, we're only talking about being one pixel out; on the other hand, sometimes one pixel errors stand out like a star in the night sky, especially if there's a line of them.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice