Please try to new XWalkWebViewEngine instead of SystemWebViewEngine,  and 
layout xwalkCordovaView.

1, cwv = new CordovaWebViewImpl(new XWalkWebViewEngine(wv));
2, <org.crossalk.engine.XWalkCordovaView
        android:id="@+id/OverlayView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

Thanks,
Junwei.
From: Alvaro Trapote [mailto:[email protected]]
Sent: Wednesday, July 20, 2016 5:25 PM
To: Fu, Junwei
Cc: [email protected]
Subject: Re: [Crosswalk-help] Using Crosswalk instead of SystemWebView in a 
Cordova plugin

I had already installed Crosswalk WebView Cordova Plugin. The project was 
working OK, it opens, firstly, using a Crosswalk webview. But when I use a 
second plugin (Catchoom plugin<https://github.com/Catchoom/craftar-phonegap>) 
to start a view of live video, it opens a System webview. What I do is:

index.html

CraftARSDK.startView(closeWindow(), null, {"loadUrl" : "liveview.html"});


CraftARPlugin.java

public class CraftARPlugin extends CordovaPlugin  {

...

else if ("startView".equals(action)) {
          String  loadUrl  = null;
          JSONObject options = args.optJSONObject(0);
          if (options != null) {
              loadUrl  = options.optString("loadUrl", loadUrl);
          } else {
              loadUrl = DEFAULT_OVERLAY;
          }

   startView(loadUrl);
}

...

protected void startView(String loadUrl) {

   Intent intent = new Intent(context, CraftARCordovaActivity.class);
   intent.putExtra(CraftARIntent.EXTRA_CONNECT_URL, loadUrl);
   activity.startActivity(intent);
}

}


CraftARCordovaActivity.java

public class CraftARCordovaActivity extends CraftARActivity implements 
CordovaInterface{

...

@Override
public void onPostCreate() {

    Intent intent = getIntent();
    loadUrl  = intent.getStringExtra(CraftARIntent.EXTRA_CONNECT_URL);
    // Initialize the UI
    FakeR fakeR = new FakeR(this);

    cordovaPlugin = CraftARPluginManager.getInstance().plugin;

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


    setContentView(layout);

    CraftARPluginManager.getInstance().initSDK(getApplicationContext(), this);
}

...

}

CatchoomLayout.java

public class CatchoomLayout extends RelativeLayout {

public CatchoomLayout(Context context) {
    super(context);
    mInflater = LayoutInflater.from(context);
    init();
}

...

void init(){
    FakeR fakeR = new FakeR(getContext());

    int layoutId = fakeR.getId("layout", "catchoom_layout");
    View layout = mInflater.inflate(layoutId, this, true);
    initUI(layout, fakeR);
}

...

 void initUI(View layout, FakeR fakeR){
        Intent intent = getActivity().getIntent();
        loadUrl  = intent.getStringExtra(CraftARIntent.EXTRA_CONNECT_URL);

        int previewId = fakeR.getId("id", "craftar_preview");

        cameraView = (CraftARCameraView) layout.findViewById(previewId);
        wv = (SystemWebView)layout.findViewById(fakeR.getId("id", 
"OverlayView"));

        cordovaInterface = new CordovaInterfaceImpl((Activity) getContext());
        loadConfig();

        cwv = new CordovaWebViewImpl(new SystemWebViewEngine(wv));
        if (!cwv.isInitialized()){
            cwv.init(cordovaInterface, pluginEntries, preferences);
        }

        cwv.handleResume(true);

        if (!TextUtils.isEmpty(loadUrl)) {
            cwv.loadUrl(CraftARPlugin.ANDROID_FILE + loadUrl);
        }

        cwv.getView().setBackgroundColor(Color.TRANSPARENT);

    }

}

craftar_camera.xml

<?xml version="1.0" encoding="utf-8"?>
<com.catchoom.craftar.CatchoomLayout
   xmlns:android="http://schemas.android.com/apk/res/android";
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:background="@android:color/background_dark" >
</com.catchoom.craftar.CatchoomLayout>


catchoom_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_dark" >
    <com.craftar.CraftARCameraView
        android:id="@+id/craftar_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />
    <org.apache.cordova.engine.SystemWebView
        android:id="@+id/OverlayView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</RelativeLayout>


This is working OK, but the UI view is a System WebView. What I was wondering 
is if it would be possible to substitute the SystemWebView for a XWalkView. 
I've been able to open XWalk webviews, following this 
example<https://crosswalk-project.org/documentation/android/embedding_crosswalk.html>,
 but I get several Javascript prompts that seem related with the calls I do 
from liveview.html to the Catchoom plugin.

So when you say ' develop new feature with Crosswalk api in embedded mode', do 
you have an example for that?

Apologies for the massive email. Just wanted to be clearer.

Many thanks





On 20 July 2016 at 01:51, Fu, Junwei 
<[email protected]<mailto:[email protected]>> wrote:
You can’t use Cordova feature in embedded mode.

So please confirm your project can work before using embedded crosswalk, then 
develop new feature with Crosswalk 
api<https://crosswalk-project.org/apis/embeddingapidocs_v6/index.html> in 
embedded mode.

Thanks,
Junwei.
From: Alvaro Trapote 
[mailto:[email protected]<mailto:[email protected]>]
Sent: Tuesday, July 19, 2016 4:46 PM
To: Fu, Junwei
Cc: 
[email protected]<mailto:[email protected]>
Subject: Re: [Crosswalk-help] Using Crosswalk instead of SystemWebView in a 
Cordova plugin

Hi,

thanks for the response.

I'm using this layout:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android";
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_dark" >
    <org.xwalk.core.XWalkView
        android:id="@+id/OverlayView"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#000000"
        />
    <com.craftar.CraftARCameraView
        android:id="@+id/craftar_preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />
</RelativeLayout>



Do you mean this example 
https://crosswalk-project.org/documentation/android/embedding_crosswalk.html ?



After I click OK in the Javascript prompts (i.e. gap: init), I get lots of 
console messages as this one:



I/chromium: [INFO:CONSOLE(1083)] "processMessage failed: invalid message: """, 
source: file:///android_asset/www/cordova.js (1083)



It seems to me that cordova bridge is not being well integrated...?



Thx




On 19 July 2016 at 03:53, Fu, Junwei 
<[email protected]<mailto:[email protected]>> wrote:
Did the found view with id changed to the xwalkView?

<org.xwalk.core.XWalkView android:id="@+id/activity_main"
  xmlns:android="http://schemas.android.com/apk/res/android";
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
</org.xwalk.core.XWalkView>

You can try to run the sample of embedding crosswalk in the cordova plugin.

Thanks,
Junwei.
From: Crosswalk-help 
[mailto:[email protected]<mailto:[email protected]>]
 On Behalf Of Alvaro Trapote
Sent: Monday, July 18, 2016 5:29 PM
To: 
[email protected]<mailto:[email protected]>
Subject: [Crosswalk-help] Using Crosswalk instead of SystemWebView in a Cordova 
plugin

Hi!

I'm trying to modify an existing Cordova plugin so it launches crosswalk 
instead of SystemWebView. The WebView is launched as follows:

 cameraView = (CraftARCameraView) layout.findViewById(previewId);
 wv = (SystemWebView)layout.findViewById(fakeR.getId("id", "OverlayView"));
 cordovaInterface = new CordovaInterfaceImpl((Activity) getContext());
 loadConfig();

 cwv = new CordovaWebViewImpl(new SystemWebViewEngine(wv));
 if (!cwv.isInitialized()){
    cwv.init(cordovaInterface, pluginEntries, preferences);
 }
 cwv.handleResume(true);
 if (!TextUtils.isEmpty(loadUrl)) {
    cwv.loadUrl(CraftARPlugin.ANDROID_FILE + loadUrl);
 }

All the examples I've seen embedding crosswalk are as in 
https://crosswalk-project.org/documentation/android/embedding_crosswalk.html 
,but this doesn't work for me. I'm getting errors (Javascript prompts as in 
http://stackoverflow.com/questions/16920596/phonegap-html-app-and-various-alerts-hang-browser).
 I reckon this is due to not getting a correct integration between crosswalk 
and cordova.

My code is:

 cameraView = (CraftARCameraView) layout.findViewById(previewId);
 mXWalkView = (XWalkView) findViewById(fakeR.getId("id", "OverlayView"));
 mXWalkView.load(CraftARPlugin.ANDROID_FILE + loadUrl, null);

Any help or guidance to carry on with the research would be very appreciated.

Thanks a lot


_______________________________________________
Crosswalk-help mailing list
[email protected]
https://lists.crosswalk-project.org/mailman/listinfo/crosswalk-help

Reply via email to