Skip to content

Commit

Permalink
Fix build errors caused with cordova-ios@7 due to CDVCommandDel.
Browse files Browse the repository at this point in the history
Cherry pick of all code in remote PR: mapsplugin#2927.
  • Loading branch information
vpatel committed May 1, 2024
1 parent bdb7af4 commit e0efbb5
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ For browser platform,

## Install optional variables (config.xml)

- ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **GOOGLE_MAPS_PLAY_SERVICES_VERSION = (16.0.1)**<br>
- ![](https://raw.githubusercontent.com/mapsplugin/cordova-plugin-googlemaps/master/images/icon-android.png) **GOOGLE_MAPS_PLAY_SERVICES_VERSION = (18.+)**<br>
The Google Play Services SDK version.
_You need to specify the same version number with all other plugins._
Check out the latest version [here](https://developers.google.com/android/guides/releases).
Expand Down
2 changes: 1 addition & 1 deletion src/android/frameworks/pgm-custom.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ android {
Properties props = new Properties()
def isKeyFound = 0
def useBetaSdk = 0
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "16.0.0");
props.setProperty("GOOGLE_MAPS_PLAY_SERVICES_VERSION", "18.+");
props.setProperty("ANDROID_SUPPORT_V4_VERSION", "27.1.1");
props.setProperty("GOOGLE_MAPS_ANDROID_SDK", "");

Expand Down
43 changes: 29 additions & 14 deletions src/android/plugin/google/maps/CordovaGoogleMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
import android.view.ViewGroup;
import android.view.ViewTreeObserver;

import androidx.annotation.NonNull;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.MapsInitializer.Renderer;
import com.google.android.gms.maps.OnMapsSdkInitializedCallback;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
Expand All @@ -44,8 +48,10 @@
import java.util.LinkedHashMap;
import java.util.Set;

import javax.swing.Renderer;

@SuppressWarnings("deprecation")
public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver.OnScrollChangedListener{
public class CordovaGoogleMaps extends CordovaPlugin implements ViewTreeObserver.OnScrollChangedListener, OnMapsSdkInitializedCallback{
private final String TAG = "GoogleMapsPlugin";
private Activity activity;
public ViewGroup root;
Expand All @@ -69,6 +75,8 @@ public void initialize(final CordovaInterface cordova, final CordovaWebView webV

pluginManager = webView.getPluginManager();

CordovaGoogleMaps that = this;

cordova.getActivity().runOnUiThread(new Runnable() {
@SuppressLint("NewApi")
public void run() {
Expand Down Expand Up @@ -202,17 +210,27 @@ public void onClick(DialogInterface dialog,int id) {
//------------------------------
if (!initialized) {
try {
MapsInitializer.initialize(cordova.getActivity());
initialized = true;
MapsInitializer.initialize(cordova.getActivity(), Renderer.LATEST, that);
} catch (Exception e) {
e.printStackTrace();
}
}

}
});
}


@Override
public void onMapsSdkInitialized(@NonNull Renderer renderer) {
initialized = true;
switch (renderer) {
case LATEST:
Log.d(TAG, "The latest version of the renderer is used");
break;
case LEGACY:
Log.d(TAG, "The legacy version of the renderer is used");
break;
}
}

@Override
Expand Down Expand Up @@ -448,15 +466,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;

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

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

Expand All @@ -470,14 +486,13 @@ 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
10 changes: 2 additions & 8 deletions src/android/plugin/google/maps/PluginMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,10 +612,7 @@ public synchronized void loadPlugin(final JSONArray args, final CallbackContext
PluginEntry pluginEntry = new PluginEntry(pluginName, plugin);
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 @@ -665,13 +662,10 @@ public void create(final JSONArray args, final CallbackContext callbackContext)
plugins.put(className, pluginEntry);
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);


} catch (Exception e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion src/ios/GoogleMaps/PluginMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ - (void)setActiveMarkerId:(CDVInvokedUrlCommand*)command {
}

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

Expand Down
44 changes: 22 additions & 22 deletions src/ios/GoogleMaps/PluginMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ -(void)create:(CDVInvokedUrlCommand *)command
[createResult setObject:markerId forKey:@"__pgmId"];

[[NSOperationQueue mainQueue] addOperationWithBlock:^{
CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
__weak __auto_type weakSelf = self;
[self _create:markerId markerOptions:json callbackBlock:^(BOOL successed, id result) {
CDVPluginResult* pluginResult;

Expand All @@ -93,7 +93,7 @@ -(void)create:(CDVInvokedUrlCommand *)command

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:createResult ];
}
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];

}];
Expand Down Expand Up @@ -255,7 +255,7 @@ -(void)showInfoWindow:(CDVInvokedUrlCommand *)command
}

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -270,7 +270,7 @@ -(void)hideInfoWindow:(CDVInvokedUrlCommand *)command
self.mapCtrl.map.selectedMarker = nil;
self.mapCtrl.activeMarker = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -295,7 +295,7 @@ -(void)getPosition:(CDVInvokedUrlCommand *)command
[json setObject:longitude forKey:@"lng"];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:json];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

Expand All @@ -319,7 +319,7 @@ -(void)setTitle:(CDVInvokedUrlCommand *)command


CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -338,7 +338,7 @@ -(void)setSnippet:(CDVInvokedUrlCommand *)command
marker.snippet = [command.arguments objectAtIndex:1];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -358,7 +358,7 @@ -(void)remove:(CDVInvokedUrlCommand *)command
marker = nil;

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand Down Expand Up @@ -424,7 +424,7 @@ -(void)setIconAnchor:(CDVInvokedUrlCommand *)command
}

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

Expand All @@ -450,7 +450,7 @@ -(void)setInfoWindowAnchor:(CDVInvokedUrlCommand *)command
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR];
}
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];

}];
Expand All @@ -470,7 +470,7 @@ -(void)setOpacity:(CDVInvokedUrlCommand *)command
marker.opacity = [[command.arguments objectAtIndex:1] floatValue];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -488,7 +488,7 @@ -(void)setZIndex:(CDVInvokedUrlCommand *)command
marker.zIndex = [[command.arguments objectAtIndex:1] intValue];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -507,7 +507,7 @@ -(void)setDraggable:(CDVInvokedUrlCommand *)command
[marker setDraggable:isEnabled];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -530,7 +530,7 @@ -(void)setDisableAutoPan:(CDVInvokedUrlCommand *)command
NSLog(@"--->propertyId = %@", propertyId);

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}

