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
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pDialog - A Native Android Progress Dialog Plugin for Cordova
pDialog - A Native Android and iOS Progress Dialog Plugin for Cordova
======================

![pDialog1](http://i.imgur.com/LmAZa2d.png)
Expand All @@ -8,10 +8,11 @@ Requirements
-------------
- Android 4 or higher
- Cordova 3.0 or higher
- iOS 7.0 or higher

Installation
-------------
cordova plugin add cordova-plugin-pdialog
cordova plugin add https://github.com/orlleite/cordova-plugin-pdialog.git

Simple Usage
-------------
Expand Down Expand Up @@ -40,6 +41,7 @@ These are the valid options:

`theme`: can be one of the following:
`TRADITIONAL`, `DEVICE_DARK`, `DEVICE_LIGHT` (default), `HOLO_DARK`, `HOLO_LIGHT`
* themes are not supported by iOS.


`progressStyle`: can be one of the following:
Expand Down Expand Up @@ -131,4 +133,4 @@ 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.



8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"name": "cordova-plugin-pdialog",
"version": "2.0.1",
"version": "2.1.1",
"description": "An Android Progress Dialog Plugin for Cordova",
"cordova": {
"id": "cordova-plugin-pdialog",
"platforms": [
"android"
"android",
"ios"
]
},
"repository": {
Expand All @@ -14,7 +15,8 @@
},
"keywords": [
"ecosystem:cordova",
"cordova-android"
"cordova-android",
"cordova-ios"
],
"engines": [
{
Expand Down
12 changes: 11 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://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-pdialog" version="2.0.1">
<name>pDialog</name>
<description>An Android Progress Dialog Plugin for Cordova.</description>
<description>An Android and iOS Progress Dialog Plugin for Cordova.</description>
<license>MIT</license>
<engines>
<engine name="cordova" version=">=3.0.0" />
Expand All @@ -18,4 +18,14 @@
</feature>
</config-file>
</platform>

<platform name="ios">
<config-file target="config.xml" parent="/*">
<feature name="PDialog">
<param name="ios-package" value="PDialog"/>
</feature>
</config-file>
<header-file src="src/ios/PDialog.h" />
<source-file src="src/ios/PDialog.m" />
</platform>
</plugin>
44 changes: 19 additions & 25 deletions src/android/io/github/pwlin/cordova/plugins/pdialog/PDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ this software and associated documentation files (the "Software"), to deal in

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONArray;

import android.app.ProgressDialog;

//import android.util.Log;
// import android.util.Log;

import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
Expand All @@ -47,38 +48,39 @@ public class PDialog extends CordovaPlugin {
* @return Whether the action was valid.
*/
@Override
public boolean execute(String action, String rawArgs, CallbackContext callbackContext) {
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
/*
* Don't run any of these if the current activity is finishing in order
* to avoid android.view.WindowManager$BadTokenException crashing the
* app.
*/

if (this.cordova.getActivity().isFinishing()) {
return true;
}
if (action.equals("init")) {
this.init(rawArgs);
this.init(args.getJSONObject(0));
} else if (action.equals("dismiss")) {
this.dismiss();
} else if (action.equals("setProgress")) {
this.setProgress(rawArgs);
this.setProgress(args.getInt(0));
} else if (action.equals("setTitle")) {
this.setTitle(rawArgs);
this.setTitle(args.getString(0));
} else if (action.equals("setMessage")) {
this.setMessage(rawArgs);
this.setMessage(args.getString(0));
} else if (action.equals("setCancelable")) {
this.setCancelable(rawArgs);
this.setCancelable(args.getBoolean(0));
}
return true;
}

/**
* Initializing the progress dialog and set various parameters
*
* @param rawArgs
* @param argsObj
* @see https://github.com/pwlin/cordova-plugin-pdialog/blob/master/README.md
*/
private void init(final String rawArgs) {
private void init(final JSONObject argsObj ) {
final CordovaInterface cordova = this.cordova;
Runnable runnable = new Runnable() {
@Override
Expand All @@ -87,13 +89,7 @@ public void run() {
PDialog.pDialogObj.dismiss();
PDialog.pDialogObj = null;
}
JSONObject argsObj = null;
try {
argsObj = new JSONObject(rawArgs);
} catch (JSONException e) {
// e.printStackTrace();
}


int theme = 5; // ProgressDialog.THEME_DEVICE_DEFAULT_LIGHT
if (argsObj.has("theme")) {
String themeArg = null;
Expand Down Expand Up @@ -183,13 +179,12 @@ public void run() {
/**
* Set the value of the progress bar when progress style is "HORIZONTAL"
*
* @param rawArgs
* @param value
*/
private void setProgress(final String rawArgs) {
private void setProgress(final int value) {
Runnable runnable = new Runnable() {
@Override
public void run() {
int value = Integer.parseInt(rawArgs);
PDialog.pDialogObj.setProgress(value);
};
};
Expand All @@ -199,7 +194,7 @@ public void run() {
/**
* Set the title of the progress dialog
*
* @param rawArgs
* @param title
*/
private void setTitle(final String title) {
Runnable runnable = new Runnable() {
Expand All @@ -214,7 +209,7 @@ public void run() {
/**
* Set the message of the progress dialog
*
* @param rawArgs
* @param message
*/
private void setMessage(final String message) {
Runnable runnable = new Runnable() {
Expand All @@ -229,7 +224,7 @@ public void run() {
/**
* Set the progress max of the progress dialog
*
* @param rawArgs
* @param max
*/
private void setMax(final String max) {
Runnable runnable = new Runnable() {
Expand All @@ -244,13 +239,12 @@ public void run() {
/**
* Set whether the progress dialog is calncelable or not
*
* @param rawArgs
* @param flag
*/
private void setCancelable(final String rawArgs) {
private void setCancelable(final boolean flag) {
Runnable runnable = new Runnable() {
@Override
public void run() {
boolean flag = Boolean.parseBoolean(rawArgs);
PDialog.pDialogObj.setCancelable(flag);
PDialog.pDialogObj.setCanceledOnTouchOutside(flag);
};
Expand Down
46 changes: 46 additions & 0 deletions src/ios/PDialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
The MIT License (MIT)

Copyright (c) 2016 Orlando Leite - orlleite gmail

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

#import <Cordova/CDV.h>

@interface PDialog : CDVPlugin
{
UITapGestureRecognizer *singleFingerTap;

UIView *dialogContainer;
UIView *oldDialogContainer;
UILabel *titleLabel;
UILabel *messageLabel;
UIProgressView *progressBar;
BOOL isCancellable;
}

- (void) init:(CDVInvokedUrlCommand*)command;
- (void) dismiss:(CDVInvokedUrlCommand*)command;
- (void) setProgress:(CDVInvokedUrlCommand*)command;
- (void) setTitle:(CDVInvokedUrlCommand*)command;
- (void) setMessage:(CDVInvokedUrlCommand*)command;
- (void) setMax:(CDVInvokedUrlCommand*)command;
- (void) setCancelable:(CDVInvokedUrlCommand*)command;

@end
Loading