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

140
LINES

< > BotCompany Repo | #1001293 // Android Cat UI (include)

JavaX fragment (include)

static boolean showPicture = true; // global switch. if false, you get the normal text display instead of the smiley
  
static L<S> emotions = litlist(
  "#1001283", "happy",
  "#1001284", "unhappy",
  "#1001285", "oh",
  "#1001286", "bored",
  "#1001287", "wide mouth");
  
static float statusFontSize = /*25*/17;
static float userFontSize = 25;
static float myFontSize = 25;
static int borderColor = 0xFFFFFFFF;
static S lastEmotionImage, lastEmotion /*, onScreenText = ""*/;
static ImageView emoView;
static TextView statusView, userTextView, myTextView, lblInputView;
sS statusText;
static EditText inputView;
sbool recogOnActivate = true; // start listening when app activated

static void showText(S text) {
  print(text);
  /*if (neq(onScreenText, text) && lastEmotion != null) {
    onScreenText = text;
    emo_show();
  }*/
}
  
static void emo(S emotion) {
  if (!showPicture) return;
  int i;
  for (i = 0; i < emotions.size(); i += 2)
    if (emotions.get(i+1).equalsIgnoreCase(emotion))
      break;
  if (i >= emotions.size()) {
    print("Emotion not found: " + emotion);
    // use the last one from the list as default
    i -= 2;
  }
  lastEmotionImage = emotions.get(i);
  lastEmotion = emotions.get(i+1);
  emo_show();
}

static void emo_show() {
  if (!showPicture) return;
  
  androidUI {
    Runnable onClick = r {
      if (!manualMode) ret;
      
      //if (listening)
      if (borderColor != -1) {
        //androidLater(500, r { stopListening(); });
        //showText("stop");
        stopListening();
      } else {
        //showText ("start");
        newRecognizer();
      }
    };
  
    if (statusView == null) {
      // init UI
      
      statusView = aFontSize(statusFontSize, aSetForeground(aBlack(), aCenteredTextView()));
      inputView = aSingleLineEditText();
      aOnEnter(inputView, r { onInput(aGetText(inputView), true) });
      //aOnChange(inputView, f cancelRecognition); // freezes!?
      //aOnChange(inputView, r { listening = false });
      //aOnChange(inputView, f cancelRecognition);
      lblInputView = aFontSize(20, aBottomTextView(inputViewLabel()));
      userTextView = aFontSize(userFontSize, aSetForeground(0xFF000055, aTextViewWithWindowFocusChangeNotify(voidfunc(Bool windowFocused) {
        if (windowFocused && recogOnActivate) newRecognizer();
      })));
      myTextView = aFontSize(myFontSize, aSetForeground(0xFF005500, aRightAlignedTextView());
      androidShow(aVerticalLinearLayout(
        statusView,
        emoView = androidClickableImage(lastEmotionImage,
          /*aWhite()*/borderColor, onClick),
        userTextView,
        myTextView,
        androidPrintLogScrollView(),
        aWestAndCenter(lblInputView, inputView)));
    }
    
    if (statusText == null) statusText = baseStatus();
    aSetText(statusView, statusText);
    aSetImageFromSnippet(emoView, lastEmotionImage);
    
    /*doEvery(1000, new Runnable {
      S text = "";
      
      public void run() {
        S s = aGetText(inputView);
        if (eq(s, text)) ret;
        text = s;
        cancelRecognition();
      }
    });*/
  }
}

static void setBorderAndStatus(int color, S status) {
  if (color != borderColor || neq(status, statusText)) {
    borderColor = color;
    statusText = status;
    if (lastEmotion != null)
      emo(lastEmotion);
  }
}

static void setBorderColor(int color) {
  if (color != borderColor) {
    borderColor = color;
    if (lastEmotion != null)
      emo(lastEmotion);
  }
}
    
static void happy() { emo("happy"); }
static void unhappy() { emo("unhappy"); }
static void oh() { emo("oh"); }
static void bored() { emo("bored"); }
static void wideMouth() { emo("wide mouth"); }

static void disappear() {
  if (!showPicture) ret;
  happy();
  androidLater(1000, r {
    androidShowFullScreenColor(0xFFFFFFFF);
    androidLater(1000, r {
      System.exit(0); // totally unrecommended but works
    });
  });
}

sS inputViewLabel() {
  ret lang("Or type here:", "Oder hier tippen:");
}

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: 772 / 2536
Version history: 54 change(s)
Referenced in: #1001290 - Unterhaltung mit Leopold 4 (with pictures)
#1001297 - Unterhaltung mit Leopold 5 (with central bot, live)
#1001306 - Emoticons test
#1001309 - Desktop: Leo's emoticons (include)
#1005192 - Leo TalkBack German (Android)
#1005193 - Leo TalkBack German (Android), no gfx
#1005194 - Leo Improve German Recognition
#1005195 - Leo Respond To Keyword German (Android), no gfx
#1005197 - Leo Test If Recognition Parameters Work At All - "minium length" doesn't :(
#1005199 - Leo TalkBack German (Android), manual start
#1005208 - Leo TalkBack German (Android), manual start, ext synthesis
#1014850 - Leo TalkBack English (Android), manual start
#1014853 - Leo TalkBack English (Android), continuous recognition
#3000382 - Answer for ferdie (>> t = 1, f = 0)
#3000383 - Answer for funkoverflow (>> t=1, f=0 okay)