Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/NachoMan/phonegap into bar
Browse files Browse the repository at this point in the history
  • Loading branch information
sintaxi committed Apr 17, 2009
2 parents 342676d + d8e6c72 commit f8beb90
Show file tree
Hide file tree
Showing 64 changed files with 1,949 additions and 1,504 deletions.
8 changes: 4 additions & 4 deletions iphone/Classes/Bonjour.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PhoneGapCommand.h"


@interface Bonjour : NSObject
@interface Bonjour : PhoneGapCommand
{
NSString* __identifier;
}

+ (void)start:(NSString*)options forWebView:(UIWebView*)webView;
+ (void)stop:(NSString*)options forWebView:(UIWebView*)webView;
- (void)start:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void)stop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

@end
4 changes: 2 additions & 2 deletions iphone/Classes/Bonjour.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

@implementation Bonjour

+ (void)start:(NSString*)options forWebView:(UIWebView*)webView
- (void)start:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
}

+ (void)stop:(NSString*)options forWebView:(UIWebView*)webView
- (void)stop:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
}

Expand Down
8 changes: 4 additions & 4 deletions iphone/Classes/Contacts.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#import <Foundation/Foundation.h>
#import <AddressBook/ABAddressBook.h>
#import "PhoneGapCommand.h"

@interface Contacts : NSObject {
@interface Contacts : PhoneGapCommand {
ABAddressBookRef addressBook;
NSArray *allPeople;
CFIndex nPeople;
Expand All @@ -18,11 +19,10 @@
@property (getter=getAddressBook,assign) ABAddressBookRef addressBook;
@property (getter=getContacts,assign) NSArray *allPeople;

+ (void)get:(NSString*)options forWebView:(UIWebView*)webView;
-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView;

//- (NSString *)stringValueForRow:(NSInteger)row;
- (void)get:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

- (id)init;
- (void) displayContact:(ABRecordRef *) person;
- (void) addContact;

Expand Down
25 changes: 12 additions & 13 deletions iphone/Classes/Contacts.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ @implementation Contacts
@synthesize addressBook;
@synthesize allPeople;

+ (void)get:(NSString*)options forWebView:(UIWebView*)webView
-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView
{
Contacts *contacts = [[Contacts alloc] init];
NSString * jsCallBack = [contacts getContacts];
NSLog(@"%@",jsCallBack);
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];

[contacts release];
self = [super initWithWebView:(UIWebView*)theWebView];
if (self) {
addressBook = ABAddressBookCreate();
}
return self;
}

- (id)init
- (void)get:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
self = [super init];
addressBook = ABAddressBookCreate();
return self;
NSMutableString* jsCallBack = [self getContacts];
NSLog(@"%@", jsCallBack);
[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}

- (NSMutableString *)getContacts {
Expand All @@ -42,8 +41,8 @@ - (NSMutableString *)getContacts {

[update appendString:@"var _contacts=["];

for (int i=0;i < numberOfPeople;i++) {
ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);
for (int i = 0; i < numberOfPeople; i++) {
ABRecordRef ref = CFArrayGetValueAtIndex((CFArrayRef)allPeople, i);

if (ABRecordCopyValue(ref, kABPersonFirstNameProperty) != nil && ABRecordCopyValue(ref, kABPersonLastNameProperty) != nil) {
CFStringRef firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
Expand Down
5 changes: 3 additions & 2 deletions iphone/Classes/DebugConsole.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "PhoneGapCommand.h"

@interface DebugConsole : NSObject {
@interface DebugConsole : PhoneGapCommand {
}

+ (void)log:(NSString*)options forWebView:(UIWebView*)webView;
- (void)log:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

@end
10 changes: 7 additions & 3 deletions iphone/Classes/DebugConsole.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@

@implementation DebugConsole

+ (void)log:(NSString*)options forWebView:(UIWebView*)webView
- (void)log:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSArray* arguments = [options componentsSeparatedByString:@"/"];
NSLog(@"[%@] %@", [arguments objectAtIndex:0], [[arguments objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]);
NSString* message = [arguments objectAtIndex:0];
NSString* log_level = @"INFO";
if ([options objectForKey:@"logLevel"])
log_level = [options objectForKey:@"logLevel"];

NSLog(@"[%@] %@", log_level, message);
}

@end
3 changes: 2 additions & 1 deletion iphone/Classes/Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#import <UIKit/UIKit.h>
#import <UIKit/UIDevice.h>
#import "PhoneGapCommand.h"

@interface Device : NSObject {
@interface Device : PhoneGapCommand {
UIDevice *myCurrentDevice;
}

Expand Down
5 changes: 2 additions & 3 deletions iphone/Classes/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
*/

#import <Foundation/Foundation.h>
#import "PhoneGapCommand.h"


@interface Image : NSObject {
@interface Image : PhoneGapCommand {
IBOutlet UIWindow *window;
IBOutlet UIWebView *webView;

UIImagePickerController *picker; // added by urbian
NSString *photoUploadUrl; // added by urbian
Expand Down
22 changes: 8 additions & 14 deletions iphone/Classes/Location.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,26 @@

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "PhoneGapCommand.h"

@protocol LocationDelegate <NSObject>
@required
@end

@interface Location : NSObject <CLLocationManagerDelegate> {
@interface Location : PhoneGapCommand <CLLocationManagerDelegate> {
CLLocationManager *locationManager;
CLLocation *lastKnownLocation;
id delegate;
BOOL __started;
}

@property (nonatomic, retain) CLLocation *lastKnownLocation;
@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic,assign) id <LocationDelegate> delegate;

+ (void)get:(NSString*)options forWebView:(UIWebView*)webView;
+ (void)start:(NSString*)options forWebView:(UIWebView*)webView;
- (void)start:(NSMutableArray*)arguments
withDict:(NSMutableDictionary*)options;

- (void)start;
- (NSString *) getPosition;
- (void)stop:(NSMutableArray*)arguments
withDict:(NSMutableDictionary*)options;

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation;

+ (Location *)sharedInstance;
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error;

@end
144 changes: 67 additions & 77 deletions iphone/Classes/Location.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,110 +8,100 @@

#import "Location.h"

#define LocStr(key) [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]

@implementation Location
@synthesize locationManager;
@synthesize lastKnownLocation;

static Location *sharedCLDelegate = nil;

+ (void)get:(NSString*)options forWebView:(UIWebView*)webView
{
NSString * jsCallBack = [[Location sharedInstance] getPosition];

[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
[jsCallBack release];
}
@synthesize locationManager;

+ (void)start:(NSString*)options forWebView:(UIWebView*)webView
-(PhoneGapCommand*) initWithWebView:(UIWebView*)theWebView
{
[[Location sharedInstance] start];
}


- (id) init {
self = [super init];
if (self != nil) {
self = [super initWithWebView:(UIWebView*)theWebView];
if (self) {
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.delegate = self; // Tells the location manager to send updates to this object
}
return self;
}

- (void)start
- (void)start:(NSMutableArray*)arguments
withDict:(NSMutableDictionary*)options
{
if (__started == YES)
return;
if ([self.locationManager locationServicesEnabled] != YES)
return;

// Tell the location manager to start notifying us of location updates
[self.locationManager startUpdatingLocation];
__started = YES;
}

- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
[lastKnownLocation release];
lastKnownLocation = newLocation;
[lastKnownLocation retain];
}


- (NSString *)getPosition
{
if (!__started)
{
[self start];
if ([options objectForKey:@"distanceFilter"]) {
CLLocationDistance distanceFilter = [(NSString *)[options objectForKey:@"distanceFilter"] doubleValue];
self.locationManager.distanceFilter = distanceFilter;
}

if ([options objectForKey:@"desiredAccuracy"]) {
int desiredAccuracy_num = [(NSString *)[options objectForKey:@"desiredAccuracy"] integerValue];
CLLocationAccuracy desiredAccuracy = kCLLocationAccuracyBest;
if (desiredAccuracy_num < 10)
desiredAccuracy = kCLLocationAccuracyBest;
else if (desiredAccuracy_num < 100)
desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
else if (desiredAccuracy_num < 1000)
desiredAccuracy = kCLLocationAccuracyHundredMeters;
else if (desiredAccuracy_num < 3000)
desiredAccuracy = kCLLocationAccuracyKilometer;
else
desiredAccuracy = kCLLocationAccuracyThreeKilometers;

return [[NSString alloc] initWithFormat:@"var geo={lat:%f,lng:%f,alt:%f};",
lastKnownLocation.coordinate.latitude,
lastKnownLocation.coordinate.longitude,
lastKnownLocation.altitude];

}

+ (Location *)sharedInstance {
@synchronized(self) {
if (sharedCLDelegate == nil) {
[[self alloc] init]; // assignment not done here
}
}
return sharedCLDelegate;
}

+ (id)allocWithZone:(NSZone *)zone {
@synchronized(self) {
if (sharedCLDelegate == nil) {
sharedCLDelegate = [super allocWithZone:zone];
return sharedCLDelegate; // assignment and return on first allocation
}
self.locationManager.desiredAccuracy = desiredAccuracy;
}
return nil; // on subsequent allocation attempts return nil
}

- (id)copyWithZone:(NSZone *)zone
- (void)stop:(NSMutableArray*)arguments
withDict:(NSMutableDictionary*)options
{
return self;
}

- (id)retain {
return self;
}

- (unsigned)retainCount {
return UINT_MAX; // denotes an object that cannot be released
if (__started == NO)
return;
if ([self.locationManager locationServicesEnabled] != YES)
return;

[self.locationManager stopUpdatingLocation];
__started = NO;
}

- (void)release {
//do nothing
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
int epoch = [newLocation.timestamp timeIntervalSince1970];
NSString * jsCallBack = [NSString stringWithFormat:@"navigator.geolocation.setLocation({timestamp: %d, latitude: %f, longitude: %f, altitude: %f, course: %f, speed: %f, accuracy: {horizontal: %f, vertical: %f}});",
epoch,
newLocation.coordinate.latitude,
newLocation.coordinate.longitude,
newLocation.altitude,
newLocation.course,
newLocation.speed,
newLocation.horizontalAccuracy,
newLocation.verticalAccuracy
];
NSLog(@"%@", jsCallBack);

[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}

- (id)autorelease {
return self;
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error
{
NSString * jsCallBack = [NSString stringWithFormat:@"navigator.geolocation.setError(\"%s\");",
[error localizedDescription]
];
NSLog(@"%@", jsCallBack);

[webView stringByEvaluatingJavaScriptFromString:jsCallBack];
}


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

Expand Down
7 changes: 3 additions & 4 deletions iphone/Classes/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
//

#import <Foundation/Foundation.h>
#import "PhoneGapCommand.h"


@interface Map : NSObject {

@interface Map : PhoneGapCommand {
}

+ (void)open:(NSString*)options forWebView:(UIWebView*)webView;
- (void)open:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;

@end

0 comments on commit f8beb90

Please sign in to comment.