8 #import <HealthKit/HealthKit.h> 15 id<Z6ParamValueEditDelegate>
delegate;
44 - (instancetype) initWithDelegate: (
id<Z6ParamValueEditDelegate>) dele {
63 massUnitsArray = [[NSArray alloc] initWithObjects: @"ug", @"mg", @"g", @"kg", nil];
66 CGRect totalFrame =
delegate.screenBound;
71 CGRect newParameterFrame = CGRectMake(2.0, 2.0, 400.0, 350.0);
73 [newParameterPicker setDelegate:self];
74 [newParameterPicker setDataSource:self];
75 [newParameterPicker setBackgroundColor:[UIColor colorWithWhite:0.76 alpha:1.0]];
76 [
self addSubview:newParameterPicker];
87 - (void) showPickerViewNot: (Boolean) flag
89 UIColor *okGreen = [UIColor colorWithHue:0.345
93 [newParameterPicker setBackgroundColor:okGreen];
97 [newParameterPicker setHidden:!flag];
103 - (void) initializeSelection
110 - (void) specializePickerView: (NSDictionary *) editSource
112 NSLog(
@"ParameterValueEditView.specializePickerView: editSource: %@", editSource);
116 NSString *incomingName = [editSource objectForKey:@"component-type"];
117 for (NSInteger parameterCardinal = 0; parameterCardinal<39; parameterCardinal++) {
119 if ([entryName isEqualToString:incomingName]) {
127 [newParameterPicker reloadAllComponents];
130 [newParameterPicker selectRow:newParameterIndex inComponent:0 animated:YES];
138 HKQuantityType *rowQuantityType = [HKObjectType quantityTypeForIdentifier:[@"HKQuantityTypeIdentifierDietary"
139 stringByAppendingString:caption]];
142 NSString *valueCaption = [componentQuanValue description];
143 NSArray<NSString *> *pieces = [valueCaption componentsSeparatedByString:@" "];
144 HKUnit *hkUnit = nil;
145 float quantityScalar = [pieces[0] floatValue];
146 if ([
@"mcg" isEqualToString:pieces[1]]) {
147 HKMetricPrefix microPrefix = HKMetricPrefixMicro;
148 hkUnit = [HKUnit gramUnitWithMetricPrefix:microPrefix];
149 }
else if ([
@"mg" isEqualToString:pieces[1]]) {
150 HKMetricPrefix milliPrefix = HKMetricPrefixMilli;
151 hkUnit = [HKUnit gramUnitWithMetricPrefix:milliPrefix];
156 int intScalar = (int)quantityScalar;
164 - (HKQuantity *) produceQuantityValue
167 NSInteger hundreds = [newParameterPicker selectedRowInComponent:1];
168 NSInteger tens = [newParameterPicker selectedRowInComponent:2];
169 NSInteger ones = [newParameterPicker selectedRowInComponent:3];
170 double inputValue = 100*hundreds + 10*tens + ones;
171 double nutritionAmount = inputValue;
175 NSUInteger unitIndex = [newParameterPicker selectedRowInComponent:4];
177 HKUnit *massUnit = [HKUnit unitFromString:@"g"];
178 HKUnit *energyUnit = [HKUnit unitFromString:@"cal"];
179 HKMetricPrefix metricPrefix;
180 HKQuantity *acceptQuantity;
183 HKUnit *prefixGramUnit = [HKUnit gramUnitWithMetricPrefix:metricPrefix];
184 acceptQuantity = [HKQuantity quantityWithUnit:prefixGramUnit doubleValue:nutritionAmount];
188 acceptQuantity = [HKQuantity quantityWithUnit:[HKUnit calorieUnit] doubleValue:nutritionAmount];
191 acceptQuantity = [HKQuantity quantityWithUnit:[HKUnit calorieUnit] doubleValue:nutritionAmount];
197 NSLog(
@"Z6ParamValueEditView.clickAcceptButton: quantity: %@", acceptQuantity);
198 return acceptQuantity;
204 - (NSDictionary *) originateParameter
213 NSDate *now = [NSDate dateWithTimeIntervalSinceNow:0];
214 HKQuantitySample *acceptedSample = [HKQuantitySample quantitySampleWithType:pickQuantityType
215 quantity:acceptQuantity
225 #pragma mark - Z6ContainedView 230 - (float) heightRequirement
237 - (void) appear:(CGRect)bound
240 switch ([
delegate getTotalEditState]) {
255 NSInteger huh = [newParameterPicker selectedRowInComponent:0];
258 NSDictionary *editParameterDictionary = [delegate selectedParameterList];
259 if (editParameterDictionary && ([editParameterDictionary count] > 0)) {
268 [newParameterPicker setFrame:pickerFrame];
269 [newParameterPicker showsSelectionIndicator];
272 #pragma mark - UIPickerViewDelegate 276 - (CGFloat)pickerView:(UIPickerView *)pickerView
277 rowHeightForComponent:(NSInteger)component
286 - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
319 - (NSAttributedString *)pickerView:(UIPickerView *)pickerView
320 attributedTitleForRow:(NSInteger)row
321 forComponent:(NSInteger)component
325 if (0 == component) {
328 }
else if (1 == component) {
329 ret = [[NSString alloc] initWithFormat:@"%ld", (long)row];
330 }
else if (2 == component) {
331 ret = [[NSString alloc] initWithFormat:@"%ld", (long)row];
332 }
else if (3 == component) {
333 ret = [[NSString alloc] initWithFormat:@"%ld", (long)row];
334 }
else if (4 == component) {
337 ret = [pickerWheel4Titles objectAtIndex:row];
342 NSLog(
@"Z6ParamValueEditView.titleForRow: unknown component: %ld", (
long)component);
345 UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:16];
346 NSDictionary *attribs = @{
347 NSForegroundColorAttributeName: [UIColor blackColor],
348 NSFontAttributeName: herefont
350 NSMutableAttributedString *attributedText =
351 [[NSMutableAttributedString alloc] initWithString:ret
353 return attributedText;
355 -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
360 if (0 == component) {
362 NSLog(
@"Z6ParamValueEditView.titleForRow: %ld: %@", (
long)row, ret);
363 }
else if (1 == component) {
364 ret = [[NSString alloc] initWithFormat:@"%ld", (long)row];
365 }
else if (2 == component) {
366 ret = [[NSString alloc] initWithFormat:@"%ld", (long)row];
367 }
else if (3 == component) {
368 ret = [[NSString alloc] initWithFormat:@"%ld", (long)row];
369 }
else if (4 == component) {
372 ret = [pickerWheel4Titles objectAtIndex:row];
377 NSLog(
@"Z6ParamValueEditView.titleForRow: unknown component: %ld", (
long)component);
380 UIFont *herefont = [UIFont fontWithName:@"Helvetica-Bold" size:20];
381 NSDictionary *attribs = @{
382 NSForegroundColorAttributeName: [UIColor blackColor],
383 NSFontAttributeName: herefont
385 NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:ret attributes:attribs];
388 UILabel *labelView = [[UILabel alloc] init];
389 [labelView setTextAlignment:NSTextAlignmentCenter];
390 labelView.attributedText = attributedString;
395 - (NSInteger) isListedAlready: (NSString *)pickedCaption
398 int parameterIndex = 0;
401 NSString *compoTypeClass = NSStringFromClass([componentType
class]);
403 if ([compoTypeClass isEqualToString:
@"NSTaggedPointerString"]) {
406 if ([componentType isEqualToString:pickedCaption]) {
407 NSLog(
@"Z6ParamValueEditView.isListedAlready: UNEXPECTED: %@", componentType);
408 ret = parameterIndex;
411 }
else if (![compoTypeClass isEqualToString:
@"NSString"]) {
412 NSLog(
@"Z6ParamValueEditView.isListedAlready: odd-bal compo-class: %@", compoTypeClass);
413 }
else if ([componentType isEqualToString:pickedCaption]) {
416 ret = parameterIndex;
430 - (void) setupDimensionWheel
436 HKUnit *massUnit = [HKUnit unitFromString:@"g"];
437 HKUnit *energyUnit = [HKUnit unitFromString:@"cal"];
444 NSLog(
@"Z6ParamValueEditView.setupDimensionWheel: count: %ld", (
long)[
pickerWheel4Titles count]);
446 - (HKUnit *) unitForQuantityType: (HKQuantityType *)quantityType
450 NSArray<HKUnit *> *unitsAvailable = [[NSArray alloc] initWithObjects: [HKUnit gramUnit],
451 [HKUnit meterUnit], [HKUnit literUnit], [HKUnit pascalUnit], [HKUnit secondUnit],
452 [HKUnit jouleUnit] , [HKUnit degreeCelsiusUnit], [HKUnit siemenUnit], nil];
453 for (HKUnit *u in unitsAvailable) {
454 if ([quantityType isCompatibleWithUnit:u]) {
468 - (void) establishPick: (NSInteger)row
471 NSInteger valueComponentIndex = 1;
472 [newParameterPicker reloadComponent:valueComponentIndex];
473 valueComponentIndex = 2;
474 [newParameterPicker reloadComponent:valueComponentIndex];
475 valueComponentIndex = 3;
476 [newParameterPicker reloadComponent:valueComponentIndex];
477 valueComponentIndex = 4;
478 [newParameterPicker reloadComponent:valueComponentIndex];
486 NSLog(
@"Z6ParamValueEditView.didSelectRow: pickQuantityUnit: %@",
pickQuantityUnit);
489 - (void)pickerView:(UIPickerView *)pickerView
490 didSelectRow:(NSInteger)row
491 inComponent:(NSInteger)component
493 NSLog(
@"Z6ParamValueEditView.didSelectPickerRow: component: %ld", (
long)component);
500 NSLog(
@"Z6ParamValueEditView.didSelectPickerRow: %ld %@", (
long)row, pickedCaption);
501 int parameterIndex = (int)[
self isListedAlready:pickedCaption];
503 if (0 <= parameterIndex) {
515 NSLog(
@"Z6ParamValueEditView.didSelectRow: reload all components at pick");
516 [pickerView reloadAllComponents];
517 NSLog(
@"Z6ParamValueEditView.didSelectRow: END -- reload all components at pick");
529 NSLog(
@"Z6ParamValueEditView.didSelectRow: component: %ld", (
long)component);
537 #pragma mark - UIPickerViewDataSource 538 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
548 - (NSInteger)pickerView:(UIPickerView *)pickerView
549 numberOfRowsInComponent:(NSInteger)component
556 ret = [typesApprovedToWrite count];
577 HKUnit *massUnit = [HKUnit unitFromString:@"g"];
578 HKUnit *energyUnit = [HKUnit unitFromString:@"cal"];
586 NSLog(
@"Z6ParamValueEditView.numberOfRowsInComponent: NULL pickQuantityType");
598 #pragma mark - picker action 601 - (void) setPickerType:(HKQuantityType* )quanType scalar:(
int)scalar andUnit:(NSString *)unit
605 for (NSString *type in types) {
606 if ([type isEqualToString:[quanType description]]) {
613 int hundreds = scalar / 100;
614 int tens = (scalar - (100*hundreds)) / 10;
615 int ones = scalar - (100*hundreds) - (10*tens);
617 [newParameterPicker selectRow:hundreds inComponent:1 animated:YES];
618 [newParameterPicker selectRow:tens inComponent:2 animated:YES];
619 [newParameterPicker selectRow:ones inComponent:3 animated:YES];
620 NSLog(
@"Z6ParamValueEditView.setPickerType");
624 - (NSString *) stringForPickerRow: (NSInteger) row
628 if ([typesApprovedToWrite count] > row) {
629 HKQuantityType *hkQtype = [typesApprovedToWrite objectAtIndex:row];
630 ret = [[hkQtype description] substringFromIndex:31];
int massUnitsMetricPrefixArray[]
void specializePickerView:(NSDictionary *editSource)
HKQuantity * produceQuantityValue()
NSMutableArray * pickerWheel4Titles
NSString * componentNameKey()
HKQuantityType * pickQuantityType
NSMutableArray * nutritionComponents
float newParameterPickerHeight
Boolean editParameterSelected
instancetype sharedInstance()
HKUnit * pickQuantityUnit
HKUnit * pickQuantityUnit
void setPickerType:scalar:andUnit:(HKQuantityType *quanType, [scalar] int scalar, [andUnit] NSString *unit)
NSString * componentSampleKey()
NSInteger newParameterIndex
void establishPick:(NSInteger row)
id< U7ParamEditControlDelegate > delegate
NSMutableDictionary * newComponentSpecDict
NSString * componentValueKey()
NSString * stringForPickerRow:(NSInteger row)
NSArray * energyUnitsArray
NSString * componentAuthorityKey()
HKUnit * unitForQuantityType:(HKQuantityType *quantityType)
NSNumber * checkTypeAuthorization:(HKQuantityType *quantityType)
Singleton interface to both core and remote data sources.
void setupDimensionWheel()
CGRect newParameterPickerFrame
NSInteger editNutritionParameter
int energyUnitsMetricPrefixArray[]
HKQuantityType * pickQuantityType
UIPickerView * newParameterPicker
void showPickerViewNot:(Boolean flag)