Example usage for org.apache.cordova CordovaWebViewClient CordovaWebViewClient

List of usage examples for org.apache.cordova CordovaWebViewClient CordovaWebViewClient

Introduction

In this page you can find the example usage for org.apache.cordova CordovaWebViewClient CordovaWebViewClient.

Prototype

public CordovaWebViewClient(CordovaInterface cordova, CordovaWebView view) 

Source Link

Document

Constructor.

Usage

From source file:cc.codehero.foodroulette.foodroulette.java

License:Apache License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.init();
    // Set by <content src="index.html" /> in config.xml
    super.loadUrl(Config.getStartUrl());
    //super.loadUrl("file:///android_asset/www/index.html")
    this.appView.setWebViewClient(new CordovaWebViewClient(this, this.appView) {

        @Override// www .  jav a 2 s  .  co  m
        public boolean shouldOverrideUrlLoading(WebView view, String url) {

            if (url.contains("http://localhost:9000/#/login")) {
                String md5_hash = url.replace("http://localhost:9000/", "");
                url = "file:///android_asset/www/index.html";
                view.loadUrl("javascript:window.location.href = '" + md5_hash + "';");
                Log.d("DEBUG", url);
                return true;
            } else {
                Log.d("DEBUG", url);
                //view.loadUrl(url);
                return super.shouldOverrideUrlLoading(view, url);
            }

        }

    });
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

/**
 * Create and initialize web container with default web view objects.
 *///  w ww .j  a  va  2  s  .co m
public void init() {
    CordovaWebView webView = new CordovaWebView(CordovaActivity.this);
    CordovaWebViewClient webViewClient;
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        webViewClient = new CordovaWebViewClient(this, webView);
    } else {
        webViewClient = new IceCreamCordovaWebViewClient(this, webView);
    }
    this.init(webView, webViewClient, new CordovaChromeClient(this, webView));
}

From source file:com.arjinmc.phonegapdemo.TestDemo.java

License:Apache License

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //this is the default sample to load the config url from local
    //super.loadUrl(Config.getStartUrl());

    //now we use customer layout to get the request statues
    setContentView(R.layout.main);/*from w  w w  .  jav  a 2  s  .  co m*/

    webView = (CordovaWebView) findViewById(R.id.tutorialView);

    //init cordovaInterface
    CordovaInterface cordovaInterface = (CordovaInterface) this;
    CordovaWebViewClient cordovaWebViewClient = new CordovaWebViewClient(cordovaInterface, webView) {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            //we use CordovaWebView postMessage() to CordovaInterface 
            //like handle to get what CordovaWebView has sent
            //post format like message_id,content
            webView.postMessage("onPageStarted ", url);
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            webView.postMessage("onPageFinished ", url);
            super.onPageFinished(view, url);
        }

        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            webView.postMessage("onReceivedError ", failingUrl);
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
    };

    //remember to init config if you don't use the default Config.getStartUrl()
    //or the url cannot be loaded
    Config.init(this);

    webView.loadUrl("http://arjinmc.com");
}

From source file:com.catchoom.craftar.CraftARActivityAR.java

License:Apache License

@Override
public void onPostCreate() {

    // Initialize the UI      
    FakeR fakeR = new FakeR(this);

    int layoutId = fakeR.getId("layout", "craftar_camera");
    View layout = (View) getLayoutInflater().inflate(layoutId, null);

    int previewId = fakeR.getId("id", "craftar_preview");
    CraftARCameraView cameraView = (CraftARCameraView) layout.findViewById(previewId);
    super.setCameraView(cameraView);

    if (!TextUtils.isEmpty(hint)) {
        int hintId = fakeR.getId("id", "craftar_hint");
        TextView hintView = (TextView) layout.findViewById(hintId);
        hintView.setText(hint);/*from  w w  w.  j  av a 2 s  .com*/
        hintView.setVisibility(View.VISIBLE);
    }

    int cwvId = fakeR.getId("id", "OverlayView");
    cwv = new CordovaWebView(this);

    CordovaWebViewClient cwvc;

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        cwvc = new CordovaWebViewClient(this, cwv);
    } else {
        cwvc = new IceCreamCordovaWebViewClient(this, cwv);
    }

    cwv.setWebViewClient(cwvc);
    cwv.setWebChromeClient(new CordovaChromeClient(this, cwv));

    FrameLayout wvLayout = (FrameLayout) layout.findViewById(cwvId);
    wvLayout.addView(cwv);
    Config.init(this);

    cwv.loadUrl("file:///android_asset/www/ar_overlay.html");
    cwv.setBackgroundColor(Color.TRANSPARENT);

    setContentView(layout);

    // Initialize the Cloud Image Recognition service
    cloudRecognition = CraftARSDK.getCloudRecognition();
    cloudRecognition.setResponseHandler(this);
    cloudRecognition.setCollectionToken(token);

    if (!TextUtils.isEmpty(connectUrl)) {
        cloudRecognition.setConnectUrl(connectUrl);
    }

    if (!TextUtils.isEmpty(searchUrl)) {
        cloudRecognition.setSearchUrl(searchUrl);
    }

    // Obtain camera
    mcamera = CraftARSDK.getCamera();
    mcamera.setImageHandler(this);

    // Obtain the Tracking module
    tracking = CraftARSDK.getTracking();

    // Start finder mode
    cloudRecognition.startFinding();

}

