diff --git a/apps/kbmulti/ChangeLog b/apps/kbmulti/ChangeLog new file mode 100644 index 000000000..04b2430bb --- /dev/null +++ b/apps/kbmulti/ChangeLog @@ -0,0 +1 @@ +0.01: New keyboard diff --git a/apps/kbmulti/README.md b/apps/kbmulti/README.md new file mode 100644 index 000000000..0c4d0ef73 --- /dev/null +++ b/apps/kbmulti/README.md @@ -0,0 +1,8 @@ +# Multitap Keyboard + +A library that provides the ability to input text in a style familiar to anyone who had a mobile phone before they went all touchscreen. + +Uses the multitap keypad logic originally from here: http://www.espruino.com/Morse+Code+Texting + +![](screenshot.png) + diff --git a/apps/kbmulti/app.png b/apps/kbmulti/app.png new file mode 100644 index 000000000..5607a0553 Binary files /dev/null and b/apps/kbmulti/app.png differ diff --git a/apps/kbmulti/lib.js b/apps/kbmulti/lib.js new file mode 100644 index 000000000..ea7bf9ec3 --- /dev/null +++ b/apps/kbmulti/lib.js @@ -0,0 +1,110 @@ +//Multitap logic originally from here: http://www.espruino.com/Morse+Code+Texting + +exports.input = function(options) { + options = options||{}; + var text = options.text; + if ("string"!=typeof text) text=""; + + var fontSize = "6x15"; + var Layout = require("Layout"); + var letters = { + "1":".,!?1","2":"ABC2","3":"DEF3", + "4":"GHI4","5":"JKL5","6":"MNO6", + "7":"PQRS7","8":"TUV8","9":"WXYZ9", + "0":"_@:/0" + }; + + var charTimeout; // timeout after a key is pressed + var charCurrent; // current character (index in letters) + var charIndex; // index in letters[charCurrent] + var caps = true; + var layout; + //var text = ""; + + function displayText() { + layout.clear(layout.text); + layout.text.label = text; + layout.render(layout.text); + } + + function backspace() { + // remove the timeout if we had one + if (charTimeout!==undefined) { + clearTimeout(charTimeout); + charTimeout = undefined; + } + text = text.slice(0, -1); + newCharacter(); + } + + function setCaps() { + caps = !caps; + for (var key in letters) { + layout[key].label = caps ? letters[key].toUpperCase() : letters[key].toLowerCase(); + } + layout.render(); + } + + function newCharacter(ch) { + text = text.replace("_", " "); + displayText(); + charCurrent = ch; + charIndex = 0; + } + + function onKeyPad(key) { + // remove the timeout if we had one + if (charTimeout!==undefined) { + clearTimeout(charTimeout); + charTimeout = undefined; + } + // work out which char was pressed + if (key==charCurrent) { + charIndex = (charIndex+1) % letters[charCurrent].length; + text = text.slice(0, -1); + } else { + newCharacter(key); + } + var newLetter = letters[charCurrent][charIndex]; + text += (caps ? newLetter.toUpperCase() : newLetter.toLowerCase()); + displayText(); + // set a timeout + charTimeout = setTimeout(function() { + charTimeout = undefined; + newCharacter(); + }, 750); + } + return new Promise((resolve,reject) => { + layout = new Layout( { + type:"v", c: [ + {type:"txt", font:"10%", label:"", id:"text", filly:1, fillx:1}, + {type:"h", c: [ + {type:"btn", font:fontSize, label:letters[1], cb: l=>onKeyPad(1), id:'1', fillx:1 }, + {type:"btn", font:fontSize, label:letters[2], cb: l=>onKeyPad(2), id:'2', fillx:1 }, + {type:"btn", font:fontSize, label:letters[3], cb: l=>onKeyPad(3), id:'3', fillx:1 }, + ]}, + {type:"h", c: [ + {type:"btn", font:fontSize, label:letters[4], cb: l=>onKeyPad(4), id:'4', fillx:1 }, + {type:"btn", font:fontSize, label:letters[5], cb: l=>onKeyPad(5), id:'5', fillx:1 }, + {type:"btn", font:fontSize, label:letters[6], cb: l=>onKeyPad(6), id:'6', fillx:1 }, + ]}, + {type:"h", c: [ + {type:"btn", font:fontSize, label:letters[7], cb: l=>onKeyPad(7), id:'7', fillx:1 }, + {type:"btn", font:fontSize, label:letters[8], cb: l=>onKeyPad(8), id:'8', fillx:1 }, + {type:"btn", font:fontSize, label:letters[9], cb: l=>onKeyPad(9), id:'9', fillx:1 }, + ]}, + {type:"h", c: [ + {type:"btn", font:fontSize, label:letters[0], cb: l=>onKeyPad(0), id:'0', fillx:1 }, + {type:"btn", font:fontSize, label:"^", cb: l=>setCaps(), id:'caps', fillx:1}, + {type:"btn", font:fontSize, label:"<", cb: l=>backspace(), fillx:1 }, + ]}, + ] + },{back: ()=>{ + Bangle.setUI(); + g.clearRect(Bangle.appRect); + resolve(text); + }}); + g.clearRect(Bangle.appRect); + layout.render(); + }); +}; \ No newline at end of file diff --git a/apps/kbmulti/metadata.json b/apps/kbmulti/metadata.json new file mode 100644 index 000000000..419824578 --- /dev/null +++ b/apps/kbmulti/metadata.json @@ -0,0 +1,14 @@ +{ "id": "kbmulti", + "name": "Multitap keyboard", + "version":"0.04", + "description": "A library for text input via multitap/T9 style keypad", + "icon": "app.png", + "type":"textinput", + "tags": "keyboard", + "supports" : ["BANGLEJS2"], + "screenshots": [{"url":"screenshot.png"}], + "readme": "README.md", + "storage": [ + {"name":"textinput","url":"lib.js"} + ] +} diff --git a/apps/kbmulti/screenshot.png b/apps/kbmulti/screenshot.png new file mode 100644 index 000000000..11788ad87 Binary files /dev/null and b/apps/kbmulti/screenshot.png differ