Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
htcgh committed May 18, 2015
1 parent a00d1ed commit 1ba7426
Show file tree
Hide file tree
Showing 45 changed files with 3,363 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# OS or Editor folders
.DS_Store
*~

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
443 changes: 443 additions & 0 deletions CutePetsExample.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions CutePetsExample/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

90 changes: 90 additions & 0 deletions CutePetsExample/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#import "AppDelegate.h"
#import "GAI.h"

//
// Google Analytics configuration constants
//

// Property ID (provided by https://www.google.com/analytics/web/ ) used to initialize a tracker.
static NSString *const kCutePetsPropertyId = @"UA-54478999-4";

// Dispatch interval for automatic dispatching of hits to Google Analytics.
// Values 0.0 or less will disable periodic dispatching. The default dispatch interval is 120 secs.
static NSTimeInterval const kCutePetsDispatchInterval = 120.0;

// Set log level to have the Google Analytics SDK report debug information only in DEBUG mode.
#if DEBUG
static GAILogLevel const kCutePetsLogLevel = kGAILogLevelVerbose;
#else
static GAILogLevel const kCutePetsLogLevel = kGAILogLevelWarning;
#endif

@interface AppDelegate ()

@property(nonatomic, copy) void (^dispatchHandler)(GAIDispatchResult result);

- (void)initializeGoogleAnalytics;
- (void)sendHitsInBackground;

@end

@implementation AppDelegate

- (void)initializeGoogleAnalytics {
// Automatically send uncaught exceptions to Google Analytics.
[GAI sharedInstance].trackUncaughtExceptions = YES;

// Set the dispatch interval for automatic dispatching.
[GAI sharedInstance].dispatchInterval = kCutePetsDispatchInterval;

// Set the appropriate log level for the default logger.
[GAI sharedInstance].logger.logLevel = kCutePetsLogLevel;

// Initialize a tracker using a Google Analytics property ID.
[[GAI sharedInstance] trackerWithTrackingId:kCutePetsPropertyId];
}

// This method sends any queued hits when the app enters the background.
- (void)sendHitsInBackground {
__block BOOL taskExpired = NO;

__block UIBackgroundTaskIdentifier taskId =
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
taskExpired = YES;
}];

if (taskId == UIBackgroundTaskInvalid) {
return;
}

__weak AppDelegate *weakSelf = self;
self.dispatchHandler = ^(GAIDispatchResult result) {
// Dispatch hits until we have none left, we run into a dispatch error,
// or the background task expires.
if (result == kGAIDispatchGood && !taskExpired) {
[[GAI sharedInstance] dispatchWithCompletionHandler:weakSelf.dispatchHandler];
} else {
[[UIApplication sharedApplication] endBackgroundTask:taskId];
}
};

[[GAI sharedInstance] dispatchWithCompletionHandler:self.dispatchHandler];
}

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self initializeGoogleAnalytics];
return YES;
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
[self sendHitsInBackground];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
// Restore the dispatch interval since dispatchWithCompletionHandler:
// disables automatic dispatching.
[GAI sharedInstance].dispatchInterval = kCutePetsDispatchInterval;
}

@end
11 changes: 11 additions & 0 deletions CutePetsExample/CutePet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#import <Foundation/Foundation.h>

@interface CutePet : NSObject

@property(nonatomic, readonly) NSString *name;
@property(nonatomic, readonly) NSString *imageName;
@property(nonatomic, assign) NSInteger score;

- (id)initWithName:(NSString *)name imageName:(NSString *)imageName;

@end
14 changes: 14 additions & 0 deletions CutePetsExample/CutePet.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#import "CutePet.h"

@implementation CutePet

- (id)initWithName:(NSString *)name imageName:(NSString *)imageName {
self = [super init];
if (self) {
_name = [name copy];
_imageName = [imageName copy];
}
return self;
}

