Fix: strange behaviors on Android
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="2.3.0-beta-20180412-1804" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="2.3.0-beta-20180413-1542" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
<name>cordova-plugin-googlemaps</name>
<js-module name="BaseClass" src="www/BaseClass.js">
<runs />

MODIFY
src/android/plugin/google/maps/CordovaGoogleMaps.java
src/android/plugin/google/maps/CordovaGoogleMaps.java
@@ -307,7 +307,7 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
}
if (mPluginLayout.isSuspended) {
- mPluginLayout.startTimer();
+ mPluginLayout.updateMapPositions();
}
callbackContext.success();
}
@@ -368,7 +368,8 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
mPluginLayout.putHTMLElements(elements);
}
- mPluginLayout.startTimer();
+ //mPluginLayout.updateMapPositions();
+ //mPluginLayout.startTimer();
callbackContext.success();
}
@@ -455,7 +456,7 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
pluginMap.initialize(cordova, webView);
pluginMap.mapCtrl = CordovaGoogleMaps.this;
pluginMap.self = pluginMap;
- ((MyPlugin)pluginMap).CURRENT_PAGE_URL = CURRENT_URL;
+ pluginMap.CURRENT_PAGE_URL = CURRENT_URL;
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
pluginManager.addService(pluginEntry);
@@ -477,7 +478,7 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
pluginStreetView.initialize(cordova, webView);
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
pluginStreetView.self = pluginStreetView;
- ((MyPlugin)pluginStreetView).CURRENT_PAGE_URL = CURRENT_URL;
+ pluginStreetView.CURRENT_PAGE_URL = CURRENT_URL;
PluginEntry pluginEntry = new PluginEntry(mapId, pluginStreetView);
pluginManager.addService(pluginEntry);
@@ -546,12 +547,6 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
}
- protected void sendNoResult(CallbackContext callbackContext) {
- PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
- pluginResult.setKeepCallback(true);
- callbackContext.sendPluginResult(pluginResult);
- }
-
/**
* Called by the system when the device configuration changes while your activity is running.
*

MODIFY
src/android/plugin/google/maps/MyPluginLayout.java
src/android/plugin/google/maps/MyPluginLayout.java
@@ -40,7 +40,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
private FrontLayerLayout frontLayer;
private ScrollView scrollView;
public FrameLayout scrollFrameLayout;
- public static Map<String, IPluginView> pluginOverlays = new ConcurrentHashMap<String, IPluginView>();
+ public Map<String, IPluginView> pluginOverlays = new ConcurrentHashMap<String, IPluginView>();
private Map<String, TouchableWrapper> touchableWrappers = new ConcurrentHashMap<String, TouchableWrapper>();
private boolean isScrolling = false;
public boolean isDebug = false;
@@ -53,7 +53,6 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
public boolean needUpdatePosition = false;
public boolean isSuspended = false;
private float zoomScale;
- public boolean isWaiting = false;
private static final Object timerLock = new Object();
private static Timer redrawTimer;
@@ -65,23 +64,10 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
observer.addOnScrollChangedListener(this);
}
-
- private class ResizeTask extends TimerTask {
+ private Runnable resizeWorker = new Runnable() {
@Override
public void run() {
- isWaiting = false;
- //final PluginMap pluginMap = pluginOverlays.get(mapId);
- //if (pluginOverlay.getDivId() == null) {
- // return;
- //}
- //int scrollX = browserView.getScrollX();
final int scrollY = browserView.getScrollY();
- //final int webviewWidth = browserView.getWidth();
- //final int webviewHeight = browserView.getHeight();
-
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
Set<String> keySet = pluginOverlays.keySet();
String[] toArrayBuf = new String[pluginOverlays.size()];
@@ -99,6 +85,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
if (drawRect == null || drawRect.left == 0 && drawRect.top == 0 && drawRect.width() == 0 && drawRect.height() == 0) {
continue;
}
+ Log.d("MyPluginLayout", "-->drawRect = " + drawRect);
int width = (int)drawRect.width();
int height = (int)drawRect.height();
@@ -109,7 +96,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
if (lParams instanceof FrameLayout.LayoutParams) {
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;
- //Log.d("MyPluginLayout", "-->FrameLayout x = " + x + ", y = " + y + ", w = " + params.width + ", h = " + params.height);
+ Log.d("MyPluginLayout", "-->FrameLayout x = " + x + ", y = " + y + ", w = " + width + ", h = " + height);
if (params.leftMargin == x && params.topMargin == y &&
params.width == width && params.height == height) {
continue;
@@ -147,8 +134,16 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
}
}
- });
+ };
+
+ public void updateMapPositions() {
+ mActivity.runOnUiThread(resizeWorker);
+ }
+ private class ResizeTask extends TimerTask {
+ @Override
+ public void run() {
+ mActivity.runOnUiThread(resizeWorker);
}
}

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
@@ -64,12 +64,18 @@ if (!cordova) {
if (cordovaGoogleMaps.followMapDivPositionOnly.call(cordovaGoogleMaps)) {
if (scrollEndTimer) {
clearTimeout(scrollEndTimer);
- }
+ cordovaGoogleMaps.isThereAnyChange = true;
+ cordovaGoogleMaps.checkRequested = false;
+ cordovaGoogleMaps.putHtmlElements.call(cordovaGoogleMaps);
+ cordovaGoogleMaps.pause();
+
+ } else {
scrollEndTimer = setTimeout(function() {
common.nextTick(followMaps);
}, 100);
}
}
+ }
document.addEventListener("transitionstart", followMaps);
document.body.addEventListener("transitionend", followMaps);

Fix: strange behaviors on Android