Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,20 +0,0 @@
Copyright (c) 2015 Domonkos Pal

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.

26 changes: 4 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ PhoneGap waiting dialog / progress dialog plugin with spinner for Android, iOS a

## Installation

Latest stable release: ```phonegap local plugin add cordova-plugin-spinner-dialog```
or ```cordova plugin add cordova-plugin-spinner-dialog```
Latest stable release: ```phonegap local plugin add hu.dpal.phonegap.plugins.spinnerdialog```
or ```cordova plugin add hu.dpal.phonegap.plugins.spinnerdialog```

Current state from git: ```phonegap local plugin add https://github.com/Paldom/SpinnerDialog.git```
or ```cordova plugin add https://github.com/Paldom/SpinnerDialog.git```

## Installation - PhoneGap Build

Add following to config.xml: ```<gap:plugin name="cordova-plugin-spinnerdialog" source="npm" />```

For older versions, use the following: ```<gap:plugin name="hu.dpal.phonegap.plugins.spinnerdialog" />```
Add following to config.xml: ```<gap:plugin name="hu.dpal.phonegap.plugins.spinnerdialog" />```
or ```<gap:plugin name="hu.dpal.phonegap.plugins.spinnerdialog" source="plugins.cordova.io" />```

## Methods
Expand Down Expand Up @@ -61,23 +59,7 @@ or ```<gap:plugin name="hu.dpal.phonegap.plugins.spinnerdialog" source="plugins.
// Set spinner dialog fixed (cannot be canceled with screen touch or Android hardware button)
window.plugins.spinnerDialog.show("title","message", true);

// Overlay opacity and text color options (IOS only)
window.plugins.spinnerDialog.show(null,"Message",true, {overlayOpacity: 0.35, textColorRed: 1, textColorGreen: 1, textColorBlue: 1});

// Change only overlay opacity (IOS only)
window.plugins.spinnerDialog.show(null,"Message",true,{overlayOpacity:0.70});

// Change only text color (IOS only)
window.plugins.spinnerDialog.show(null,"message",true, { textColorRed: 0.1, textColorGreen: 0.1, textColorBlue: 1});


// Hide spinner dialog
window.plugins.spinnerDialog.hide();




Note: on Android platform, multiple show calls builds up a stack (LIFO) which means hide will dismiss the last spinner added with show call.

## License

MIT License
39 changes: 0 additions & 39 deletions package.json

This file was deleted.

9 changes: 8 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>

<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
id="cordova-plugin-spinner-dialog"
id="hu.dpal.phonegap.plugins.SpinnerDialog"
version="1.3.1">

<name>SpinnerDialog</name>
Expand Down Expand Up @@ -50,6 +50,13 @@

<source-file src="src/wp/SpinnerDialog.cs" />
</platform>

<!-- windows -->
<platform name="windows">
<js-module src="src/windows/SpinnerDialogProxy.js" name="SpinnerDialogProxy">
<merges target="" />
</js-module>
</platform>

</plugin>

2 changes: 2 additions & 0 deletions src/android/SpinnerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.widget.ProgressBar;
import android.graphics.drawable.ColorDrawable;

public class SpinnerDialog extends CordovaPlugin {

Expand Down Expand Up @@ -49,6 +50,7 @@ public void onCancel(DialogInterface dialog) {
}

if (title == null && message == null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.setContentView(new ProgressBar(cordova.getActivity()));
}

Expand Down
40 changes: 29 additions & 11 deletions src/ios/CDVSpinnerDialog.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

#import "CDVSpinnerDialog.h"

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1]

#define UIColorFromRGBOpaque(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:0.65]

@interface CDVSpinnerDialog () {
UIActivityIndicatorView *indicator;
NSString *callbackId;
NSString *title;
NSString *message;
NSNumber *isFixed;
NSString *alpha;
NSString *red;
NSString *green;
NSString *blue;
NSString *color;
NSString *backgorundColor;
}

@property (nonatomic, retain) UIActivityIndicatorView *indicator;
Expand Down Expand Up @@ -53,18 +55,36 @@ - (void)handleTapGesture:(UITapGestureRecognizer *)gesture
- (UIView *)overlay {
if (!_overlay) {
_overlay = [[UIView alloc] initWithFrame:self.rectForView];
_overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:[alpha floatValue]];
_indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
_indicator.center = _overlay.center;
if(backgorundColor && ![backgorundColor isEqualToString: @"null"] && ![backgorundColor isEqualToString: @""]){
if([backgorundColor rangeOfString:@"#"].location != NSNotFound){
backgorundColor = [backgorundColor stringByReplacingOccurrencesOfString:@"#" withString:@""];
}
unsigned int baseValue;
[[NSScanner scannerWithString:backgorundColor] scanHexInt:&baseValue];
_overlay.backgroundColor = UIColorFromRGBOpaque(baseValue);
} else
_overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.65];
[_indicator startAnimating];
[_overlay addSubview:_indicator];

_messageView = [[UILabel alloc] initWithFrame: self.rectForView];
[_messageView setText: message == nil ? title : message];
[_messageView setTextColor: [UIColor colorWithRed:[red floatValue] green:[green floatValue] blue:[blue floatValue] alpha:0.85]];
//[_messageView setTextColor: [UIColor colorWithRed:1 green:1 blue:1 alpha:0.85]];
if(color && ![color isEqualToString: @"null"] && ![color isEqualToString: @""]){
if([color rangeOfString:@"#"].location != NSNotFound){
color = [color stringByReplacingOccurrencesOfString:@"#" withString:@""];
}
unsigned int baseValue;
[[NSScanner scannerWithString:color] scanHexInt:&baseValue];
[_messageView setTextColor: UIColorFromRGB(baseValue)];
}
[_messageView setBackgroundColor: [UIColor colorWithRed:0 green:0 blue:0 alpha:0]];
[_messageView setTextAlignment: NSTextAlignmentCenter];
_messageView.center = (CGPoint){_overlay.center.x, _overlay.center.y + 40};
_messageView.lineBreakMode = NSLineBreakByWordWrapping;
_messageView.numberOfLines = 0;
[_overlay addSubview:_messageView];

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
Expand All @@ -81,11 +101,9 @@ - (void) show:(CDVInvokedUrlCommand*)command {
title = [command argumentAtIndex:0];
message = [command argumentAtIndex:1];
isFixed = [command argumentAtIndex:2];
alpha = [command argumentAtIndex:3];
red = [command argumentAtIndex:4];
green = [command argumentAtIndex:5];
blue = [command argumentAtIndex:6];

color = [command argumentAtIndex:3];
backgorundColor = [command argumentAtIndex:4];

UIViewController *rootViewController = [[[[UIApplication sharedApplication] delegate] window] rootViewController];

[rootViewController.view addSubview:self.overlay];
Expand Down
63 changes: 63 additions & 0 deletions src/windows/SpinnerDialogProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cordova.commandProxy.add("SpinnerDialog", {
show: function (successCallback, errorCallback, params) {
if(!document.getElementById("SpinnerDialogPlugin"))
addSpinner(params);
else {
hideSpinner();
addSpinner(params);
}
},
hide: function (successCallback, errorCallback, params) {
hideSpinner();
}
});

function showSpinner(){
var element = document.getElementById("SpinnerDialogPlugin");
if(element) element.style.display = "block";
};

function hideSpinner(){
var element = document.getElementById("SpinnerDialogPlugin");
if(element) {
//element.style.display = "none";
element.parentNode.removeChild(element);
}
};

function addSpinner(params) {
var element = element || document.createElement("div");
element.setAttribute("id", "SpinnerDialogPlugin");
element.style.width = "100%";
element.style.height = "100%";
element.style.position = "absolute";
element.style.top = "0px";
element.style.left = "0px";
element.style.opacity = .5; //For real browsers;
element.style.filter = "alpha(opacity=50)"; //For IE;
element.style.background = params[4] ? params[4] : "#000000";
element.style.zIndex = "999999";
//element.style.display = "none";

var progressContainer = progressContainer || document.createElement("div");
progressContainer.style.position = "absolute";
progressContainer.style.top = "50%";
progressContainer.style.left = "50%";
progressContainer.style.transform = "translate(-50%, -50%)";

var progress = progress || document.createElement("progress");

var progressMessage = progressMessage|| document.createElement("div");
progressMessage.style.marginTop = "2px;"
progressMessage.style.textAlign = "center";
progressMessage.style.color = params[3] ? params[3] : "#FFFFFF";
progressMessage.innerHTML = params[1] ? params[1] : "";

progressContainer.appendChild(progress);
progressContainer.appendChild(progressMessage);
element.appendChild(progressContainer);

//element.innerHTML = "<progress class=\"win-ring\" style=\"position: absolute; top: 50%; left: 50%;transform: translate(-50%, -50%);\"></progress>";

document.body.appendChild(element);
};
20 changes: 6 additions & 14 deletions www/spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,15 @@ var exec = require('cordova/exec');

module.exports = {

show: function (title, message, cancelCallback, iosOptions) {
show : function(title, message, cancelCallback, color, backgroundColor) {
if (cancelCallback == true && typeof cancelCallback !== "function") {
cancelCallback = function () { };
cancelCallback = function () {};
}
var isPlatformIos = (navigator.userAgent.match(/iPad/i)) == "iPad" || (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? true : false;
var params = [title, message, !!cancelCallback];
if (isPlatformIos) {
if (typeof iosOptions != "object") {
iosOptions = { overlayOpacity: 0.35, textColorRed: 1, textColorGreen: 1, textColorBlue: 1 }
}
params = params.concat([(iosOptions.overlayOpacity || 0.35), (iosOptions.textColorRed || 1), (iosOptions.textColorGreen || 1), (iosOptions.textColorBlue || 1)])
}
cordova.exec(cancelCallback, null, 'SpinnerDialog', 'show', params);

cordova.exec(cancelCallback, null, 'SpinnerDialog', 'show', [ title, message, !!cancelCallback, color, backgroundColor ]);
},
hide: function (success, fail) {
cordova.exec(success, fail, 'SpinnerDialog', 'hide', ["", ""]);

hide : function(success, fail) {
cordova.exec(success, fail, 'SpinnerDialog', 'hide', [ "","" ]);
}

};