Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1001109 // Local storage android (texts + images)

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (1079L/8K/26K).

1  
!747
2  
3  
m {
4  
  static long nextID = 5000000;
5  
  
6  
  static new Map<S, S> titles;
7  
  static new Map<S, S> texts;
8  
  static new Map<S, File> images;
9  
  
10  
  p {
11  
    readLocally("nextID titles texts images");
12  
    //print("New ID: " + newID());
13  
    print("Next ID is at: " + nextID);
14  
    makeAndroid("This is the local storage android.", stringfunc {
15  
      answer(s)
16  
    });
17  
  }
18  
  
19  
  static synchronized S answer(S s) ctex {
20  
    new Matches m;
21  
    
22  
    if (match3("can you store snippets", s))
23  
      return "yes";
24  
    if (match3("what is the next snippet ID", s))
25  
      return "#" + nextID;
26  
    if (match3("what do you store on", s))
27  
      return "file system (local)";
28  
    if (match3("please create a new snippet id", s))
29  
      return newID();
30  
    if (match3("please set title for snippet * to *", s, m)) {
31  
      titles.put(formatSnippetID(m.m[0]), m.m[1]);
32  
      saveLocally("titles");
33  
      return "ok";
34  
    }
35  
    if (match3("please set text for snippet * to *", s, m)) {
36  
      texts.put(formatSnippetID(m.m[0]), m.m[1]);
37  
      saveLocally("texts");
38  
      return "ok";
39  
    }
40  
    if (match3("please load image for snippet * from *", s, m)) {
41  
      byte[] data = loadBinaryPage(m.m[1]);
42  
      File file = new File(programDir(), "images/" + formatSnippetID(m.m[0]));
43  
      saveBinaryFile(file, data);
44  
      images.put(formatSnippetID(m.m[0]), file);
45  
      saveLocally("images");
46  
      return "ok - " + data.length + " bytes loaded and saved";
47  
    }
48  
    if (match3("what is the title of snippet *?", s, m))
49  
      return titles.get(formatSnippetID(m.m[0]));
50  
    if (match3("what is the text of snippet *?", s, m))
51  
      return texts.get(formatSnippetID(m.m[0]));
52  
    if (match3("where is the image of snippet *?", s, m)) {
53  
      File f = images.get(formatSnippetID(m.m[0]));
54  
      return f != null ? f.getAbsolutePath() : "There is no image there.";
55  
    }
56  
    return "lalala";
57  
  }
58  
  
59  
  static synchronized S newID() {
60  
    S id = "#" + nextID++;
61  
    saveLocally("nextID");
62  
    return id;
63  
  }
64  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, teubizvjbppd, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1001109
Snippet name: Local storage android (texts + images)
Eternal ID of this version: #1001109/1
Text MD5: ea7e845b4dcebb9ad1ba402a34b98bff
Transpilation MD5: cd47c522eb4c32d9ed1af74520377a9c
Author: stefan
Category: javax
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2015-09-22 15:43:05
Source code size: 2039 bytes / 64 lines
Pitched / IR pitched: No / Yes
Views / Downloads: 667 / 716
Referenced in: [show references]