Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. java.import "android/webkit/WebView"
  2.  
  3. class Main < JamRuby::Activity
  4. HTML = <<-HTML
  5. <html><body>
  6. <button id=b>Click Me</button>
  7. </body>
  8. <script>
  9. document.getElementByID("b").onclick = function() {num()};
  10. alert(ruby.hello());
  11. </script>
  12. </html>
  13. HTML
  14.  
  15. def on_create state
  16. wv = Android::Webkit::WebView.new(self)
  17.  
  18. wv.getSettings().setJavaScriptEnabled(true);
  19.  
  20. wv.addJavascriptInterface((JamRuby::JavascriptInterface.new() do
  21. def hello
  22. toast "hello!"
  23. end
  24.  
  25. def num
  26. 3
  27. end
  28. end), "ruby");
  29.  
  30. wv.loadDataWithBaseURL("", HTML, "text/html", "UTF-8", "")
  31.  
  32. setContentView wv
  33. end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement