Skip to content

Commit d940b59

Browse files
Android works well now, all changes are now documented
1 parent f3d7f72 commit d940b59

File tree

4 files changed

+77
-27
lines changed

4 files changed

+77
-27
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ instance, or the system browser.
101101

102102
- __options__: Options for the `InAppBrowser`. Optional, defaulting to: `location=yes`. _(String)_
103103

104-
The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive.
105-
104+
The `options` string must not contain any blank space, and each feature's name/value pairs must be separated by a comma. Feature names are case insensitive.
105+
106106
All platforms support:
107107

108108
- __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off.
@@ -112,7 +112,13 @@ instance, or the system browser.
112112
- __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
113113
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
114114
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
115+
- __closebuttoncaption__: set to a string to use as the close buttons caption instead of a X. Note that you need to localize this value yourself.
116+
- __closebuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the
117+
close button color from default, regardless of being a text or default X. Only has effect if user has location set to `yes`.
115118
- __hardwareback__: set to `yes` to use the hardware back button to navigate backwards through the `InAppBrowser`'s history. If there is no previous page, the `InAppBrowser` will close. The default value is `yes`, so you must set it to `no` if you want the back button to simply close the InAppBrowser.
119+
- __hidenavigationbuttons__: set to `yes` to hide the navigation buttons on the location toolbar, only has effect if user has location set to `yes`. The default value is `no`.
120+
- __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`.
121+
- __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`.
116122
- __zoom__: set to `yes` to show Android browser's zoom controls, set to `no` to hide them. Default value is `yes`.
117123
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
118124
- __shouldPauseOnSuspend__: Set to `yes` to make InAppBrowser WebView to pause/resume with the app to stop background audio (this may be required to avoid Google Play issues like described in [CB-11013](https://issues.apache.org/jira/browse/CB-11013)).
@@ -123,9 +129,13 @@ instance, or the system browser.
123129
- __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
124130
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
125131
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
132+
- __closebuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default __Done__ button's color. Only applicable if toolbar is not disabled.
126133
- __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself.
127134
- __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property.
135+
- __hidetoolbarnavigationbuttons__: set to `yes` or `no` to turn the toolbar navigation buttons on or off (defaults to `no`). Only applicable if toolbar is not disabled.
128136
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
137+
- __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.
138+
- __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled.
129139
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
130140
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
131141
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`)

src/android/InAppBrowser.java

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ Licensed to the Apache Software Foundation (ASF) under one
7171
import java.lang.reflect.InvocationTargetException;
7272
import java.lang.reflect.Field;
7373
import java.lang.reflect.Method;
74+
import java.util.Arrays;
75+
import java.util.List;
7476
import java.util.HashMap;
7577
import java.util.StringTokenizer;
7678

@@ -95,8 +97,14 @@ public class InAppBrowser extends CordovaPlugin {
9597
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
9698
private static final Boolean DEFAULT_HARDWARE_BACK = true;
9799
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
98-
private static final String CLOSE_BUTTON_TEXT = "closeButtonText";
99-
private static final String CLOSE_BUTTON_COLOR = "closeButtonColor";
100+
private static final String TOOLBAR_COLOR = "toolbarcolor";
101+
private static final String CLOSE_BUTTON_CAPTION = "closebuttoncaption";
102+
private static final String CLOSE_BUTTON_COLOR = "closebuttoncolor";
103+
private static final String HIDE_NAVIGATION = "hidenavigationbuttons";
104+
private static final String NAVIGATION_COLOR = "navigationbuttoncolor";
105+
private static final String HIDE_URL = "hideurlbar";
106+
107+
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR);
100108

101109
private InAppBrowserDialog dialog;
102110
private WebView inAppWebView;
@@ -115,8 +123,12 @@ public class InAppBrowser extends CordovaPlugin {
115123
private ValueCallback<Uri[]> mUploadCallbackLollipop;
116124
private final static int FILECHOOSER_REQUESTCODE = 1;
117125
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2;
118-
private String closeButtonText = "";
119-
private int closeButtonColor = android.graphics.Color.LTGRAY;
126+
private String closeButtonCaption = "";
127+
private String closeButtonColor = "";
128+
private int toolbarColor = android.graphics.Color.LTGRAY;
129+
private boolean hideNavigationButtons = false;
130+
private String navigationButtonColor = "";
131+
private boolean hideUrlBar = false;
120132

121133
/**
122134
* Executes the request and returns PluginResult.
@@ -386,10 +398,10 @@ private HashMap<String, String> parseFeature(String optString) {
386398
if (option.hasMoreElements()) {
387399
String key = option.nextToken();
388400
String value = null;
389-
if (key.equals(CLOSE_BUTTON_TEXT)) value = option.nextToken();
401+
if (customizableOptions.contains(key)) value = option.nextToken();
390402
else {
391403
String token = option.nextToken();
392-
value = token.equals("yes") || token.equals("no") ? token : "yes"; // hér!!
404+
value = token.equals("yes") || token.equals("no") ? token : "yes";
393405
}
394406
map.put(key, value);
395407
}
@@ -548,6 +560,12 @@ public String showWebPage(final String url, HashMap<String, String> features) {
548560
if (show != null) {
549561
showLocationBar = show.equals("yes") ? true : false;
550562
}
563+
if(showLocationBar) {
564+
String hideNavigation = features.get(HIDE_NAVIGATION);
565+
String hideUrl = features.get(HIDE_URL);
566+
if(hideNavigation != null) hideNavigationButtons = hideNavigation.equals("yes") ? true : false;
567+
if(hideUrl != null) hideUrlBar = hideUrl.equals("yes") ? true : false;
568+
}
551569
String zoom = features.get(ZOOM);
552570
if (zoom != null) {
553571
showZoomControls = zoom.equals("yes") ? true : false;
@@ -583,13 +601,21 @@ public String showWebPage(final String url, HashMap<String, String> features) {
583601
if (wideViewPort != null ) {
584602
useWideViewPort = wideViewPort.equals("yes") ? true : false;
585603
}
586-
String closeButtonTextSet = features.get(CLOSE_BUTTON_TEXT);
587-
if (closeButtonTextSet != null) {
588-
closeButtonText = closeButtonTextSet;
604+
String closeButtonCaptionSet = features.get(CLOSE_BUTTON_CAPTION);
605+
if (closeButtonCaptionSet != null) {
606+
closeButtonCaption = closeButtonCaptionSet;
607+
}
608+
String closeButtonColorSet = features.get(CLOSE_BUTTON_COLOR);
609+
if (closeButtonColorSet != null) {
610+
closeButtonColor = closeButtonColorSet;
611+
}
612+
String toolbarColorSet = features.get(TOOLBAR_COLOR);
613+
if (toolbarColorSet != null) {
614+
toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
589615
}
590-
String closeButtonTextColorSet = features.get(CLOSE_BUTTON_COLOR);
591-
if (closeButtonTextColorSet != null) {
592-
closeButtonColor = Color.parseColor(closeButtonTextColorSet);
616+
String navigationButtonColorSet = features.get(NAVIGATION_COLOR);
617+
if (navigationButtonColorSet != null) {
618+
navigationButtonColor = navigationButtonColorSet;
593619
}
594620
}
595621

@@ -633,7 +659,7 @@ public void run() {
633659
// Toolbar layout
634660
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
635661
//Please, no more black!
636-
toolbar.setBackgroundColor(closeButtonColor);
662+
toolbar.setBackgroundColor(toolbarColor);
637663
toolbar.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44)));
638664
toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
639665
toolbar.setHorizontalGravity(Gravity.LEFT);
@@ -656,6 +682,7 @@ public void run() {
656682
Resources activityRes = cordova.getActivity().getResources();
657683
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
658684
Drawable backIcon = activityRes.getDrawable(backResId);
685+
if (navigationButtonColor != "") back.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
659686
if (Build.VERSION.SDK_INT >= 16)
660687
back.setBackground(null);
661688
else
@@ -681,6 +708,7 @@ public void onClick(View v) {
681708
forward.setId(Integer.valueOf(3));
682709
int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
683710
Drawable fwdIcon = activityRes.getDrawable(fwdResId);
711+
if (navigationButtonColor != "") forward.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
684712
if (Build.VERSION.SDK_INT >= 16)
685713
forward.setBackground(null);
686714
else
@@ -721,13 +749,25 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
721749
});
722750

723751
// Close/Done button
724-
if (closeButtonText != "") {
725-
/* Use TextView for text */
752+
if (closeButtonCaption != "") {
753+
// Use TextView for text
726754
TextView close = new TextView(cordova.getActivity());
727-
close.setText(closeButtonText);
728-
close.setTextSize(25);
729-
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
755+
close.setText(closeButtonCaption);
756+
close.setTextSize(20);
757+
if (closeButtonColor != "") close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
758+
close.setGravity(android.view.Gravity.CENTER_VERTICAL);
759+
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
760+
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
761+
close.setLayoutParams(closeLayoutParams);
762+
763+
close.setContentDescription("Close Button");
730764
close.setId(Integer.valueOf(5));
765+
if (Build.VERSION.SDK_INT >= 16)
766+
close.setBackground(null);
767+
else
768+
close.setBackgroundDrawable(null);
769+
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
770+
close.setPadding(this.dpToPixels(10), 0, this.dpToPixels(10), 0);
731771
close.setOnClickListener(new View.OnClickListener() {
732772
public void onClick(View v) {
733773
closeDialog();
@@ -744,6 +784,7 @@ public void onClick(View v) {
744784
close.setId(Integer.valueOf(5));
745785
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
746786
Drawable closeIcon = activityRes.getDrawable(closeResId);
787+
if (closeButtonColor != "") close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor));
747788
if (Build.VERSION.SDK_INT >= 16)
748789
close.setBackground(null);
749790
else
@@ -863,10 +904,9 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
863904
actionButtonContainer.addView(back);
864905
actionButtonContainer.addView(forward);
865906

866-
// Add the views to our toolbar
867-
toolbar.addView(actionButtonContainer);
868-
toolbar.addView(edittext);
869-
// toolbar.addView(close);
907+
// Add the views to our toolbar if they haven't been disabled
908+
if (!hideNavigationButtons) toolbar.addView(actionButtonContainer);
909+
if (!hideUrlBar) toolbar.addView(edittext);
870910

871911
// Don't add the toolbar if its been disabled
872912
if (getShowLocationBar()) {

src/ios/CDVInAppBrowser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
@property (nonatomic, copy) NSString* toolbarposition;
5454
@property (nonatomic, copy) NSString* toolbarcolor;
5555
@property (nonatomic, assign) BOOL toolbartranslucent;
56-
@property (nonatomic, assign) BOOL hideToolbarNavigationButtons;
56+
@property (nonatomic, assign) BOOL hidetoolbarnavigationbuttons;
5757
@property (nonatomic, assign) BOOL clearcache;
5858
@property (nonatomic, assign) BOOL clearsessioncache;
5959

src/ios/CDVInAppBrowser.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ - (void)createViews
649649
self.backButton.imageInsets = UIEdgeInsetsZero;
650650

651651
// Filter out Navigation Buttons if user requests so
652-
if (_browserOptions.hideToolbarNavigationButtons) {
652+
if (_browserOptions.hidetoolbarnavigationbuttons) {
653653
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
654654
} else {
655655
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
@@ -1020,7 +1020,7 @@ - (id)init
10201020
self.suppressesincrementalrendering = NO;
10211021
self.hidden = NO;
10221022
self.disallowoverscroll = NO;
1023-
self.hideToolbarNavigationButtons = NO;
1023+
self.hideToolbarnavigationbuttons = NO;
10241024
self.closebuttoncolor = nil;
10251025
self.toolbarcolor = nil;
10261026
self.toolbartranslucent = YES;

0 commit comments

Comments
 (0)