Expand Down Expand Up @@ -560,7 +560,7 @@ -(void)setVisible:(CDVInvokedUrlCommand *)command
[self.mapCtrl.objects setObject:properties forKey:propertyId];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -582,7 +582,7 @@ -(void)setPosition:(CDVInvokedUrlCommand *)command
[marker setPosition:position];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -601,7 +601,7 @@ -(void)setFlat:(CDVInvokedUrlCommand *)command
[marker setFlat: isFlat];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand Down Expand Up @@ -645,15 +645,15 @@ -(void)setIcon:(CDVInvokedUrlCommand *)command
[iconProperty setObject:[rgbColor parsePluginColor] forKey:@"iconColor"];
}

CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
__weak __auto_type weakSelf = self;
[self setIcon_:marker iconProperty:iconProperty callbackBlock:^(BOOL successed, id resultObj) {
CDVPluginResult* pluginResult;
if (successed == NO) {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:resultObj];
} else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
}
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -671,7 +671,7 @@ -(void)setRotation:(CDVInvokedUrlCommand *)command
[marker setRotation:degrees];

CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Expand All @@ -686,11 +686,11 @@ -(void)setAnimation:(CDVInvokedUrlCommand *)command
GMSMarker *marker = [self.mapCtrl.objects objectForKey:markerId];

NSString *animation = [command.arguments objectAtIndex:1];
CDVCommandDelegateImpl *cmdDelegate = (CDVCommandDelegateImpl *)self.commandDelegate;
__weak __auto_type weakSelf = self;

[self setMarkerAnimation_:animation marker:marker callbackBlock:^(void) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[cmdDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}];
Expand Down
2 changes: 1 addition & 1 deletion src/ios/GoogleMaps/PluginMarkerCluster.m
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ - (void)redrawClusters:(CDVInvokedUrlCommand*)command {
- (void) endRedraw:(CDVInvokedUrlCommand*)command {
NSLog(@"--->allResults = %@", self.allResults);
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:self.allResults];
[(CDVCommandDelegateImpl *)self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void) deleteProcess:(NSDictionary *) params clusterId:(NSString *)clusterId{
Expand Down
5 changes: 0 additions & 5 deletions src/ios/GoogleMaps/PluginUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#import "IPluginProtocol.h"
#import "PluginViewController.h"
#import <Cordova/CDVCommandDelegate.h>
#import <Cordova/CDVCommandDelegateImpl.h>

typedef void (^MYCompletionHandler)(NSError *error);

Expand Down Expand Up @@ -49,10 +48,6 @@ typedef void (^MYCompletionHandler)(NSError *error);
- (UIImage *)resize:(CGFloat)width height:(CGFloat)height;
@end

@interface CDVCommandDelegateImpl (GoogleMapsPlugin)
- (void)hookSendPluginResult:(CDVPluginResult*)result callbackId:(NSString*)callbackId;
@end

//
// animationDidStop for group animation
// http://stackoverflow.com/a/28051909/697856
Expand Down
Loading

0 comments on commit e0efbb5

Please sign in to comment.