Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow changing location bg and text color #921

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ instance, or the system browser.
- __hideurlbar__: set to `yes` to hide the url bar on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
- __navigationbuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of both navigation buttons from default. Only has effect if user has location set to `yes` and not hidenavigationbuttons set to `yes`.
- __toolbarcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color the toolbar from default. Only has effect if user has location set to `yes`.
- __locationtextcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of the location text (URL) from default. Only has effect if user has location set to `yes`.
- __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, navigation buttons go to the right and close button to the left. Default value is `no`.
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
Expand All @@ -140,6 +141,8 @@ instance, or the system browser.
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
- __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
- __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled.
- __locationcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of the location bar from default. Only has effect if user has location set to `yes`.
- __locationtextcolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the color of the location text (URL) from default. Only has effect if user has location set to `yes`.
- __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left.
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
Expand Down
9 changes: 8 additions & 1 deletion src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,9 @@ public class InAppBrowser extends CordovaPlugin {
private static final String FOOTER_COLOR = "footercolor";
private static final String BEFORELOAD = "beforeload";
private static final String FULLSCREEN = "fullscreen";
private static final String LOCATION_TEXT_COLOR = "locationtextcolor";

private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR, LOCATION_TEXT_COLOR);

private InAppBrowserDialog dialog;
private WebView inAppWebView;
Expand Down Expand Up @@ -145,6 +146,7 @@ public class InAppBrowser extends CordovaPlugin {
private String footerColor = "";
private String beforeload = "";
private boolean fullscreen = true;
private String locationTextColor = "";
private String[] allowedSchemes;
private InAppBrowserClient currentClient;

Expand Down Expand Up @@ -710,6 +712,10 @@ public String showWebPage(final String url, HashMap<String, String> features) {
if (fullscreenSet != null) {
fullscreen = fullscreenSet.equals("yes") ? true : false;
}
String locationTextColorSet = features.get(LOCATION_TEXT_COLOR);
if (locationTextColorSet != null) {
locationTextColor = locationTextColorSet;
}
}

final CordovaWebView thatWebView = this.webView;
Expand Down Expand Up @@ -870,6 +876,7 @@ public void onClick(View v) {
textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
edittext.setLayoutParams(textLayoutParams);
edittext.setId(Integer.valueOf(4));
if (locationTextColor != "") edittext.setTextColor(android.graphics.Color.parseColor(locationTextColor));
edittext.setSingleLine(true);
edittext.setText(url);
edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
Expand Down
2 changes: 2 additions & 0 deletions src/ios/CDVInAppBrowserOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
@property (nonatomic, assign) BOOL lefttoright;
@property (nonatomic, copy) NSString* toolbarposition;
@property (nonatomic, copy) NSString* toolbarcolor;
@property (nonatomic, copy) NSString* locationcolor;
@property (nonatomic, copy) NSString* locationtextcolor;
@property (nonatomic, assign) BOOL toolbartranslucent;
@property (nonatomic, assign) BOOL hidenavigationbuttons;
@property (nonatomic, copy) NSString* navigationbuttoncolor;
Expand Down
2 changes: 2 additions & 0 deletions src/ios/CDVInAppBrowserOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ - (id)init
self.closebuttoncolor = nil;
self.lefttoright = false;
self.toolbarcolor = nil;
self.locationcolor = nil;
self.locationtextcolor = nil;
self.toolbartranslucent = YES;
self.beforeload = @"";
}
Expand Down
16 changes: 12 additions & 4 deletions src/ios/CDVWKInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -856,28 +856,36 @@ - (void)createViews
self.addressLabel.alpha = 1.000;
self.addressLabel.autoresizesSubviews = YES;
self.addressLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin;
self.addressLabel.backgroundColor = [UIColor clearColor];
if (_browserOptions.locationcolor != nil) { // Set background color if user sets it in options
self.addressLabel.backgroundColor = [self colorFromHexString:_browserOptions.locationcolor];
} else {
self.addressLabel.backgroundColor = [UIColor clearColor];
}
self.addressLabel.baselineAdjustment = UIBaselineAdjustmentAlignCenters;
self.addressLabel.clearsContextBeforeDrawing = YES;
self.addressLabel.clipsToBounds = YES;
self.addressLabel.contentMode = UIViewContentModeScaleToFill;
self.addressLabel.enabled = YES;
self.addressLabel.hidden = NO;
self.addressLabel.lineBreakMode = NSLineBreakByTruncatingTail;

if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumScaleFactor:")]) {
[self.addressLabel setValue:@(10.0/[UIFont labelFontSize]) forKey:@"minimumScaleFactor"];
} else if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumFontSize:")]) {
[self.addressLabel setValue:@(10.0) forKey:@"minimumFontSize"];
}

self.addressLabel.multipleTouchEnabled = NO;
self.addressLabel.numberOfLines = 1;
self.addressLabel.opaque = NO;
self.addressLabel.shadowOffset = CGSizeMake(0.0, -1.0);
self.addressLabel.text = NSLocalizedString(@"Loading...", nil);
self.addressLabel.textAlignment = NSTextAlignmentLeft;
self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000];
if (_browserOptions.locationtextcolor != nil) { // Set text color if user sets it in options
self.addressLabel.textColor = [self colorFromHexString:_browserOptions.locationtextcolor];
} else {
self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000];
}
self.addressLabel.userInteractionEnabled = NO;

NSString* frontArrowString = NSLocalizedString(@"►", nil); // create arrow from Unicode char
Expand Down