From 2e4b670bb38839b5341f4c1bda61a53244f414df Mon Sep 17 00:00:00 2001 From: Philipp Schaefer Date: Sat, 21 Dec 2013 17:39:39 +0100 Subject: [PATCH] outsourced webchromeclient --- .../iitc_mobile/IITC_WebChromeClient.java | 52 ++++++++++++++++ .../com/cradle/iitc_mobile/IITC_WebView.java | 59 ++++--------------- 2 files changed, 65 insertions(+), 46 deletions(-) create mode 100644 mobile/src/com/cradle/iitc_mobile/IITC_WebChromeClient.java diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebChromeClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebChromeClient.java new file mode 100644 index 00000000..2098855d --- /dev/null +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebChromeClient.java @@ -0,0 +1,52 @@ +package com.cradle.iitc_mobile; + +import android.app.Activity; +import android.webkit.ConsoleMessage; +import android.webkit.GeolocationPermissions; +import android.webkit.WebChromeClient; +import android.webkit.WebView; + +/** + * Created by cradle on 12/21/13. + */ +public class IITC_WebChromeClient extends WebChromeClient { + + private IITC_Mobile mIitcm; + + public IITC_WebChromeClient(IITC_Mobile iitcm) { + mIitcm = iitcm; + } + /** + * our webchromeclient should share geolocation with the iitc script + * + * allow access by default + */ + @Override + public void onGeolocationPermissionsShowPrompt(String origin, + GeolocationPermissions.Callback callback) { + callback.invoke(origin, true, false); + } + + /** + * display progress bar in activity + */ + @Override + public void onProgressChanged(WebView view, int newProgress) { + super.onProgressChanged(view, newProgress); + + // maximum for newProgress is 100 + // maximum for setProgress is 10,000 + mIitcm.setProgress(newProgress * 100); + } + + /** + * remove splash screen if any JS error occurs + */ + @Override + public boolean onConsoleMessage(ConsoleMessage consoleMessage) { + if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) { + mIitcm.setLoadingState(false); + } + return super.onConsoleMessage(consoleMessage); + } +} diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java index a9745ae1..23ceb645 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebView.java @@ -37,6 +37,7 @@ public class IITC_WebView extends WebView { private WebSettings mSettings; private IITC_WebViewClient mIitcWebViewClient; + private IITC_WebChromeClient mIitcWebChromeClient; private IITC_JSInterface mJsInterface; private IITC_Mobile mIitc; private SharedPreferences mSharedPrefs; @@ -66,56 +67,22 @@ public class IITC_WebView extends WebView { mNavHider = new Runnable() { @Override public void run() { - if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) { - int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION; - // in immersive mode the user can interact with the app while the navbar is hidden - // this mode is available since KitKat - // you can leave this mode by swiping down from the top of the screen. this does only work - // when the app is in total-fullscreen mode - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) { - systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE; - } - setSystemUiVisibility(systemUiVisibility); + if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) { + int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION; + // in immersive mode the user can interact with the app while the navbar is hidden + // this mode is available since KitKat + // you can leave this mode by swiping down from the top of the screen. this does only work + // when the app is in total-fullscreen mode + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) { + systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE; } + setSystemUiVisibility(systemUiVisibility); + } } }; - setWebChromeClient(new WebChromeClient() { - /** - * our webchromeclient should share geolocation with the iitc script - * - * allow access by default - */ - @Override - public void onGeolocationPermissionsShowPrompt(String origin, - GeolocationPermissions.Callback callback) { - callback.invoke(origin, true, false); - } - - /** - * display progress bar in activity - */ - @Override - public void onProgressChanged(WebView view, int newProgress) { - super.onProgressChanged(view, newProgress); - - // maximum for newProgress is 100 - // maximum for setProgress is 10,000 - ((Activity) getContext()).setProgress(newProgress * 100); - } - - /** - * remove splash screen if any JS error occurs - */ - @Override - public boolean onConsoleMessage(ConsoleMessage consoleMessage) { - if (consoleMessage.messageLevel() == ConsoleMessage.MessageLevel.ERROR) { - mIitc.setLoadingState(false); - } - return super.onConsoleMessage(consoleMessage); - } - }); - + mIitcWebChromeClient = new IITC_WebChromeClient(mIitc); + setWebChromeClient(mIitcWebChromeClient); mIitcWebViewClient = new IITC_WebViewClient(mIitc); setWebViewClient(mIitcWebViewClient); }