Skip to content

Commit

Permalink
Android works well now, all changes are now documented
Browse files Browse the repository at this point in the history
  • Loading branch information
steinaragustli committed Oct 6, 2017
1 parent f3d7f72 commit d940b59
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 27 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ instance, or the system browser.

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

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.
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.

All platforms support:

- __location__: Set to `yes` or `no` to turn the `InAppBrowser`'s location bar on or off.
Expand All @@ -112,7 +112,13 @@ instance, or the system browser.
- __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.
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
- __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.
- __closebuttoncolor__: set to a valid hex color string, for example: `#00ff00`, and it will change the
close button color from default, regardless of being a text or default X. Only has effect if user has location set to `yes`.
- __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.
- __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`.
- __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`.
- __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`).
- __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)).
Expand All @@ -123,9 +129,13 @@ instance, or the system browser.
- __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.
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
- __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.
- __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself.
- __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property.
- __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.
- __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.
- __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`).
- __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`)
Expand Down
84 changes: 62 additions & 22 deletions src/android/InAppBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.HashMap;
import java.util.StringTokenizer;

Expand All @@ -95,8 +97,14 @@ public class InAppBrowser extends CordovaPlugin {
private static final String SHOULD_PAUSE = "shouldPauseOnSuspend";
private static final Boolean DEFAULT_HARDWARE_BACK = true;
private static final String USER_WIDE_VIEW_PORT = "useWideViewPort";
private static final String CLOSE_BUTTON_TEXT = "closeButtonText";
private static final String CLOSE_BUTTON_COLOR = "closeButtonColor";
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 HIDE_NAVIGATION = "hidenavigationbuttons";
private static final String NAVIGATION_COLOR = "navigationbuttoncolor";
private static final String HIDE_URL = "hideurlbar";

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

private InAppBrowserDialog dialog;
private WebView inAppWebView;
Expand All @@ -115,8 +123,12 @@ public class InAppBrowser extends CordovaPlugin {
private ValueCallback<Uri[]> mUploadCallbackLollipop;
private final static int FILECHOOSER_REQUESTCODE = 1;
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2;
private String closeButtonText = "";
private int closeButtonColor = android.graphics.Color.LTGRAY;
private String closeButtonCaption = "";
private String closeButtonColor = "";
private int toolbarColor = android.graphics.Color.LTGRAY;
private boolean hideNavigationButtons = false;
private String navigationButtonColor = "";
private boolean hideUrlBar = false;

/**
* Executes the request and returns PluginResult.
Expand Down Expand Up @@ -386,10 +398,10 @@ private HashMap<String, String> parseFeature(String optString) {
if (option.hasMoreElements()) {
String key = option.nextToken();
String value = null;
if (key.equals(CLOSE_BUTTON_TEXT)) value = option.nextToken();
if (customizableOptions.contains(key)) value = option.nextToken();
else {
String token = option.nextToken();
value = token.equals("yes") || token.equals("no") ? token : "yes"; // hér!!
value = token.equals("yes") || token.equals("no") ? token : "yes";
}
map.put(key, value);
}
Expand Down Expand Up @@ -548,6 +560,12 @@ public String showWebPage(final String url, HashMap<String, String> features) {
if (show != null) {
showLocationBar = show.equals("yes") ? true : false;
}
if(showLocationBar) {
String hideNavigation = features.get(HIDE_NAVIGATION);
String hideUrl = features.get(HIDE_URL);
if(hideNavigation != null) hideNavigationButtons = hideNavigation.equals("yes") ? true : false;
if(hideUrl != null) hideUrlBar = hideUrl.equals("yes") ? true : false;
}
String zoom = features.get(ZOOM);
if (zoom != null) {
showZoomControls = zoom.equals("yes") ? true : false;
Expand Down Expand Up @@ -583,13 +601,21 @@ public String showWebPage(final String url, HashMap<String, String> features) {
if (wideViewPort != null ) {
useWideViewPort = wideViewPort.equals("yes") ? true : false;
}
String closeButtonTextSet = features.get(CLOSE_BUTTON_TEXT);
if (closeButtonTextSet != null) {
closeButtonText = closeButtonTextSet;
String closeButtonCaptionSet = features.get(CLOSE_BUTTON_CAPTION);
if (closeButtonCaptionSet != null) {
closeButtonCaption = closeButtonCaptionSet;
}
String closeButtonColorSet = features.get(CLOSE_BUTTON_COLOR);
if (closeButtonColorSet != null) {
closeButtonColor = closeButtonColorSet;
}
String toolbarColorSet = features.get(TOOLBAR_COLOR);
if (toolbarColorSet != null) {
toolbarColor = android.graphics.Color.parseColor(toolbarColorSet);
}
String closeButtonTextColorSet = features.get(CLOSE_BUTTON_COLOR);
if (closeButtonTextColorSet != null) {
closeButtonColor = Color.parseColor(closeButtonTextColorSet);
String navigationButtonColorSet = features.get(NAVIGATION_COLOR);
if (navigationButtonColorSet != null) {
navigationButtonColor = navigationButtonColorSet;
}
}

Expand Down Expand Up @@ -633,7 +659,7 @@ public void run() {
// Toolbar layout
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
//Please, no more black!
toolbar.setBackgroundColor(closeButtonColor);
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));
toolbar.setHorizontalGravity(Gravity.LEFT);
Expand All @@ -656,6 +682,7 @@ public void run() {
Resources activityRes = cordova.getActivity().getResources();
int backResId = activityRes.getIdentifier("ic_action_previous_item", "drawable", cordova.getActivity().getPackageName());
Drawable backIcon = activityRes.getDrawable(backResId);
if (navigationButtonColor != "") back.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
if (Build.VERSION.SDK_INT >= 16)
back.setBackground(null);
else
Expand All @@ -681,6 +708,7 @@ public void onClick(View v) {
forward.setId(Integer.valueOf(3));
int fwdResId = activityRes.getIdentifier("ic_action_next_item", "drawable", cordova.getActivity().getPackageName());
Drawable fwdIcon = activityRes.getDrawable(fwdResId);
if (navigationButtonColor != "") forward.setColorFilter(android.graphics.Color.parseColor(navigationButtonColor));
if (Build.VERSION.SDK_INT >= 16)
forward.setBackground(null);
else
Expand Down Expand Up @@ -721,13 +749,25 @@ public boolean onKey(View v, int keyCode, KeyEvent event) {
});

// Close/Done button
if (closeButtonText != "") {
/* Use TextView for text */
if (closeButtonCaption != "") {
// Use TextView for text
TextView close = new TextView(cordova.getActivity());
close.setText(closeButtonText);
close.setTextSize(25);
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
close.setText(closeButtonCaption);
close.setTextSize(20);
if (closeButtonColor != "") close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
close.setGravity(android.view.Gravity.CENTER_VERTICAL);
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
close.setLayoutParams(closeLayoutParams);

close.setContentDescription("Close Button");
close.setId(Integer.valueOf(5));
if (Build.VERSION.SDK_INT >= 16)
close.setBackground(null);
else
close.setBackgroundDrawable(null);
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
close.setPadding(this.dpToPixels(10), 0, this.dpToPixels(10), 0);
close.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
closeDialog();
Expand All @@ -744,6 +784,7 @@ public void onClick(View v) {
close.setId(Integer.valueOf(5));
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
Drawable closeIcon = activityRes.getDrawable(closeResId);
if (closeButtonColor != "") close.setColorFilter(android.graphics.Color.parseColor(closeButtonColor));
if (Build.VERSION.SDK_INT >= 16)
close.setBackground(null);
else
Expand Down Expand Up @@ -863,10 +904,9 @@ public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType)
actionButtonContainer.addView(back);
actionButtonContainer.addView(forward);

// Add the views to our toolbar
toolbar.addView(actionButtonContainer);
toolbar.addView(edittext);
// toolbar.addView(close);
// Add the views to our toolbar if they haven't been disabled
if (!hideNavigationButtons) toolbar.addView(actionButtonContainer);
if (!hideUrlBar) toolbar.addView(edittext);

// Don't add the toolbar if its been disabled
if (getShowLocationBar()) {
Expand Down
2 changes: 1 addition & 1 deletion src/ios/CDVInAppBrowser.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
@property (nonatomic, copy) NSString* toolbarposition;
@property (nonatomic, copy) NSString* toolbarcolor;
@property (nonatomic, assign) BOOL toolbartranslucent;
@property (nonatomic, assign) BOOL hideToolbarNavigationButtons;
@property (nonatomic, assign) BOOL hidetoolbarnavigationbuttons;
@property (nonatomic, assign) BOOL clearcache;
@property (nonatomic, assign) BOOL clearsessioncache;

Expand Down
4 changes: 2 additions & 2 deletions src/ios/CDVInAppBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ - (void)createViews
self.backButton.imageInsets = UIEdgeInsetsZero;

// Filter out Navigation Buttons if user requests so
if (_browserOptions.hideToolbarNavigationButtons) {
if (_browserOptions.hidetoolbarnavigationbuttons) {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
} else {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
Expand Down Expand Up @@ -1020,7 +1020,7 @@ - (id)init
self.suppressesincrementalrendering = NO;
self.hidden = NO;
self.disallowoverscroll = NO;
self.hideToolbarNavigationButtons = NO;
self.hideToolbarnavigationbuttons = NO;
self.closebuttoncolor = nil;
self.toolbarcolor = nil;
self.toolbartranslucent = YES;
Expand Down

0 comments on commit d940b59

Please sign in to comment.