Skip to content

Commit

Permalink
Merge branch 'pull_442_ios' into pull_442 (#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
wf9a5m75 committed Mar 20, 2015
2 parents 9db1a77 + 24c9454 commit 5eb845a
Show file tree
Hide file tree
Showing 17 changed files with 304 additions and 74 deletions.
6 changes: 6 additions & 0 deletions platforms/ios/DevApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
A046F7401A74DFDA004678D8 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D85846C38A094BD7AE0421C1 /* OpenGLES.framework */; };
A046F7411A74DFDA004678D8 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3943BDD383F0494ABF86A8D1 /* QuartzCore.framework */; };
A046F7421A74DFDA004678D8 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3CE5F4C8A9E143DD88320223 /* SystemConfiguration.framework */; };
A07514851AAEDE5500068A7D /* MyTouchableView.m in Sources */ = {isa = PBXBuildFile; fileRef = A07514841AAEDE5500068A7D /* MyTouchableView.m */; };
A0A6C8B519DE8B61006FA408 /* CDVLogger.m in Sources */ = {isa = PBXBuildFile; fileRef = 2642A164D871458CAA0E7CD2 /* CDVLogger.m */; };
A0B15AF119D406AE00CECFE9 /* plugin.xml in Resources */ = {isa = PBXBuildFile; fileRef = A0B15AF019D406AD00CECFE9 /* plugin.xml */; };
A0C8C25419D11E8B00E46F7E /* MyPluginScrollView.m in Sources */ = {isa = PBXBuildFile; fileRef = A0C8C25319D11E8B00E46F7E /* MyPluginScrollView.m */; };
Expand Down Expand Up @@ -188,6 +189,8 @@
8D1107310486CEB800E47090 /* DevApp-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "DevApp-Info.plist"; path = "../DevApp-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
94B42436A54042BB8390247A /* HttpRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HttpRequest.h; path = plugin.http.request/HttpRequest/HttpRequest.h; sourceTree = "<group>"; };
9D0482B04E60450894AB403B /* libz.dylib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
A07514841AAEDE5500068A7D /* MyTouchableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MyTouchableView.m; path = ../../../../src/ios/GoogleMaps/MyTouchableView.m; sourceTree = "<group>"; };
A07514871AAEDF8F00068A7D /* MyTouchableView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MyTouchableView.h; path = ../../../../src/ios/GoogleMaps/MyTouchableView.h; sourceTree = "<group>"; };
A0B15AF019D406AD00CECFE9 /* plugin.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; name = plugin.xml; path = ../../plugin.xml; sourceTree = "<group>"; };
A0C8C25219D11E8B00E46F7E /* MyPluginScrollView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MyPluginScrollView.h; path = ../../../../src/ios/GoogleMaps/MyPluginScrollView.h; sourceTree = "<group>"; };
A0C8C25319D11E8B00E46F7E /* MyPluginScrollView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MyPluginScrollView.m; path = ../../../../src/ios/GoogleMaps/MyPluginScrollView.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -349,6 +352,7 @@
307C750510C5A3420062BCA9 /* Plugins */ = {
isa = PBXGroup;
children = (
A07514871AAEDF8F00068A7D /* MyTouchableView.h */,
6904C34219D0F1A3008FFD15 /* Circle.h */,
6904C34319D0F1A3008FFD15 /* Circle.m */,
6904C34419D0F1A3008FFD15 /* External.h */,
Expand Down Expand Up @@ -395,6 +399,7 @@
5210F5E958CC4FCFA68923E4 /* R9HTTPRequest.h */,
A0C8C25519D120FC00E46F7E /* MyPluginLayerDebugView.h */,
A0C8C25619D120FC00E46F7E /* MyPluginLayerDebugView.m */,
A07514841AAEDE5500068A7D /* MyTouchableView.m */,
);
name = Plugins;
path = DevApp/Plugins;
Expand Down Expand Up @@ -624,6 +629,7 @@
6904C37019D0F1A3008FFD15 /* MyPluginLayer.m in Sources */,
6904C37219D0F1A3008FFD15 /* NSData+Base64.m in Sources */,
6904C36A19D0F1A3008FFD15 /* GoogleMaps.m in Sources */,
A07514851AAEDE5500068A7D /* MyTouchableView.m in Sources */,
6904C36E19D0F1A3008FFD15 /* Map.m in Sources */,
6904C37719D0F1A3008FFD15 /* TBXML.m in Sources */,
C92E8F2094FE418B921242FD /* BSD-LICENSE in Sources */,
Expand Down
68 changes: 56 additions & 12 deletions src/android/plugin/google/maps/MyPluginLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.os.Build;
import android.os.Build.VERSION;
Expand All @@ -26,6 +27,10 @@
import android.widget.LinearLayout;
import android.widget.ScrollView;

import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.LatLng;

@SuppressWarnings("deprecation")
public class MyPluginLayout extends FrameLayout {
private CordovaWebView webView;
Expand All @@ -34,10 +39,9 @@ public class MyPluginLayout extends FrameLayout {
private Context context;
private FrontLayerLayout frontLayer;
private ScrollView scrollView = null;
private FrameLayout scrollFrameLayout = null;
private TouchableWrapper scrollFrameLayout = null;
private View backgroundView = null;
private TouchableWrapper touchableWrapper;
private ViewGroup myView = null;
private MapView myView = null;
private boolean isScrolling = false;
private ViewGroup.LayoutParams orgLayoutParams = null;
private boolean isDebug = false;
Expand Down Expand Up @@ -67,14 +71,14 @@ public MyPluginLayout(CordovaWebView webView, Activity activity) {
backgroundView.setHorizontalScrollBarEnabled(false);
backgroundView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 9999));

scrollFrameLayout = new FrameLayout(this.context);
scrollFrameLayout = new TouchableWrapper(this.context);
scrollFrameLayout.addView(backgroundView);
scrollFrameLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

scrollView.setHorizontalScrollBarEnabled(false);
scrollView.setVerticalScrollBarEnabled(false);

this.touchableWrapper = new TouchableWrapper(this.context);
//this.touchableWrapper = new TouchableWrapper(this.context);

}

Expand Down Expand Up @@ -180,7 +184,6 @@ public void detachMyView() {
frontLayer.removeView(webView);

scrollFrameLayout.removeView(myView);
myView.removeView(this.touchableWrapper);

this.removeView(this.scrollView);
this.scrollView.removeView(scrollFrameLayout);
Expand All @@ -193,19 +196,19 @@ public void detachMyView() {
mActivity.getWindow().getDecorView().requestFocus();
}

public void attachMyView(ViewGroup pluginView) {
public void attachMyView(MapView mapView) {
scrollView.setHorizontalScrollBarEnabled(false);
scrollView.setVerticalScrollBarEnabled(false);

scrollView.scrollTo(webView.getScrollX(), webView.getScrollY());
if (myView == pluginView) {
if (myView == mapView) {
return;
} else {
this.detachMyView();
}
//backgroundView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int) (webView.getContentHeight() * webView.getScale() + webView.getHeight())));

myView = pluginView;
myView = mapView;
ViewGroup.LayoutParams lParams = myView.getLayoutParams();
orgLayoutParams = null;
if (lParams != null) {
Expand All @@ -215,8 +218,7 @@ public void attachMyView(ViewGroup pluginView) {
scrollView.addView(scrollFrameLayout);
this.addView(scrollView);

pluginView.addView(this.touchableWrapper);
scrollFrameLayout.addView(pluginView);
scrollFrameLayout.addView(mapView);

frontLayer.addView(webView);
this.addView(frontLayer);
Expand Down Expand Up @@ -247,14 +249,18 @@ public void inValidate() {
this.frontLayer.invalidate();
}


private class FrontLayerLayout extends FrameLayout {

public FrontLayerLayout(Context context) {
super(context);
this.setWillNotDraw(false);
}

/**
* True if the touch event should be received by MapView.
* False, the event is received by WebView.
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (isClickable == false || myView == null || myView.getVisibility() != View.VISIBLE) {
Expand Down Expand Up @@ -338,6 +344,44 @@ public TouchableWrapper(Context context) {
super(context);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (isClickable == false || myView == null || myView.getVisibility() != View.VISIBLE) {
webView.requestFocus(View.FOCUS_DOWN);
return false;
}
String eventName = null;
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
eventName = "touchstart";
break;
case MotionEvent.ACTION_MOVE:
eventName = "touchmove";
break;
case MotionEvent.ACTION_UP:
eventName = "touchend";
break;
case MotionEvent.ACTION_CANCEL:
eventName = "touchcancel";
break;
case MotionEvent.ACTION_OUTSIDE:
eventName = "touchleave";
break;
default:
break;
}
int x = (int)event.getX() - myView.getLeft();
int y = (int)event.getY() - myView.getTop();
Projection projection = myView.getMap().getProjection();
Point point = new Point(x, y);
LatLng latLng = projection.fromScreenLocation(point);
webView.loadUrl(
String.format("javascript:plugin.google.maps.Map._onTouchEvent('%s', [%d, %d], new window.plugin.google.maps.LatLng(%f, %f));",
eventName, x, y, latLng.latitude, latLng.longitude));

return false;
}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int action = event.getAction();
Expand Down
2 changes: 2 additions & 0 deletions src/ios/GoogleMaps/GoogleMaps.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ - (void)pluginInitialize
self.webView.scrollView.delegate = self;
[self.pluginScrollView setContentSize:CGSizeMake(320, 960) ];

self.pluginLayer.touchableView = self.pluginScrollView.touchableView;

//[self.webView removeFromSuperview];
self.pluginLayer.webView = self.webView;
[self.pluginLayer addSubview:self.pluginScrollView];
Expand Down
5 changes: 4 additions & 1 deletion src/ios/GoogleMaps/GoogleMapsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "PluginUtil.h"
#import "NSData+Base64.h"

@interface GoogleMapsViewController : UIViewController<GMSMapViewDelegate>
@interface GoogleMapsViewController : UIViewController<GMSMapViewDelegate, GMSIndoorDisplayDelegate>

@property (nonatomic, strong) GMSMapView* map;
@property (nonatomic, strong) UIWebView* webView;
Expand All @@ -37,4 +37,7 @@

- (void)removeObjectForKey: (NSString *)key;
- (BOOL)didTapMyLocationButtonForMapView:(GMSMapView *)mapView;

- (void) didChangeActiveBuilding: (GMSIndoorBuilding *)building;
- (void) didChangeActiveLevel: (GMSIndoorLevel *)level;
@end
40 changes: 40 additions & 0 deletions src/ios/GoogleMaps/GoogleMapsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ - (void)viewDidLoad
//self.map.autoresizingMask = UIViewAutoresizingNone;
self.map.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

//indoor display
self.map.indoorDisplay.delegate = self;


BOOL isEnabled = NO;
//controls
Expand Down Expand Up @@ -647,6 +650,43 @@ -(UIImage *)loadImageFromGoogleMap:(NSString *)fileName {
}


- (void) didChangeActiveBuilding: (GMSIndoorBuilding *)building {
//Notify to the JS
NSString* jsString = @"javascript:plugin.google.maps.Map._onMapEvent('indoor_building_focused')";
[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}

- (void) didChangeActiveLevel: (GMSIndoorLevel *)activeLevel {

GMSIndoorBuilding *building = self.map.indoorDisplay.activeBuilding;

NSMutableDictionary *result = [NSMutableDictionary dictionary];

NSUInteger activeLevelIndex = [building.levels indexOfObject:activeLevel];
[result setObject:[NSNumber numberWithInteger:activeLevelIndex] forKey:@"activeLevelIndex"];
[result setObject:[NSNumber numberWithInteger:building.defaultLevelIndex] forKey:@"defaultLevelIndex"];

GMSIndoorLevel *level;
NSMutableDictionary *levelInfo;
NSMutableArray *levels = [NSMutableArray array];
for (level in building.levels) {
levelInfo = [NSMutableDictionary dictionary];

[levelInfo setObject:[NSString stringWithString:level.name] forKey:@"name"];
[levelInfo setObject:[NSString stringWithString:level.shortName] forKey:@"shortName"];
[levels addObject:levelInfo];
}
[result setObject:levels forKey:@"levels"];

NSError *error;
NSData *data = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:&error];

NSString *JSONstring = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
NSString *jsString = [NSString stringWithFormat:@"javascript:plugin.google.maps.Map._onMapEvent('indoor_level_activated', %@)", JSONstring];

[self.webView stringByEvaluatingJavaScriptFromString:jsString];
}



Expand Down
1 change: 1 addition & 0 deletions src/ios/GoogleMaps/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
- (void)setAllGesturesEnabled:(CDVInvokedUrlCommand*)command;
- (void)setPadding:(CDVInvokedUrlCommand*)command;
- (void)panBy:(CDVInvokedUrlCommand*)command;
- (void)getFocusedBuilding:(CDVInvokedUrlCommand*)command;
@end
31 changes: 31 additions & 0 deletions src/ios/GoogleMaps/Map.m
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,35 @@ - (void)setPadding:(CDVInvokedUrlCommand *)command {

[self.mapCtrl.map setPadding:padding];
}

- (void)getFocusedBuilding:(CDVInvokedUrlCommand*)command {
GMSIndoorBuilding *building = self.mapCtrl.map.indoorDisplay.activeBuilding;
if (building != nil) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
GMSIndoorLevel *activeLevel = self.mapCtrl.map.indoorDisplay.activeLevel;

NSMutableDictionary *result = [NSMutableDictionary dictionary];

NSUInteger activeLevelIndex = [building.levels indexOfObject:activeLevel];
[result setObject:[NSNumber numberWithInteger:activeLevelIndex] forKey:@"activeLevelIndex"];
[result setObject:[NSNumber numberWithInteger:building.defaultLevelIndex] forKey:@"defaultLevelIndex"];

GMSIndoorLevel *level;
NSMutableDictionary *levelInfo;
NSMutableArray *levels = [NSMutableArray array];
for (level in building.levels) {
levelInfo = [NSMutableDictionary dictionary];

[levelInfo setObject:[NSString stringWithString:level.name] forKey:@"name"];
[levelInfo setObject:[NSString stringWithString:level.shortName] forKey:@"shortName"];
[levels addObject:levelInfo];
}
[result setObject:levels forKey:@"levels"];


CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:result];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@end
2 changes: 2 additions & 0 deletions src/ios/GoogleMaps/MyPluginLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

#import <UIKit/UIKit.h>
#import <GoogleMaps/GoogleMaps.h>
#import "MyTouchableView.h";
#import "GoogleMapsViewController.h"

@interface MyPluginLayer : UIView

@property (nonatomic) UIWebView *webView;
@property (nonatomic) GoogleMapsViewController* mapCtrl;
@property (nonatomic) MyTouchableView* touchableView;
@property (nonatomic) NSDictionary *embedRect;
@property (nonatomic) BOOL debuggable;
@property (nonatomic) BOOL clickable;
Expand Down
8 changes: 6 additions & 2 deletions src/ios/GoogleMaps/MyPluginLayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
return nil;
}
}
return hitView;

self.touchableView.mapCtrl = self.mapCtrl;

//NSLog(@"hitClass = %@", hitView);
return self.touchableView;
//return hitView;
}

return [super hitTest:point withEvent:event];
Expand Down Expand Up @@ -139,5 +144,4 @@ - (void)drawRect:(CGRect)rect
CGContextFillRect(context, rectangle);
}


@end
2 changes: 2 additions & 0 deletions src/ios/GoogleMaps/MyPluginScrollView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
//

#import <UIKit/UIKit.h>
#import "MyTouchableView.h"
#import "MyPluginLayerDebugView.h"

@interface MyPluginScrollView : UIScrollView
@property (nonatomic) MyPluginLayerDebugView *debugView;
@property (nonatomic) MyTouchableView *touchableView;
- (void)attachView:(UIView *)view;
- (void)dettachView;
@end
3 changes: 3 additions & 0 deletions src/ios/GoogleMaps/MyPluginScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ - (id)initWithFrame:(CGRect)aRect
{
self = [super initWithFrame:aRect];
self.debugView = [[MyPluginLayerDebugView alloc] initWithFrame:aRect];
self.touchableView = [[MyTouchableView alloc] initWithFrame:aRect];
return self;
}

- (void)attachView:(UIView *)view {
myView = view;
[myView addSubview:self.touchableView];
[self addSubview:view];
[self addSubview:self.debugView];
}
- (void)dettachView {
[self.touchableView removeFromSuperview];
[myView removeFromSuperview];
[self.debugView removeFromSuperview];
}
Expand Down
Loading

0 comments on commit 5eb845a

Please sign in to comment.