Make available current card's and deck's details in WebView#6307
Make available current card's and deck's details in WebView#6307mikehardy merged 53 commits intoankidroid:masterfrom krmanik:master
Conversation
Update Ankidroid forked repo - DONE
Updating Fork
Revert "don't put "undo" to color enabled"
Prefrences.java 03-dialogs.xml Updated
|
I have made an AnkiDroid deck for this. |
|
For getting nextTime1, nextTime2, nextTime3, nextTime4. @JavascriptInterface
public String ankiGetNextTime1() { return (String) mNext1.getText(); }
@JavascriptInterface
public String ankiGetNextTime2() { return (String) mNext2.getText(); }
@JavascriptInterface
public String ankiGetNextTime3() { return (String) mNext3.getText(); }
@JavascriptInterface
public String ankiGetNextTime4() { return (String) mNext4.getText(); }This will help when answerButtonEase4 is called from webview and not get called then answerButtonEase3 will be called. In WebView function button4Clicked() {
if (AnkiDroidJS.ankiGetNextTime4() == "") {
answerButtonEase3();
} else {
answerButtonEase4();
}
}Fourth button can be hidden if (AnkiDroidJS.ankiGetNextTime4() == "")
{
hideButton4();
}And also showing options menu // Show options menu
if (url.startsWith("signal:show_options_menu")) {
openOptionsMenu();
return true;
}Show Navigation Drawer // Show side menu
if (url.startsWith("signal:show_navigation_drawer")) {
DrawerLayout mDrawerLayout = (DrawerLayout)findViewById(R.id.drawer_layout);
mDrawerLayout.openDrawer(Gravity.LEFT);
return true;
}Should I add those to this PR? |
david-allison
left a comment
There was a problem hiding this comment.
Re-review and slight nitpick
|
@infinyte7, I don't disagree, but it'd be better to move the additional changes into a separate PR, so we can get this into the codebase as soon as possible after @mikehardy has had a look. I think we also need to consider how to best display "Good/(Hard)/Again/Easy" to developers, especially as there are cases where only 2 buttons can be displayed. |
|
The all button get exposed to card developer. if (AnkiDroidJS.ankiGetNextTime1() == "") {
document.getElementById('button1').style.display ="hidden";
}
if (AnkiDroidJS.ankiGetNextTime2() == "") {
document.getElementById('button2').style.display ="hidden";
}
if (AnkiDroidJS.ankiGetNextTime3() == "") {
document.getElementById('button3').style.display ="hidden";
}
if (AnkiDroidJS.ankiGetNextTime4() == "") {
document.getElementById('button4').style.display ="hidden";
} |
….java Co-authored-by: david-allison-1 <62114487+david-allison-1@users.noreply.github.com>
|
Issues
======
- Added 2
See the complete overview on Codacy |
|
This change looks good - I'll merge it and put it in the next alpha |

Pull Request template
Purpose / Description
This PR make available the following details about cards
Also following functions available to make any design of button using css and calling using JS
Usage of
ankiToggleFlag()Using numeric values
Using above and css & js, following type of card can be designed
https://github.com/infinyte7/Anki-Custom-Card-Layout
Fixes
Fixes #6306
Approach
How does this change address the problem?
Using JavascriptInterface.
How Has This Been Tested?
Sample Deck can be used for testing (Contents in deck may be changed to get it work)
To make available following details to AnkiDroid WebView, add it to Front / Back side of Card in
<script>tag.Demo
Learning (optional, can help others)
https://developer.android.com/reference/android/webkit/JavascriptInterface
https://stackoverflow.com/questions/21173888/how-to-pass-non-primitive-object-from-java-to-js-by-android-addjavascriptinterfa
https://stackoverflow.com/questions/175739/built-in-way-in-javascript-to-check-if-a-string-is-a-valid-number
https://grid.layoutit.com/
https://codepen.io/
https://www.w3schools.com/
Checklist
Please, go through these checks before submitting the PR.
ifstatements)