outsourced webchromeclient

This commit is contained in:
Philipp Schaefer 2013-12-21 17:39:39 +01:00
parent eed11120da
commit 2e4b670bb3
2 changed files with 65 additions and 46 deletions

View File

@ -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);
}
}

View File

@ -37,6 +37,7 @@ public class IITC_WebView extends WebView {
private WebSettings mSettings; private WebSettings mSettings;
private IITC_WebViewClient mIitcWebViewClient; private IITC_WebViewClient mIitcWebViewClient;
private IITC_WebChromeClient mIitcWebChromeClient;
private IITC_JSInterface mJsInterface; private IITC_JSInterface mJsInterface;
private IITC_Mobile mIitc; private IITC_Mobile mIitc;
private SharedPreferences mSharedPrefs; private SharedPreferences mSharedPrefs;
@ -66,56 +67,22 @@ public class IITC_WebView extends WebView {
mNavHider = new Runnable() { mNavHider = new Runnable() {
@Override @Override
public void run() { public void run() {
if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) { if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION; int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION;
// in immersive mode the user can interact with the app while the navbar is hidden // in immersive mode the user can interact with the app while the navbar is hidden
// this mode is available since KitKat // this mode is available since KitKat
// you can leave this mode by swiping down from the top of the screen. this does only work // 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 // when the app is in total-fullscreen mode
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE; systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
}
setSystemUiVisibility(systemUiVisibility);
} }
setSystemUiVisibility(systemUiVisibility);
}
} }
}; };
setWebChromeClient(new WebChromeClient() { mIitcWebChromeClient = new IITC_WebChromeClient(mIitc);
/** setWebChromeClient(mIitcWebChromeClient);
* 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);
}
});
mIitcWebViewClient = new IITC_WebViewClient(mIitc); mIitcWebViewClient = new IITC_WebViewClient(mIitc);
setWebViewClient(mIitcWebViewClient); setWebViewClient(mIitcWebViewClient);
} }