From source file:com.example.cordovajsalertbug.CordovaOnJsAlertBug.java

License:Apache License

@Override
public void init() {
    Log.e(TAG, "init()");
    CordovaWebView webView = new CordovaWebView(CordovaOnJsAlertBug.this);
    CordovaWebViewClient webViewClient;//ww  w  .  j a  v a2  s  .  c o m
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        webViewClient = new CordovaWebViewClient(this, webView);
    } else {
        webViewClient = new IceCreamCordovaWebViewClient(this, webView);
    }
    this.init(webView, webViewClient, new MyCordovaChromeClient(this, webView));
}

From source file:com.moodstocks.phonegap.demo.Demo.java

License:Open Source License

@Override
public void init() {
    MoodstocksWebView webView = new MoodstocksWebView(Demo.this);
    CordovaWebViewClient webViewClient;//w w  w  . j  a  va 2s . c  o m

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        webViewClient = new CordovaWebViewClient(this, webView);
    } else {
        webViewClient = new IceCreamCordovaWebViewClient(this, webView);
    }

    this.init(webView, webViewClient, new CordovaChromeClient(this, webView));
}

From source file:com.phonegap.plugins.mmAd.mmAd.java

License:BSD License

@Override
public void onResume(boolean multitasking) {
    webView.setWebViewClient(new CordovaWebViewClient(ctx, webView));
    this.initialized = false;
    webView.reload();//from  w ww . j a  v a2 s.co  m
    resizeAd();
}

From source file:com.phonegap.plugins.mmAd.mmAd.java

License:BSD License

private void resizeAd() {
    this.webView.post(new Runnable() {
        public void run() {

            android.view.ViewGroup.LayoutParams params = webView.getLayoutParams();
            if (params.height != LayoutParams.MATCH_PARENT) {
                oldHeight = webView.getMeasuredHeight();
                params.height = LayoutParams.MATCH_PARENT;
                webView.setWebViewClient(new CordovaWebViewClient(ctx, webView) {
                    @Override//from w  w  w  .  j a  v a2s.  c om
                    public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
                        if (view.getHitTestResult().getType() > 0) {
                            webView.stopLoading();
                            webView.showWebPage(url, true, true, null);
                        }
                    }
                });
            } else {
                params.height = oldHeight;
            }

            webView.setLayoutParams(params);
            webView.forceLayout();

            //stuff that updates ui

        }
    });
}

From source file:com.virtualama.application.Virtualama.java

License:Apache License

@Override
public void init() {
    MoodstocksWebView webView = new MoodstocksWebView(this);
    webView.setBackgroundColor(0x00000000);
    CordovaWebViewClient webViewClient;// w w  w  .ja v  a2  s.co m

    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        webViewClient = new CordovaWebViewClient(this, webView);
    } else {
        webViewClient = new IceCreamCordovaWebViewClient(this, webView);
    }

    super.init(webView, webViewClient, new CordovaChromeClient(this, webView));
}

From source file:edu.cornell.shift.Shift.java

License:Apache License

private void runOcr(String lang) {
    appView.setWebViewClient(new CordovaWebViewClient(this, appView) {
        @Override/*from w w  w  . j  ava  2 s . co m*/
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            Log.d("Shift", "shouldOverrideUrlLoading " + url);
            if (url.startsWith("app://ocr")) {
                Uri uri = Uri.parse(url);
                String success = uri.getQueryParameter("success");
                String message = uri.getQueryParameter("message");
                if ("true".equals(success)) {
                    generateResult(message);
                    finish();
                } else {
                    Intent result = new Intent();
                    result.putExtra("score", 0.0);
                    setResult(Activity.RESULT_CANCELED, result);
                    finish();
                }
                return true;
            } else {
                return super.shouldOverrideUrlLoading(view, url);
            }
        }
    });
    loadUrl(Config.getStartUrl() + "#ocr-options?service=true&lang=" + lang);
}