Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/NachoMan/phonegap into edge
Browse files Browse the repository at this point in the history
  • Loading branch information
sintaxi committed Apr 24, 2009
2 parents f8beb90 + f4f758c commit 537c4a2
Show file tree
Hide file tree
Showing 66 changed files with 3,905 additions and 1,362 deletions.
19 changes: 18 additions & 1 deletion README.md
Expand Up @@ -34,22 +34,39 @@ API

### Device

Exposes properties of the phone, such as its device ID, model, and OS version number.

### Location

Gain access to the Latitude / Longitude of the device, and depending on the type of device, the course, speed, and altitude.

### Accelerometer

Monitor the accelerometer on the device to detect orientation, shaking and other similar actions.

### Contacts

Query the phone addressbook to read the users contacts.

### Orientation

Read the device layout orientation, e.g. landscape vs portrait.

### Camera

Brings up the camera or photo browser on the phone to allow the user to upload a photo.

### Vibrate

Triggers the vibration alert on the phone, if it is supported.

### Sound

Play sound files (WAV, MP3, etc).

### Telephony

Trigger and activate phone calls.

XUI
-------------------------------------------------------------
Expand Down Expand Up @@ -91,4 +108,4 @@ THE SOFTWARE.

-------------------------------------------------------------

*phonegap is a [nitobi](http://nitobi.com) sponsored project*
*phonegap is a [nitobi](http://nitobi.com) sponsored project*
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -22,7 +22,7 @@ def doc
end
FileUtils.mkdir_p "#{ LIBPATH }tmp"
open(final,'w'){|f| f.puts( js )}
sh "java -jar util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }jsrun.jar util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }app#{ File::SEPARATOR }run.js -a -t=util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }templates#{ File::SEPARATOR }jsdoc tmp#{ File::SEPARATOR }phonegap.js"
sh "java -jar util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }jsrun.jar util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }app#{ File::SEPARATOR }run.js -a -d=javascripts/docs -t=util#{ File::SEPARATOR }jsdoc-toolkit#{ File::SEPARATOR }templates#{ File::SEPARATOR }jsdoc tmp#{ File::SEPARATOR }phonegap.js"
end

def build
Expand Down
7 changes: 7 additions & 0 deletions iphone/Classes/Notification.m
Expand Up @@ -31,11 +31,18 @@ - (void)alert:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
- (void)activityStart:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
//[(UIActivityIndicatorView*)[self.webView.window viewWithTag:2] startAnimating];
NSLog(@"Starting");
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = YES;
}

- (void)activityStop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
//[(UIActivityIndicatorView*)[self.webView.window viewWithTag:2] stopAnimating];

NSLog(@"Stopping ");
UIApplication* app = [UIApplication sharedApplication];
app.networkActivityIndicatorVisible = NO;
}

- (void)vibrate:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
Expand Down
6 changes: 5 additions & 1 deletion iphone/Classes/PhoneGapCommand.h
Expand Up @@ -10,11 +10,15 @@
#import <UIKit/UIKit.h>

@interface PhoneGapCommand : NSObject {
UIWebView* webView;
UIWebView* webView;
NSDictionary* settings;
}
@property (nonatomic, retain) UIWebView *webView;
@property (nonatomic, retain) NSDictionary *settings;

-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView settings:(NSDictionary*)classSettings;
-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView;
-(void) setWebView:(UIWebView*) theWebView;
-(void) setSettings:(NSDictionary*) classSettings;

@end
25 changes: 22 additions & 3 deletions iphone/Classes/PhoneGapCommand.m
Expand Up @@ -10,14 +10,21 @@

@implementation PhoneGapCommand
@synthesize webView;
@synthesize settings;

-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView settings:(NSDictionary*)classSettings
{
self = [self initWithWebView:theWebView];
if (self)
[self setSettings:classSettings];
return self;
}

-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView
{
NSLog(@"phonegap command initializing");
self = [super init];
if (self) {
if (self)
[self setWebView:theWebView];
}
return self;
}

Expand All @@ -26,4 +33,16 @@ -(void) setWebView:(UIWebView*) theWebView
webView = theWebView;
}

-(void) setSettings:(NSDictionary*) classSettings
{
settings = classSettings;
}

- (void)dealloc
{
if (self.settings)
[self.settings release];
[super dealloc];
}

@end
4 changes: 3 additions & 1 deletion iphone/Classes/PhoneGapDelegate.h
@@ -1,7 +1,7 @@

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import <UIKit/UINavigationController.h>
#import <JSON/JSON.h>

