Skip to content

Commit

Permalink
Bug fix: map.clear() does not work correctly (#1639, #1669)
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Aug 25, 2017
1 parent e66cd25 commit dbc1520
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-googlemaps" version="2.0.0-beta3-20170823-2235" 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.0.0-beta3-20170824-1832" 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 />
Expand Down
59 changes: 24 additions & 35 deletions src/android/plugin/google/maps/PluginMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,54 +100,48 @@ public void run() {
@Override
protected void clear() {
synchronized (semaphoreAsync) {
semaphoreAsync.put("waitCnt", 2);

//--------------------------------------
// Cancel tasks
//--------------------------------------
cordova.getThreadPool().submit(new Runnable() {
@Override
public void run() {
//--------------------------------------
// Cancel tasks
//--------------------------------------
AsyncTask task;
if (iconLoadingTasks != null && iconLoadingTasks.size() > 0) {
int i, ilen = iconLoadingTasks.size();
for (i = 0; i < ilen; i++) {
task = iconLoadingTasks.remove(i);
task = iconLoadingTasks.get(i);
task.cancel(true);
task = null;
}
}
iconLoadingTasks = null;
synchronized (semaphoreAsync) {
int waitCnt = semaphoreAsync.get("waitCnt");
waitCnt = waitCnt - 1;
semaphoreAsync.put("waitCnt", waitCnt);
if (waitCnt < 1) {
semaphoreAsync.notify();
}
}
}
});


//--------------------------------------
// Recycle bitmaps as much as possible
//--------------------------------------
String[] cacheKeys = iconCacheKeys.keySet().toArray(new String[iconCacheKeys.size()]);
for (int i = 0; i < cacheKeys.length; i++) {
AsyncLoadImage.removeBitmapFromMemCahce(cacheKeys[i]);
iconCacheKeys.remove(cacheKeys[i]);
if (iconCacheKeys != null) {
String[] cacheKeys = iconCacheKeys.keySet().toArray(new String[iconCacheKeys.size()]);
for (int i = 0; i < cacheKeys.length; i++) {
AsyncLoadImage.removeBitmapFromMemCahce(cacheKeys[i]);
iconCacheKeys.remove(cacheKeys[i]);
}
cacheKeys = null;
}
cacheKeys = null;
Bitmap[] cachedBitmaps = icons.toArray(new Bitmap[icons.size()]);
Bitmap image;
for (int i = 0; i < cachedBitmaps.length; i++) {
image = icons.remove(0);
if (image != null && !image.isRecycled()) {
image.recycle();
if (icons != null) {
Bitmap[] cachedBitmaps = icons.toArray(new Bitmap[icons.size()]);
Bitmap image;
for (int i = 0; i < cachedBitmaps.length; i++) {
image = icons.remove(0);
if (image != null && !image.isRecycled()) {
image.recycle();
}
image = null;
}
image = null;
icons.clear();
}
icons.clear();

//--------------------------------------
// clean up properties as much as possible
Expand Down Expand Up @@ -177,19 +171,14 @@ public void run() {
}

synchronized (semaphoreAsync) {
int waitCnt = semaphoreAsync.get("waitCnt");
waitCnt = waitCnt - 1;
semaphoreAsync.put("waitCnt", waitCnt);
if (waitCnt < 1) {
semaphoreAsync.notify();
}
semaphoreAsync.notify();
}

}
});

try {
semaphoreAsync.wait();
semaphoreAsync.wait(5);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down

0 comments on commit dbc1520

Please sign in to comment.