My input text is cut off halfway on some Android devices!! PLS HELP!

OK T, I think I got it. I only have an iPad retina and a motorola atrix to test on, but the font size looks identical (scaled I mean, irl the ipad font is much larger because it’s scaled up like my other content).

But the font really does look identical on these devices. I have plugged in screen height numbers for the other iOS devices which I think are correct, but I’ll have to test on the devices.

For droid, it retrieves the screen height as in your post above, and uses that to do the calc. The code also compensates for corona chopping off the top and bottom of the screen to map the virtual content into. Only seen that code execute on my droid atrix, and it seems to be right, but I’ll need to try it on some other devices to make sure all my add/subtract stuff is correct. Font size looks perfect (relative to my other content) on my atrix though (identical to how it appears on my retina ipad).

[lua]

    print(" – calcFontSize()")
    print("-----------------------" )    
            
    local sysType = system.getInfo(“architectureInfo”)
    print(" – sysType == “, sysType)            
    print(” – display.contentScaleY  == “, display.contentScaleY )
    print(” – display.screenOriginY  == “, display.screenOriginY )          
    
    inputFontSize = targetFontSize / display.contentScaleY    – old method is fallback (ends up being sim setting)
    
    if( utils.isAndroid == true ) then      – try and get the real width / height and deal with it            
        print(” – -- Android font size calc…")
        
        local missingInches = display.screenOriginY * -2     – account for both top and bottom area (x2), and change the sign sign since originY is always negative, if it exists…
        
        missingInches = missingInches / 320             – 320 is 1 inch, in my 640x960 virual content space (960 == 3 inches for my app, designed for a standard iphone 4 display)        
                                                        – different contentScale sizes will use a different virtual pixel / inch value (eg, 320x480 virtual content = missingInches / 160)
        print(" – missing inches == “, missingInches)
        
        local fontScale = 1
        local heightIn = system.getInfo( “androidDisplayHeightInInches” )
        local widthIn = system.getInfo( “androidDisplayWidthInInches” )
        print(” – original height == “, heightIn)
        
        heightIn = heightIn - missingInches               
     
        --Make sure its not nil… e.g. the simulator will return nil, perhaps some bad devices will too…
        if heightIn ~= nil then
            – heightIn is height of actual droid app is running on
            fontScale =  heightIn / 3.0 – 3.0 is actual iPhone 3gs /4 /4s height
            print(” – fontsize set on actual droid screen inch height")
            print(" – widthIn = “, widthIn)
            print(” – heightIn = “, heightIn)
        else
            fontScale = 4/3  --Default to a 4 inch diagonal (iphone is 3.0)
            print(” – fontsize set to 4 inch phone size")
        end
        
        print(" fontScale == “, fontScale)
        inputFontSize = targetFontSize*fontScale            
    else                                    – else is iOS
        print(” – -- iOS font size calc…")
        local fontScale = 1
        local heightIn = 3                                  – default to stnadard iPhone size        

        local missingInches = display.screenOriginY * -2    – account for both top and bottom area (x2), and change the sign sign originY is negative, if it exists…
        
        missingInches = missingInches / 320             – 320 is 1 inch, in my 640x960 virual content space (960 == 3 inches for my app, designed for a standard iphone 4 display)
                                                        – different contentScale sizes will use a different virtual pixel / inch value (eg, 320x480 virtual content = missingInches / 160)        
        print(" – missing inches == ", missingInches)

        –
        – Since there is no corona facility to get the screen height of the device on iOS, we’ll determine it ourselves.
        –
        if( sysType == “iPhone2,1” ) then       – 3GS        
            heightIn = 3.0 - missingInches      – original iPhone size
            print(" – iPhone 3GS detected")        
        elseif( string.match(sysType, “iPhone3”) or string.match(sysType, “iPhone4”) ) then       – iPhone 4, 4S        
            heightIn = 3.0 - missingInches      – Same size as the old 3gs- better resolution, but same size
            print(" – iPhone 4 detected")        
        elseif( string.match(sysType, “iPhone5”)  ) then       – iPhone 5
            heightIn = 4.0 - missingInches      – Should go back to 3, after missing inches chopped off by corona are deducted.
            print(" – iPhone 5 detected")      – This phones screen is taller, a little… Corona will end up chopping it off though
        elseif sysType == “iPad2,5” or sysType == “iPad2,6” or sysType == “iPad2,7” or sysType == “iPad2,8” then    – 2,8 is unknown, just a guess at next mini #
            heightIn = 6.25 - missingInches     – mini
            print(" – iPad mini detected")     – A good amount taller. Need a much bigger point size for this device, for the input fonts to look scaled right     
        elseif( string.match(sysType, “iPad”) ) then       – standard iPad
            heightIn = 7.75 - missingInches     – iPad
            print(" – iPad detected")          – MUCH taller screen, really gonna need to scale fonts up in point size for this bad boy (or they will look less than half size for the field)
        else
            print(" – unrecognized iOS device, using default 3.5 inches tall") – iPods will fall to here, they are 3.5 anyways…
            if( missingInches == 0 ) then
                – iPod falls through to here (and it is 3 inches tall, and any missing inches accounted for in a tall version, so that works for now)
                heightIn = 3.0 - missingInches  – I would hope this is typical, zero extra on an unknown ios device
            else
                heightIn = 4.0 - missingInches  – otherwise, we’ll take a flying guess that the unknown device is bigger than a tiny breadbox, and smaller than a car. (4 inches tall, iphone 5 format)
            end
        end        

        fontScale =  heightIn / 3.0                 – 3.0 inches is actual iPhone 4 height (that my content is based on)
        inputFontSize = targetFontSize*fontScale            
    end
                
    print(" – final fontsize == “, inputFontSize)
    print(”-----------------------" )    

    return inputFontSize

[/lua]

So the big question to me is, are there many droid devices actually reporting the *wrong* height. If so, then this might not work out. If, however, they are returning the right height (but it was being used as if it were diagonal height, or some other mistake), then this should work mint.

what is your config.lua like? 

What device are you running on? 

Can you post your code that creates your native.newTextField?

Thanks for the response Rob.
Btw, I am using your “Ultimate Config.lua” code. And I am building it on Nexus 7, so I can tweak it into different resolutions.
Here is a part of my code: 

yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.45), 35) yearIF.font = native.newFont( native.systemFont, \_G.fontSize ) yearIF.size = \_G.fontSize yearIF.text = "" yearIF:setTextColor( 81, 81, 81 ) yearIF.inputType = "number"

my _G.fontSize is like this: 
 

\_G.fontSize = 12 / display.contentScaleY

 

In regards to dpi, i meant that phones reporting the incorrect width and height may also return the incorrect dpi. Therefore you could check the actual versus reported dpi to see if you need to consider that phone as “dodgy”.  If they are wildly different you know that the calculations your doing above won’t be correct for that phone and that you should go back to the default 4 inch height. I’ll need to test that on a few devices to see if theres anything to it though…

You codes looking good! I’ll give that a go shortly. This may be me being a little stupid, but why exactly do you need to calculate the missing height when you are already setting the height in inches to the correct value? 

And finally when it comes to Android devices i’m afraid there probably is a fair few who give the wrong height. My Samsung S3 mini i use for testing does, my clients Galaxy Ace (i think thats the one) does and also his Droid Razr. Considering we only have about 7 Android devices between us three of them being wrong is a pretty considerable percentage. All of those devices return the wrong height and width which was throwing off my original diagonal calculation. Therefore some kind of validation check for each device would be handy, maybe the dpi check may work but i’m hoping theres some more options to try out as well. 

Heya T,

missingInches represents the amount in the borders above and below the app, the little apron corona makes above and below your app. When you use content scaling, corona determines if the device aspect ratio is the same as your and of not, maps your app inside - leaving that area unused (as you know, I’m sure).

So now, your app is mapped to a smaller height than the entire screen. To calculate the correct (and proportionally accurate) font size for this smaller area (smaller inches), a reduction needs to be made (called missing inches). If this is not removed, the font will be a little too large (it would be calculated as if the app were stretched to the whole screen without this reduction.) Hope that all makes sense.

Thanks for the tip on DPI, I’ll look into it. Also, curious as to what specific incorrect values you have seen, as in - what specifically did it report the height of the S3, Galaxy Ace, and / or droid razr report?

Is that working for you?

Too bad, it is still not working well for me. I tried to change the font size formula to 10 / display.contentScaleY , but still the text is cut off halfway… please help!
 

All of these “fixed” are workarounds for broken textfield components. This is a rather well-known problem I heard about before I even downloaded the sdk.

This is a problem with Android and if you search on Google you will find a 100 different hacks in native code to try and deal with it. I do not know if any of them deal with it correctly or how much research Corona devs have put into testing them to get a good Corona’sized solution. I do know handling it now in Corona is a ridiculous pain or at least my initial work into it was.

In the end I had to use a brute force method. By testing and retesting on every device size and dpi available to me I came up with a number to adjust the text size to fit the textbox’s height on whichever device it is currently loaded on. It’s a horrible hack and has not been tested in a released app yet.

What blows my mind is that the OS doesn’t handle this on it’s own somehow. If the text is too tall for the textbox, the textbox should resize to fit, regardless of what the programmer has set the size to be. Also if no font size is put at all it should auto-size the text to fit the padding of the textbox on it’s own. I can think of no circumstance where anyone would want to put text in a textbox that is cut off.

It worked for me:

local fontSize = 12 / display.contentScaleY print(fontSize) print(display.contentScaleY)     local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.45), 35)     yearIF.font = native.newFont( native.systemFont, \_G.fontSize )     yearIF.size = fontSize     yearIF.text = ""     yearIF:setTextColor( 81, 81, 81 )     yearIF.inputType = "number"

It printed:

I/Corona  (28615): 25.457746386707
I/Corona  (28615): 0.47136929631233

and here is what I got:

android.png

This was on my Google Nexus 7.  The config.lua for this test was:

    application =     {         content =         {             width = 320,             height = 568,             scale = "letterBox",             --xAlign = "center",             --yAlign = "center",             imageSuffix =             {                 ["@2x"] = 1.5,                 ["@4x"] = 3.0,             },         },     }

For fun, I did the test with the config.lua in the Ultimate Config.lua and it produced the same thing.

@Anderoth yeah it is a big problem for us … 

@Rob hmm I am currently having a problem for those devices that have a resolution of 320x480 below ( especially 240x320 ) . In what resolution did you tested it on?

@09.SemperFidelis, what is your config.lua like?  What is your code where you are creating the native text field?  What device are you using?  What version of Corona SDK?

Hi Rob! I already posted my config.lua, textfield code, and test-device in this thread. Hmm my Corona version is 2013.1076. Is that the correct version code?
I found a little solution for my problem: 

in my main.lua I have this little code:

\_G.fontSize = 12 / display.contentScaleY if display.pixelWidth \<= 240 and display.pixelHeight \<= 320 then \_G.fieldSize = 40 elseif display.pixelWidth \<= 320 and display.pixelHeight \<= 480 then \_G.fieldSize = 37 elseif display.pixelWidth \<= 480 and display.pixelHeight \<= 800 then \_G.fieldSize = 34 else \_G.fieldSize = 30 end

and for my native text field(s):
 

 yearIF = native.newTextField( (display.contentWidth / 2), 190, (display.contentWidth\*0.45), \_G.fieldSize) yearIF.font = native.newFont( native.systemFont, \_G.fontSize ) yearIF.size = \_G.fontSize yearIF.text = "" yearIF:setTextColor( 81, 81, 81 ) yearIF.inputType = "number" yearIF:addEventListener( "userInput", fieldHandler )

– But I still have a little problem on the 240x320 device resolutions…

For Android devices why don’t you do something like the following:

[lua]

    local textBoxScale = 1

    local textBoxFontSize = 16

    local widthIn = system.getInfo( “androidDisplayWidthInInches” ) 

    local heightIn = system.getInfo( “androidDisplayHeightInInches” ) 

    --Make sure its not nil… e.g. the simulator will return nil.

    if widthIn ~= nil and heightIn ~= nil then 

        local diagIn = math.sqrt((widthIn*widthIn)+(heightIn*heightIn))  --Diagonal in inches

        textBoxScale = diagIn/3.5   --3.5 is the iphones diagonal in inches…

    else

        textBoxScale = 4/3.5  --Default to a 4 inch diagonal.

    end

    textBoxFontSize = textBoxFontSize*textBoxScale

[/lua]

Some Android devices don’t actually give you the correct width and height, but you can run extra checks against the  device name to do those manually. I haven’t actually tested the exact code above, but if your using letterBox and 480x320 in config then i don’t see why it wouldn’t work :slight_smile:

[Edit]

ps. I forgot to mention that changing the font size based off the contentScaleY variable will not work in a lot of cases if your using a plain config with scaling and a size of 480x320. For example without any changes to the font size it will fit on both the iPhone3GS and the iPhone4 perfectly despite the latter having twice the pixel resolution. If your using the contentScale to base your font size off and not the diagonal in inches, your iPhone4 text would be twice the size as a iPhone3GS. Therefore using the actual inches of the device is the way to go in my opinion. I’ve just started setting up a more advanced version of the above in my code so i’ll test it on multiple devices to see how it goes!

If you want, I’ve got few devices with different resolutions I could test that for you [both tablets and phones], just send me links to your test apks in private messages.

@TandG – thanks a lot bro! I’ll try your code!
@krystian6 – thanks! but I can test my apk into different resolutions with our Nexus 7 :slight_smile:

Are you changing the nexus 7 resolution some how?

yes! using some command prompt thingy while connected on my device. For example: 
 

adb shell am display-size 320x480 adb shell am display-density 165

Well first, I think you need Android SDK and NDK running in your computer. And just a reminder, this is only a simulation, results may vary in an actual device with that resolution,

@TandG , @mpappas
As a very young developer, Ive learned a lot from you guys. Thanks a lot! 
By the way, I am receiving an error on:

local heightIn = system.getInfo( "androidDisplayHeightInInches" )

as well as on widthIn. They are returning nil in my device. Any ideas?

@09.SemperFidelis - Thanks for the props!

What device is returning the nil? Specifically, what model and Android OS version is it?

Where there any issues from Apple review team for those that have done the solution where the real input input is hidden and using a rect as a “fake” input? Seeing that the text is not selectable and it may not look exactly native.