#import "Location.h"
#import "Device.h"
Expand Down Expand Up @@ -43,6 +43,7 @@
//UIImagePickerController *imagePickerController;

UIInterfaceOrientation orientationType;
NSDictionary *settings;

NSURLConnection *callBackConnection;
Sound *sound;
Expand All @@ -58,6 +59,7 @@
//@property (nonatomic, retain) UIImagePickerController *imagePickerController;
@property (nonatomic, retain) UIActivityIndicatorView *activityView;
@property (nonatomic, retain) NSMutableDictionary *commandObjects;
@property (nonatomic, retain) NSDictionary *settings;

//- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image2 editingInfo:(NSDictionary *)editingInfo;
//- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker;
Expand Down
83 changes: 61 additions & 22 deletions iphone/Classes/PhoneGapDelegate.m
Expand Up @@ -8,6 +8,7 @@ @implementation PhoneGapDelegate
@synthesize viewController;
@synthesize activityView;
@synthesize commandObjects;
@synthesize settings;

//@synthesize imagePickerController;

Expand All @@ -24,8 +25,14 @@ -(id) getCommandInstance:(NSString*)className
{
id obj = [commandObjects objectForKey:className];
if (!obj) {
obj = [[NSClassFromString(className) alloc] initWithWebView:webView];
NSLog(@"******* Object %@ created from scratch for %@", obj, className);
// attempt to load the settings for this command class
NSDictionary* classSettings;
classSettings = [settings objectForKey:className];

if (classSettings)
obj = [[NSClassFromString(className) alloc] initWithWebView:webView settings:classSettings];
else
obj = [[NSClassFromString(className) alloc] initWithWebView:webView];

[commandObjects setObject:obj forKey:className];
}
Expand All @@ -39,30 +46,31 @@ -(id) getCommandInstance:(NSString*)className
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
/*
* Settings.plist
* PhoneGap.plist
*
* This block of code navigates to the Settings.plist in the Config Group and reads the XML into an Hash (Dictionary)
* This block of code navigates to the PhoneGap.plist in the Config Group and reads the XML into an Hash (Dictionary)
*
*/
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"PhoneGap" ofType:@"plist"];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format errorDescription:&errorDesc];
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format errorDescription:&errorDesc];
settings = [[NSDictionary alloc] initWithDictionary:temp];

NSNumber *offline = [temp objectForKey:@"Offline"];
NSString *url = [temp objectForKey:@"Callback"];
NSNumber *detectNumber = [temp objectForKey:@"DetectPhoneNumber"];
NSNumber *useLocation = [temp objectForKey:@"UseLocation"];
NSNumber *useAccelerometer = [temp objectForKey:@"UseAccelerometer"];
NSNumber *autoRotate = [temp objectForKey:@"AutoRotate"];
NSString *startOrientation = [temp objectForKey:@"StartOrientation"];
NSString *rotateOrientation = [temp objectForKey:@"RotateOrientation"];
NSString *topStatusBar = [temp objectForKey:@"TopStatusBar"];
NSString *topActivityIndicator = [temp objectForKey:@"TopActivityIndicator"];
NSNumber *offline = [settings objectForKey:@"Offline"];
NSString *url = [settings objectForKey:@"Callback"];
NSNumber *detectNumber = [settings objectForKey:@"DetectPhoneNumber"];
NSNumber *useLocation = [settings objectForKey:@"UseLocation"];
NSNumber *useAccelerometer = [settings objectForKey:@"UseAccelerometer"];
NSNumber *autoRotate = [settings objectForKey:@"AutoRotate"];
NSString *startOrientation = [settings objectForKey:@"StartOrientation"];
NSString *rotateOrientation = [settings objectForKey:@"RotateOrientation"];
NSString *topStatusBar = [settings objectForKey:@"TopStatusBar"];
NSString *topActivityIndicator = [settings objectForKey:@"TopActivityIndicator"];

