Bug fix: Second map is not displayed for some reason
MODIFY
src/android/plugin/google/maps/CordovaGoogleMaps.java
src/android/plugin/google/maps/CordovaGoogleMaps.java
@@ -53,6 +53,7 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
public boolean initialized = false;
public PluginManager pluginManager;
public static String CURRENT_URL;
+ private static final Object timerLock = new Object();
@SuppressLint("NewApi") @Override
public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
@@ -169,7 +170,6 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
webView.getView().setBackgroundColor(Color.TRANSPARENT);
webView.getView().setOverScrollMode(View.OVER_SCROLL_NEVER);
mPluginLayout = new MyPluginLayout(webView, activity);
- mPluginLayout.isSuspended = true;
mPluginLayout.stopTimer();
@@ -221,7 +221,6 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
@Override
public boolean onOverrideUrlLoading(String url) {
- mPluginLayout.isSuspended = true;
mPluginLayout.stopTimer();
/*
this.activity.runOnUiThread(new Runnable() {
@@ -308,7 +307,6 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
}
if (mPluginLayout.isSuspended) {
- mPluginLayout.isSuspended = false;
mPluginLayout.startTimer();
}
callbackContext.success();
@@ -327,26 +325,30 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
- public void pause(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ public synchronized void pause(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ synchronized (timerLock) {
+ Log.i(TAG, "------------>pause, callbackId = " + callbackContext.getCallbackId());
if (mPluginLayout == null) {
callbackContext.success();
return;
}
- mPluginLayout.isSuspended = true;
mPluginLayout.stopTimer();
callbackContext.success();
}
- public void resume(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ }
+ public synchronized void resume(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
+ synchronized (timerLock) {
if (mPluginLayout == null) {
callbackContext.success();
return;
}
+ Log.i(TAG, "------------>resume : isSuspended = " + mPluginLayout.isSuspended + ", callbackId = " + callbackContext.getCallbackId());
if (mPluginLayout.isSuspended) {
- mPluginLayout.isSuspended = false;
mPluginLayout.startTimer();
}
callbackContext.success();
}
+ }
public void clearHtmlElements(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (mPluginLayout == null) {
callbackContext.success();

MODIFY
src/android/plugin/google/maps/MyPluginLayout.java
src/android/plugin/google/maps/MyPluginLayout.java
@@ -24,13 +24,13 @@ import org.apache.cordova.CordovaWebView;
import org.json.JSONObject;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
+import java.util.concurrent.ConcurrentHashMap;
@SuppressWarnings("deprecation")
public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnScrollChangedListener, ViewTreeObserver.OnGlobalLayoutListener {
@@ -40,13 +40,13 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
private FrontLayerLayout frontLayer;
private ScrollView scrollView;
public FrameLayout scrollFrameLayout;
- public HashMap<String, IPluginView> pluginOverlays = new HashMap<String, IPluginView>();
- private HashMap<String, TouchableWrapper> touchableWrappers = new HashMap<String, TouchableWrapper>();
+ public static 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;
public final Object _lockHtmlNodes = new Object();
- public HashMap<String, Bundle> HTMLNodes = new HashMap<String, Bundle>();
- public HashMap<String, RectF> HTMLNodeRectFs = new HashMap<String, RectF>();
+ public Map<String, Bundle> HTMLNodes = new ConcurrentHashMap<String, Bundle>();
+ public Map<String, RectF> HTMLNodeRectFs = new ConcurrentHashMap<String, RectF>();
private Activity mActivity = null;
private Paint debugPaint = new Paint();
public boolean stopFlag = false;
@@ -54,7 +54,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
public boolean isSuspended = false;
private float zoomScale;
public boolean isWaiting = false;
- private final Object timerLock = new Object();
+ private static final Object timerLock = new Object();
public Timer redrawTimer;
@@ -112,7 +112,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
//Log.d("MyPluginLayout", "-->FrameLayout x = " + x + ", y = " + y + ", w = " + params.width + ", h = " + params.height);
if (params.leftMargin == x && params.topMargin == y &&
params.width == width && params.height == height) {
- return;
+ continue;
}
params.width = width;
params.height = height;
@@ -124,7 +124,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
AbsoluteLayout.LayoutParams params = (AbsoluteLayout.LayoutParams) lParams;
if (params.x == x && params.y == y &&
params.width == width && params.height == height) {
- return;
+ continue;
}
params.width = width;
params.height = height;
@@ -136,7 +136,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
if (params.leftMargin == x && params.topMargin == y &&
params.width == width && params.height == height) {
- return;
+ continue;
}
params.width = width;
params.height = height;
@@ -221,6 +221,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
redrawTimer.purge();
ResizeTask task = new ResizeTask();
task.run();
+ isSuspended = true;
}
} catch (Exception e) {
e.printStackTrace();
@@ -238,6 +239,7 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
redrawTimer = new Timer();
redrawTimer.scheduleAtFixedRate(new ResizeTask(), 0, 25);
mActivity.getWindow().getDecorView().requestFocus();
+ isSuspended = false;
}
}
@@ -256,8 +258,8 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
public void putHTMLElements(JSONObject elements) {
- HashMap<String, Bundle> newBuffer = new HashMap<String, Bundle>();
- HashMap<String, RectF> newBufferRectFs = new HashMap<String, RectF>();
+ Map<String, Bundle> newBuffer = new ConcurrentHashMap<String, Bundle>();
+ Map<String, RectF> newBufferRectFs = new ConcurrentHashMap<String, RectF>();
Bundle elementsBundle = PluginUtil.Json2Bundle(elements);
@@ -286,8 +288,8 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
newBuffer.put(domId, domInfo);
}
- HashMap<String, Bundle> oldBuffer = HTMLNodes;
- HashMap<String, RectF> oldBufferRectFs = HTMLNodeRectFs;
+ Map<String, Bundle> oldBuffer = HTMLNodes;
+ Map<String, RectF> oldBufferRectFs = HTMLNodeRectFs;
synchronized (_lockHtmlNodes) {
HTMLNodes = newBuffer;

MODIFY
src/android/plugin/google/maps/PluginMap.java
src/android/plugin/google/maps/PluginMap.java
@@ -75,6 +75,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
public class PluginMap extends MyPlugin implements OnMarkerClickListener,
@@ -96,7 +97,7 @@ public class PluginMap extends MyPlugin implements OnMarkerClickListener,
private boolean isClickable = true;
private final String TAG = mapId;
private String mapDivId;
- public HashMap<String, PluginEntry> plugins = new HashMap<String, PluginEntry>();
+ public Map<String, PluginEntry> plugins = new ConcurrentHashMap<String, PluginEntry>();
private final float DEFAULT_CAMERA_PADDING = 20;
private Projection projection = null;
public Marker activeMarker = null;

MODIFY
www/CordovaGoogleMaps.js
www/CordovaGoogleMaps.js
var utils = require('cordova/utils'),
common = require('./Common'),
cordova_exec = require('cordova/exec'),
+ BaseClass = require('./BaseClass'),
Map = require('./Map'),
StreetViewPanorama = require('./StreetViewPanorama');
function CordovaGoogleMaps(execCmd) {
var self = this;
+ BaseClass.apply(this);
// Ignore checking for thse tags.
self.doNotTraceTags = [
@@ -34,7 +36,7 @@ function CordovaGoogleMaps(execCmd) {
self.isThereAnyChange = false;
// Indicate the native timer is stopped or not.
- self.isSuspended = false;
+ self.set("isSuspended", false);
// Cache for updateMapPositionOnly
self.prevMapRects = {};
@@ -96,9 +98,17 @@ function CordovaGoogleMaps(execCmd) {
subtree: true,
attributeFilter: ['style', 'class']
});
-}
+ self.on("isSuspended_changed", function(oldValue, newValue) {
+ if (newValue) {
+ cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
+ } else {
+ cordova_exec(null, null, 'CordovaGoogleMaps', 'resume', []);
+ }
+ });
+}
+utils.extend(CordovaGoogleMaps, BaseClass);
CordovaGoogleMaps.prototype.traceDomTree = function(element, elemId, isMapChild) {
//------------------------------------------
@@ -307,10 +317,7 @@ CordovaGoogleMaps.prototype.putHtmlElements = function() {
//-----------------------------------------------------------------
// Pass the DOM hierarchy tree graph to native side
//-----------------------------------------------------------------
- if (self.isSuspended) {
- // start the native timer
self.resume();
- }
//console.log("--->putHtmlElements to native (start)", JSON.parse(JSON.stringify(self.domPositions)));
cordova_exec(function() {
@@ -333,20 +340,14 @@ CordovaGoogleMaps.prototype.putHtmlElements = function() {
CordovaGoogleMaps.prototype.pause = function() {
var self = this;
- if (!self.isSuspended) {
- // Stop the native timer
- cordova_exec(null, null, 'CordovaGoogleMaps', 'pause', []);
- }
- self.isSuspended = true;
+ self.set("isSuspended", true);
self.isThereAnyChange = false;
self.isChecking = false;
};
CordovaGoogleMaps.prototype.resume = function() {
var self = this;
-
- cordova_exec(null, null, 'CordovaGoogleMaps', 'resume', []);
- self.isSuspended = false;
+ self.set("isSuspended", false);
};
@@ -403,8 +404,6 @@ CordovaGoogleMaps.prototype.invalidate = function(opts) {
opts = opts || {};
if (opts.force) {
self.isThereAnyChange = true;
- self.isSuspended = false;
- self.resume();
}
common.nextTick(function() {
@@ -677,10 +676,9 @@ CordovaGoogleMaps.prototype.getMap = function(div, mapOptions) {
self.domPositions[elemId].isMap = true;
cordova_exec(function() {
- cordova_exec(function() {
+ self.resume();
map.getMap.apply(map, args);
}, null, 'CordovaGoogleMaps', 'putHtmlElements', [self.domPositions]);
- }, null, 'CordovaGoogleMaps', 'resume', []);
} else {
map.getMap.apply(map, args);
}
@@ -691,7 +689,7 @@ CordovaGoogleMaps.prototype.getMap = function(div, mapOptions) {
CordovaGoogleMaps.prototype.getPanorama = function(div, streetViewOptions) {
var self = this;
- var mapId = "map_" + self.MAP_CNT + "_" + self.saltHash;
+ var mapId = "streetview_" + self.MAP_CNT + "_" + self.saltHash;
// Create a panorama instance.
var panorama = new StreetViewPanorama(mapId, self.execCmd);
@@ -732,10 +730,9 @@ CordovaGoogleMaps.prototype.getPanorama = function(div, streetViewOptions) {
args.unshift(mapId);
cordova_exec(function() {
- cordova_exec(function() {
+ self.resume();
panorama.getPanorama.apply(panorama, args);
}, null, 'CordovaGoogleMaps', 'putHtmlElements', [self.domPositions]);
- }, null, 'CordovaGoogleMaps', 'resume', []);
return panorama;
};

MODIFY
www/googlemaps-cdv-plugin.js
www/googlemaps-cdv-plugin.js
/* global cordova, plugin, CSSPrimitiveValue */
if (!cordova) {
document.addEventListener("deviceready", function() {
- isSuspended = true;
require('cordova/exec')(null, null, 'CordovaGoogleMaps', 'pause', []);
}, {
once: true

Bug fix: Second map is not displayed for some reason