Search in sources :

Example 1 with QuotaUpdater

use of android.webkit.WebStorage.QuotaUpdater in project OpenMEAP by OpenMEAP.

the class MainActivity method createDefaultWebView.

/**
	 * Sets up the window title, per the properties
	 * 
	 * private void setupWindowTitle() { if( config.getApplicationTitle()!=null
	 * ) { if( config.getApplicationTitle().equals("off") ) {
	 * requestWindowFeature(Window.FEATURE_NO_TITLE); } else {
	 * setTitle(config.getApplicationTitle()); } } else
	 * setTitle(config.getApplicationName()); }
	 */
/**
	 * Creates the default WebView where we'll run javascript and render content
	 */
public WebView createDefaultWebView() {
    WebView webView = new com.openmeap.android.WebView(this, this);
    // make sure javascript and our api is available to the webview
    JsApiCoreImpl jsApi = new JsApiCoreImpl(this, webView, updateHandler);
    webView.addJavascriptInterface(jsApi, JS_API_NAME);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    //making web database enabled.
    webView.getSettings().setDatabaseEnabled(true);
    //making Dom storage enabled.
    webView.getSettings().setDomStorageEnabled(true);
    //requesting to create directory with name "localstorage" in /data/data/.../App_localstorage, 
    //so that, localstorage related data files saved into that directory.
    String databasePath = this.getApplicationContext().getDir("localstorage", Context.MODE_PRIVATE).getPath();
    //setting local storage database path.
    webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
    // enable navigator.geolocation
    webView.getSettings().setGeolocationEnabled(true);
    webView.getSettings().setGeolocationDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
    // removes vertical and horizontal scroll bars
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    //WebChromeClient class is set, so that the overridden methods are executed,
    //when something that might impact a browser UI happens.
    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
            callback.invoke(origin, true, false);
        }

        @Override
        public void onExceededDatabaseQuota(String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, QuotaUpdater quotaUpdater) {
            // TODO Auto-generated method stub
            super.onExceededDatabaseQuota(url, databaseIdentifier, quota, estimatedDatabaseSize, totalQuota, quotaUpdater);
        }
    });
    // make sure the web view fills the viewable area
    webView.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    return webView;
}
Also used : LoginFormCallback(com.openmeap.thinclient.LoginFormCallback) Callback(android.webkit.GeolocationPermissions.Callback) WebChromeClient(android.webkit.WebChromeClient) QuotaUpdater(android.webkit.WebStorage.QuotaUpdater) OmWebView(com.openmeap.thinclient.OmWebView) JsApiCoreImpl(com.openmeap.thinclient.javascript.JsApiCoreImpl) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Aggregations

Callback (android.webkit.GeolocationPermissions.Callback)1 WebChromeClient (android.webkit.WebChromeClient)1 QuotaUpdater (android.webkit.WebStorage.QuotaUpdater)1 WebViewClient (android.webkit.WebViewClient)1 LinearLayout (android.widget.LinearLayout)1 LoginFormCallback (com.openmeap.thinclient.LoginFormCallback)1 OmWebView (com.openmeap.thinclient.OmWebView)1 JsApiCoreImpl (com.openmeap.thinclient.javascript.JsApiCoreImpl)1