Widget for text input...

Yes, try a font you know to exist.  The font thing I suggested was worth a shot.  

Here’ something that might help.  In my apps that are multi-platform, I usually use my device.lua to determine if I’m a Kindle Fire, Nook, Android or iOS device.   Then I do something like:

mydata.serif = "Georgia" mydata.sans = "Helvetica" mydata.sansbold = "Helvetica-Bold" mydata.isAndroid = device.isAndroid mydata.isKindleFire = device.isKindleFire mydata.isNook = device.isNook mydata.kindlePadding = 0 if mydata.isAndroid then         mydata.serif = "DroidSerif"     mydata.sans = "DroidSans"     mydata.sansbold = "DroidSans-Bold"     if mydata.isNook then         mydata.serif = "Georgia"         mydata.sans = "AscenderSans"         mydata.sansbold = "AscenderSans"       end     if mydata.isKindleFire then         mydata.serif = "georgia"         mydata.sans = "arial"         mydata.sansbold = "arial-Bold"     end end

Then I just use the mydata.sans where I want a normal font, etc.  However I just was verifying the font names and it seems that with Ice Cream Sandwich (I really wish Google would use numbers… so that would 4.4 - KitKat, 4.3 Jelly Bean, 4.2 Ice Cream Sandwich), since 4.2 they are using a font called Roboto.  (See: http://developer.android.com/design/style/typography.html)

I suspect they added these to the Droid family but they do encourage using Roboto now, so you might be interested in putting in an OS test to see if you’re on 4.2 or later and use Roboto instead of Droid.

Rob

Hi Rob, 

Thanks for your input. I tried “DroidSans” and that did not change anything either. 

I then tried running a piece of code I had written few months ago to run on Android devices to collect their screen specifications and loaded fonts list etc. This code used to run nicely on this particular Android device. Now when I run it the font list comes back empty. The number of fonts installed is still shown correctly as 12 but somehow the font names are not showing at all. They still show on IOS devices and my Mac.

The code is using native.getFontNames() to get the font details so maybe there is something wrong with the newer builds that is breaking something like this on an older Android 2.2 device. Not sure how best to troubleshoot this. 

Just to rule out recent changes I went back to an older build, 2013.1232 to be specific and the font names not showing issue is still there. Can’t recall the build I used this code with last but I am sure it was working at some point. Oh well. Need to look it over and see what is wrong with it now.

Edit : Just printing out the fonts on device give me a nice list once again. The following is the list I get :

DroidSansFallback
DroidSansThai
DroidSansHebrew
DroidSerif-Regular
DroidSansArabic
DroidSans-Bold
DroidSerif-Bold
Clockopia
DroidSerif-Italic
DroidSans
DroidSerif-BoldItalic
DroidSansMono

So nothing wrong with the device or the core Corona SDK functions relating to accessing the fonts. The scaling is somehow not working.

Try one more thing for me:

Change:

field.textField.font = native.newFont( opt.font  )

to:

field.textField.font = native.newFont( opt.font, opt.fontSize * deviceScale )

native.newFont can take a size passed to it.  So it’s worth a shot.   Also I just went back and looked at your screen shots and it looks like the font is the right size, it’s just showing a few pixels from the bottom of it.  Are you seeing a tiny font or a cut off font?

Thanks

Rob

Hi Rob, 

Tried this code variation. Same result. 

You are right. The font size is probably not too far off. It just seems to display the lower 1/5th of the text or so. It appears that the whole text is offset vertically with the top of text being cut off at the natural border of the native.newTextField.

Hope this helps.

Rob, just to try something else… I built and loaded the Corona Labs sample called NativeDisplayObjects and loaded it onto this same device. The text field displays beautifully. Font, placement and all. Need to see what is different there. 

Interesting.   In that sample app is this code:

local isAndroid = “Android” == system.getInfo(“platformName”)

            local tHeight = 30
            if isAndroid then tHeight = 40 end        – adjust for Android
            textField = native.newTextField( 15, 80, 280, tHeight )

So they are adding 10 pixels to the height of the box.  Now I’m not sure if they are adding 25% or 10px. It could be either.  Perhaps you could change this line:

    field.textField = native.newTextField(0, 0, opt.width - opt.cornerRadius, opt.height - opt.strokeWidth * 2)

to:

    local tHeight = opt.height - opt.strokeWidth * 2

    if “Android” == system.getInfo(“platformName”) then

         tHeight = tHeight * 1.25

    end

    field.textField = native.newTextField(0, 0, opt.width - opt.cornerRadius, tHeight )

This is a 25% increase.  I’m going to guess that it’s 25% and not 10px.

Rob

Ok. This is definitely helping. Now I get about %60 of the text visible. See attached screenshot.

Instead of a percent, make it 10 and see if that does the trick. 

Do you mean something like this?

if “Android” == system.getInfo(“platformName”) then

tHeight = tHeight + 10

end

Yes!!! tHeight = tHeight + 10 did the trick. I can now see all of the text entered.

So the question is why this issue did not affect the newer Android that you tested on and affected this particular one and how can the inputText tutorial be improved to cater for all. 

Thanks for your continued efforts to give us something we can rely on.

I seem to remember something from a couple of years ago that had to do with the fact that Android’s “chrome” around native widgets was different and needed compensated for.  I guess as more people move to a 4.x version, this is less important.    I’ll go update the blog post to add this adjustment for people grabbing it in the future.

Rob

So can we live with one version that runs on all Android devices and does tHeight = tHeight + 10  or do we need to determine if Android version is < 4.x and then do tHeight = tHeight + 10? If Android 4.x and later will not have the same problem the code needs to be selective right?

I think it will be fine on all Android devices, since we have the background off, it won’t matter.

Rob

Ok. Its best to try on your newer Android device and see how it goes then before committing. Look forward to your findings. Thanks much!

It’s fine on my Nexus 7 running 4.4

Rob

Super. Then the code used in CL NativeDisplayObjects sample 

local tHeight = 30 if isAndroid then tHeight = 40 end

is a viable solution for all Android editions. Glad we could get to the bottom of this.

Going back to the original topic… The feature request votes now stand at 296 + 167 for this very much sought out capability. Rob’s tutorial was a good start in the right direction but I sure hope it won’t be the last we hear from Corona Labs on this key topic. Bumping this one up so it can get some more attention and votes. Thank you!!! 

Anyone know when the finalize event was added ?

Am using 1202 (last public release before Graphics 2) and can’t get it to fire using Robs example.

The problem am having is adding the code to a StoryBoard Overlay and getting it to disappear when the overlay closes.

I have added textField.RemoveSelf() to exitScene but that does nothing, you can still see the text on the screen when the overlay closes.

Dave

I’m not sure when it was added, but my sample was only tested on 2076 and later.   You can use a technique where you override the removeSelf() function on the field group by making a copy of removeSelf() then writing yours that removes the native.newTextField() then calls the saved real removeSelf().

There will be other G2.0 vs. G1.0 changes that will need to be made as well.

Rob