From dc6c5371252008a8a0312c0dab98b1f87589f78c Mon Sep 17 00:00:00 2001 From: EddyVerbruggen Date: Thu, 28 Apr 2016 19:52:33 +0200 Subject: [PATCH] #86 Is there anyway to get a significantly larger font on IOS and Android? --- LICENSE | 19 ++++++++++++++++ README.md | 25 ++------------------- package.json | 2 +- plugin.xml | 2 +- src/android/nl/xservices/plugins/Toast.java | 4 ++++ src/ios/Toast+UIView.m | 10 ++++++--- www/Toast.js | 4 ++-- 7 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..28ba826 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +[The MIT License (MIT)](http://www.opensource.org/licenses/mit-license.html) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md index c7fbe36..c7702a6 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ If you like this plugin and want to say thanks please send a PR or donation. Bot 4. [Styling](#styling) 5. [Credits](#5-credits) 6. [Changelog](#6-changelog) -7. [License](#7-license) ## 1. Description @@ -230,6 +229,7 @@ Note that on WP this object is currently ignored. opacity: 0.75, // 0.0 (transparent) to 1.0 (opaque). Default 0.8 backgroundColor: '#FF0000', // make sure you use #RRGGBB. Default #333333 textColor: '#FFFF00', // Ditto. Default #FFFFFF + textSize: 20.5, // Default is approx. 13. cornerRadius: 16, // minimum is 0 (square). iOS default 20, Android default 100 horizontalPadding: 20, // iOS default 16, Android default 50 verticalPadding: 16 // iOS default 12, Android default 30 @@ -254,6 +254,7 @@ The Android code was entirely created by me. For iOS most credits go to this excellent [Toast for iOS project by Charles Scalesse] (https://github.com/scalessec/Toast). ## 6. CHANGELOG +- 2.5.1: You can now specify the `textSize` used in the font for iOS and Android. - 2.5.0: By popular demand: Specify the duration of the Toast on iOS and Android. Pass in `short` (2000ms), `long` (4000ms), or any nr of milliseconds: `900`. - 2.4.2: You can now also set the Toast `opacity` for iOS. - 2.4.1: As an addition to 2.4.0, [Sino](https://github.com/SinoBoeckmann) added the option to change the text color! @@ -263,25 +264,3 @@ For iOS most credits go to this excellent [Toast for iOS project by Charles Scal - 2.0.1: iOS messages are hidden when another one is shown. [Thanks Richie Min!](https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin/pull/13) - 2.0: WP8 support - 1.0: initial version supporting Android and iOS - -## 7. License - -[The MIT License (MIT)](http://www.opensource.org/licenses/mit-license.html) - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/package.json b/package.json index 43a53df..7713e3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-x-toast", - "version": "2.5.0", + "version": "2.5.1", "description": "This plugin allows you to show a Toast. A Toast is a little non intrusive buttonless popup which automatically disappears.", "cordova": { "id": "cordova-plugin-x-toast", diff --git a/plugin.xml b/plugin.xml index 1134fd0..d4945f0 100755 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="2.5.1"> Toast diff --git a/src/android/nl/xservices/plugins/Toast.java b/src/android/nl/xservices/plugins/Toast.java index 3b43b98..12f7542 100644 --- a/src/android/nl/xservices/plugins/Toast.java +++ b/src/android/nl/xservices/plugins/Toast.java @@ -90,6 +90,7 @@ public class Toast extends CordovaPlugin { // the defaults mimic the default toast as close as possible final String backgroundColor = styling.optString("backgroundColor", "#333333"); final String textColor = styling.optString("textColor", "#ffffff"); + final Double textSize = styling.optDouble("textSize", -1); final double opacity = styling.optDouble("opacity", 0.8); final int cornerRadius = styling.optInt("cornerRadius", 100); final int horizontalPadding = styling.optInt("horizontalPadding", 50); @@ -104,6 +105,9 @@ public class Toast extends CordovaPlugin { final TextView toastTextView; toastTextView = (TextView) toast.getView().findViewById(android.R.id.message); toastTextView.setTextColor(Color.parseColor(textColor)); + if (textSize > -1) { + toastTextView.setTextSize(textSize.floatValue()); + } toast.getView().setPadding(horizontalPadding, verticalPadding, horizontalPadding, verticalPadding); diff --git a/src/ios/Toast+UIView.m b/src/ios/Toast+UIView.m index 8b33055..5ba14a7 100644 --- a/src/ios/Toast+UIView.m +++ b/src/ios/Toast+UIView.m @@ -323,10 +323,14 @@ static id styling; UIColor *theColor = backgroundColor == nil ? [UIColor blackColor] : [self colorFromHexString:backgroundColor]; NSNumber * horizontalPadding = styling[@"horizontalPadding"]; - NSNumber * verticalPadding = styling[@"verticalPadding"]; CGFloat theHorizontalPadding = horizontalPadding == nil ? CSToastHorizontalPadding : [horizontalPadding floatValue]; + + NSNumber * verticalPadding = styling[@"verticalPadding"]; CGFloat theVerticalPadding = verticalPadding == nil ? CSToastVerticalPadding : [verticalPadding floatValue]; + NSNumber * textSize = styling[@"textSize"]; + CGFloat theTextSize = textSize == nil ? CSToastFontSize : [textSize floatValue]; + wrapperView.backgroundColor = theColor; if(image != nil) { @@ -352,7 +356,7 @@ static id styling; titleLabel = [[UILabel alloc] init]; titleLabel.numberOfLines = CSToastMaxTitleLines; - titleLabel.font = [UIFont boldSystemFontOfSize:CSToastFontSize]; + titleLabel.font = [UIFont boldSystemFontOfSize:theTextSize]; titleLabel.textAlignment = NSTextAlignmentLeft; titleLabel.lineBreakMode = NSLineBreakByWordWrapping; titleLabel.textColor = theTitleLabelTextColor; @@ -372,7 +376,7 @@ static id styling; messageLabel = [[UILabel alloc] init]; messageLabel.numberOfLines = CSToastMaxMessageLines; - messageLabel.font = [UIFont systemFontOfSize:CSToastFontSize]; + messageLabel.font = [UIFont systemFontOfSize:theTextSize]; messageLabel.lineBreakMode = NSLineBreakByWordWrapping; messageLabel.textColor = theMessageLabelTextColor; messageLabel.backgroundColor = [UIColor clearColor]; diff --git a/www/Toast.js b/www/Toast.js index ca95231..585b3e7 100755 --- a/www/Toast.js +++ b/www/Toast.js @@ -36,9 +36,9 @@ Toast.prototype.optionsBuilder = function () { duration: duration, position: position, addPixelsY: addPixelsY - } + }; } - } + }; };