diff --git a/android-samples/WebViewDemo/Rakefile b/android-samples/WebViewDemo/Rakefile new file mode 100644 index 00000000..f01355fd --- /dev/null +++ b/android-samples/WebViewDemo/Rakefile @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +$:.unshift("../../lib") +require 'motion/project/template/android' + +Motion::Project::App.setup do |app| + # Use `rake config' to see complete project settings. + app.name = 'WebViewDemo' + app.main_activity = 'WebViewDemo' + app.api_version = '18' + app.sdk_path = File.expand_path('~/src/android-sdk-macosx') + app.ndk_path = File.expand_path('~/src/android-ndk-r9d') +end diff --git a/android-samples/WebViewDemo/app/WebViewDemo.rb b/android-samples/WebViewDemo/app/WebViewDemo.rb new file mode 100644 index 00000000..531f6ff0 --- /dev/null +++ b/android-samples/WebViewDemo/app/WebViewDemo.rb @@ -0,0 +1,51 @@ +class WebViewDemo < Android::App::Activity + def onCreate(savedInstanceState) + super + @handler = Android::Os::Handler.new + + @webview = Android::Webkit::WebView.new(self) + settings = @webview.getSettings + settings.savePassword = false + settings.saveFormData = false + settings.javaScriptEnabled = true + settings.supportZoom = false + + @webview.webChromeClient = MyWebChromeClient.new + js_interface = DemoJavaScriptInterface.new + js_interface.set_context(self) + @webview.addJavascriptInterface(js_interface, "demo") + + @webview.loadUrl("file:///android_asset/demo.html") + + self.contentView = @webview + end + + def webview + @webview + end + + def handler + @handler + end +end + +class DemoJavaScriptInterface < Java::Lang::Object + def set_context(context) + @context = context + end + + __annotation__('@android.webkit.JavascriptInterface') + def clickOnAndroid + # This method will be called from another thread, and WebView calls must + # happen in the main thread, so we dispatch it via a Handler object. + @context.handler.post -> { @context.webview.loadUrl("javascript:wave()") } + end +end + +class MyWebChromeClient < Android::Webkit::WebChromeClient + def onJsAlert(view, url, message, result) + puts message + result.confirm + true + end +end diff --git a/android-samples/WebViewDemo/resources/android_normal.png b/android-samples/WebViewDemo/resources/android_normal.png new file mode 100755 index 00000000..1654b5f1 Binary files /dev/null and b/android-samples/WebViewDemo/resources/android_normal.png differ diff --git a/android-samples/WebViewDemo/resources/android_waving.png b/android-samples/WebViewDemo/resources/android_waving.png new file mode 100755 index 00000000..2455f97d Binary files /dev/null and b/android-samples/WebViewDemo/resources/android_waving.png differ diff --git a/android-samples/WebViewDemo/resources/demo.html b/android-samples/WebViewDemo/resources/demo.html new file mode 100755 index 00000000..476cc225 --- /dev/null +++ b/android-samples/WebViewDemo/resources/demo.html @@ -0,0 +1,20 @@ + + +
+ +