Commit 2fbd7ea4 authored by Scott Nichols's avatar Scott Nichols Committed by Commit Bot

Adding a menu option to move FAB in the quick actions in session.

Change-Id: Ifcb9b811b00bf009a202196623430a9d30d25c65
Reviewed-on: https://chromium-review.googlesource.com/596609
Commit-Queue: Yuwei Huang <yuweih@chromium.org>
Reviewed-by: default avatarYuwei Huang <yuweih@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491493}
parent db092e5e
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
static const CGFloat kFabInset = 15.f; static const CGFloat kFabInset = 15.f;
static const CGFloat kKeyboardAnimationTime = 0.3; static const CGFloat kKeyboardAnimationTime = 0.3;
static const CGFloat kMoveFABAnimationTime = 0.3;
@interface HostViewController ()<ClientKeyboardDelegate, @interface HostViewController ()<ClientKeyboardDelegate,
ClientGesturesDelegate, ClientGesturesDelegate,
...@@ -44,7 +45,9 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -44,7 +45,9 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
CGSize _keyboardSize; CGSize _keyboardSize;
BOOL _surfaceCreated; BOOL _surfaceCreated;
HostSettings* _settings; HostSettings* _settings;
BOOL _fabIsRight;
NSArray<NSLayoutConstraint*>* _fabLeftConstraints;
NSArray<NSLayoutConstraint*>* _fabRightConstraints;
// When set to true, ClientKeyboard will immediately resign first responder // When set to true, ClientKeyboard will immediately resign first responder
// after it becomes first responder. // after it becomes first responder.
BOOL _blocksKeyboard; BOOL _blocksKeyboard;
...@@ -62,6 +65,14 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -62,6 +65,14 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
_blocksKeyboard = NO; _blocksKeyboard = NO;
_settings = _settings =
[[RemotingPreferences instance] settingsForHost:client.hostInfo.hostId]; [[RemotingPreferences instance] settingsForHost:client.hostInfo.hostId];
if ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:
self.view.semanticContentAttribute] ==
UIUserInterfaceLayoutDirectionRightToLeft) {
_fabIsRight = NO;
} else {
_fabIsRight = YES;
}
} }
return self; return self;
} }
...@@ -89,6 +100,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -89,6 +100,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
action:@selector(didTap:) action:@selector(didTap:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
[_floatingButton sizeToFit]; [_floatingButton sizeToFit];
_floatingButton.translatesAutoresizingMaskIntoConstraints = NO;
_actionImageView = _actionImageView =
[[MDCActionImageView alloc] initWithFrame:_floatingButton.bounds [[MDCActionImageView alloc] initWithFrame:_floatingButton.bounds
...@@ -102,7 +114,28 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -102,7 +114,28 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
_clientKeyboard = [[ClientKeyboard alloc] init]; _clientKeyboard = [[ClientKeyboard alloc] init];
_clientKeyboard.delegate = self; _clientKeyboard.delegate = self;
[self.view addSubview:_clientKeyboard]; [self.view addSubview:_clientKeyboard];
// TODO(nicholss): need to pass some keyboard injection interface here.
NSDictionary* views = @{@"fab" : _floatingButton};
NSDictionary* metrics = @{ @"inset" : @(kFabInset) };
_fabLeftConstraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:|-(inset)-[fab]"
options:NSLayoutFormatDirectionLeftToRight
metrics:metrics
views:views];
_fabRightConstraints = [NSLayoutConstraint
constraintsWithVisualFormat:@"H:[fab]-(inset)-|"
options:NSLayoutFormatDirectionLeftToRight
metrics:metrics
views:views];
[NSLayoutConstraint
activateConstraints:[NSLayoutConstraint
constraintsWithVisualFormat:@"V:[fab]-(inset)-|"
options:0
metrics:metrics
views:views]];
} }
- (void)viewDidUnload { - (void)viewDidUnload {
...@@ -184,11 +217,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -184,11 +217,7 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
[self resizeHostToFitIfNeeded]; [self resizeHostToFitIfNeeded];
} }
CGSize btnSize = _floatingButton.frame.size; [self updateFABConstraintsAnimated:NO];
_floatingButton.frame =
CGRectMake(self.view.frame.size.width - btnSize.width - kFabInset,
self.view.frame.size.height - btnSize.height - kFabInset,
btnSize.width, btnSize.height);
} }
#pragma mark - Keyboard #pragma mark - Keyboard
...@@ -296,8 +325,32 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -296,8 +325,32 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
_client.keyboardInterpreter->HandlePrintScreenEvent(); _client.keyboardInterpreter->HandlePrintScreenEvent();
} }
- (void)moveFAB {
_fabIsRight = !_fabIsRight;
[self updateFABConstraintsAnimated:YES];
}
#pragma mark - Private #pragma mark - Private
- (void)updateFABConstraintsAnimated:(BOOL)animated {
[NSLayoutConstraint deactivateConstraints:_fabRightConstraints];
[NSLayoutConstraint deactivateConstraints:_fabLeftConstraints];
if (_fabIsRight) {
[NSLayoutConstraint activateConstraints:_fabRightConstraints];
} else {
[NSLayoutConstraint activateConstraints:_fabLeftConstraints];
}
if (animated) {
[UIView animateWithDuration:kMoveFABAnimationTime
animations:^{
[self.view layoutIfNeeded];
}];
} else {
[self.view layoutIfNeeded];
}
}
- (void)resizeHostToFitIfNeeded { - (void)resizeHostToFitIfNeeded {
// Don't adjust the host resolution if the keyboard is active. That would end // Don't adjust the host resolution if the keyboard is active. That would end
// up with a very narrow desktop. // up with a very narrow desktop.
...@@ -414,6 +467,18 @@ static const CGFloat kKeyboardAnimationTime = 0.3; ...@@ -414,6 +467,18 @@ static const CGFloat kKeyboardAnimationTime = 0.3;
restoresKeyboard:NO restoresKeyboard:NO
handler:settingsHandler]; handler:settingsHandler];
void (^moveFABHandler)(UIAlertAction*) = ^(UIAlertAction*) {
[weakSelf moveFAB];
[_actionImageView setActive:NO animated:YES];
};
[alert addAction:[UIAlertAction
actionWithTitle:l10n_util::GetNSString(
(_fabIsRight)
? IDS_MOVE_FAB_LEFT_BUTTON
: IDS_MOVE_FAB_RIGHT_BUTTON)
style:UIAlertActionStyleDefault
handler:moveFABHandler]];
__weak UIAlertController* weakAlert = alert; __weak UIAlertController* weakAlert = alert;
void (^cancelHandler)() = ^() { void (^cancelHandler)() = ^() {
[weakAlert dismissViewControllerAnimated:YES completion:nil]; [weakAlert dismissViewControllerAnimated:YES completion:nil];
......
...@@ -717,6 +717,12 @@ For information about privacy, please see the Google Privacy Policy (http://goo. ...@@ -717,6 +717,12 @@ For information about privacy, please see the Google Privacy Policy (http://goo.
<message desc="Title for the button that brings up a settings menu." name="IDS_SETTINGS_BUTTON"> <message desc="Title for the button that brings up a settings menu." name="IDS_SETTINGS_BUTTON">
Settings Settings
</message> </message>
<message desc="Title for the button that moves the floating action button to the other left side of the screen." name="IDS_MOVE_FAB_LEFT_BUTTON">
Dock Left
</message>
<message desc="Title for the button that moves the floating action button to the right side of the screen." name="IDS_MOVE_FAB_RIGHT_BUTTON">
Dock Right
</message>
<message desc="Short placeholder text on a text box to prompt the user to enter the PIN." name="IDS_ENTER_PIN"> <message desc="Short placeholder text on a text box to prompt the user to enter the PIN." name="IDS_ENTER_PIN">
Enter PIN Enter PIN
</message> </message>
......
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