Commit 95595ce3 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Update RadialProgressView to draw progress track.

Progress track used to be a part of download state icon. Now that state
icon is programatically drawn the track should be a part of
RadialProgressView.

Bug: 820178
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I4b20faa6fbbc622de2763b962cc40539b22d24fc
Reviewed-on: https://chromium-review.googlesource.com/966936
Commit-Queue: Eugene But <eugenebut@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543910}
parent e8c6f424
...@@ -478,7 +478,8 @@ NSString* GetSizeString(long long size_in_bytes) { ...@@ -478,7 +478,8 @@ NSString* GetSizeString(long long size_in_bytes) {
_progressView = [[RadialProgressView alloc] initWithFrame:CGRectZero]; _progressView = [[RadialProgressView alloc] initWithFrame:CGRectZero];
_progressView.translatesAutoresizingMaskIntoConstraints = NO; _progressView.translatesAutoresizingMaskIntoConstraints = NO;
_progressView.lineWidth = 2; _progressView.lineWidth = 2;
_progressView.tintColor = [MDCPalette bluePalette].tint600; _progressView.progressTintColor = [MDCPalette bluePalette].tint600;
_progressView.trackTintColor = [MDCPalette greyPalette].tint300;
[self updateProgressView]; [self updateProgressView];
} }
return _progressView; return _progressView;
......
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
// The line width used when stroking the progress arc. // The line width used when stroking the progress arc.
@property(nonatomic) CGFloat lineWidth; @property(nonatomic) CGFloat lineWidth;
@property(nonatomic, nullable) UIColor* progressTintColor;
// Track is drawn underneath the progress.
@property(nonatomic, nullable) UIColor* trackTintColor;
@end @end
#endif // IOS_CHROME_BROWSER_UI_DOWNLOAD_RADIAL_PROGRESS_VIEW_H_ #endif // IOS_CHROME_BROWSER_UI_DOWNLOAD_RADIAL_PROGRESS_VIEW_H_
...@@ -13,14 +13,22 @@ ...@@ -13,14 +13,22 @@
#endif #endif
@interface RadialProgressView () @interface RadialProgressView ()
// CALayer that backs this view up.
@property(nonatomic, readonly) CAShapeLayer* shapeLayer; // CALayer that backs this view up. Serves as progress track.
@property(nonatomic, readonly) CAShapeLayer* trackLayer;
// CALayer added as a sublayer for self.layer. Serves as progress.
@property(nonatomic, readonly) CAShapeLayer* progressLayer;
@end @end
@implementation RadialProgressView @implementation RadialProgressView
@synthesize progress = _progress; @synthesize progress = _progress;
@synthesize lineWidth = _lineWidth; @synthesize lineWidth = _lineWidth;
@synthesize progressTintColor = _progressTintColor;
@synthesize trackTintColor = _trackTintColor;
@synthesize progressLayer = _progressLayer;
#pragma mark - UIView overrides #pragma mark - UIView overrides
...@@ -28,37 +36,62 @@ ...@@ -28,37 +36,62 @@
return [CAShapeLayer class]; return [CAShapeLayer class];
} }
- (void)setBounds:(CGRect)bounds {
[super setBounds:bounds];
// progressPathWithEndAngle: relies on self.bounds and must be updated here.
// Track starts at 12 o'clock and ends at 12 o'clock.
self.trackLayer.path =
[self progressPathWithEndAngle:M_PI * 2 - M_PI_2].CGPath;
}
- (void)willMoveToSuperview:(UIView*)newSuperview { - (void)willMoveToSuperview:(UIView*)newSuperview {
if (newSuperview) { if (newSuperview && !self.progressLayer.superlayer) {
self.shapeLayer.fillColor = [UIColor clearColor].CGColor; self.trackLayer.fillColor = [UIColor clearColor].CGColor;
self.shapeLayer.strokeColor = self.tintColor.CGColor; self.trackLayer.strokeColor = self.trackTintColor.CGColor;
self.shapeLayer.lineWidth = self.lineWidth; self.trackLayer.lineWidth = self.lineWidth;
[self.trackLayer addSublayer:self.progressLayer];
} }
} }
#pragma mark - Public #pragma mark - Public
- (void)setProgress:(float)progress { - (void)setProgress:(float)progress {
if (_progress == progress) if (_progress != progress) {
return; _progress = progress;
self.progressLayer.path =
[self progressPathWithEndAngle:M_PI * 2 * progress - M_PI_2].CGPath;
}
}
#pragma mark - Private
_progress = progress; // Returns Bezier path for drawing radial progress or track. Start angle is
// always 12 o'clock.
- (UIBezierPath*)progressPathWithEndAngle:(CGFloat)endAngleInRadians {
CGPoint center = CGPoint center =
CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds)); CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
CGFloat radius = CGRectGetWidth(self.bounds) / 2 - 1; CGFloat radius = CGRectGetWidth(self.bounds) / 2 - self.lineWidth;
UIBezierPath* path = return [UIBezierPath bezierPathWithArcCenter:center
[UIBezierPath bezierPathWithArcCenter:center radius:radius
radius:radius startAngle:-M_PI_2
startAngle:0 - M_PI_2 // 12 o'clock endAngle:endAngleInRadians
endAngle:M_PI * 2 * progress - M_PI_2 clockwise:YES];
clockwise:YES];
self.shapeLayer.path = path.CGPath;
} }
#pragma mark - Private - (CAShapeLayer*)trackLayer {
- (CAShapeLayer*)shapeLayer {
return base::mac::ObjCCastStrict<CAShapeLayer>(self.layer); return base::mac::ObjCCastStrict<CAShapeLayer>(self.layer);
} }
- (CAShapeLayer*)progressLayer {
if (!_progressLayer) {
_progressLayer = [CAShapeLayer layer];
_progressLayer.fillColor = [UIColor clearColor].CGColor;
_progressLayer.strokeColor = self.progressTintColor.CGColor;
_progressLayer.lineWidth = self.lineWidth;
}
return _progressLayer;
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment