diff --git a/README.md b/README.md index 66e99d373..e08c483a7 100644 --- a/README.md +++ b/README.md @@ -38,13 +38,15 @@ This plugin launches an in-app web view on top the existing [CordovaWebView](htt }, title: { color: '#003264ff', - showPageTitle: true + showPageTitle: true, + size: 17 }, backButton: { image: 'back', imagePressed: 'back_pressed', align: 'left', - event: 'backPressed' + event: 'backPressed', + showFirstTime: false }, forwardButton: { image: 'forward', @@ -122,11 +124,13 @@ In addition to InAppBrowser's properties, following properties were added to ful + `color` sets title text color in RGBA web hex format. eg. `#fff0f0ff`. Default to black. + `staticText` sets static text for title. This property overrides `showPageTitle` (see below). + `showPageTitle` when set to true, title of the current web page will be shown. + + `size` set font-size for title. + `backButton` + `image` sets image for back button. This property references to a **native** image resource, therefore it is platform dependent. + `imagePressed` sets image for back button in its pressed state. This property references to a **native** image resource, therefore it is platform dependent. + `align` aligns back button to either `left` or `right`. Default to `left`. + `event` raises an custom event with given text as event name when back button is pressed. Optional. + + 'showFirstTime' to show/hide back button at first time. (default = true). + `forwardButton` + `image` sets image for forward button. This property references to a **native** image resource, therefore it is platform dependent. + `imagePressed` sets image for forward button in its pressed state. This property references to a **native** image resource, therefore it is platform dependent. diff --git a/src/android/ThemeableBrowser.java b/src/android/ThemeableBrowser.java index 673e0d828..2b4bfe857 100644 --- a/src/android/ThemeableBrowser.java +++ b/src/android/ThemeableBrowser.java @@ -96,6 +96,8 @@ public class ThemeableBrowser extends CordovaPlugin { private static final int TOOLBAR_DEF_HEIGHT = 44; private static final int DISABLED_ALPHA = 127; // 50% AKA 127/255. + private static final int VISIBLE = 0; + private static final int INVISIBLE = 4; private static final String EVT_ERR = "ThemeableBrowserError"; private static final String EVT_WRN = "ThemeableBrowserWarning"; @@ -108,7 +110,7 @@ public class ThemeableBrowser extends CordovaPlugin { private WebView inAppWebView; private EditText edittext; private CallbackContext callbackContext; - + /** * Executes the request and returns PluginResult. * @@ -483,7 +485,7 @@ public void goBack() { * @return boolean */ public boolean canGoBack() { - return this.inAppWebView != null && this.inAppWebView.canGoBack(); + return this.inAppWebView != null && this.inAppWebView.canGoBack(); } /** @@ -637,6 +639,9 @@ public void onClick(View v) { if (back != null) { back.setEnabled(features.backButtonCanClose); + if(features.backButton != null && !features.backButton.showFirstTime) { + back.setVisibility(INVISIBLE); + } } // Forward button @@ -656,6 +661,9 @@ public void onClick(View v) { if (back != null) { back.setEnabled(false); + if(features.backButton != null && !features.backButton.showFirstTime) { + back.setVisibility(INVISIBLE); + } } @@ -746,6 +754,9 @@ public void onNothingSelected( if (features.title.staticText != null) { title.setText(features.title.staticText); } + if (features.title.size != 0) { + title.setTextSize(features.title.size); + } } // WebView @@ -770,6 +781,15 @@ public void onPageFinished(String url, boolean canGoBack, boolean canGoForward) if (back != null) { back.setEnabled(canGoBack || features.backButtonCanClose); + + if(features.backButton != null && !features.backButton.showFirstTime) { + if(canGoBack) { + back.setVisibility(VISIBLE); + }else { + back.setVisibility(INVISIBLE); + } + } + } if (forward != null) { @@ -861,7 +881,7 @@ public void onClick(View view) { } if (back != null && features.backButton != null - && !ALIGN_RIGHT.equals(features.backButton.align)) { + && !ALIGN_RIGHT.equals(features.backButton.align)) { leftButtonContainer.addView(back, 0); leftContainerWidth += back.getLayoutParams().width; @@ -1403,7 +1423,7 @@ private static class Options { public BrowserButton[] customButtons; public boolean backButtonCanClose; public boolean disableAnimation; - public boolean fullscreen; + public boolean fullscreen; } private static class Event { @@ -1425,6 +1445,7 @@ private static class BrowserButton extends Event { public String wwwImagePressed; public double wwwImageDensity = 1; public String align = ALIGN_LEFT; + public boolean showFirstTime = true; } private static class BrowserMenu extends BrowserButton { @@ -1443,5 +1464,6 @@ private static class Title { public String color; public String staticText; public boolean showPageTitle; + public float size = 0; } } diff --git a/src/ios/CDVThemeableBrowser.m b/src/ios/CDVThemeableBrowser.m index ce09b20ce..b35a017d8 100644 --- a/src/ios/CDVThemeableBrowser.m +++ b/src/ios/CDVThemeableBrowser.m @@ -42,6 +42,8 @@ Licensed to the Apache Software Foundation (ASF) under one #define kThemeableBrowserPropWwwImageDensity @"wwwImageDensity" #define kThemeableBrowserPropStaticText @"staticText" #define kThemeableBrowserPropShowPageTitle @"showPageTitle" +#define kThemeableBrowserPropSize @"size" +#define kThemeableBrowserPropShowFirstTime @"showFirstTime" #define kThemeableBrowserPropAlign @"align" #define kThemeableBrowserPropTitle @"title" #define kThemeableBrowserPropCancel @"cancel" @@ -805,6 +807,11 @@ - (void)createViews leftWidth += width; } } + + BOOL showFirstTime = [self getBoolFromDict:_browserOptions.backButton withKey:kThemeableBrowserPropShowFirstTime]; + if (showFirstTime == false) { + self.backButton.hidden = YES; + } // Back and forward buttons must be added with special ordering logic such // that back button is always on the left of forward button if both buttons @@ -882,6 +889,11 @@ - (void)createViews if (_browserOptions.title[kThemeableBrowserPropStaticText]) { self.titleLabel.text = _browserOptions.title[kThemeableBrowserPropStaticText]; } + + if (_browserOptions.title[kThemeableBrowserPropSize]) { + CGFloat textSize = [self getFloatFromDict:_browserOptions.title withKey:kThemeableBrowserPropSize withDefault:13.0]; + self.titleLabel.font = [UIFont boldSystemFontOfSize:textSize]; + } [self.toolbar addSubview:self.titleLabel]; } @@ -1486,6 +1498,16 @@ - (void)updateButton:(UIWebView*)theWebView { if (self.backButton) { self.backButton.enabled = _browserOptions.backButtonCanClose || theWebView.canGoBack; + + BOOL showFirstTime = [self getBoolFromDict:_browserOptions.backButton withKey:kThemeableBrowserPropShowFirstTime]; + if (showFirstTime == false) { + if(theWebView.canGoBack) { + self.backButton.hidden = NO; + }else { + self.backButton.hidden = YES; + } + } + } if (self.forwardButton) {