!747 m { static long nextID = 5000000; static new Map titles; static new Map texts; static new Map images; p { readLocally("nextID titles texts images"); //print("New ID: " + newID()); print("Next ID is at: " + nextID); makeAndroid("This is the local storage android.", stringfunc { answer(s) }); } static synchronized S answer(S s) ctex { new Matches m; if (match3("can you store snippets", s)) return "yes"; if (match3("what is the next snippet ID", s)) return "#" + nextID; if (match3("what do you store on", s)) return "file system (local)"; if (match3("please create a new snippet id", s)) return newID(); if (match3("please set title for snippet * to *", s, m)) { titles.put(formatSnippetID(m.m[0]), m.m[1]); saveLocally("titles"); return "ok"; } if (match3("please set text for snippet * to *", s, m)) { texts.put(formatSnippetID(m.m[0]), m.m[1]); saveLocally("texts"); return "ok"; } if (match3("please load image for snippet * from *", s, m)) { byte[] data = loadBinaryPage(m.m[1]); File file = new File(programDir(), "images/" + formatSnippetID(m.m[0])); saveBinaryFile(file, data); images.put(formatSnippetID(m.m[0]), file); saveLocally("images"); return "ok - " + data.length + " bytes loaded and saved"; } if (match3("what is the title of snippet *?", s, m)) return titles.get(formatSnippetID(m.m[0])); if (match3("what is the text of snippet *?", s, m)) return texts.get(formatSnippetID(m.m[0])); if (match3("where is the image of snippet *?", s, m)) { File f = images.get(formatSnippetID(m.m[0])); return f != null ? f.getAbsolutePath() : "There is no image there."; } return "lalala"; } static synchronized S newID() { S id = "#" + nextID++; saveLocally("nextID"); return id; } }