Permalink
Browse files

updated ExternalScreen plugin for Cordova naming conventions, updated…

… multi-screen fleet manager demo, moved PGLowLatencyAudio samples to the iOS directory

Updated ExternalScreen plugin for Cordova naming conventions - works
with PhoneGap 2.0

Updated multi-screen fleet manager demo - uses updated ExternalScreen
plugin, uses Leaflet instead of google maps (better animation, no api
key dependency)

Moved PGLowLatencyAudio samples to the iOS directory
  • Loading branch information...
triceam committed Aug 13, 2012
1 parent 5ea295e commit 90ab3140c2312ef001cbdcdd9dd5f4cf4c08763e
Showing with 11,696 additions and 0 deletions.
  1. +36 −0 iOS/ExternalScreen/README
  2. +24 −0 iOS/ExternalScreen/plugin/ExternalScreen.js
  3. +46 −0 iOS/ExternalScreen/plugin/PGExternalScreen.h
  4. +241 −0 iOS/ExternalScreen/plugin/PGExternalScreen.m
  5. +47 −0 iOS/ExternalScreen/samples/basic usage/www/index.html
  6. +11 −0 iOS/ExternalScreen/samples/basic usage/www/secondary.html
  7. +20 −0 iOS/ExternalScreen/samples/fbi rss/www/assets/activityIndicator.css
  8. +121 −0 iOS/ExternalScreen/samples/fbi rss/www/assets/styles.css
  9. +36 −0 iOS/ExternalScreen/samples/fbi rss/www/index.html
  10. +140 −0 iOS/ExternalScreen/samples/fbi rss/www/js/application.js
  11. +1,073 −0 iOS/ExternalScreen/samples/fbi rss/www/js/iscroll.js
  12. +4 −0 iOS/ExternalScreen/samples/fbi rss/www/js/jquery-1.7.1.min.js
  13. +47 −0 iOS/ExternalScreen/samples/fbi rss/www/js/noClickDelay.js
  14. +20 −0 iOS/ExternalScreen/samples/fleet manager/www/assets/activityIndicator.css
  15. BIN iOS/ExternalScreen/samples/fleet manager/www/assets/airplane.png
  16. +153 −0 iOS/ExternalScreen/samples/fleet manager/www/assets/styles.css
  17. +36 −0 iOS/ExternalScreen/samples/fleet manager/www/index.html
  18. +125 −0 iOS/ExternalScreen/samples/fleet manager/www/js/application.js
  19. +1,073 −0 iOS/ExternalScreen/samples/fleet manager/www/js/iscroll.js
  20. +4 −0 iOS/ExternalScreen/samples/fleet manager/www/js/jquery-1.7.1.min.js
  21. BIN iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/images/layers.png
  22. BIN iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/images/marker-icon.png
  23. BIN iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/images/marker-shadow.png
  24. BIN iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/images/zoom-in.png
  25. BIN iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/images/zoom-out.png
  26. +7,638 −0 iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/leaflet-src.js
  27. +379 −0 iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/leaflet.css
  28. +44 −0 iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/leaflet.ie.css
  29. +6 −0 iOS/ExternalScreen/samples/fleet manager/www/js/leaflet/leaflet.js
  30. +47 −0 iOS/ExternalScreen/samples/fleet manager/www/js/noClickDelay.js
  31. +75 −0 iOS/ExternalScreen/samples/fleet manager/www/map.html
  32. +4 −0 iOS/LowLatencyAudio/examples/drum machine/assets/README.txt
  33. BIN iOS/LowLatencyAudio/examples/drum machine/assets/bass drum.mp3
  34. BIN iOS/LowLatencyAudio/examples/drum machine/assets/bongo.mp3
  35. BIN iOS/LowLatencyAudio/examples/drum machine/assets/carbonFiber.png
  36. BIN iOS/LowLatencyAudio/examples/drum machine/assets/high hat closed.mp3
  37. BIN iOS/LowLatencyAudio/examples/drum machine/assets/snare drum.mp3
  38. +110 −0 iOS/LowLatencyAudio/examples/drum machine/index.html
  39. +27 −0 iOS/LowLatencyAudio/examples/game simulator/assets/README.txt
  40. BIN iOS/LowLatencyAudio/examples/game simulator/assets/background.mp3
  41. +109 −0 iOS/LowLatencyAudio/examples/game simulator/index.html
