http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/UGEntityViewController.h ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/UGEntityViewController.h b/sdks/other/ios/samples/Browser/browser/UGEntityViewController.h new file mode 100644 index 0000000..af95c4c --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/UGEntityViewController.h @@ -0,0 +1,22 @@ +// +// UGEntityViewController.h +// Browser +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +@interface UGEntityViewController : UITableViewController +@property (nonatomic, strong) NSDictionary *entity; +@end
http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/UGEntityViewController.m ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/UGEntityViewController.m b/sdks/other/ios/samples/Browser/browser/UGEntityViewController.m new file mode 100644 index 0000000..7cb2d17 --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/UGEntityViewController.m @@ -0,0 +1,86 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// UGEntityViewController.m +// Browser +// + +#import "UGEntityViewController.h" +#import "UGTextViewController.h" + +@interface UGEntityViewController () + +@end + +@implementation UGEntityViewController + +- (id)initWithStyle:(UITableViewStyle)style +{ + self = [super initWithStyle:style]; + if (self) { + // Custom initialization + } + return self; +} + +- (void) loadView +{ + [super loadView]; + self.navigationItem.title = self.entity[@"name"]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [self.entity count]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"]; + return cell; +} + +#pragma mark - Table view delegate + +- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSArray *keys = [[self.entity allKeys] sortedArrayUsingSelector:@selector(compare:)]; + NSString *key = keys[[indexPath row]]; + cell.textLabel.text = key; + id entity = self.entity[key]; + cell.detailTextLabel.text = [entity description]; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSArray *keys = [[self.entity allKeys] sortedArrayUsingSelector:@selector(compare:)]; + NSString *key = keys[[indexPath row]]; + UGTextViewController *textViewController = [[UGTextViewController alloc] init]; + textViewController.key = key; + textViewController.binding = self.entity; + [self.navigationController pushViewController:textViewController animated:YES]; +} + +@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/UGSignInViewController.h ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/UGSignInViewController.h b/sdks/other/ios/samples/Browser/browser/UGSignInViewController.h new file mode 100644 index 0000000..58481cf --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/UGSignInViewController.h @@ -0,0 +1,24 @@ +// +// UGSignInViewController.h +// Browser +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +@class UGAppViewController; + +@interface UGSignInViewController : UITableViewController +@property (nonatomic, weak) UGAppViewController *appViewController; +@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/UGSignInViewController.m ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/UGSignInViewController.m b/sdks/other/ios/samples/Browser/browser/UGSignInViewController.m new file mode 100644 index 0000000..7e346c9 --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/UGSignInViewController.m @@ -0,0 +1,185 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// UGSignInViewController.m +// Browser +// + +#import "UGHTTPClient.h" +#import "UGConnection.h" +#import "UGSignInViewController.h" +#import "UGAppViewController.h" + +#define SERVER @"http://api.usergrid.com" + +@interface UGFormTableViewCell : UITableViewCell <UITextFieldDelegate> +@property (nonatomic, strong) UILabel *label; +@property (nonatomic, strong) UITextField *textField; +@property (nonatomic, strong) NSString *key; +@property (nonatomic, weak) id binding; +@end + +@implementation UGFormTableViewCell + +- (id) initWithTitle:(NSString *)title key:(NSString *) key binding:(id) binding +{ + if (self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]) { + self.label = [[UILabel alloc] initWithFrame:CGRectMake(10,0,90,14)]; + self.label.backgroundColor = [UIColor clearColor]; + self.label.font = [UIFont systemFontOfSize:10]; + self.label.textColor = [UIColor grayColor]; + self.label.textAlignment = UITextAlignmentLeft; + [self.contentView addSubview:self.label]; + self.textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 14, 100, 30)]; + self.textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; + self.textField.font = [UIFont systemFontOfSize:18]; + self.textField.autocorrectionType = UITextAutocorrectionTypeNo; + self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone; + self.textField.delegate = self; + if ([key isEqualToString:@"password"]) { + self.textField.secureTextEntry = YES; + } + [self.contentView addSubview:self.textField]; + self.selectionStyle = UITableViewCellSelectionStyleNone; + // individual cell properties + self.label.text = title; + self.key = key; + self.binding = binding; + } + return self; +} + +- (void) layoutSubviews +{ + [super layoutSubviews]; + CGRect textFieldFrame = self.textField.frame; + textFieldFrame.size.width = self.textField.superview.bounds.size.width - textFieldFrame.origin.x - 5; + self.textField.frame = textFieldFrame; +} + +- (void) textFieldDidEndEditing:(UITextField *)textField +{ + [self.binding setObject:textField.text forKey:self.key]; +} + +@end + +@interface UGSignInViewController () +@property (nonatomic, strong) NSMutableDictionary *values; +@property (nonatomic, strong) NSArray *cells; +@end + +@implementation UGSignInViewController + +- (id)init { + if (self = [super initWithStyle:UITableViewStyleGrouped]) { + self.values = [[[NSUserDefaults standardUserDefaults] objectForKey:@"usergrid"] mutableCopy]; + if (!self.values) { + self.values = [NSMutableDictionary dictionary]; + [self.values setObject:SERVER forKey:@"server"]; + } + self.cells = + @[[[UGFormTableViewCell alloc] initWithTitle:@"Server" key:@"server" binding:self.values], + [[UGFormTableViewCell alloc] initWithTitle:@"Organization" key:@"organization" binding:self.values], + [[UGFormTableViewCell alloc] initWithTitle:@"Application" key:@"application" binding:self.values], + [[UGFormTableViewCell alloc] initWithTitle:@"Username" key:@"username" binding:self.values], + [[UGFormTableViewCell alloc] initWithTitle:@"Password" key:@"password" binding:self.values]]; + } + return self; +} + +- (void) loadView +{ + [super loadView]; + self.title = @"Connection"; + self.tableView.backgroundView = nil; + self.tableView.backgroundColor = [UIColor darkGrayColor]; + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] + initWithTitle:@"Cancel" + style:UIBarButtonItemStyleBordered + target:self + action:@selector(cancel:)]; + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] + initWithTitle:@"Sign In" + style:UIBarButtonItemStyleBordered + target:self + action:@selector(signin:)]; +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return [self.cells count]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return [self.cells objectAtIndex:[indexPath row]]; +} + +#pragma mark - Table view delegate + +- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath +{ + UGFormTableViewCell *formCell = (UGFormTableViewCell *) cell; + formCell.textField.text = [formCell.binding objectForKey:formCell.key]; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + UGFormTableViewCell *formCell = (UGFormTableViewCell *)[tableView cellForRowAtIndexPath:indexPath]; + [formCell.textField becomeFirstResponder]; +} + +#pragma mark - Sign In + +- (void) cancel:(id) sender +{ + [self dismissModalViewControllerAnimated:YES]; +} + +- (void) signin:(id) sender +{ + for (UGFormTableViewCell *cell in self.cells) { + [cell.textField resignFirstResponder]; + } + [[NSUserDefaults standardUserDefaults] setObject:self.values forKey:@"usergrid"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + + UGConnection *connection = [UGConnection sharedConnection]; + connection.server = [self.values objectForKey:@"server"]; + connection.organization = [self.values objectForKey:@"organization"]; + connection.application = [self.values objectForKey:@"application"]; + + [[[UGHTTPClient alloc] initWithRequest: + [connection getAccessTokenForApplicationWithUsername:[self.values objectForKey:@"username"] + password:[self.values objectForKey:@"password"]]] + connectWithCompletionHandler:^(UGHTTPResult *result) { + [connection authenticateWithResult:result]; + [(UGAppViewController *) self.appViewController downloadApplicationDescription]; + [self dismissModalViewControllerAnimated:YES]; + }]; +} + +@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/UGTextViewController.h ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/UGTextViewController.h b/sdks/other/ios/samples/Browser/browser/UGTextViewController.h new file mode 100644 index 0000000..57e2c8f --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/UGTextViewController.h @@ -0,0 +1,23 @@ +// +// UGTextViewController.h +// Browser +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +@interface UGTextViewController : UIViewController +@property (nonatomic, strong) NSString *key; +@property (nonatomic, strong) NSDictionary *binding; +@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/UGTextViewController.m ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/UGTextViewController.m b/sdks/other/ios/samples/Browser/browser/UGTextViewController.m new file mode 100644 index 0000000..d428913 --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/UGTextViewController.m @@ -0,0 +1,43 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// UGTextViewController.m +// Browser +// + + +#import "UGTextViewController.h" + +@interface UGTextViewController () +@property (nonatomic, strong) UITextView *textView; +@end + +@implementation UGTextViewController + +- (void) loadView +{ + [super loadView]; + self.textView = [[UITextView alloc] initWithFrame:self.view.bounds]; + self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth+UIViewAutoresizingFlexibleHeight; + self.textView.font = [UIFont systemFontOfSize:20]; + [self.view addSubview:self.textView]; + self.textView.text = [self.binding[self.key] description]; + self.navigationItem.title = self.key; +} + +@end http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/browser-Info.plist ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/browser-Info.plist b/sdks/other/ios/samples/Browser/browser/browser-Info.plist new file mode 100644 index 0000000..212588c --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/browser-Info.plist @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +--> +<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> +<plist version="1.0"> +<dict> + <key>CFBundleDevelopmentRegion</key> + <string>en</string> + <key>CFBundleDisplayName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundleExecutable</key> + <string>${EXECUTABLE_NAME}</string> + <key>CFBundleIdentifier</key> + <string>com.apigee.${PRODUCT_NAME:rfc1034identifier}</string> + <key>CFBundleInfoDictionaryVersion</key> + <string>6.0</string> + <key>CFBundleName</key> + <string>${PRODUCT_NAME}</string> + <key>CFBundlePackageType</key> + <string>APPL</string> + <key>CFBundleShortVersionString</key> + <string>1.0</string> + <key>CFBundleSignature</key> + <string>????</string> + <key>CFBundleVersion</key> + <string>1.0</string> + <key>LSRequiresIPhoneOS</key> + <true/> + <key>UIRequiredDeviceCapabilities</key> + <array> + <string>armv7</string> + </array> + <key>UISupportedInterfaceOrientations</key> + <array> + <string>UIInterfaceOrientationPortrait</string> + <string>UIInterfaceOrientationLandscapeLeft</string> + <string>UIInterfaceOrientationLandscapeRight</string> + </array> + <key>UISupportedInterfaceOrientations~ipad</key> + <array> + <string>UIInterfaceOrientationPortrait</string> + <string>UIInterfaceOrientationPortraitUpsideDown</string> + <string>UIInterfaceOrientationLandscapeLeft</string> + <string>UIInterfaceOrientationLandscapeRight</string> + </array> +</dict> +</plist> http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/browser-Prefix.pch ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/browser-Prefix.pch b/sdks/other/ios/samples/Browser/browser/browser-Prefix.pch new file mode 100644 index 0000000..86a5940 --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/browser-Prefix.pch @@ -0,0 +1,14 @@ +// +// Prefix header for all source files of the 'browser' target in the 'browser' project +// + +#import <Availability.h> + +#ifndef __IPHONE_3_0 +#warning "This project uses features only available in iOS SDK 3.0 and later." +#endif + +#ifdef __OBJC__ + #import <UIKit/UIKit.h> + #import <Foundation/Foundation.h> +#endif http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/en.lproj/InfoPlist.strings ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/en.lproj/InfoPlist.strings b/sdks/other/ios/samples/Browser/browser/en.lproj/InfoPlist.strings new file mode 100644 index 0000000..477b28f --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/en.lproj/InfoPlist.strings @@ -0,0 +1,2 @@ +/* Localized versions of Info.plist keys */ + http://git-wip-us.apache.org/repos/asf/usergrid/blob/867060fa/sdks/other/ios/samples/Browser/browser/main.m ---------------------------------------------------------------------- diff --git a/sdks/other/ios/samples/Browser/browser/main.m b/sdks/other/ios/samples/Browser/browser/main.m new file mode 100644 index 0000000..11cecbf --- /dev/null +++ b/sdks/other/ios/samples/Browser/browser/main.m @@ -0,0 +1,30 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// + +// +// main.m +// Browser +// + +#import "UGAppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([UGAppDelegate class])); + } +}