mirror of
https://github.com/shuto-cn/cordova-plugin-inappbrowser.git
synced 2026-01-26 00:00:04 +08:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6211dd65ac | ||
|
|
98ee2e148c | ||
|
|
b73ba93884 | ||
|
|
c80c338e51 | ||
|
|
8e3f2f2c53 | ||
|
|
8f66f075dd | ||
|
|
1876869a05 | ||
|
|
260542d13c | ||
|
|
b9e0a80837 | ||
|
|
7c1ea3b5c2 | ||
|
|
3a2c4ef5c0 | ||
|
|
5f072a752d | ||
|
|
e428556e25 | ||
|
|
84a4644cd1 | ||
|
|
d46f5d45d5 | ||
|
|
ff230d429a | ||
|
|
ec2f12c872 | ||
|
|
6c2a8f4576 | ||
|
|
55b02285f9 | ||
|
|
4af420c592 | ||
|
|
e691212c96 | ||
|
|
8711ee3f21 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,4 +21,3 @@ node_modules
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ matrix:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-5.1
|
||||
os: linux
|
||||
language: android
|
||||
@@ -52,6 +53,7 @@ matrix:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-6.0
|
||||
os: linux
|
||||
language: android
|
||||
@@ -61,6 +63,7 @@ matrix:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
- env: PLATFORM=android-7.0
|
||||
os: linux
|
||||
language: android
|
||||
@@ -70,6 +73,7 @@ matrix:
|
||||
- tools
|
||||
- platform-tools
|
||||
- tools
|
||||
- build-tools-26.0.2
|
||||
before_install:
|
||||
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm
|
||||
&& git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm
|
||||
|
||||
19
README.md
19
README.md
@@ -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.
|
||||
@@ -112,7 +112,18 @@ 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 button's 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`.
|
||||
- __footer__: set to `yes` to show a close button in the footer similar to the iOS __Done__ button.
|
||||
The close button will appear the same as for the header hence use __closebuttoncaption__ and __closebuttoncolor__ to set its properties.
|
||||
- __footercolor__: set to a valid hex color string, for example `#00ff00` or `#CC00ff00` (`#aarrggbb`) , and it will change the footer color from default.
|
||||
Only has effect if user has __footer__ 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`.
|
||||
- __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`.
|
||||
- __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)).
|
||||
@@ -123,9 +134,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.
|
||||
- __hidenavigationbuttons__: 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`)
|
||||
|
||||
@@ -20,6 +20,21 @@
|
||||
-->
|
||||
# Release Notes
|
||||
|
||||
### 2.0.2 (Jan 24, 2018)
|
||||
* [CB-13791](https://issues.apache.org/jira/browse/CB-13791) Add **Android** support for a footer close button
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) restore gitignore to default
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) ignore idea folder
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) change hidetoolbarnavigationbuttons to hidenavigationbuttons in iso
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) **Android** works well now, all changes are now documented
|
||||
* [CB-13409](https://issues.apache.org/jira/browse/CB-13409) Lets user adjust color of toolbar, hide navigation buttons and set custom text on close button
|
||||
* [CB-13746](https://issues.apache.org/jira/browse/CB-13746) Add build-tools-26.0.2 to travis
|
||||
|
||||
### 2.0.1 (Dec 27, 2017)
|
||||
* [CB-13699](https://issues.apache.org/jira/browse/CB-13699) Fix to allow 2.0.0 version install
|
||||
|
||||
### 2.0.0 (Dec 15, 2017)
|
||||
* [CB-13662](https://issues.apache.org/jira/browse/CB-13662) remove deprecated platforms
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-inappbrowser",
|
||||
"version": "2.0.0",
|
||||
"version": "2.0.2",
|
||||
"description": "Cordova InAppBrowser Plugin",
|
||||
"types": "./types/index.d.ts",
|
||||
"cordova": {
|
||||
@@ -42,7 +42,7 @@
|
||||
"0.2.3": {
|
||||
"cordova": ">=3.1.0"
|
||||
},
|
||||
"2.0.0": {
|
||||
"3.0.0": {
|
||||
"cordova": ">100"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser"
|
||||
version="2.0.0">
|
||||
version="2.0.2">
|
||||
|
||||
<name>InAppBrowser</name>
|
||||
<description>Cordova InAppBrowser Plugin</description>
|
||||
|
||||
@@ -25,6 +25,9 @@ import android.provider.Browser;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -51,6 +54,7 @@ import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.apache.cordova.Config;
|
||||
@@ -67,6 +71,8 @@ import org.json.JSONObject;
|
||||
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;
|
||||
|
||||
@@ -91,6 +97,16 @@ 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 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 String FOOTER = "footer";
|
||||
private static final String FOOTER_COLOR = "footercolor";
|
||||
|
||||
private static final List customizableOptions = Arrays.asList(CLOSE_BUTTON_CAPTION, TOOLBAR_COLOR, NAVIGATION_COLOR, CLOSE_BUTTON_COLOR, FOOTER_COLOR);
|
||||
|
||||
private InAppBrowserDialog dialog;
|
||||
private WebView inAppWebView;
|
||||
@@ -109,6 +125,14 @@ 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 closeButtonCaption = "";
|
||||
private String closeButtonColor = "";
|
||||
private int toolbarColor = android.graphics.Color.LTGRAY;
|
||||
private boolean hideNavigationButtons = false;
|
||||
private String navigationButtonColor = "";
|
||||
private boolean hideUrlBar = false;
|
||||
private boolean showFooter = false;
|
||||
private String footerColor = "";
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
@@ -127,7 +151,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
t = SELF;
|
||||
}
|
||||
final String target = t;
|
||||
final HashMap<String, Boolean> features = parseFeature(args.optString(2));
|
||||
final HashMap<String, String> features = parseFeature(args.optString(2));
|
||||
|
||||
LOG.d(LOG_TAG, "target = " + target);
|
||||
|
||||
@@ -366,18 +390,21 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
* @param optString
|
||||
* @return
|
||||
*/
|
||||
private HashMap<String, Boolean> parseFeature(String optString) {
|
||||
private HashMap<String, String> parseFeature(String optString) {
|
||||
if (optString.equals(NULL)) {
|
||||
return null;
|
||||
} else {
|
||||
HashMap<String, Boolean> map = new HashMap<String, Boolean>();
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
StringTokenizer features = new StringTokenizer(optString, ",");
|
||||
StringTokenizer option;
|
||||
while(features.hasMoreElements()) {
|
||||
option = new StringTokenizer(features.nextToken(), "=");
|
||||
if (option.hasMoreElements()) {
|
||||
String key = option.nextToken();
|
||||
Boolean value = option.nextToken().equals("no") ? Boolean.FALSE : Boolean.TRUE;
|
||||
String value = option.nextToken();
|
||||
if (!customizableOptions.contains(key)){
|
||||
value = value.equals("yes") || value.equals("no") ? value : "yes";
|
||||
}
|
||||
map.put(key, value);
|
||||
}
|
||||
}
|
||||
@@ -406,7 +433,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
|
||||
this.cordova.getActivity().startActivity(intent);
|
||||
return "";
|
||||
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
|
||||
// not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
|
||||
} catch (java.lang.RuntimeException e) {
|
||||
LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
|
||||
return e.toString();
|
||||
@@ -523,7 +550,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
* @param url the url to load.
|
||||
* @param features jsonObject
|
||||
*/
|
||||
public String showWebPage(final String url, HashMap<String, Boolean> features) {
|
||||
public String showWebPage(final String url, HashMap<String, String> features) {
|
||||
// Determine if we should hide the location bar.
|
||||
showLocationBar = true;
|
||||
showZoomControls = true;
|
||||
@@ -531,44 +558,74 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
mediaPlaybackRequiresUserGesture = false;
|
||||
|
||||
if (features != null) {
|
||||
Boolean show = features.get(LOCATION);
|
||||
String show = features.get(LOCATION);
|
||||
if (show != null) {
|
||||
showLocationBar = show.booleanValue();
|
||||
showLocationBar = show.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean zoom = features.get(ZOOM);
|
||||
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.booleanValue();
|
||||
showZoomControls = zoom.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean hidden = features.get(HIDDEN);
|
||||
String hidden = features.get(HIDDEN);
|
||||
if (hidden != null) {
|
||||
openWindowHidden = hidden.booleanValue();
|
||||
openWindowHidden = hidden.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean hardwareBack = features.get(HARDWARE_BACK_BUTTON);
|
||||
String hardwareBack = features.get(HARDWARE_BACK_BUTTON);
|
||||
if (hardwareBack != null) {
|
||||
hadwareBackButton = hardwareBack.booleanValue();
|
||||
hadwareBackButton = hardwareBack.equals("yes") ? true : false;
|
||||
} else {
|
||||
hadwareBackButton = DEFAULT_HARDWARE_BACK;
|
||||
}
|
||||
Boolean mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
|
||||
String mediaPlayback = features.get(MEDIA_PLAYBACK_REQUIRES_USER_ACTION);
|
||||
if (mediaPlayback != null) {
|
||||
mediaPlaybackRequiresUserGesture = mediaPlayback.booleanValue();
|
||||
mediaPlaybackRequiresUserGesture = mediaPlayback.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean cache = features.get(CLEAR_ALL_CACHE);
|
||||
String cache = features.get(CLEAR_ALL_CACHE);
|
||||
if (cache != null) {
|
||||
clearAllCache = cache.booleanValue();
|
||||
clearAllCache = cache.equals("yes") ? true : false;
|
||||
} else {
|
||||
cache = features.get(CLEAR_SESSION_CACHE);
|
||||
if (cache != null) {
|
||||
clearSessionCache = cache.booleanValue();
|
||||
clearSessionCache = cache.equals("yes") ? true : false;
|
||||
}
|
||||
}
|
||||
Boolean shouldPause = features.get(SHOULD_PAUSE);
|
||||
String shouldPause = features.get(SHOULD_PAUSE);
|
||||
if (shouldPause != null) {
|
||||
shouldPauseInAppBrowser = shouldPause.booleanValue();
|
||||
shouldPauseInAppBrowser = shouldPause.equals("yes") ? true : false;
|
||||
}
|
||||
Boolean wideViewPort = features.get(USER_WIDE_VIEW_PORT);
|
||||
String wideViewPort = features.get(USER_WIDE_VIEW_PORT);
|
||||
if (wideViewPort != null ) {
|
||||
useWideViewPort = wideViewPort.booleanValue();
|
||||
useWideViewPort = wideViewPort.equals("yes") ? true : false;
|
||||
}
|
||||
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 navigationButtonColorSet = features.get(NAVIGATION_COLOR);
|
||||
if (navigationButtonColorSet != null) {
|
||||
navigationButtonColor = navigationButtonColorSet;
|
||||
}
|
||||
String showFooterSet = features.get(FOOTER);
|
||||
if (showFooterSet != null) {
|
||||
showFooter = showFooterSet.equals("yes") ? true : false;
|
||||
}
|
||||
String footerColorSet = features.get(FOOTER_COLOR);
|
||||
if (footerColorSet != null) {
|
||||
footerColor = footerColorSet;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -583,13 +640,60 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
*/
|
||||
private int dpToPixels(int dipValue) {
|
||||
int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
|
||||
(float) dipValue,
|
||||
cordova.getActivity().getResources().getDisplayMetrics()
|
||||
(float) dipValue,
|
||||
cordova.getActivity().getResources().getDisplayMetrics()
|
||||
);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private View createCloseButton(int id){
|
||||
View _close;
|
||||
Resources activityRes = cordova.getActivity().getResources();
|
||||
|
||||
if (closeButtonCaption != "") {
|
||||
// Use TextView for text
|
||||
TextView close = new TextView(cordova.getActivity());
|
||||
close.setText(closeButtonCaption);
|
||||
close.setTextSize(20);
|
||||
if (closeButtonColor != "") close.setTextColor(android.graphics.Color.parseColor(closeButtonColor));
|
||||
close.setGravity(android.view.Gravity.CENTER_VERTICAL);
|
||||
close.setPadding(this.dpToPixels(10), 0, this.dpToPixels(10), 0);
|
||||
_close = close;
|
||||
}
|
||||
else {
|
||||
ImageButton close = new ImageButton(cordova.getActivity());
|
||||
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));
|
||||
close.setImageDrawable(closeIcon);
|
||||
close.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
close.getAdjustViewBounds();
|
||||
|
||||
_close = close;
|
||||
}
|
||||
|
||||
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
|
||||
closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
_close.setLayoutParams(closeLayoutParams);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
_close.setBackground(null);
|
||||
else
|
||||
_close.setBackgroundDrawable(null);
|
||||
|
||||
_close.setContentDescription("Close Button");
|
||||
_close.setId(Integer.valueOf(id));
|
||||
_close.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
|
||||
return _close;
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public void run() {
|
||||
|
||||
@@ -612,7 +716,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
// Toolbar layout
|
||||
RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
|
||||
//Please, no more black!
|
||||
toolbar.setBackgroundColor(android.graphics.Color.LTGRAY);
|
||||
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);
|
||||
@@ -635,6 +739,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
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
|
||||
@@ -660,6 +765,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
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
|
||||
@@ -692,37 +798,37 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||
// If the event is a key-down event on the "enter" button
|
||||
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
|
||||
navigate(edittext.getText().toString());
|
||||
return true;
|
||||
navigate(edittext.getText().toString());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Close/Done button
|
||||
ImageButton close = new ImageButton(cordova.getActivity());
|
||||
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));
|
||||
int closeResId = activityRes.getIdentifier("ic_action_remove", "drawable", cordova.getActivity().getPackageName());
|
||||
Drawable closeIcon = activityRes.getDrawable(closeResId);
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
close.setBackground(null);
|
||||
else
|
||||
close.setBackgroundDrawable(null);
|
||||
close.setImageDrawable(closeIcon);
|
||||
close.setScaleType(ImageView.ScaleType.FIT_CENTER);
|
||||
back.setPadding(0, this.dpToPixels(10), 0, this.dpToPixels(10));
|
||||
if (Build.VERSION.SDK_INT >= 16)
|
||||
close.getAdjustViewBounds();
|
||||
|
||||
close.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
closeDialog();
|
||||
}
|
||||
});
|
||||
// Header Close/Done button
|
||||
View close = createCloseButton(5);
|
||||
toolbar.addView(close);
|
||||
|
||||
// Footer
|
||||
RelativeLayout footer = new RelativeLayout(cordova.getActivity());
|
||||
int _footerColor;
|
||||
if(footerColor != ""){
|
||||
_footerColor = Color.parseColor(footerColor);
|
||||
}else{
|
||||
_footerColor = android.graphics.Color.LTGRAY;
|
||||
}
|
||||
footer.setBackgroundColor(_footerColor);
|
||||
RelativeLayout.LayoutParams footerLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, this.dpToPixels(44));
|
||||
footerLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
|
||||
footer.setLayoutParams(footerLayout);
|
||||
if (closeButtonCaption != "") footer.setPadding(this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8), this.dpToPixels(8));
|
||||
footer.setHorizontalGravity(Gravity.LEFT);
|
||||
footer.setVerticalGravity(Gravity.BOTTOM);
|
||||
|
||||
View footerClose = createCloseButton(7);
|
||||
footer.addView(footerClose);
|
||||
|
||||
|
||||
// WebView
|
||||
inAppWebView = new WebView(cordova.getActivity());
|
||||
@@ -825,10 +931,9 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
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()) {
|
||||
@@ -837,7 +942,14 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
}
|
||||
|
||||
// Add our webview to our main view/layout
|
||||
main.addView(inAppWebView);
|
||||
RelativeLayout webViewLayout = new RelativeLayout(cordova.getActivity());
|
||||
webViewLayout.addView(inAppWebView);
|
||||
main.addView(webViewLayout);
|
||||
|
||||
// Don't add the footer unless it's been enabled
|
||||
if (showFooter) {
|
||||
webViewLayout.addView(footer);
|
||||
}
|
||||
|
||||
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
|
||||
lp.copyFrom(dialog.getWindow().getAttributes());
|
||||
@@ -1027,7 +1139,7 @@ public class InAppBrowser extends CordovaPlugin {
|
||||
// Update the UI if we haven't already
|
||||
if (!newloc.equals(edittext.getText().toString())) {
|
||||
edittext.setText(newloc);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
@@ -49,7 +49,11 @@
|
||||
@property (nonatomic, assign) BOOL location;
|
||||
@property (nonatomic, assign) BOOL toolbar;
|
||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||
@property (nonatomic, copy) NSString* toolbarposition;
|
||||
@property (nonatomic, copy) NSString* toolbarcolor;
|
||||
@property (nonatomic, assign) BOOL toolbartranslucent;
|
||||
@property (nonatomic, assign) BOOL hidenavigationbuttons;
|
||||
@property (nonatomic, assign) BOOL clearcache;
|
||||
@property (nonatomic, assign) BOOL clearsessioncache;
|
||||
|
||||
@@ -74,13 +78,13 @@
|
||||
NSString* _prevUserAgent;
|
||||
NSInteger _userAgentLockToken;
|
||||
CDVInAppBrowserOptions *_browserOptions;
|
||||
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
CDVUIWebViewDelegate* _webViewDelegate;
|
||||
#else
|
||||
CDVWebViewDelegate* _webViewDelegate;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) IBOutlet UIWebView* webView;
|
||||
@@ -99,7 +103,7 @@
|
||||
- (void)navigateTo:(NSURL*)url;
|
||||
- (void)showLocationBar:(BOOL)show;
|
||||
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
|
||||
- (void)setCloseButtonTitle:(NSString*)title;
|
||||
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
|
||||
@@ -110,4 +114,3 @@
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -162,8 +162,8 @@
|
||||
|
||||
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
|
||||
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
|
||||
if (browserOptions.closebuttoncaption != nil) {
|
||||
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption];
|
||||
if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) {
|
||||
[self.inAppBrowserViewController setCloseButtonTitle:browserOptions.closebuttoncaption :browserOptions.closebuttoncolor];
|
||||
}
|
||||
// Set Presentation Style
|
||||
UIModalPresentationStyle presentationStyle = UIModalPresentationFullScreen; // default
|
||||
@@ -599,6 +599,12 @@
|
||||
self.toolbar.multipleTouchEnabled = NO;
|
||||
self.toolbar.opaque = NO;
|
||||
self.toolbar.userInteractionEnabled = YES;
|
||||
if (_browserOptions.toolbarcolor != nil) { // Set toolbar color if user sets it in options
|
||||
self.toolbar.barTintColor = [self colorFromHexString:_browserOptions.toolbarcolor];
|
||||
}
|
||||
if (!_browserOptions.toolbartranslucent) { // Set toolbar translucent to no if user sets it in options
|
||||
self.toolbar.translucent = NO;
|
||||
}
|
||||
|
||||
CGFloat labelInset = 5.0;
|
||||
float locationBarY = toolbarIsAtBottom ? self.view.bounds.size.height - FOOTER_HEIGHT : self.view.bounds.size.height - LOCATIONBAR_HEIGHT;
|
||||
@@ -642,7 +648,13 @@
|
||||
self.backButton.enabled = YES;
|
||||
self.backButton.imageInsets = UIEdgeInsetsZero;
|
||||
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
|
||||
// Filter out Navigation Buttons if user requests so
|
||||
if (_browserOptions.hidenavigationbuttons) {
|
||||
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton]];
|
||||
} 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];
|
||||
@@ -655,14 +667,16 @@
|
||||
[self.webView setFrame:frame];
|
||||
}
|
||||
|
||||
- (void)setCloseButtonTitle:(NSString*)title
|
||||
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString
|
||||
{
|
||||
// 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)
|
||||
self.closeButton = nil;
|
||||
self.closeButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)];
|
||||
// Initialize with title if title is set, otherwise the title will be 'Done' localized
|
||||
self.closeButton = title != nil ? [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStyleBordered target:self action:@selector(close)] : [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
|
||||
self.closeButton.enabled = YES;
|
||||
self.closeButton.tintColor = [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1];
|
||||
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default
|
||||
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];
|
||||
@@ -877,6 +891,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to convert hex color string to UIColor
|
||||
// Assumes input like "#00FF00" (#RRGGBB).
|
||||
// Taken from https://stackoverflow.com/questions/1560081/how-can-i-create-a-uicolor-from-a-hex-string
|
||||
- (UIColor *)colorFromHexString:(NSString *)hexString {
|
||||
unsigned rgbValue = 0;
|
||||
NSScanner *scanner = [NSScanner scannerWithString:hexString];
|
||||
[scanner setScanLocation:1]; // bypass '#' character
|
||||
[scanner scanHexInt:&rgbValue];
|
||||
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
|
||||
}
|
||||
|
||||
#pragma mark UIWebViewDelegate
|
||||
|
||||
- (void)webViewDidStartLoad:(UIWebView*)theWebView
|
||||
@@ -995,6 +1020,10 @@
|
||||
self.suppressesincrementalrendering = NO;
|
||||
self.hidden = NO;
|
||||
self.disallowoverscroll = NO;
|
||||
self.hidenavigationbuttons = NO;
|
||||
self.closebuttoncolor = nil;
|
||||
self.toolbarcolor = nil;
|
||||
self.toolbartranslucent = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -1104,4 +1133,3 @@
|
||||
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser-tests"
|
||||
version="2.0.0">
|
||||
version="2.0.2">
|
||||
<name>Cordova InAppBrowser Plugin Tests</name>
|
||||
<license>Apache 2.0</license>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user