Android Multiline Input Fix (Hack using WidgetCandy keyboard and pipe)

All,

Below is a hack that solves the need for a multi-line text input box on an Android device. 

Note it requires that you have the Widget Candy GUI library

I did test it on my S3 and it works fine. Basically I use an invisible NewInput widget to receive the keyboard input which I then send through the OnChange event of the input to update the caption of the NewTextSimple widget.  I hide the NewInput widget but setting alpha to 0 and activate the keyboard by layering a “nearly” invisible white image (just a 10x10 dpi white spacer png file…attached to this post) that has the OnPress callback to activate the keyboard.

This is a hack so feel free to use it as inspiration for a better solution but at least it works. 

Cheers

Ken

------- Main.lua -----------

local composer = require “composer”
local widget = require “widget”

— Setup Widget Candy GUI lib
_G.GUI = require(“widget_candy”)
_G.GUI.LoadTheme(“theme_5”, “themes/theme_5/”)
_G.GUI.ShowTouches(true, 128, {.7,.7,1})

_G.GUI.NewTextSimple(
    {
    x           = “center”,
    y           = “30%”,
    name        = “msg”,
    theme       = “theme_5”,
    width       = “400”,
    height      = “auto”,
    caption     = “”,
    textAlign   = “left”,
    textColor   = {1,1,1},
    fontSize    = 20,
    border          = {“inset”,4,1, .7,1,.7,.25},
    } )

local shape = _G.GUI.GetShape(“msg”)

_G.GUI.NewImage( display.newImage(“space.png”),
    {
    x               = “center”,
    y               = “30%”,
    width           = shape.w,
    height          = shape.h,
    name            = “mask”,
    parentGroup     = nil,
    alpha           = 0.01,
    onPress         = function(EventData) _G.GUI.Keyboard_Show(
                        {
                            height   = “50%”,
                            target   = “tempMsg”,
                            align    = “bottom”,
                        } )
                     end,
    } )

_G.GUI.NewInput(
    {
    x               = “center”,
    y               = “top”,
    width           = “70%”,
    theme           = “theme_5”,
    name            = “tempMsg”,
    caption         = “”,
        alpha       = 0,
    notEmpty        = true,
    onChange        = function(EventData)
                             _G.GUI.Set(“msg”,{caption=EventData.value})
                        end,
    } )