1 | static boolean showPicture = true; // global switch. if false, you get the normal text display instead of the smiley |
2 | |
3 | static L<S> emotions = litlist( |
4 | "#1001283", "happy", |
5 | "#1001284", "unhappy", |
6 | "#1001285", "oh", |
7 | "#1001286", "bored", |
8 | "#1001287", "wide mouth"); |
9 | |
10 | static float statusFontSize = /*25*/17; |
11 | static float userFontSize = 25; |
12 | static float myFontSize = 25; |
13 | static int borderColor = 0xFFFFFFFF; |
14 | static S lastEmotionImage, lastEmotion /*, onScreenText = ""*/; |
15 | static ImageView emoView; |
16 | static TextView statusView, userTextView, myTextView, lblInputView; |
17 | sS statusText; |
18 | static EditText inputView; |
19 | sbool recogOnActivate = true; // start listening when app activated |
20 | |
21 | static void showText(S text) { |
22 | print(text); |
23 | /*if (neq(onScreenText, text) && lastEmotion != null) { |
24 | onScreenText = text; |
25 | emo_show(); |
26 | }*/ |
27 | } |
28 | |
29 | static void emo(S emotion) { |
30 | if (!showPicture) return; |
31 | int i; |
32 | for (i = 0; i < emotions.size(); i += 2) |
33 | if (emotions.get(i+1).equalsIgnoreCase(emotion)) |
34 | break; |
35 | if (i >= emotions.size()) { |
36 | print("Emotion not found: " + emotion); |
37 | // use the last one from the list as default |
38 | i -= 2; |
39 | } |
40 | lastEmotionImage = emotions.get(i); |
41 | lastEmotion = emotions.get(i+1); |
42 | emo_show(); |
43 | } |
44 | |
45 | static void emo_show() { |
46 | if (!showPicture) return; |
47 | |
48 | androidUI { |
49 | Runnable onClick = r { |
50 | if (!manualMode) ret; |
51 | |
52 | //if (listening) |
53 | if (borderColor != -1) { |
54 | //androidLater(500, r { stopListening(); }); |
55 | //showText("stop"); |
56 | stopListening(); |
57 | } else { |
58 | //showText ("start"); |
59 | newRecognizer(); |
60 | } |
61 | }; |
62 | |
63 | if (statusView == null) { |
64 | // init UI |
65 | |
66 | statusView = aFontSize(statusFontSize, aSetForeground(aBlack(), aCenteredTextView())); |
67 | inputView = aSingleLineEditText(); |
68 | aOnEnter(inputView, r { onInput(aGetText(inputView), true) }); |
69 | //aOnChange(inputView, f cancelRecognition); // freezes!? |
70 | //aOnChange(inputView, r { listening = false }); |
71 | //aOnChange(inputView, f cancelRecognition); |
72 | lblInputView = aFontSize(20, aBottomTextView(inputViewLabel())); |
73 | userTextView = aFontSize(userFontSize, aSetForeground(0xFF000055, aTextViewWithWindowFocusChangeNotify(voidfunc(Bool windowFocused) { |
74 | if (windowFocused && recogOnActivate) newRecognizer(); |
75 | }))); |
76 | myTextView = aFontSize(myFontSize, aSetForeground(0xFF005500, aRightAlignedTextView()); |
77 | androidShow(aVerticalLinearLayout( |
78 | statusView, |
79 | emoView = androidClickableImage(lastEmotionImage, |
80 | /*aWhite()*/borderColor, onClick), |
81 | userTextView, |
82 | myTextView, |
83 | androidPrintLogScrollView(), |
84 | aWestAndCenter(lblInputView, inputView))); |
85 | } |
86 | |
87 | if (statusText == null) statusText = baseStatus(); |
88 | aSetText(statusView, statusText); |
89 | aSetImageFromSnippet(emoView, lastEmotionImage); |
90 | |
91 | /*doEvery(1000, new Runnable { |
92 | S text = ""; |
93 | |
94 | public void run() { |
95 | S s = aGetText(inputView); |
96 | if (eq(s, text)) ret; |
97 | text = s; |
98 | cancelRecognition(); |
99 | } |
100 | });*/ |
101 | } |
102 | } |
103 | |
104 | static void setBorderAndStatus(int color, S status) { |
105 | if (color != borderColor || neq(status, statusText)) { |
106 | borderColor = color; |
107 | statusText = status; |
108 | if (lastEmotion != null) |
109 | emo(lastEmotion); |
110 | } |
111 | } |
112 | |
113 | static void setBorderColor(int color) { |
114 | if (color != borderColor) { |
115 | borderColor = color; |
116 | if (lastEmotion != null) |
117 | emo(lastEmotion); |
118 | } |
119 | } |
120 | |
121 | static void happy() { emo("happy"); } |
122 | static void unhappy() { emo("unhappy"); } |
123 | static void oh() { emo("oh"); } |
124 | static void bored() { emo("bored"); } |
125 | static void wideMouth() { emo("wide mouth"); } |
126 | |
127 | static void disappear() { |
128 | if (!showPicture) ret; |
129 | happy(); |
130 | androidLater(1000, r { |
131 | androidShowFullScreenColor(0xFFFFFFFF); |
132 | androidLater(1000, r { |
133 | System.exit(0); // totally unrecommended but works |
134 | }); |
135 | }); |
136 | } |
137 | |
138 | sS inputViewLabel() { |
139 | ret lang("Or type here:", "Oder hier tippen:"); |
140 | } |
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1001293 |
Snippet name: | Android Cat UI (include) |
Eternal ID of this version: | #1001293/55 |
Text MD5: | 17e47c9d3f2fd3108be87fb6285a5f77 |
Author: | stefan |
Category: | |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-05-21 13:47:22 |
Source code size: | 4132 bytes / 140 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 774 / 2539 |
Version history: | 54 change(s) |
Referenced in: | [show references] |