Skip to content

Commit

Permalink
Show Toast using JavaScript function in WebView
Browse files Browse the repository at this point in the history
* Added function ankiShowToast card.js
* Added url decoding of msg
* Added encode toast msg, card.js
  • Loading branch information
krmanik authored Jun 20, 2020
1 parent 7122f0d commit 7d68b87
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions AnkiDroid/src/main/assets/scripts/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ function ankiToggleFlag(flag) {
}
}

// Show toast using js
function ankiShowToast(message) {
var msg = encodeURI(message);
window.location.href = "signal:anki_show_toast:" + msg;
}

/* Tell the app the text in the input box when it loses focus */
function taBlur(itag) {
//#5944 - percent wasn't encoded, but Mandarin was.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3181,6 +3181,14 @@ private boolean filterUrl(String url) {
}
}

// Show toast using JS
if (url.startsWith("signal:anki_show_toast:")) {
String msg = url.replaceFirst("signal:anki_show_toast:", "");
String msgDecode = decodeUrl(msg);
UIUtils.showThemedToast(AbstractFlashcardViewer.this, msgDecode, true);
return true;
}

int signalOrdinal = WebViewSignalParserUtils.getSignalFromUrl(url);
switch (signalOrdinal) {
case WebViewSignalParserUtils.SIGNAL_UNHANDLED:
Expand Down

0 comments on commit 7d68b87

Please sign in to comment.