CB-13969 cordova-inappbrowser:iOS&Android now includes a extra, optional parameter to swap position of navigationbuttons and close/done button

This commit is contained in:
Landsbankinn 2018-03-13 11:39:22 +00:00
parent 313e0ae6f9
commit cbe3a428f4
3 changed files with 37 additions and 12 deletions

View File

@ -98,6 +98,7 @@ public class InAppBrowser extends CordovaPlugin {
private static final String TOOLBAR_COLOR = "toolbarcolor"; private static final String TOOLBAR_COLOR = "toolbarcolor";
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption"; private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption";
private static final String CLOSE_BUTTON_COLOR = "closebuttoncolor"; private static final String CLOSE_BUTTON_COLOR = "closebuttoncolor";
private static final String LEFT_TO_RIGHT = "lefttoright";
private static final String HIDE_NAVIGATION = "hidenavigationbuttons"; private static final String HIDE_NAVIGATION = "hidenavigationbuttons";
private static final String NAVIGATION_COLOR = "navigationbuttoncolor"; private static final String NAVIGATION_COLOR = "navigationbuttoncolor";
private static final String HIDE_URL = "hideurlbar"; private static final String HIDE_URL = "hideurlbar";
@ -125,6 +126,7 @@ public class InAppBrowser extends CordovaPlugin {
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2; private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2;
private String closeButtonCaption = ""; private String closeButtonCaption = "";
private String closeButtonColor = ""; private String closeButtonColor = "";
private boolean leftToRight = false;
private int toolbarColor = android.graphics.Color.LTGRAY; private int toolbarColor = android.graphics.Color.LTGRAY;
private boolean hideNavigationButtons = false; private boolean hideNavigationButtons = false;
private String navigationButtonColor = ""; private String navigationButtonColor = "";
@ -609,6 +611,10 @@ public class InAppBrowser extends CordovaPlugin {
if (closeButtonColorSet != null) { if (closeButtonColorSet != null) {
closeButtonColor = closeButtonColorSet; closeButtonColor = closeButtonColorSet;
} }
String leftToRightSet = features.get(LEFT_TO_RIGHT);
if (leftToRightSet != null) {
leftToRight = leftToRightSet.equals("yes") ? true : false;
}
String toolbarColorSet = features.get(TOOLBAR_COLOR); String toolbarColorSet = features.get(TOOLBAR_COLOR);
if (toolbarColorSet != null) { if (toolbarColorSet != null) {
toolbarColor = android.graphics.Color.parseColor(toolbarColorSet); toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
@ -673,7 +679,8 @@ public class InAppBrowser extends CordovaPlugin {
} }
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); if (leftToRight) closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
else closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
_close.setLayoutParams(closeLayoutParams); _close.setLayoutParams(closeLayoutParams);
if (Build.VERSION.SDK_INT >= 16) if (Build.VERSION.SDK_INT >= 16)
@ -717,15 +724,22 @@ public class InAppBrowser extends CordovaPlugin {
toolbar.setBackgroundColor(toolbarColor); toolbar.setBackgroundColor(toolbarColor);
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44))); toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2)); toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
toolbar.setHorizontalGravity(Gravity.LEFT); if (leftToRight) {
toolbar.setHorizontalGravity(Gravity.LEFT);
} else {
toolbar.setHorizontalGravity(Gravity.RIGHT);
}
toolbar.setVerticalGravity(Gravity.TOP); toolbar.setVerticalGravity(Gravity.TOP);
// Action Button Container layout // Action Button Container layout
RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity()); RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
actionButtonContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); RelativeLayout.LayoutParams actionButtonLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if (leftToRight) actionButtonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
else actionButtonLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
actionButtonContainer.setLayoutParams(actionButtonLayoutParams);
actionButtonContainer.setHorizontalGravity(Gravity.LEFT); actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL); actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
actionButtonContainer.setId(Integer.valueOf(1)); actionButtonContainer.setId(leftToRight ? Integer.valueOf(5) : Integer.valueOf(1));
// Back button // Back button
ImageButton back = new ImageButton(cordova.getActivity()); ImageButton back = new ImageButton(cordova.getActivity());
@ -805,7 +819,8 @@ public class InAppBrowser extends CordovaPlugin {
// Header Close/Done button // Header Close/Done button
View close = createCloseButton(5); int closeButtonId = leftToRight ? 1 : 5;
View close = createCloseButton(closeButtonId);
toolbar.addView(close); toolbar.addView(close);
// Footer // Footer

View File

@ -50,6 +50,7 @@
@property (nonatomic, assign) BOOL toolbar; @property (nonatomic, assign) BOOL toolbar;
@property (nonatomic, copy) NSString* closebuttoncaption; @property (nonatomic, copy) NSString* closebuttoncaption;
@property (nonatomic, copy) NSString* closebuttoncolor; @property (nonatomic, copy) NSString* closebuttoncolor;
@property (nonatomic, assign) BOOL lefttoright;
@property (nonatomic, copy) NSString* toolbarposition; @property (nonatomic, copy) NSString* toolbarposition;
@property (nonatomic, copy) NSString* toolbarcolor; @property (nonatomic, copy) NSString* toolbarcolor;
@property (nonatomic, assign) BOOL toolbartranslucent; @property (nonatomic, assign) BOOL toolbartranslucent;
@ -103,7 +104,7 @@
- (void)navigateTo:(NSURL*)url; - (void)navigateTo:(NSURL*)url;
- (void)showLocationBar:(BOOL)show; - (void)showLocationBar:(BOOL)show;
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition; - (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString; - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions; - (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;

View File

@ -163,7 +163,8 @@
[self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showLocationBar:browserOptions.location];
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) { if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) {
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor]; int closeButtonIndex = browserOptions.lefttoright ? (browserOptions.hidenavigationbuttons ? 1 : 4) : 0;
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor :closeButtonIndex];
} }
// Set Presentation Style // Set Presentation Style
UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default
@ -650,11 +651,18 @@
// Filter out Navigation Buttons if user requests so // Filter out Navigation Buttons if user requests so
if (_browserOptions.hidenavigationbuttons) { if (_browserOptions.hidenavigationbuttons) {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]]; if (_browserOptions.lefttoright) {
[self.toolbar setItems:@[flexibleSpaceButton, self.closeButton]];
} else {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
}
} else { } else {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; if (_browserOptions.lefttoright) {
[self.toolbar setItems:@[self.backButton, fixedSpaceButton, self.forwardButton, flexibleSpaceButton, self.closeButton]];
} else {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
}
} }
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
self.view.backgroundColor = [UIColor grayColor]; self.view.backgroundColor = [UIColor grayColor];
[self.view addSubview:self.toolbar]; [self.view addSubview:self.toolbar];
@ -667,7 +675,7 @@
[self.webView setFrame:frame]; [self.webView setFrame:frame];
} }
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString - (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex
{ {
// the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically // the advantage of using UIBarButtonSystemItemDone is the system will localize it for you automatically
// but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one) // but, if you want to set this yourself, knock yourself out (we can't set the title for a system Done button, so we have to create a new one)
@ -679,7 +687,7 @@
self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1]; self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1];
NSMutableArray* items = [self.toolbar.items mutableCopy]; NSMutableArray* items = [self.toolbar.items mutableCopy];
[items replaceObjectAtIndex:0 withObject:self.closeButton]; [items replaceObjectAtIndex:buttonIndex withObject:self.closeButton];
[self.toolbar setItems:items]; [self.toolbar setItems:items];
} }
@ -1022,6 +1030,7 @@
self.disallowoverscroll = NO; self.disallowoverscroll = NO;
self.hidenavigationbuttons = NO; self.hidenavigationbuttons = NO;
self.closebuttoncolor = nil; self.closebuttoncolor = nil;
self.lefttoright = false;
self.toolbarcolor = nil; self.toolbarcolor = nil;
self.toolbartranslucent = YES; self.toolbartranslucent = YES;
} }