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

Engineering made a suggestion:

   – Determine the content height for the following font size.

   local fontSize = 22

   local textToMeasure = display.newText(“X”, 0, 0, native.systemFont, fontSize)

   local textHeight = textToMeasure.contentHeight

   textToMeasure.removeSelf()

   textToMeasure = nil

Then use textHeight + some padding for native.newTextField().  I’ve not tried this, but then it’s not an issue on my devices.

Rob

config.lua:

application = { content = { width = 800, height = 1200, scale = "letterBox", }, }

main.lua:

local fontSize = 22 local textToMeasure = display.newText("X", 0, 0, native.systemFont, fontSize) local textHeight = textToMeasure.contentHeight textToMeasure:removeSelf() textToMeasure = nil textHeight = textHeight + 40 local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.5), textHeight) yearIF.font = native.newFont( native.systemFont, fontSize) --yearIF.size = fontSize yearIF.text = "" yearIF:setTextColor( 81/255, 81/255, 81/255 )

Here is my testresult.

Thanks,

Thomas

I’m at a loss.  That code runs perfectly on my Nexus 7 and Kindle Fire.  I looked around for a device setting that might impact it and didn’t find any thing.  Let me share this screen shot with the Engineers and see if they have any ideas.

Thanks

Rob

Oh, try changing your “letterBox” to “letterbox” and see if that has any impact.

Hi Rob,

thanks for your help. changing “letterBox” to “letterbox” did not help. If i change the config.lua to 320x480 the result is perfect. Please see attachment. (and textHeight was only textHeight + 10).

Can you also get the values for these:

system.getInfo(“androidDisplayApproximateDpi”)

system.getInfo(“androidDisplayWidthInInches”)

system.getInfo(“androidDisplayHeightInInches”)

system.getInfo(“androidDisplayXDpi”)

system.getInfo(“androidDisplayYDpi”)

Rob

code:

local fontSize = 22 local textToMeasure = display.newText("TEST0123456", (display.contentWidth / 2), 100, native.systemFont, fontSize) local textHeight = textToMeasure.contentHeight --textToMeasure:removeSelf() --textToMeasure = nil local function onComplete( event ) if event.action == "clicked" then local i = event.index if i == 1 then -- Do nothing; dialog will simply dismiss end end end local output = system.getInfo("androidDisplayApproximateDpi") .. ", " .. system.getInfo("androidDisplayWidthInInches") .. ", " .. system.getInfo("androidDisplayHeightInInches") .. ", " .. system.getInfo("androidDisplayXDpi") .. ", " .. system.getInfo("androidDisplayYDpi") local alert = native.showAlert( "Corona", output, { "OK" }, onComplete ) textHeight = textHeight + 60 local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth\*0.5), textHeight) yearIF.font = native.newFont( native.systemFont, fontSize) yearIF.size = fontSize yearIF.text = "" yearIF:setTextColor( 81/255, 81/255, 81/255 ) --yearIF.inputType = "number"

Results see attachments.

If i add a value of 60 to tHeight the text is perfect. but why is my Input text so much higher than the text in Display.newText (same font size for both)? It seems to me that the Input text “thinks” that i have only 320x480 resolution.

But I’m testing it on a 800x1200 content area just like you are and it’s working.  Your Nexus 4 is a 320 dot per inch device, where my Nexus 7 is more like 213.

Hi Rob,

i have the same issue on my oneplus one (dpi is 403). But on my Samsung galaxy tab S (dpi 286) it is working.

When i change the content area to 320x480 then it works on all 3 devices. Looks like a very strange scaling bug in corona.

Actually has to do with scaling, or more precisely the lack of scaling.  Engineering worked out some Lua code to make it fit but it has some restrictions.  They think there are some things that they can do to fix this, but it will likely be a breaking change so they are trying to figure out the best way to handle it.

fontSize = fontSize / (system.getInfo(“androidDisplayApproximateDpi”) / 160)

yearIF.font = native.newFont( native.systemFont, fontSize)

Can you try that and see if it’s any better?

Hi Rob,

i tried it and there is no improvement. But the not scaling native textfield is not my real problem. With some calculations it is possible to calculate the font size for the different content sizes. But the big issue is the textHeight of the native textfield. there is no correct calculation for that. Sometimes i have to take textHeight = 4 x fontSize. Why?? sometimes it is ok wenn i only add  (textHeight + 15) some litle padding. If i have the resolution 320x480 only adding some constant values of 15 works great for all fontSizes. But in 800x1200 for every fontsize and devices you need different text heights. Why. that makes no sense for me and therefore i think it is a Corona bug. Perhaps corona scales something (font size) in native.newTextField but does not scale the height of the Input field?

So to sum up. I need no scaling for the native.newTextField. I only need a predictable text height for content areas bigger than 320x480.

Ok, i give up. I have no idea what corona is doing internally when executing native.newTextField.

I have tried the following simple code on my 2 devices (Nexus 4 and Samsung galaxy Tabs) with the 2 resolutions 320x480 and 800x1200. Please see attached results. Does this make any sense?

local fontSize = 22
textHeight = fontSize + 20
local yearIF = native.newTextField( (display.contentWidth / 2), 180, (display.contentWidth*0.5), textHeight)
yearIF.font = native.newFont( native.systemFont, fontSize)

Basically there is a lack of scaling problem.  If its okay with you, I’m going to email you two samples. Lets see if it solves the problems or not.  This isn’t production ready code.  I need to know if your nexus 4 has issues with it.  

Rob

Hi,

i am also not able to get it working. I only need a simple highscore text input field which works on all devices. I use the following config file:

application = { content = { width = 800, height = 1200, scale = "letterBox", fps = 60, imageSuffix = { ["@2x"] = 1.3, }, }, }

with the “standard” (320x480) config file the solutions and also the CoronaSDK > SampleCode > Interface > NativeKeyboard are working. But not with my 800x1200 config.

Any help is very appreciated. Thanks.

Thomas

Can you give us a better description or screen shots or something more than “it’s not working”.

Rob

Hi Rob,

i tried it with your example on the second page but with my config file (800x1200). Here is the code:

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

I only changed the font size from 12 to 22 and set the height of the text field to 3*fontSize.

The result on a Nexus 4 is that the text is cut off halfway. Is there any formula how big the height of the text field must be compared to the font size? 3*fontSize seems not enough.

P.S.

If i take your original values:

local fontSize = 12 / display.contentScaleY

and height of text = 35 i do not see any chars in the text field with my config file.

Android has more “chrome” around their text fields that have to be accounted for.  If you look at the native.textField sample apps you will see for Android we add some extra height.  It’s not predictable as to how much you need because all android devices are different.

Rob

So if the text height is not predictable native.newTextField is useless. It is very frustrating. I only need a highscore name input field. What is your implementation in your apps? 

If you’re on Android, make the field height higher, perhaps 50% + 10-12 pixels.  So if your iOS field is 30 pixels high, then on Android make it 55 pixels.

Rob

Hi Rob,

that would be great if it would be so easy. But if you have a look at my example my height was three times bigger ( fontSize*3) than the font size and that was not enough on my device. At the moment i believe the native objects do only work with 320x480.

Is there any save calculation for the dependency between font size and text field height (config is 800x1200)? ny Little example would be helpful.

Thanks

Thomas