Add: stop the resize timer completely if there is no map
MODIFY
plugin.xml
plugin.xml
<?xml version='1.0' encoding='utf-8'?>
-<plugin id="cordova-plugin-googlemaps" version="cluster-20170818-1545" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
+<plugin id="cordova-plugin-googlemaps" version="cluster-20170818-2345" 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
@@ -53,10 +53,12 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;
@@ -191,6 +193,7 @@ 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;
// Check the API key
@@ -241,7 +244,13 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
@Override
public boolean onOverrideUrlLoading(String url) {
- Log.d(TAG, "onOverrideUrlLoading = " + url);
+ mPluginLayout.isSuspended = true;
+ this.activity.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ webView.loadUrl("javascript:if(window.cordova){cordova.fireDocumentEvent('plugin_url_changed', {});}");
+ }
+ });
CURRENT_URL = url;
return false;
}
@@ -298,21 +307,16 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
}
public void resumeResizeTimer(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
- cordova.getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
+ if (mPluginLayout.isWaiting) {
mPluginLayout.pauseResize = false;
+ synchronized (mPluginLayout.timerLock) {
+ mPluginLayout.timerLock.notify();
+ }
}
- });
}
public void pauseResizeTimer(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
- cordova.getActivity().runOnUiThread(new Runnable() {
- @Override
- public void run() {
mPluginLayout.pauseResize = true;
}
- });
- }
public void backHistory(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
cordova.getActivity().runOnUiThread(new Runnable() {
@Override
@@ -370,7 +374,12 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
callbackContext.success();
return;
}
+ if (mPluginLayout.isSuspended) {
mPluginLayout.isSuspended = false;
+ synchronized (mPluginLayout.timerLock) {
+ mPluginLayout.timerLock.notify();
+ }
+ }
callbackContext.success();
}
public void clearHtmlElements(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
@@ -739,8 +748,25 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
mPluginLayout.HTMLNodes.remove(mapId);
pluginMap = null;
}
+
+ try {
+ Field pluginMapField = pluginManager.getClass().getDeclaredField("pluginMap");
+ pluginMapField.setAccessible(true);
+ LinkedHashMap<String, CordovaPlugin> pluginMapInstance = (LinkedHashMap<String, CordovaPlugin>) pluginMapField.get(pluginManager);
+ pluginMapInstance.remove(mapId);
+ Field entryMapField = pluginManager.getClass().getDeclaredField("entryMap");
+ entryMapField.setAccessible(true);
+ LinkedHashMap<String, PluginEntry> entryMapInstance = (LinkedHashMap<String, PluginEntry>) entryMapField.get(pluginManager);
+ entryMapInstance.remove(mapId);
+ } catch (Exception e) {
+ e.printStackTrace();
}
+
+ }
+
+
+
System.gc();
Runtime.getRuntime().gc();
callbackContext.success();
@@ -761,6 +787,13 @@ public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
pluginManager.addService(pluginEntry);
+ if (mPluginLayout.isSuspended) {
+ mPluginLayout.isSuspended = false;
+ synchronized (mPluginLayout.timerLock) {
+ mPluginLayout.timerLock.notify();
+ }
+ }
+
pluginMap.getMap(args, callbackContext);
}

MODIFY
src/android/plugin/google/maps/MyPluginLayout.java
src/android/plugin/google/maps/MyPluginLayout.java
@@ -55,6 +55,8 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
public boolean isSuspended = false;
public boolean pauseResize = false;
private float zoomScale;
+ public final Object timerLock = new Object();
+ public boolean isWaiting = false;
public Timer redrawTimer;
@@ -75,8 +77,17 @@ public class MyPluginLayout extends FrameLayout implements ViewTreeObserver.OnSc
@Override
public void run() {
if (isSuspended || pauseResize) {
+ synchronized (timerLock) {
+ isWaiting = true;
+ try {
+ timerLock.wait();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
return;
}
+ isWaiting = false;
//final PluginMap pluginMap = pluginMaps.get(mapId);
//if (pluginMap.mapDivId == null) {
// return;

Add: stop the resize timer completely if there is no map