Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Sample code enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
umeshma committed Apr 11, 2013
1 parent 21cedd6 commit 92c46e4
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 99 deletions.
6 changes: 6 additions & 0 deletions Samples/SDKFeatures/SDKFeatures.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
5D78993A171739FB0015D375 /* HVConditionFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D789939171739FB0015D375 /* HVConditionFactory.m */; };
5D78993D17173B520015D375 /* HVImmunizationFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D78993C17173B520015D375 /* HVImmunizationFactory.m */; };
5D78994017173D2A0015D375 /* HVProcedureFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D78993F17173D290015D375 /* HVProcedureFactory.m */; };
5D789957171758E90015D375 /* HVStatusLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = 5D789956171758E90015D375 /* HVStatusLabel.m */; };
5DAFC630166FC5AC00363FA2 /* HVDietaryIntakeFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DAFC62F166FC5AC00363FA2 /* HVDietaryIntakeFactory.m */; };
5DD6C1EB1676C2F900A658D8 /* HVEmotionalStateFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DD6C1EA1676C2F800A658D8 /* HVEmotionalStateFactory.m */; };
5DD6C23F1677D2C600A658D8 /* HVExerciseFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 5DD6C23E1677D2C600A658D8 /* HVExerciseFactory.m */; };
Expand Down Expand Up @@ -91,6 +92,8 @@
5D78993C17173B520015D375 /* HVImmunizationFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HVImmunizationFactory.m; sourceTree = "<group>"; };
5D78993E17173D270015D375 /* HVProcedureFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HVProcedureFactory.h; sourceTree = "<group>"; };
5D78993F17173D290015D375 /* HVProcedureFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HVProcedureFactory.m; sourceTree = "<group>"; };
5D789955171758E90015D375 /* HVStatusLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HVStatusLabel.h; sourceTree = "<group>"; };
5D789956171758E90015D375 /* HVStatusLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HVStatusLabel.m; sourceTree = "<group>"; };
5DAFC62E166FC5AC00363FA2 /* HVDietaryIntakeFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HVDietaryIntakeFactory.h; sourceTree = "<group>"; };
5DAFC62F166FC5AC00363FA2 /* HVDietaryIntakeFactory.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = HVDietaryIntakeFactory.m; sourceTree = "<group>"; };
5DD6C1E91676C2F800A658D8 /* HVEmotionalStateFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HVEmotionalStateFactory.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -199,6 +202,8 @@
5DD6C2DF16791ACD00A658D8 /* HVSleepJournalAMFactory.m */,
5D3EBB0B16794B1C00BDE25E /* HVWeightFactory.h */,
5D3EBB0C16794B1C00BDE25E /* HVWeightFactory.m */,
5D789955171758E90015D375 /* HVStatusLabel.h */,
5D789956171758E90015D375 /* HVStatusLabel.m */,
5D09134B166ED1980031F5F9 /* Supporting Files */,
);
path = SDKFeatures;
Expand Down Expand Up @@ -309,6 +314,7 @@
5D78993A171739FB0015D375 /* HVConditionFactory.m in Sources */,
5D78993D17173B520015D375 /* HVImmunizationFactory.m in Sources */,
5D78994017173D2A0015D375 /* HVProcedureFactory.m in Sources */,
5D789957171758E90015D375 /* HVStatusLabel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
13 changes: 11 additions & 2 deletions Samples/SDKFeatures/SDKFeatures/HVMoreFeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,25 @@

#import <Foundation/Foundation.h>
#import "HVLib.h"
#import "HVStatusLabel.h"

@class HVTypeListViewController;

@interface HVMoreFeatures : NSObject
{
@private
HVTypeListViewController* m_controller; // Weak ref
}

@property (readwrite, nonatomic, assign) HVTypeListViewController* controller; // Weak ref

//
// How to disconnect an app
//
+(void) disconnectApp:(UIViewController *) parentController;
-(void) disconnectApp;
//
// Get service definition
//
+(void) getServiceDefinition;
-(void) getServiceDefinition;

@end
33 changes: 25 additions & 8 deletions Samples/SDKFeatures/SDKFeatures/HVMoreFeatures.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
//

#import "HVMoreFeatures.h"
#import "HVTypeListViewController.h"

@implementation HVMoreFeatures

+(void)disconnectApp:(UIViewController *)parentController
@synthesize controller = m_controller; // Weak ref

-(void)disconnectApp
{
[HVUIAlert showYesNoWithMessage:@"Are you sure you want to disconnect this application from HealthVault?\r\nIf you click Yes, you will need to re-authorize the next time you run it." callback:^(id sender) {

Expand All @@ -30,24 +33,36 @@ +(void)disconnectApp:(UIViewController *)parentController
{
return;
}


[m_controller.statusLabel showBusy];
//
// REMOVE RECORD AUTHORIZATION.
//
[[HVClient current].user removeAuthForRecord:[HVClient current].currentRecord withCallback:^(HVTask *task) {

[[HVClient current] resetProvisioning]; // Removes local state

[parentController.navigationController popViewControllerAnimated:TRUE];
[m_controller.navigationController popViewControllerAnimated:TRUE];
}];
}];
}

+(void)getServiceDefinition
-(void)getServiceDefinition
{
[m_controller.statusLabel showBusy];
//
// LAUNCH the GetServiceDefinition task
//
[[[[HVGetServiceDefinitionTask alloc] initWithCallback:^(HVTask *task) {
//
// Verify success. This will throw if there was a failure
// You can also detect failure by checking task.hasError
//
[task checkSuccess];

[task checkSuccess];
HVServiceDefinition* serviceDef = ((HVGetServiceDefinitionTask *) task).serviceDef;
//
// Show some sample information
//
// Show some sample information to the user
//
HVConfigurationEntry* configEntry = [serviceDef.platform.config objectAtIndex:0];
HVConfigurationEntry* configEntry2 = [serviceDef.platform.config objectAtIndex:1];
Expand All @@ -64,7 +79,9 @@ +(void)getServiceDefinition

[HVUIAlert showInformationalMessage:output];

}] autorelease] start];
[m_controller.statusLabel clearStatus];

}] autorelease] start]; // NOTE: Make sure you always call start
}

@end
35 changes: 35 additions & 0 deletions Samples/SDKFeatures/SDKFeatures/HVStatusLabel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// HVStatusLabel.h
// SDKFeatures
//
// Copyright (c) 2013 Microsoft Corporation. All rights reserved.
//
// Licensed 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.
//

#import <UIKit/UIKit.h>

@interface HVStatusLabel : UILabel
{
@private
UIActivityIndicatorView* m_activity;
}

-(void) showStatus:(NSString *) format, ...;
-(void) clearStatus;
-(void) showActivity;
-(void) hideActivity;

-(void) showBusy;

@end
112 changes: 112 additions & 0 deletions Samples/SDKFeatures/SDKFeatures/HVStatusLabel.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//
// HVStatusLabel.m
// SDKFeatures
//
// Copyright (c) 2013 Microsoft Corporation. All rights reserved.
//
// Licensed 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.
//

#import "HVStatusLabel.h"

@interface HVStatusLabel (HVPrivate)

-(void) ensureSpinner;

@end

@implementation HVStatusLabel

-(void)dealloc
{
[m_activity release];
[super dealloc];
}

-(void)showStatus:(NSString *)format, ...
{
va_list args;
va_start(args, format);

NSLogv(format, args);
NSString* message = [[NSString alloc] initWithFormat:format arguments:args];

va_end(args);

self.text = message;
[message release];

[self hideActivity];
}

-(void)clearStatus
{
self.text = nil;
[self hideActivity];
}

-(void)showActivity
{
[self ensureSpinner];
[m_activity setHidden:FALSE];
[m_activity startAnimating];
}

-(void)hideActivity
{
if (m_activity)
{
[m_activity stopAnimating];
[m_activity setHidden:TRUE];
}
}

-(void)showBusy
{
[self showStatus:@"Working. Please wait..."];
[self showActivity];
}

@end

@implementation HVStatusLabel (HVPrivate)

-(void)ensureSpinner
{
if (m_activity)
{
return;
}

m_activity = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

CGRect frame = self.frame;
float side = frame.size.height; // We'll size the spinner so it is a square as tall as this label

if (self.textAlignment == NSTextAlignmentRight)
{
frame.origin.x = 0;
}
else
{
frame.origin.x = frame.size.width - side;
}
frame.origin.y = 0;
frame.size.width = side;
frame.size.height = side;

[self addSubview:m_activity];

}

@end
4 changes: 4 additions & 0 deletions Samples/SDKFeatures/SDKFeatures/HVTypeListViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,23 @@
#import "HVTypeViewController.h"
#import "HVMoreFeatures.h"
#import "HVFeatureActions.h"
#import "HVStatusLabel.h"

@interface HVTypeListViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
{
@private
UITableView* m_tableView;
UIBarButtonItem* m_moreButton;
HVStatusLabel* m_statusLabel;

NSArray* m_classesForTypes;
HVFeatureActions* m_actions;
HVMoreFeatures* m_features;
}

@property (retain, nonatomic) IBOutlet UITableView* tableView;
@property (retain, nonatomic) IBOutlet UIBarButtonItem* moreButton;
@property (retain, nonatomic) IBOutlet HVStatusLabel* statusLabel;

- (IBAction)moreFeatures:(id)sender;

Expand Down
21 changes: 17 additions & 4 deletions Samples/SDKFeatures/SDKFeatures/HVTypeListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ @implementation HVTypeListViewController

@synthesize tableView = m_tableView;
@synthesize moreButton = m_moreButton;
@synthesize statusLabel = m_statusLabel;

-(void)dealloc
{
Expand All @@ -44,6 +45,7 @@ -(void)dealloc
[m_moreButton release];
[m_classesForTypes release];
[m_actions release];
[m_features release];

[super dealloc];
}
Expand Down Expand Up @@ -161,16 +163,27 @@ -(Class )getSelectedClass
return [m_classesForTypes objectAtIndex:selectedRow.row];
}

-(void) addStandardFeatures
-(BOOL) addStandardFeatures
{
m_features = [[HVMoreFeatures alloc] init];
HVCHECK_NOTNULL(m_features);
m_features.controller = self;

m_actions = [[HVFeatureActions alloc] init];

HVCHECK_NOTNULL(m_actions);

[m_actions addFeature:@"Disconnect app" andAction:^{
[HVMoreFeatures disconnectApp:self];
[m_features disconnectApp];
}];

[m_actions addFeature:@"GetServiceDefintion" andAction:^{
[HVMoreFeatures getServiceDefinition];
[m_features getServiceDefinition];
}];

return TRUE;

LError:
return FALSE;
}

@end
Loading

0 comments on commit 92c46e4

Please sign in to comment.