View
@@ -0,0 +1,36 @@
+PhoneGap iOS ExternalScreen Plugin
+
+THIS SOFTWARE IS PROVIDED BY THE ANDREW TRICE "AS IS" AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The PhoneGap iOS ExternalScreen Plugin is a native Plugin for PhoneGap/Apache Cordova which enables multi-screen application scenarios for PhoneGap projects. This plugin is only for for iOS devices.
+
+The PhoneGap native plugin is written in Objective C, with a JavaScript interface to integrate with the client application.
+
+Detail on creating PhoneGap projects for iOS at:
+http://phonegap.com/start#ios-x4
+
+More detail on PhoneGap Native Plugins at:
+http://wiki.phonegap.com/w/page/36752779/PhoneGap%20Plugins
+http://wiki.phonegap.com/w/page/36753496/How%20to%20Create%20a%20PhoneGap%20Plugin%20for%20iOS
+http://wiki.phonegap.com/w/page/43708792/How%20to%20Install%20a%20PhoneGap%20Plugin%20for%20iOS"
+
+The ExternalScreen plugin creates a UIWebView for the the external screen, and exposes methods for interacting with the UIWebView.   Note: This is just a normal UIWebView, it does not have support for all PhoneGap libraries... just a standard HTML container.
+
+The "plugin" directory contains both the Objective-C native code, as well as the client-side javascript libraries. To use this code, you must create PhoneGap project for iOS, copy the PGExternalScreen.h and PGExternalScreen.m files into the native code project under the "Plugins" directory. You will need to copy the ExternalScreen.js file into the www folder for the phonegap project (or any child of that), and add references to your HTML/JS files. You will also need to add a mapping in PhoneGap.plist for the native plugin.
+
+The "samples" directory contains 3 sample applications:
+ * Basic usage of javascript functions
+ * FBI RSS Reader
+ * Fleet Manager Scenario
+
+Further explanation, plus videos showing the sample applications at:
+http://www.tricedesigns.com/2012/01/12/multi-screen-ios-apps-with-phonegap
@@ -0,0 +1,24 @@
+var PGExternalScreen = {
+
+ setupScreenConnectionNotificationHandlers: function (success, fail) {
+ return cordova.exec(success, fail, "PGExternalScreen", "setupScreenConnectionNotificationHandlers", []);
+ },
+
+ loadHTMLResource: function (url, success, fail) {
+ return cordova.exec(success, fail, "PGExternalScreen", "loadHTMLResource", [url]);
+ },
+
+ loadHTML: function (url, success, fail) {
+ return cordova.exec(success, fail, "PGExternalScreen", "loadHTML", [url]);
+ },
+
+ invokeJavaScript: function (scriptString, success, fail) {
+ return cordova.exec(success, fail, "PGExternalScreen", "invokeJavaScript", [scriptString]);
+ },
+
+ checkExternalScreenAvailable: function (success, fail) {
+ return cordova.exec(success, fail, "PGExternalScreen", "checkExternalScreenAvailable", []);
+ }
+
+
+};
@@ -0,0 +1,46 @@
+//
+// PGExternalScreen.h
+// MultiScreenPlugin
+//
+// Created by Andrew Trice on 1/9/12.
+//
+//
+// THIS SOFTWARE IS PROVIDED BY THE ANDREW TRICE "AS IS" AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#import <Foundation/Foundation.h>
+#import <Cordova/CDV.h>
+
+
+@interface PGExternalScreen : CDVPlugin {
+
+ UIWindow* externalWindow;
+ UIScreen* externalScreen;
+ UIWebView* webView;
+ NSString *baseURLAddress;
+ NSURL *baseURL;
+}
+
+
+//Public Instance Method (visible in phonegap API)
+- (void) setupScreenConnectionNotificationHandlers:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options ;
+- (void) loadHTMLResource:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) loadHTML:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) invokeJavaScript:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+- (void) checkExternalScreenAvailable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
+
+
+//Instance Method
+- (void) attemptSecondScreenView;
+- (void) handleScreenConnectNotification:(NSNotification*)aNotification;
+- (void) handleScreenDisconnectNotification:(NSNotification*)aNotification;
+@end
@@ -0,0 +1,241 @@
+//
+// PGExternalScreen.m
+// MultiScreenPlugin
+//
+// Created by Andrew Trice on 1/9/12.
+//
+//
+// THIS SOFTWARE IS PROVIDED BY THE ANDREW TRICE "AS IS" AND ANY EXPRESS OR
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL ANDREW TRICE OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#import "PGExternalScreen.h"
+
+
+@implementation PGExternalScreen
+
+
+NSString* WEBVIEW_UNAVAILABLE = @"External Web View Unavailable";
+NSString* WEBVIEW_OK = @"OK";
+NSString* SCREEN_NOTIFICATION_HANDLERS_OK =@"External screen notification handlers initialized";
+
+//used to load an HTML file in external screen web view
+- (void) loadHTMLResource:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+ NSString* callbackId = [arguments objectAtIndex:0];
+ CDVPluginResult* pluginResult;
+
+ if (webView)
+ {
+
+ NSString *stringObtainedFromJavascript = [arguments objectAtIndex:1];
+ [stringObtainedFromJavascript retain];
+
+ NSRange textRange;
+ textRange =[[stringObtainedFromJavascript lowercaseString] rangeOfString:@"http://"];
+ NSError *error = nil;
+ NSURL *url;
+
+ //found "http://", so load remote resource
+ if(textRange.location != NSNotFound)
+ {
+ url = [NSURL URLWithString:stringObtainedFromJavascript];
+ [url retain];
+ }
+ //load local resource
+ else
+ {
+
+ NSString* path = [NSString stringWithFormat:@"%@/%@", baseURLAddress, stringObtainedFromJavascript];
+ [path retain];
+ url = [NSURL fileURLWithPath:path isDirectory:NO];
+ [url retain];
+ [path release];
+ }
+ NSURLRequest *request = [NSURLRequest requestWithURL:url];
+ [webView loadRequest:request];
+
+ [url release];
+ [stringObtainedFromJavascript release];
+
+ if(error) {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: [error localizedDescription]];
+ [self writeJavascript: [pluginResult toErrorCallbackString:callbackId]];
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: WEBVIEW_OK];
+ [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
+ }
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: WEBVIEW_UNAVAILABLE];
+ [self writeJavascript: [pluginResult toErrorCallbackString:callbackId]];
+ }
+}
+
+//used to load an HTML string in external screen web view
+- (void) loadHTML:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+
+ NSString* callbackId = [arguments objectAtIndex:0];
+ CDVPluginResult* pluginResult;
+
+ if (webView)
+ {
+ NSString *stringObtainedFromJavascript = [arguments objectAtIndex:1];
+ [stringObtainedFromJavascript retain];
+ [webView loadHTMLString:stringObtainedFromJavascript baseURL:baseURL];
+ [stringObtainedFromJavascript release];
+
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: WEBVIEW_OK];
+ [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: WEBVIEW_UNAVAILABLE];
+ [self writeJavascript: [pluginResult toErrorCallbackString:callbackId]];
+ }
+
+}
+
+
+//used to invoke javascript in external screen web view
+- (void) invokeJavaScript:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+
+ NSString* callbackId = [arguments objectAtIndex:0];
+ CDVPluginResult* pluginResult;
+
+ if (webView)
+ {
+ NSString *stringObtainedFromJavascript = [arguments objectAtIndex:1];
+ [stringObtainedFromJavascript retain];
+ [webView stringByEvaluatingJavaScriptFromString: stringObtainedFromJavascript];
+ [stringObtainedFromJavascript release];
+
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: WEBVIEW_OK];
+ [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
+ }
+ else
+ {
+ pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString: WEBVIEW_UNAVAILABLE];
+ [self writeJavascript: [pluginResult toErrorCallbackString:callbackId]];
+ }
+
+}
+
+//used to initialize monitoring of external screen
+- (void)setupScreenConnectionNotificationHandlers:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+ NSString* callbackId = [arguments objectAtIndex:0];
+
+ NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
+
+ [center addObserver:self selector:@selector(handleScreenConnectNotification:)
+ name:UIScreenDidConnectNotification object:nil];
+ [center addObserver:self selector:@selector(handleScreenDisconnectNotification:)
+ name:UIScreenDidDisconnectNotification object:nil];
+
+ [self attemptSecondScreenView];
+
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: SCREEN_NOTIFICATION_HANDLERS_OK];
+
+ [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
+}
+
+//used to determine if an external screen is available
+- (void) checkExternalScreenAvailable:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
+{
+ NSString* callbackId = [arguments objectAtIndex:0];
+
+ NSString* result = nil;
+ if ([[UIScreen screens] count] > 1) {
+ result = @"YES";
+ }
+ else
+ {
+ result = @"NO";
+ }
+ [result retain];
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString: result];
+ [self writeJavascript: [pluginResult toSuccessCallbackString:callbackId]];
+ [result release];
+}
+
+
+
+//invoked when an additional screen is connected to iOS device (VGA or Airplay)
+- (void)handleScreenConnectNotification:(NSNotification*)aNotification
+{
+ if (!externalWindow)
+ {
+ [self attemptSecondScreenView];
+ }
+}
+
+//invoked when an additional screen is disconnected
+- (void)handleScreenDisconnectNotification:(NSNotification*)aNotification
+{
+ if (externalWindow)
+ {
+ externalWindow.hidden = YES;
+ [externalWindow release];
+ externalWindow = nil; }
+
+ if (webView)
+ {
+ [webView release];
+ webView = nil;
+ }
+
+}
+
+
+- (void) attemptSecondScreenView
+{
+ if ([[UIScreen screens] count] > 1) {
+
+ // Internal display is 0, external is 1.
+ externalScreen = [[[UIScreen screens] objectAtIndex:1] retain];
+
+ CGRect screenBounds = externalScreen.bounds;
+
+ externalWindow = [[UIWindow alloc] initWithFrame:screenBounds];
+ externalWindow.screen = externalScreen;
+
+ externalWindow.frame = screenBounds;
+ externalWindow.clipsToBounds = YES;
+
+ webView = [[UIWebView alloc] initWithFrame:screenBounds];
+ [webView retain];
+
+ baseURLAddress = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"www"];
+ [baseURLAddress retain];
+
+ baseURL = [NSURL URLWithString:baseURLAddress];
+ [baseURL retain];
+
+ [webView loadHTMLString:@"loading..." baseURL:baseURL];
+
+ [externalWindow addSubview:webView];
+ [externalWindow makeKeyAndVisible];
+ externalWindow.hidden = NO;
+ }
+ else
+ {
+ externalWindow.hidden = YES;
+ }
+}
+
+
+@end
Oops, something went wrong.

0 comments on commit 90ab314

Please sign in to comment.