CommandClassControlNodeView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. //
  2. // CommandClassControlNodeView.m
  3. // kneet2
  4. //
  5. // Created by Jason Lee on 11/5/15.
  6. // Copyright © 2015 ntels. All rights reserved.
  7. //
  8. #import "JDObject.h"
  9. #import "RequestHandler.h"
  10. #import "JDJSONModel.h"
  11. #import "DeviceModel.h"
  12. #import "CommandClassControlNodeView.h"
  13. #define kfSwitchLabelPadding 20.0f
  14. #define kfCommandClassSwitchLeftPadding 20.0f
  15. #define kfCommandClassSwitchRightPadding 20.0f
  16. #define kfCommandClassLockRightPadding 20.0f
  17. #define kfControlDefaultWidth 215.0f;
  18. #define kfControlMaxWidth IPHONE_WIDTH - 105.0f
  19. #define kfControlDefaultHeight 35.0f
  20. @implementation CommandClassControlNodeView
  21. + (CommandClassControlNodeView *)viewForCommandClass:(CmdClsType)cmdClsType
  22. {
  23. CommandClassControlNodeView *controlView = nil;
  24. for (UIView *view in [CommonUtil nibViews:@"CommandClassControlNodeView"]) {
  25. if (view.tag == cmdClsType) {
  26. controlView = (CommandClassControlNodeView *)view;
  27. controlView.width = kfControlDefaultWidth;
  28. controlView.height = kfControlDefaultHeight;
  29. break;
  30. }
  31. }
  32. return controlView;
  33. }
  34. - (CGSize)sizeForIntrinsic {
  35. return CGSizeMake(kfControlMaxWidth, kfControlDefaultHeight);
  36. }
  37. - (CGSize)sizeForIntrinsicForItemCount:(NSInteger)count {
  38. return CGSizeMake(kfControlMaxWidth, kfControlDefaultHeight);
  39. }
  40. @end
  41. @implementation CommandClassControlNodeSensorBinaryView
  42. @end
  43. @implementation CommandClassControlNodeSensorMultiLevelView
  44. @end
  45. @implementation CommandClassControlNodeValveView
  46. - (void)willMoveToSuperview:(UIView *)newSuperview {
  47. if (!newSuperview)
  48. return;
  49. [self initControl];
  50. }
  51. - (void)initControl {
  52. [self setLayoutUI];
  53. }
  54. - (void)setLayoutUI {
  55. NSString *stmp = _subItem.cmdclsValueMsgLongest;
  56. CGFloat width = [CommonUtil getSizeFromString:stmp font:_btnOpen.titleLabel.font width:FLT_MAX].width + kfSwitchLabelPadding;
  57. CGFloat eWidth = width + kfCommandClassSwitchLeftPadding + kfCommandClassSwitchRightPadding;
  58. _constraintBtnOpenWidth.constant = eWidth;
  59. // CGRect sr = self.frame;
  60. // sr.size.width = eWidth;
  61. // self.frame = sr;
  62. CmdClsValueModel *cmdclsValueOn = _subItem.cmdclsValueList[0];
  63. CmdClsValueModel *cmdclsValueOff = _subItem.cmdclsValueList[1];
  64. _subItem.cmdclsValue = cmdclsValueOn.cmdclsValue;
  65. [_btnOpen setTitle:cmdclsValueOn.cmdclsValueMsg forState:UIControlStateNormal];
  66. [_btnClose setTitle:cmdclsValueOff.cmdclsValueMsg forState:UIControlStateNormal];
  67. _btnOpen.rectForCapBackground = CGRectMake(kfCommandClassSwitchLeftPadding, 0, kfCommandClassSwitchRightPadding, 0);
  68. _btnClose.rectForCapBackground = CGRectMake(kfCommandClassSwitchLeftPadding, 0, kfCommandClassSwitchRightPadding, 0);
  69. }
  70. - (IBAction)btnOpenTouched:(id)sender {
  71. }
  72. - (IBAction)btnCloseTouched:(id)sender {
  73. }
  74. @end
  75. @implementation CommandClassControlNodeSwitchBinaryView
  76. - (void)willMoveToSuperview:(UIView *)newSuperview {
  77. if (!newSuperview)
  78. return;
  79. [self initControl];
  80. }
  81. - (void)initControl {
  82. [self setLayoutUI];
  83. }
  84. - (void)setLayoutUI {
  85. NSString *stmp = _subItem.cmdclsValueMsgLongest;
  86. CGFloat width = [CommonUtil getSizeFromString:stmp font:_btnOff.titleLabel.font width:FLT_MAX].width + kfSwitchLabelPadding;
  87. CGFloat eWidth = width + kfCommandClassSwitchLeftPadding + kfCommandClassSwitchRightPadding;
  88. _constraintBtnOnWidth.constant = eWidth;
  89. CmdClsValueModel *cmdclsValueOn = _subItem.cmdclsValueList[0];
  90. CmdClsValueModel *cmdclsValueOff = _subItem.cmdclsValueList[1];
  91. _subItem.cmdclsValue = cmdclsValueOn.cmdclsValue;
  92. [_btnOn setTitle:cmdclsValueOn.cmdclsValueMsg forState:UIControlStateNormal];
  93. [_btnOff setTitle:cmdclsValueOff.cmdclsValueMsg forState:UIControlStateNormal];
  94. _btnOn.rectForCapBackground = CGRectMake(kfCommandClassSwitchLeftPadding, 0, kfCommandClassSwitchRightPadding, 0);
  95. _btnOff.rectForCapBackground = CGRectMake(kfCommandClassSwitchLeftPadding, 0, kfCommandClassSwitchRightPadding, 0);
  96. }
  97. - (IBAction)btnOnTouched:(id)sender {
  98. _selectedCmdClsValue = _subItem.cmdclsValueList[0];
  99. [[JDFacade facade] setRadioButtonStatus:@YES object:_subItem.cmdclsValueList[0]];
  100. [[JDFacade facade] setRadioButtonStatus:@NO object:_subItem.cmdclsValueList[1]];
  101. _btnOn.selected = YES;
  102. _btnOff.selected = NO;
  103. }
  104. - (IBAction)btnOffTouched:(id)sender {
  105. _selectedCmdClsValue = _subItem.cmdclsValueList[1];
  106. [[JDFacade facade] setRadioButtonStatus:@NO object:_subItem.cmdclsValueList[0]];
  107. [[JDFacade facade] setRadioButtonStatus:@YES object:_subItem.cmdclsValueList[1]];
  108. _btnOn.selected = NO;
  109. _btnOff.selected = YES;
  110. }
  111. @end
  112. @implementation CommandClassControlNodeSwitchMultiLevelView
  113. @end