Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | 5 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 6 #error "This file requires ARC support." | 6 #error "This file requires ARC support." |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #import <UIKit/UIKit.h> | 9 #import <UIKit/UIKit.h> |
| 10 | 10 |
| 11 #import "remoting/ios/app/host_collection_view_cell.h" | 11 #import "remoting/ios/app/host_collection_view_cell.h" |
| 12 | 12 |
| 13 #import "ios/third_party/material_components_ios/src/components/ShadowElevations /src/MaterialShadowElevations.h" | |
| 14 #import "ios/third_party/material_components_ios/src/components/ShadowLayer/src/ MaterialShadowLayer.h" | |
| 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" | 13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" |
| 16 #import "remoting/ios/domain/host_info.h" | 14 #import "remoting/ios/domain/host_info.h" |
| 17 | 15 |
| 18 static const CGFloat kLinePadding = 2.f; | 16 static const CGFloat kLinePadding = 2.f; |
| 19 static const CGFloat kHostCardIconInset = 10.f; | 17 static const CGFloat kHostCardIconInset = 10.f; |
| 20 static const CGFloat kHostCardPadding = 4.f; | 18 static const CGFloat kHostCardPadding = 4.f; |
| 21 static const CGFloat kHostCardIconSize = 45.f; | 19 static const CGFloat kHostCardIconSize = 45.f; |
| 22 | 20 |
| 23 @interface HostCollectionViewCell () { | 21 @interface HostCollectionViewCell () { |
| 24 UIImageView* _imageView; | 22 UIImageView* _imageView; |
| 25 UILabel* _statusLabel; | 23 UILabel* _statusLabel; |
| 26 UILabel* _titleLabel; | 24 UILabel* _titleLabel; |
| 27 UIView* _cellView; | 25 UIView* _cellView; |
| 26 UIView* _labelView; | |
| 28 } | 27 } |
| 29 @end | 28 @end |
| 30 | 29 |
| 31 // | 30 // |
| 32 // This is the implementation of the info card for a host's status shown in | 31 // This is the implementation of the info card for a host's status shown in |
| 33 // the host list. This will also be the selection for which host to connect | 32 // the host list. This will also be the selection for which host to connect |
| 34 // to and other managements actions for a host in this list. | 33 // to and other managements actions for a host in this list. |
| 35 // | 34 // |
| 36 @implementation HostCollectionViewCell | 35 @implementation HostCollectionViewCell |
| 37 | 36 |
| 38 @synthesize hostInfo = _hostInfo; | 37 @synthesize hostInfo = _hostInfo; |
| 39 | 38 |
| 40 + (Class)layerClass { | |
| 41 return [MDCShadowLayer class]; | |
|
Yuwei
2017/06/01 04:27:17
The collection view by default has its own separat
| |
| 42 } | |
| 43 | |
| 44 - (id)initWithFrame:(CGRect)frame { | 39 - (id)initWithFrame:(CGRect)frame { |
| 45 self = [super initWithFrame:frame]; | 40 self = [super initWithFrame:frame]; |
| 46 if (self) { | 41 if (self) { |
| 47 self.backgroundColor = [UIColor clearColor]; | 42 self.backgroundColor = [UIColor clearColor]; |
| 48 [self commonInit]; | 43 [self commonInit]; |
| 49 } | 44 } |
| 50 return self; | 45 return self; |
| 51 } | 46 } |
| 52 | 47 |
| 53 - (void)commonInit { | 48 - (void)commonInit { |
| 54 _cellView = [[UIView alloc] initWithFrame:self.bounds]; | 49 _cellView = [[UIView alloc] init]; |
|
Yuwei
2017/06/01 04:27:17
Looks like we don't need the extra cellView in our
Yuwei
2017/06/01 18:56:32
Done.
| |
| 55 _cellView.autoresizingMask = | 50 _cellView.translatesAutoresizingMaskIntoConstraints = NO; |
| 56 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
| 57 _cellView.backgroundColor = [UIColor whiteColor]; | |
|
Yuwei
2017/06/01 04:27:17
Changing the background color will weirdly hide th
| |
| 58 _cellView.clipsToBounds = YES; | 51 _cellView.clipsToBounds = YES; |
| 59 [self addSubview:_cellView]; | 52 [self addSubview:_cellView]; |
| 60 | 53 |
| 61 MDCShadowLayer* shadowLayer = (MDCShadowLayer*)self.layer; | 54 _imageView = [[UIImageView alloc] init]; |
| 62 shadowLayer.shadowMaskEnabled = NO; | 55 _imageView.translatesAutoresizingMaskIntoConstraints = NO; |
| 63 [shadowLayer setElevation:MDCShadowElevationCardResting]; | |
| 64 | |
| 65 CGRect imageViewFrame = | |
| 66 CGRectMake(kHostCardIconInset, | |
| 67 self.frame.size.height / 2.f - kHostCardIconSize / 2.f, | |
| 68 kHostCardIconSize, kHostCardIconSize); | |
| 69 _imageView = [[UIImageView alloc] initWithFrame:imageViewFrame]; | |
| 70 _imageView.contentMode = UIViewContentModeCenter; | 56 _imageView.contentMode = UIViewContentModeCenter; |
| 71 _imageView.alpha = 0.87f; | 57 _imageView.alpha = 0.87f; |
| 72 _imageView.backgroundColor = UIColor.lightGrayColor; | 58 _imageView.backgroundColor = UIColor.lightGrayColor; |
| 73 _imageView.layer.cornerRadius = kHostCardIconSize / 2.f; | 59 _imageView.layer.cornerRadius = kHostCardIconSize / 2.f; |
| 74 _imageView.layer.masksToBounds = YES; | 60 _imageView.layer.masksToBounds = YES; |
| 75 [_cellView addSubview:_imageView]; | 61 [_cellView addSubview:_imageView]; |
| 76 | 62 |
| 63 // Holds both of the labels. | |
| 64 _labelView = [[UIView alloc] init]; | |
| 65 _labelView.translatesAutoresizingMaskIntoConstraints = NO; | |
| 66 [_cellView addSubview:_labelView]; | |
| 67 | |
| 77 _titleLabel = [[UILabel alloc] init]; | 68 _titleLabel = [[UILabel alloc] init]; |
| 69 _titleLabel.translatesAutoresizingMaskIntoConstraints = NO; | |
| 78 _titleLabel.font = [MDCTypography titleFont]; | 70 _titleLabel.font = [MDCTypography titleFont]; |
| 79 _titleLabel.alpha = [MDCTypography titleFontOpacity]; | 71 _titleLabel.alpha = [MDCTypography titleFontOpacity]; |
| 80 _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f]; | 72 _titleLabel.textColor = [UIColor colorWithWhite:0 alpha:0.87f]; |
| 81 _titleLabel.frame = CGRectMake( | 73 [_labelView addSubview:_titleLabel]; |
| 82 imageViewFrame.origin.x + imageViewFrame.size.width + kHostCardIconInset, | |
| 83 (self.frame.size.height / 2.f) - | |
| 84 (_titleLabel.font.pointSize + kHostCardPadding / 2.f), | |
| 85 self.frame.size.width, _titleLabel.font.pointSize + kLinePadding); | |
| 86 [_cellView addSubview:_titleLabel]; | |
| 87 | 74 |
| 88 _statusLabel = [[UILabel alloc] init]; | 75 _statusLabel = [[UILabel alloc] init]; |
| 76 _statusLabel.translatesAutoresizingMaskIntoConstraints = NO; | |
| 89 _statusLabel.font = [MDCTypography captionFont]; | 77 _statusLabel.font = [MDCTypography captionFont]; |
| 90 _statusLabel.alpha = [MDCTypography captionFontOpacity]; | 78 _statusLabel.alpha = [MDCTypography captionFontOpacity]; |
| 91 _statusLabel.textColor = [UIColor colorWithWhite:0 alpha:0.60f]; | 79 _statusLabel.textColor = [UIColor colorWithWhite:0 alpha:0.60f]; |
| 92 _statusLabel.frame = CGRectMake( | 80 [_labelView addSubview:_statusLabel]; |
| 93 imageViewFrame.origin.x + imageViewFrame.size.width + kHostCardIconInset, | 81 |
| 94 (self.frame.size.height / 2.f) + kHostCardPadding / 2.f, | 82 // Constraints |
| 95 self.frame.size.width, _statusLabel.font.pointSize + kLinePadding); | 83 NSArray* constraints = @[ |
| 96 [_cellView addSubview:_statusLabel]; | 84 // Expand _cellView to the whole view |
| 85 [[_cellView leadingAnchor] constraintEqualToAnchor:[self leadingAnchor]], | |
|
Yuwei
2017/06/01 04:27:17
FYI leading and trailing are left and right in LTR
| |
| 86 [[_cellView trailingAnchor] constraintEqualToAnchor:[self trailingAnchor]], | |
| 87 [[_cellView topAnchor] constraintEqualToAnchor:[self topAnchor]], | |
| 88 [[_cellView bottomAnchor] constraintEqualToAnchor:[self bottomAnchor]], | |
| 89 | |
| 90 // Arranging [_imageView]-[_labelView] | |
| 91 [[_imageView leadingAnchor] | |
| 92 constraintEqualToAnchor:[_cellView leadingAnchor] | |
| 93 constant:kHostCardIconInset], | |
| 94 [[_imageView centerYAnchor] | |
| 95 constraintEqualToAnchor:[_cellView centerYAnchor]], | |
| 96 [[_imageView widthAnchor] constraintEqualToConstant:kHostCardIconSize], | |
| 97 [[_imageView heightAnchor] constraintEqualToConstant:kHostCardIconSize], | |
| 98 | |
| 99 [[_labelView leadingAnchor] | |
| 100 constraintEqualToAnchor:[_imageView trailingAnchor] | |
| 101 constant:kHostCardIconInset], | |
| 102 [[_labelView trailingAnchor] | |
| 103 constraintEqualToAnchor:[_cellView trailingAnchor] | |
| 104 constant:-kHostCardPadding / 2.f], | |
| 105 [[_labelView topAnchor] constraintEqualToAnchor:[_cellView topAnchor]], | |
| 106 [[_labelView bottomAnchor] | |
| 107 constraintEqualToAnchor:[_cellView bottomAnchor]], | |
| 108 | |
| 109 // Put titleLable and statusLable symmetrically on centerY. | |
| 110 [[_titleLabel leadingAnchor] | |
| 111 constraintEqualToAnchor:[_labelView leadingAnchor]], | |
| 112 [[_titleLabel trailingAnchor] | |
| 113 constraintEqualToAnchor:[_labelView trailingAnchor]], | |
| 114 [[_titleLabel bottomAnchor] | |
| 115 constraintEqualToAnchor:[_labelView centerYAnchor]], | |
| 116 | |
| 117 [[_statusLabel leadingAnchor] | |
| 118 constraintEqualToAnchor:[_labelView leadingAnchor]], | |
| 119 [[_statusLabel trailingAnchor] | |
| 120 constraintEqualToAnchor:[_labelView trailingAnchor]], | |
| 121 [[_statusLabel topAnchor] constraintEqualToAnchor:[_labelView centerYAnchor] | |
| 122 constant:kLinePadding], | |
| 123 ]; | |
| 124 | |
| 125 [NSLayoutConstraint activateConstraints:constraints]; | |
| 97 } | 126 } |
| 98 | 127 |
| 99 #pragma mark - HostCollectionViewCell Public | 128 #pragma mark - HostCollectionViewCell Public |
| 100 | 129 |
| 101 - (void)populateContentWithHostInfo:(HostInfo*)hostInfo { | 130 - (void)populateContentWithHostInfo:(HostInfo*)hostInfo { |
| 102 _hostInfo = hostInfo; | 131 _hostInfo = hostInfo; |
| 103 | 132 |
| 104 _titleLabel.text = _hostInfo.hostName; | 133 _titleLabel.text = _hostInfo.hostName; |
| 105 | 134 |
| 106 _imageView.image = [UIImage imageNamed:@"ic_desktop"]; | 135 _imageView.image = [UIImage imageNamed:@"ic_desktop"]; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 120 #pragma mark - UICollectionReusableView | 149 #pragma mark - UICollectionReusableView |
| 121 | 150 |
| 122 - (void)prepareForReuse { | 151 - (void)prepareForReuse { |
| 123 [super prepareForReuse]; | 152 [super prepareForReuse]; |
| 124 _hostInfo = nil; | 153 _hostInfo = nil; |
| 125 _statusLabel.text = nil; | 154 _statusLabel.text = nil; |
| 126 _titleLabel.text = nil; | 155 _titleLabel.text = nil; |
| 127 } | 156 } |
| 128 | 157 |
| 129 @end | 158 @end |
| OLD | NEW |