Skip to content

Commit

Permalink
For android sdk 30, update agp, fix from: mapsplugin#2872
Browse files Browse the repository at this point in the history
  • Loading branch information
lempere committed Sep 6, 2021
1 parent 3b965e3 commit 60f833e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 37 deletions.
20 changes: 8 additions & 12 deletions src/android/plugin/google/maps/CordovaGoogleMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,13 @@ public void getMap(final JSONArray args, final CallbackContext callbackContext)
//------------------------------------------
JSONObject meta = args.getJSONObject(0);
String mapId = meta.getString("__pgmId");
PluginMap pluginMap = new PluginMap();
pluginMap.privateInitialize(mapId, cordova, webView, null);
pluginMap.initialize(cordova, webView);
pluginMap.mapCtrl = CordovaGoogleMaps.this;
pluginMap.self = pluginMap;

PluginMap pluginMap = new PluginMap();
PluginEntry pluginEntry = new PluginEntry(mapId, pluginMap);
pluginManager.addService(pluginEntry);

pluginMap.mapCtrl = CordovaGoogleMaps.this;
pluginMap.self = pluginMap;
pluginMap.getMap(args, callbackContext);
}

Expand All @@ -470,14 +468,12 @@ public void getPanorama(final JSONArray args, final CallbackContext callbackCont
String mapId = meta.getString("__pgmId");
Log.d(TAG, "---> mapId = " + mapId);
PluginStreetViewPanorama pluginStreetView = new PluginStreetViewPanorama();
pluginStreetView.privateInitialize(mapId, cordova, webView, null);
pluginStreetView.initialize(cordova, webView);
pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
pluginStreetView.self = pluginStreetView;

PluginEntry pluginEntry = new PluginEntry(mapId, pluginStreetView);
pluginManager.addService(pluginEntry);

pluginStreetView.mapCtrl = CordovaGoogleMaps.this;
pluginStreetView.self = pluginStreetView;

pluginStreetView.getPanorama(args, callbackContext);
}

Expand Down Expand Up @@ -524,12 +520,12 @@ public void onPause(boolean multitasking) {
@Override
public void onResume(boolean multitasking) {
Collection<PluginEntry>pluginEntries = pluginManager.getPluginEntries();
for (PluginEntry pluginEntry: pluginEntries) {
for (Iterator<PluginEntry> iterator = pluginEntries.iterator(); iterator.hasNext();) {
PluginEntry pluginEntry = iterator.next();
if (pluginEntry.service.startsWith("map_")) {
pluginEntry.plugin.onResume(multitasking);
}
}

}

@Override
Expand Down
69 changes: 44 additions & 25 deletions src/android/plugin/google/maps/PluginMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,6 @@ public synchronized void loadPlugin(final JSONArray args, final CallbackContext
plugins.put(pluginName, pluginEntry);
mapCtrl.pluginManager.addService(pluginEntry);

plugin.privateInitialize(pluginName, cordova, webView, null);

plugin.initialize(cordova, webView);
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
MyPlugin myPlugin = (MyPlugin) plugin;
myPlugin.self = (MyPlugin)plugin;
Expand Down Expand Up @@ -666,8 +663,6 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
pluginMap = PluginMap.this;
pluginMap.mapCtrl.pluginManager.addService(pluginEntry);

plugin.privateInitialize(className, cordova, webView, null);
plugin.initialize(cordova, webView);
((MyPluginInterface)plugin).setPluginMap(PluginMap.this);
pluginEntry.plugin.execute("create", args, callbackContext);

Expand Down Expand Up @@ -724,28 +719,32 @@ public void run() {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (mapDivId != null) {
RectF drawRect = mapCtrl.mPluginLayout.HTMLNodeRectFs.get(mapDivId);

//Log.d(TAG, "--->mapDivId = " + mapDivId + ", drawRect = " + drawRect);
if (drawRect != null) {
final int scrollY = webView.getView().getScrollY();

int width = (int) drawRect.width();
int height = (int) drawRect.height();
int x = (int) drawRect.left;
int y = (int) drawRect.top + scrollY;
ViewGroup.LayoutParams lParams = mapView.getLayoutParams();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;

params.width = width;
params.height = height;
params.leftMargin = x;
params.topMargin = y;
mapView.setLayoutParams(params);

if(mapCtrl.mPluginLayout == null || mapDivId == null) {
callbackContext.success();
}
return;
}

RectF drawRect = mapCtrl.mPluginLayout.HTMLNodeRectFs.get(mapDivId);

//Log.d(TAG, "--->mapDivId = " + mapDivId + ", drawRect = " + drawRect);
if (drawRect != null) {
final int scrollY = webView.getView().getScrollY();

int width = (int) drawRect.width();
int height = (int) drawRect.height();
int x = (int) drawRect.left;
int y = (int) drawRect.top + scrollY;
ViewGroup.LayoutParams lParams = mapView.getLayoutParams();
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lParams;

params.width = width;
params.height = height;
params.leftMargin = x;
params.topMargin = y;
mapView.setLayoutParams(params);

callbackContext.success();
}
}
});
Expand Down Expand Up @@ -1748,6 +1747,26 @@ public void run() {
});
}


/**
* Stop camera animation
* @param args
* @param callbackContext
* @throws JSONException
*/
public void stopAnimation(JSONArray args, final CallbackContext callbackContext) throws JSONException {

this.activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if(map != null) {
map.stopAnimation();
}
callbackContext.success();
}
});
}

/**
* Pan by the specified pixel
* @param args
Expand Down

0 comments on commit 60f833e

Please sign in to comment.