@end
68 changes: 68 additions & 0 deletions CutePetsExample/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "1x"
},
{
"idiom" : "ipad",
"size" : "76x76",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
53 changes: 53 additions & 0 deletions CutePetsExample/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!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>Cute Pets Example</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>com.google.analytics.$(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</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Storyboard-iPad</string>
<key>UIMainStoryboardFile~ipad</key>
<string>Storyboard-iPad</string>
<key>UIMainStoryboardFile~iphone</key>
<string>Storyboard-iPhone</string>
<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>
7 changes: 7 additions & 0 deletions CutePetsExample/InstructionsViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import "GAITrackedViewController.h"

// Extend GAITrackedViewController to enable automatic screenview tracking for this view controller.
// Set the view controller's screen name in viewDidLoad.
@interface InstructionsViewController : GAITrackedViewController

@end
32 changes: 32 additions & 0 deletions CutePetsExample/InstructionsViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#import "InstructionsViewController.h"

#import "NavigationController.h"

@interface InstructionsViewController ()

@property(nonatomic, weak) IBOutlet UILabel *instructionsLabel;

@end

@implementation InstructionsViewController

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (void)viewDidLoad {
[super viewDidLoad];

self.navigationItem.hidesBackButton = YES;
self.instructionsLabel.text = NSLocalizedString(@"Instructions", nil);

// Set the screen name for automatic screenview tracking.
self.screenName = @"Instructions";
}

- (IBAction)handleStartButton:(id)sender {
NavigationController *navigationController = (NavigationController *)self.navigationController;
[navigationController pushNextViewControllerWithCurrentPet:nil];
}

@end
42 changes: 42 additions & 0 deletions CutePetsExample/LaunchScreen.xib
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6254" systemVersion="13F1077" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6247"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<view contentMode="scaleToFill" id="iN0-l3-epB">
<rect key="frame" x="0.0" y="0.0" width="480" height="480"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Google. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="20.5"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Cute Pets Example" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140.5" width="441" height="42"/>
<fontDescription key="fontDescription" name="ArialRoundedMTBold" family="Arial Rounded MT Bold" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="kId-c2-rCX" firstAttribute="centerY" secondItem="iN0-l3-epB" secondAttribute="bottom" multiplier="1/3" constant="1" id="5cJ-9S-tgC"/>
<constraint firstAttribute="centerX" secondItem="kId-c2-rCX" secondAttribute="centerX" id="Koa-jz-hwk"/>
<constraint firstAttribute="bottom" secondItem="8ie-xW-0ye" secondAttribute="bottom" constant="20" id="Kzo-t9-V3l"/>
<constraint firstItem="8ie-xW-0ye" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="MfP-vx-nX0"/>
<constraint firstAttribute="centerX" secondItem="8ie-xW-0ye" secondAttribute="centerX" id="ZEH-qu-HZ9"/>
<constraint firstItem="kId-c2-rCX" firstAttribute="leading" secondItem="iN0-l3-epB" secondAttribute="leading" constant="20" symbolic="YES" id="fvb-Df-36g"/>
</constraints>
<nil key="simulatedStatusBarMetrics"/>
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
<point key="canvasLocation" x="548" y="455"/>
</view>
</objects>
</document>
17 changes: 17 additions & 0 deletions CutePetsExample/Localizable.strings
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"AppName" = "Cute Pets Example";

"Question_Gender" = "What is your gender?";
"Question_Age" = "What is your age group?";
"Question_Pet" = "Which pets do you own?";

"Instructions" = "You will be shown a series of image pairs comparing two pets.\
\nTap on the pet who you think is cuter.";
"TapPrompt" = "Tap the cuter pet";
"Results" = "Thank you for your answers!\n\nHere are your top three pets.";

"Choice_Cats" = "Cat(s)";
"Choice_Dogs" = "Dog(s)";

"AgeGroup_1" = "Under 24 years old";
"AgeGroup_2" = "25-54 years old";
"AgeGroup_3" = "55 years or older";
10 changes: 10 additions & 0 deletions CutePetsExample/NavigationController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#import <UIKit/UIKit.h>

@class CutePet;

@interface NavigationController : UINavigationController

- (void)pushNextViewControllerWithCurrentPet:(CutePet *)currentPet;
- (void)startOver;

@end
Loading

0 comments on commit 1ba7426

Please sign in to comment.