this is WVX-Lite (for B4J), as in webviewextras-lite (with props to @warwound for his groundbreaking contribution to B4A).
the principal idea was to provide a contextmenu for webview that allowed for image downloads. once you start down that road,
you find you need a listener to override the default contextmenu. to find out how things are going with that, you need to implement
javascript's console.log (that's missing too in webview). to your surprise, you will learn that some sites block javascript's alert().
you willl also find out that there is no actual download function. that means you have to have a way to make calls from javascript
back to the b4j app (aka, javascript interface). taken together, what's missing is the b4j equivalent of webviewextras for b4a.
wvx-lite comes with a "loader" script that sets everything up. since executejavascript is supported, the user can modify it or add
their own scripts. you just need to add a button to run the script and include the built-in functions provided by the loader to make
calls back to b4j. the interface accepts objects, so you can return what you need. sadly, you can't return an array from javascript,
but that's easily handled by a string with a separator. (a javascript array is not the same as a java array. you need some kind of
converter if you must return an array, but i've used a string with separator to mimic an array for years with the original webviewextras.)
attached is a series of screen captures.
1) standard load view
2) standard right click on b4x.com "nasa" image. (screen cap doesn't show where the cursor clicked)
3) custom right click
4) custom contextmenu changes color on mouseover (like real contextmenu)
5) "nasa" image is downloaded, shown on app screen and save on user's desktop. i chose there for convenience.
6) went to google for another image
7) grabbed an image of a hyena
8) sample message that appears when user right-clicks on some element that's not an image. (again, cursor doesn't appear in screen cap)
note: in image #8, you can see all the console.log entries, which without the listener, would not appear.
images from <img> and <a download> tags are supported, as well as <svg>. <picture> tags are tricky, but i'm working on handling them.
the principal idea was to provide a contextmenu for webview that allowed for image downloads. once you start down that road,
you find you need a listener to override the default contextmenu. to find out how things are going with that, you need to implement
javascript's console.log (that's missing too in webview). to your surprise, you will learn that some sites block javascript's alert().
you willl also find out that there is no actual download function. that means you have to have a way to make calls from javascript
back to the b4j app (aka, javascript interface). taken together, what's missing is the b4j equivalent of webviewextras for b4a.
wvx-lite comes with a "loader" script that sets everything up. since executejavascript is supported, the user can modify it or add
their own scripts. you just need to add a button to run the script and include the built-in functions provided by the loader to make
calls back to b4j. the interface accepts objects, so you can return what you need. sadly, you can't return an array from javascript,
but that's easily handled by a string with a separator. (a javascript array is not the same as a java array. you need some kind of
converter if you must return an array, but i've used a string with separator to mimic an array for years with the original webviewextras.)
attached is a series of screen captures.
1) standard load view
2) standard right click on b4x.com "nasa" image. (screen cap doesn't show where the cursor clicked)
3) custom right click
4) custom contextmenu changes color on mouseover (like real contextmenu)
5) "nasa" image is downloaded, shown on app screen and save on user's desktop. i chose there for convenience.
6) went to google for another image
7) grabbed an image of a hyena
8) sample message that appears when user right-clicks on some element that's not an image. (again, cursor doesn't appear in screen cap)
note: in image #8, you can see all the console.log entries, which without the listener, would not appear.
images from <img> and <a download> tags are supported, as well as <svg>. <picture> tags are tricky, but i'm working on handling them.
Attachments
Last edited: