Bug fix: the marker cluster does not work with the Crosswalk plugin on Android
MODIFY
src/android/plugin/google/maps/AsyncLoadImage.java
src/android/plugin/google/maps/AsyncLoadImage.java
package plugin.google.maps;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
import android.annotation.SuppressLint;
import android.content.res.AssetManager;
import android.content.res.Resources;
@@ -21,13 +11,22 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.util.Log;
-import android.util.LruCache;
+import android.view.View;
import android.webkit.WebView;
import org.apache.cordova.CordovaInterface;
+import org.apache.cordova.CordovaPreferences;
import org.apache.cordova.CordovaResourceApi;
import org.apache.cordova.CordovaWebView;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+
public class AsyncLoadImage extends AsyncTask<Void, Void, AsyncLoadImage.AsyncLoadImageResult> {
private AsyncLoadImageInterface callback;
private float density = Resources.getSystem().getDisplayMetrics().density;
@@ -127,9 +126,34 @@ public class AsyncLoadImage extends AsyncTask<Void, Void, AsyncLoadImage.AsyncLo
}
this.currentPageUrl = webView.getUrl();
+
+ View browserView = webView.getView();
+ String browserViewName = browserView.getClass().getName();
+ this.userAgent = "";
+
+ if("org.xwalk.core.XWalkView".equals(browserViewName) ||
+ "org.crosswalk.engine.XWalkCordovaView".equals(browserViewName)) {
+
+ CordovaPreferences preferences = webView.getPreferences();
+ // Set xwalk webview settings by Cordova preferences.
+ String xwalkUserAgent = preferences == null ? "" : preferences.getString("xwalkUserAgent", "");
+ if (!xwalkUserAgent.isEmpty()) {
+ this.userAgent = xwalkUserAgent;
+ }
+
+ String appendUserAgent = preferences.getString("AppendUserAgent", "");
+ if (!appendUserAgent.isEmpty()) {
+ this.userAgent = this.userAgent + " " + appendUserAgent;
+ }
+ if ("".equals(this.userAgent)) {
+ this.userAgent = "Mozilla";
+ }
+ } else {
this.userAgent = ((WebView) webView.getEngine().getView()).getSettings().getUserAgentString();
}
+ }
+
protected AsyncLoadImageResult doInBackground(Void... params) {
int mWidth = mOptions.width;

MODIFY
src/android/plugin/google/maps/PluginTileOverlay.java
src/android/plugin/google/maps/PluginTileOverlay.java
package plugin.google.maps;
import android.content.res.AssetManager;
-import android.util.Log;
+import android.view.View;
import android.webkit.WebView;
import com.google.android.gms.maps.model.TileOverlay;
import com.google.android.gms.maps.model.TileOverlayOptions;
-import com.google.android.gms.maps.model.TileProvider;
import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaPreferences;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -53,7 +53,7 @@ public class PluginTileOverlay extends MyPlugin implements MyPluginInterface {
@Override
public void run() {
- String userAgent = "Mozilla";
+ String userAgent = "";
if (opts.has("userAgent")) {
try {
userAgent = opts.getString("userAgent");
@@ -61,6 +61,28 @@ public class PluginTileOverlay extends MyPlugin implements MyPluginInterface {
//e.printStackTrace();
}
}
+ if ("".equals(userAgent)) {
+ View browserView = webView.getView();
+ String browserViewName = browserView.getClass().getName();
+ if ("org.xwalk.core.XWalkView".equals(browserViewName) ||
+ "org.crosswalk.engine.XWalkCordovaView".equals(browserViewName)) {
+
+ CordovaPreferences preferences = webView.getPreferences();
+ // Set xwalk webview settings by Cordova preferences.
+ String xwalkUserAgent = preferences == null ? "" : preferences.getString("xwalkUserAgent", "");
+ if (!xwalkUserAgent.isEmpty()) {
+ userAgent = xwalkUserAgent;
+ }
+
+ String appendUserAgent = preferences.getString("AppendUserAgent", "");
+ if (!appendUserAgent.isEmpty()) {
+ userAgent = userAgent + " " + appendUserAgent;
+ }
+ } else {
+ userAgent = ((WebView) webView.getEngine().getView()).getSettings().getUserAgentString();
+ }
+ }
+
String currentPageUrl = webView.getUrl();
AssetManager assetManager = cordova.getActivity().getAssets();

Bug fix: the marker cluster does not work with the Crosswalk plugin on Android