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:
parent
313e0ae6f9
commit
cbe3a428f4
@ -98,6 +98,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
private static final String TOOLBAR_COLOR = "toolbarcolor";
|
||||
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption";
|
||||
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 NAVIGATION_COLOR = "navigationbuttoncolor";
|
||||
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 String closeButtonCaption = "";
|
||||
private String closeButtonColor = "";
|
||||
private boolean leftToRight = false;
|
||||
private int toolbarColor = android.graphics.Color.LTGRAY;
|
||||
private boolean hideNavigationButtons = false;
|
||||
private String navigationButtonColor = "";
|
||||
@ -609,6 +611,10 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
if (closeButtonColorSet != null) {
|
||||
closeButtonColor = closeButtonColorSet;
|
||||
}
|
||||
String leftToRightSet = features.get(LEFT_TO_RIGHT);
|
||||
if (leftToRightSet != null) {
|
||||
leftToRight = leftToRightSet.equals("yes") ? true : false;
|
||||
}
|
||||
String toolbarColorSet = features.get(TOOLBAR_COLOR);
|
||||
if (toolbarColorSet != null) {
|
||||
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);
|
||||
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
if (leftToRight) closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
else closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
_close.setLayoutParams(closeLayoutParams);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
@ -717,15 +724,22 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
toolbar.setBackgroundColor(toolbarColor);
|
||||
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));
|
||||
if (leftToRight) {
|
||||
toolbar.setHorizontalGravity(Gravity.LEFT);
|
||||
} else {
|
||||
toolbar.setHorizontalGravity(Gravity.RIGHT);
|
||||
}
|
||||
toolbar.setVerticalGravity(Gravity.TOP);
|
||||
|
||||
// Action Button Container layout
|
||||
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.setVerticalGravity(Gravity.CENTER_VERTICAL);
|
||||
actionButtonContainer.setId(Integer.valueOf(1));
|
||||
actionButtonContainer.setId(leftToRight ? Integer.valueOf(5) : Integer.valueOf(1));
|
||||
|
||||
// Back button
|
||||
ImageButton back = new ImageButton(cordova.getActivity());
|
||||
@ -805,7 +819,8 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
|
||||
|
||||
// Header Close/Done button
|
||||
View close = createCloseButton(5);
|
||||
int closeButtonId = leftToRight ? 1 : 5;
|
||||
View close = createCloseButton(closeButtonId);
|
||||
toolbar.addView(close);
|
||||
|
||||
// Footer
|
||||
|
@ -50,6 +50,7 @@
|
||||
@property (nonatomic, assign) BOOL toolbar;
|
||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||
@property (nonatomic, assign) BOOL lefttoright;
|
||||
@property (nonatomic, copy) NSString* toolbarposition;
|
||||
@property (nonatomic, copy) NSString* toolbarcolor;
|
||||
@property (nonatomic, assign) BOOL toolbartranslucent;
|
||||
@ -103,7 +104,7 @@
|
||||
- (void)navigateTo:(NSURL*)url;
|
||||
- (void)showLocationBar:(BOOL)show;
|
||||
- (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;
|
||||
|
||||
|
@ -163,7 +163,8 @@
|
||||
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
|
||||
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
|
||||
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
|
||||
UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default
|
||||
@ -650,11 +651,18 @@
|
||||
|
||||
// Filter out Navigation Buttons if user requests so
|
||||
if (_browserOptions.hidenavigationbuttons) {
|
||||
if (_browserOptions.lefttoright) {
|
||||
[self.toolbar setItems:@[flexibleSpaceButton, self.closeButton]];
|
||||
} else {
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
|
||||
}
|
||||
} else {
|
||||
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 addSubview:self.toolbar];
|
||||
@ -667,7 +675,7 @@
|
||||
[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
|
||||
// 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];
|
||||
|
||||
NSMutableArray* items = [self.toolbar.items mutableCopy];
|
||||
[items replaceObjectAtIndex:0 withObject:self.closeButton];
|
||||
[items replaceObjectAtIndex:buttonIndex withObject:self.closeButton];
|
||||
[self.toolbar setItems:items];
|
||||
}
|
||||
|
||||
@ -1022,6 +1030,7 @@
|
||||
self.disallowoverscroll = NO;
|
||||
self.hidenavigationbuttons = NO;
|
||||
self.closebuttoncolor = nil;
|
||||
self.lefttoright = false;
|
||||
self.toolbarcolor = nil;
|
||||
self.toolbartranslucent = YES;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user