/*
* Fire up the GPS Service right away as it takes a moment for data to come back.
Expand Down Expand Up @@ -115,7 +123,7 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
]];

/*
* detectNumber - If we want to Automagically convery phone numbers to links - Set in Settings.plist
* detectNumber - If we want to Automagically convery phone numbers to links - Set in PhoneGap.plist
* Value should be BOOL (YES|NO)
*/
webView.detectsPhoneNumbers = [detectNumber boolValue];
Expand Down Expand Up @@ -153,7 +161,7 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
/*
* rotateOrientation - This option is only enabled when AutoRotate is enabled. If the phone is still rotated
* when AutoRotate is disabled, this will control what orientations will be rotated to. If you wish your app to
* only use landscape or portrait orientations, change the value in Settings.plist to indicate that.
* only use landscape or portrait orientations, change the value in PhoneGap.plist to indicate that.
* Value should be one of: any, portrait, landscape
*/
[viewController setRotateOrientation:rotateOrientation];
Expand All @@ -175,7 +183,14 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application
topStatusBarStyle = UIStatusBarStyleDefault;
}
if ([topStatusBar isEqualToString:@"none"]) {
int toolbarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
CGRect webViewBounds = webView.bounds;
[webView setFrame:CGRectMake(webViewBounds.origin.x,
webViewBounds.origin.y - toolbarHeight,
webViewBounds.size.width,
webViewBounds.size.height + toolbarHeight
)];
} else {
[[UIApplication sharedApplication] setStatusBarStyle:topStatusBarStyle animated:NO];
}
Expand Down Expand Up @@ -212,7 +227,29 @@ - (void)webViewDidStartLoad:(UIWebView *)theWebView {
/*
* This is the Device.platform information
*/
[theWebView stringByEvaluatingJavaScriptFromString:[[Device alloc] init]];
NSString *deviceStr = [[Device alloc] init];

/* Settings.plist
* Read the optional Settings.plist file and push these user-defined settings down into the web application.
* This can be useful for supplying build-time configuration variables down to the app to change its behaviour,
* such as specifying Full / Lite version, or localization (English vs German, for instance).
*/
NSString *errorDesc = nil;
NSPropertyListFormat format;
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"plist"];
NSData *plistXML = [[NSFileManager defaultManager] contentsAtPath:plistPath];
NSDictionary *temp = (NSDictionary *)[NSPropertyListSerialization
propertyListFromData:plistXML
mutabilityOption:NSPropertyListMutableContainersAndLeaves
format:&format errorDescription:&errorDesc];
if ([temp respondsToSelector:@selector(JSONFragment)]) {
NSString *initString = [[NSString alloc] initWithFormat:@"%@\nwindow.Settings = %@;", deviceStr, [temp JSONFragment]];
NSLog(@"%@", initString);
[theWebView stringByEvaluatingJavaScriptFromString:initString];
[initString release];
} else {
[theWebView stringByEvaluatingJavaScriptFromString:deviceStr];
}
}

- (void)webViewDidFinishLoad:(UIWebView *)theWebView {
Expand Down Expand Up @@ -301,9 +338,11 @@ - (BOOL)webView:(UIWebView *)theWebView shouldStartLoadWithRequest:(NSURLRequest
NSString* className = [components objectAtIndex:0];
NSString* methodName = [components objectAtIndex:1];

// Fetch an instance of this class
PhoneGapCommand* obj = [self getCommandInstance:className];

// construct the fill method name to ammend the second argument.
NSString* fullMethodName = [[NSString alloc] initWithFormat:@"%@:withDict:", methodName];
PhoneGapCommand* obj = [self getCommandInstance:className];
if ([obj respondsToSelector:NSSelectorFromString(fullMethodName)])
{
[obj performSelector:NSSelectorFromString(fullMethodName) withObject:arguments withObject:options];
Expand Down
37 changes: 33 additions & 4 deletions iphone/Classes/UIControls.h
Expand Up @@ -8,13 +8,42 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
/*
#import <UIKit/UITabBar.h>
#import <UIKit/UITabBarController.h>
*/
#import <UIKit/UIToolbar.h>

#import "PhoneGapCommand.h"

@interface UIControls : PhoneGapCommand {
@interface UIControls : PhoneGapCommand <UITabBarDelegate> {
UITabBar* tabBar;
NSMutableDictionary* tabBarItems;

UIToolbar* toolBar;
UIBarButtonItem* toolBarTitle;
NSMutableDictionary* toolBarItems;
}

/* Tab Bar methods
*/
- (void)createTabBar:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)showTabBar:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)hideTabBar:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)showTabBarItems:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)createTabBarItem:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)updateTabBarItem:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)selectTabBarItem:(NSArray*)arguments withDict:(NSDictionary*)options;

/* Tool Bar methods
*/
- (void)createToolBar:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)setToolBarTitle:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)toolBarTitleClicked;

/*
- (void)createToolBarButton:(NSArray*)arguments withDict:(NSDictionary*)options;
- (void)createToolBarTitle:(NSArray*)arguments withDict:(NSDictionary*)options;
*/

//- (void)setToolBarTitle:(NSArray*)arguments withDict:(NSDictionary*)options;
//- (void)setToolBarButtons:(NSArray*)arguments withDict:(NSDictionary*)options;

@end

0 comments on commit 537c4a2

Please sign in to comment.