You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by na...@apache.org on 2014/04/28 21:16:46 UTC
[1/4] git commit: add ubuntu platform
Repository: cordova-plugin-dialogs
Updated Branches:
refs/heads/dev 64a72e551 -> 3a17d55bf
add ubuntu platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/bd814b28
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/bd814b28
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/bd814b28
Branch: refs/heads/dev
Commit: bd814b28eb7a30ac9e86cbf2aaf12640c797da86
Parents: 55b096a
Author: Maxim Ermilov <er...@gmail.com>
Authored: Fri Oct 4 17:02:11 2013 +0400
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Apr 28 12:15:40 2014 -0700
----------------------------------------------------------------------
plugin.xml | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/bd814b28/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8cf2f25..ae8089c 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -76,6 +76,13 @@
<resource-file src="src/ubuntu/notification.qml" />
</platform>
+ <!-- ubuntu -->
+ <platform name="ubuntu">
+ <header-file src="src/ubuntu/notification.h" />
+ <source-file src="src/ubuntu/notification.cpp" />
+ <resource-file src="src/ubuntu/notification.qml" />
+ </platform>
+
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
[4/4] git commit: add ubuntu platform
Posted by na...@apache.org.
add ubuntu platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/3a17d55b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/3a17d55b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/3a17d55b
Branch: refs/heads/dev
Commit: 3a17d55bf5834440b2e902c2be4e0bddb6b324e2
Parents: 80ea75d
Author: Maxim Ermilov <er...@gmail.com>
Authored: Fri Oct 4 17:02:11 2013 +0400
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Apr 28 12:16:29 2014 -0700
----------------------------------------------------------------------
plugin.xml | 7 +++++++
1 file changed, 7 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/3a17d55b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index ae8089c..81dcf75 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -83,6 +83,13 @@
<resource-file src="src/ubuntu/notification.qml" />
</platform>
+ <!-- ubuntu -->
+ <platform name="ubuntu">
+ <header-file src="src/ubuntu/notification.h" />
+ <source-file src="src/ubuntu/notification.cpp" />
+ <resource-file src="src/ubuntu/notification.qml" />
+ </platform>
+
<!-- ios -->
<platform name="ios">
<config-file target="config.xml" parent="/*">
[3/4] git commit: Added check for isFinishing() on the parent
activity to prevent crashes when trying to display dialogs when activity is
in this phase of it's lifecycle
Posted by na...@apache.org.
Added check for isFinishing() on the parent activity
to prevent crashes when trying to display dialogs when activity
is in this phase of it's lifecycle
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/80ea75de
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/80ea75de
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/80ea75de
Branch: refs/heads/dev
Commit: 80ea75de560c5c46c823bfbe8779c0c78238721f
Parents: bd814b2
Author: Archana Naik <na...@lab126.com>
Authored: Wed Apr 9 22:42:33 2014 -0700
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Apr 28 12:16:29 2014 -0700
----------------------------------------------------------------------
src/android/Notification.java | 435 +++++++++++++++++++++++++++++++++++++
1 file changed, 435 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/80ea75de/src/android/Notification.java
----------------------------------------------------------------------
diff --git a/src/android/Notification.java b/src/android/Notification.java
new file mode 100755
index 0000000..d068612
--- /dev/null
+++ b/src/android/Notification.java
@@ -0,0 +1,435 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+package org.apache.cordova.dialogs;
+
+import org.apache.cordova.CallbackContext;
+import org.apache.cordova.CordovaInterface;
+import org.apache.cordova.CordovaPlugin;
+import org.apache.cordova.PluginResult;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import android.app.AlertDialog;
+import android.app.ProgressDialog;
+import android.content.DialogInterface;
+import android.media.Ringtone;
+import android.media.RingtoneManager;
+import android.net.Uri;
+import android.widget.EditText;
+
+/**
+ * This class provides access to notifications on the device.
+ */
+public class Notification extends CordovaPlugin {
+
+ public int confirmResult = -1;
+ public ProgressDialog spinnerDialog = null;
+ public ProgressDialog progressDialog = null;
+
+ /**
+ * Constructor.
+ */
+ public Notification() {
+ }
+
+ /**
+ * Executes the request and returns PluginResult.
+ *
+ * @param action The action to execute.
+ * @param args JSONArray of arguments for the plugin.
+ * @param callbackContext The callback context used when calling back into JavaScript.
+ * @return True when the action was valid, false otherwise.
+ */
+ 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. Just return true here since false should only
+ * be returned in the event of an invalid action.
+ */
+ if(this.cordova.getActivity().isFinishing()) return true;
+
+ if (action.equals("beep")) {
+ this.beep(args.getLong(0));
+ }
+ else if (action.equals("alert")) {
+ this.alert(args.getString(0), args.getString(1), args.getString(2), callbackContext);
+ return true;
+ }
+ else if (action.equals("confirm")) {
+ this.confirm(args.getString(0), args.getString(1), args.getJSONArray(2), callbackContext);
+ return true;
+ }
+ else if (action.equals("prompt")) {
+ this.prompt(args.getString(0), args.getString(1), args.getJSONArray(2), args.getString(3), callbackContext);
+ return true;
+ }
+ else if (action.equals("activityStart")) {
+ this.activityStart(args.getString(0), args.getString(1));
+ }
+ else if (action.equals("activityStop")) {
+ this.activityStop();
+ }
+ else if (action.equals("progressStart")) {
+ this.progressStart(args.getString(0), args.getString(1));
+ }
+ else if (action.equals("progressValue")) {
+ this.progressValue(args.getInt(0));
+ }
+ else if (action.equals("progressStop")) {
+ this.progressStop();
+ }
+ else {
+ return false;
+ }
+
+ // Only alert and confirm are async.
+ callbackContext.success();
+ return true;
+ }
+
+ //--------------------------------------------------------------------------
+ // LOCAL METHODS
+ //--------------------------------------------------------------------------
+
+ /**
+ * Beep plays the default notification ringtone.
+ *
+ * @param count Number of times to play notification
+ */
+ public void beep(long count) {
+ Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
+ Ringtone notification = RingtoneManager.getRingtone(this.cordova.getActivity().getBaseContext(), ringtone);
+
+ // If phone is not set to silent mode
+ if (notification != null) {
+ for (long i = 0; i < count; ++i) {
+ notification.play();
+ long timeout = 5000;
+ while (notification.isPlaying() && (timeout > 0)) {
+ timeout = timeout - 100;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Builds and shows a native Android alert with given Strings
+ * @param message The message the alert should display
+ * @param title The title of the alert
+ * @param buttonLabel The label of the button
+ * @param callbackContext The callback context
+ */
+ public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) {
+ final CordovaInterface cordova = this.cordova;
+
+ Runnable runnable = new Runnable() {
+ public void run() {
+
+ AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
+ dlg.setMessage(message);
+ dlg.setTitle(title);
+ dlg.setCancelable(true);
+ dlg.setPositiveButton(buttonLabel,
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
+ }
+ });
+ dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
+ public void onCancel(DialogInterface dialog)
+ {
+ dialog.dismiss();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
+ }
+ });
+
+ dlg.create();
+ dlg.show();
+ };
+ };
+ this.cordova.getActivity().runOnUiThread(runnable);
+ }
+
+ /**
+ * Builds and shows a native Android confirm dialog with given title, message, buttons.
+ * This dialog only shows up to 3 buttons. Any labels after that will be ignored.
+ * The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
+ *
+ * @param message The message the dialog should display
+ * @param title The title of the dialog
+ * @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
+ * @param callbackContext The callback context.
+ */
+ public synchronized void confirm(final String message, final String title, final JSONArray buttonLabels, final CallbackContext callbackContext) {
+ final CordovaInterface cordova = this.cordova;
+
+ Runnable runnable = new Runnable() {
+ public void run() {
+ AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
+ dlg.setMessage(message);
+ dlg.setTitle(title);
+ dlg.setCancelable(true);
+
+ // First button
+ if (buttonLabels.length() > 0) {
+ try {
+ dlg.setNegativeButton(buttonLabels.getString(0),
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1));
+ }
+ });
+ } catch (JSONException e) { }
+ }
+
+ // Second button
+ if (buttonLabels.length() > 1) {
+ try {
+ dlg.setNeutralButton(buttonLabels.getString(1),
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2));
+ }
+ });
+ } catch (JSONException e) { }
+ }
+
+ // Third button
+ if (buttonLabels.length() > 2) {
+ try {
+ dlg.setPositiveButton(buttonLabels.getString(2),
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3));
+ }
+ });
+ } catch (JSONException e) { }
+ }
+ dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
+ public void onCancel(DialogInterface dialog)
+ {
+ dialog.dismiss();
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
+ }
+ });
+
+ dlg.create();
+ dlg.show();
+ };
+ };
+ this.cordova.getActivity().runOnUiThread(runnable);
+ }
+
+ /**
+ * Builds and shows a native Android prompt dialog with given title, message, buttons.
+ * This dialog only shows up to 3 buttons. Any labels after that will be ignored.
+ * The following results are returned to the JavaScript callback identified by callbackId:
+ * buttonIndex Index number of the button selected
+ * input1 The text entered in the prompt dialog box
+ *
+ * @param message The message the dialog should display
+ * @param title The title of the dialog
+ * @param buttonLabels A comma separated list of button labels (Up to 3 buttons)
+ * @param callbackContext The callback context.
+ */
+ public synchronized void prompt(final String message, final String title, final JSONArray buttonLabels, final String defaultText, final CallbackContext callbackContext) {
+
+ final CordovaInterface cordova = this.cordova;
+ final EditText promptInput = new EditText(cordova.getActivity());
+ promptInput.setHint(defaultText);
+
+ Runnable runnable = new Runnable() {
+ public void run() {
+ AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
+ dlg.setMessage(message);
+ dlg.setTitle(title);
+ dlg.setCancelable(true);
+
+ dlg.setView(promptInput);
+
+ final JSONObject result = new JSONObject();
+
+ // First button
+ if (buttonLabels.length() > 0) {
+ try {
+ dlg.setNegativeButton(buttonLabels.getString(0),
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ try {
+ result.put("buttonIndex",1);
+ result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
+ } catch (JSONException e) { e.printStackTrace(); }
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
+ }
+ });
+ } catch (JSONException e) { }
+ }
+
+ // Second button
+ if (buttonLabels.length() > 1) {
+ try {
+ dlg.setNeutralButton(buttonLabels.getString(1),
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ try {
+ result.put("buttonIndex",2);
+ result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
+ } catch (JSONException e) { e.printStackTrace(); }
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
+ }
+ });
+ } catch (JSONException e) { }
+ }
+
+ // Third button
+ if (buttonLabels.length() > 2) {
+ try {
+ dlg.setPositiveButton(buttonLabels.getString(2),
+ new AlertDialog.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ dialog.dismiss();
+ try {
+ result.put("buttonIndex",3);
+ result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
+ } catch (JSONException e) { e.printStackTrace(); }
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
+ }
+ });
+ } catch (JSONException e) { }
+ }
+ dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
+ public void onCancel(DialogInterface dialog){
+ dialog.dismiss();
+ try {
+ result.put("buttonIndex",0);
+ result.put("input1", promptInput.getText().toString().trim().length()==0 ? defaultText : promptInput.getText());
+ } catch (JSONException e) { e.printStackTrace(); }
+ callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
+ }
+ });
+
+ dlg.create();
+ dlg.show();
+
+ };
+ };
+ this.cordova.getActivity().runOnUiThread(runnable);
+ }
+
+ /**
+ * Show the spinner.
+ *
+ * @param title Title of the dialog
+ * @param message The message of the dialog
+ */
+ public synchronized void activityStart(final String title, final String message) {
+ if (this.spinnerDialog != null) {
+ this.spinnerDialog.dismiss();
+ this.spinnerDialog = null;
+ }
+ final CordovaInterface cordova = this.cordova;
+ Runnable runnable = new Runnable() {
+ public void run() {
+ Notification.this.spinnerDialog = ProgressDialog.show(cordova.getActivity(), title, message, true, true,
+ new DialogInterface.OnCancelListener() {
+ public void onCancel(DialogInterface dialog) {
+ Notification.this.spinnerDialog = null;
+ }
+ });
+ }
+ };
+ this.cordova.getActivity().runOnUiThread(runnable);
+ }
+
+ /**
+ * Stop spinner.
+ */
+ public synchronized void activityStop() {
+ if (this.spinnerDialog != null) {
+ this.spinnerDialog.dismiss();
+ this.spinnerDialog = null;
+ }
+ }
+
+ /**
+ * Show the progress dialog.
+ *
+ * @param title Title of the dialog
+ * @param message The message of the dialog
+ */
+ public synchronized void progressStart(final String title, final String message) {
+ if (this.progressDialog != null) {
+ this.progressDialog.dismiss();
+ this.progressDialog = null;
+ }
+ final Notification notification = this;
+ final CordovaInterface cordova = this.cordova;
+ Runnable runnable = new Runnable() {
+ public void run() {
+ notification.progressDialog = new ProgressDialog(cordova.getActivity());
+ notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
+ notification.progressDialog.setTitle(title);
+ notification.progressDialog.setMessage(message);
+ notification.progressDialog.setCancelable(true);
+ notification.progressDialog.setMax(100);
+ notification.progressDialog.setProgress(0);
+ notification.progressDialog.setOnCancelListener(
+ new DialogInterface.OnCancelListener() {
+ public void onCancel(DialogInterface dialog) {
+ notification.progressDialog = null;
+ }
+ });
+ notification.progressDialog.show();
+ }
+ };
+ this.cordova.getActivity().runOnUiThread(runnable);
+ }
+
+ /**
+ * Set value of progress bar.
+ *
+ * @param value 0-100
+ */
+ public synchronized void progressValue(int value) {
+ if (this.progressDialog != null) {
+ this.progressDialog.setProgress(value);
+ }
+ }
+
+ /**
+ * Stop progress dialog.
+ */
+ public synchronized void progressStop() {
+ if (this.progressDialog != null) {
+ this.progressDialog.dismiss();
+ this.progressDialog = null;
+ }
+ }
+}
[2/4] git commit: add ubuntu platform
Posted by na...@apache.org.
add ubuntu platform
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/55b096ac
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/55b096ac
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/55b096ac
Branch: refs/heads/dev
Commit: 55b096ac100676dd819e741f0ba4936c0070a8a6
Parents: 64a72e5
Author: Maxim Ermilov <er...@gmail.com>
Authored: Fri Oct 4 17:02:11 2013 +0400
Committer: Archana Naik <na...@lab126.com>
Committed: Mon Apr 28 12:15:40 2014 -0700
----------------------------------------------------------------------
plugin.xml | 138 +++++++++++++++++++++++++++++++++++++++
src/ubuntu/notification.cpp | 81 +++++++++++++++++++++++
src/ubuntu/notification.h | 63 ++++++++++++++++++
src/ubuntu/notification.qml | 44 +++++++++++++
www/notification.js | 109 +++++++++++++++++++++++++++++++
5 files changed, 435 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..8cf2f25
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,138 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+ id="org.apache.cordova.dialogs"
+ version="0.2.4-dev">
+
+ <name>Notification</name>
+ <description>Cordova Notification Plugin</description>
+ <license>Apache 2.0</license>
+ <keywords>cordova,notification</keywords>
+ <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs.git</repo>
+ <issue>https://issues.apache.org/jira/browse/CB/component/12320642</issue>
+
+ <js-module src="www/notification.js" name="notification">
+ <merges target="navigator.notification" />
+ </js-module>
+
+ <!-- firefoxos -->
+ <platform name="firefoxos">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Notification">
+ <param name="firefoxos-package" value="Notification" />
+ </feature>
+ </config-file>
+
+ <asset src="www/firefoxos/notification.css" target="css/notification.css" />
+ <asset src="www/firefoxos/danger-press.png" target="css/danger-press.png" />
+ <asset src="www/firefoxos/danger.png" target="css/danger.png" />
+ <asset src="www/firefoxos/default.png" target="css/default.png" />
+ <asset src="www/firefoxos/gradient.png" target="css/gradient.png" />
+ <asset src="www/firefoxos/pattern.png" target="css/pattern.png" />
+ <asset src="www/firefoxos/recommend.png" target="css/recommend.png" />
+ <js-module src="src/firefoxos/notification.js" name="dialogs-impl">
+ <runs />
+ </js-module>
+ </platform>
+
+ <!-- android -->
+ <platform name="android">
+ <config-file target="res/xml/config.xml" parent="/*">
+ <feature name="Notification">
+ <param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
+ </feature>
+ </config-file>
+
+ <source-file src="src/android/Notification.java" target-dir="src/org/apache/cordova/dialogs" />
+
+ <!-- android specific notification apis -->
+ <js-module src="www/android/notification.js" name="notification_android">
+ <merges target="navigator.notification" />
+ </js-module>
+
+ </platform>
+
+ <!-- amazon-fireos -->
+ <platform name="amazon-fireos">
+ <config-file target="res/xml/config.xml" parent="/*">
+ <feature name="Notification">
+ <param name="android-package" value="org.apache.cordova.dialogs.Notification"/>
+ </feature>
+ </config-file>
+
+ <source-file src="src/android/Notification.java" target-dir="src/org/apache/cordova/dialogs" />
+
+ <!-- android specific notification apis -->
+ <js-module src="www/android/notification.js" name="notification_android">
+ <merges target="navigator.notification" />
+ </js-module>
+
+ </platform>
+
+ <!-- ubuntu -->
+ <platform name="ubuntu">
+ <header-file src="src/ubuntu/notification.h" />
+ <source-file src="src/ubuntu/notification.cpp" />
+ <resource-file src="src/ubuntu/notification.qml" />
+ </platform>
+
+ <!-- ios -->
+ <platform name="ios">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Notification">
+ <param name="ios-package" value="CDVNotification"/>
+ </feature>
+ </config-file>
+ <header-file src="src/ios/CDVNotification.h" />
+ <source-file src="src/ios/CDVNotification.m" />
+ <resource-file src="src/ios/CDVNotification.bundle" />
+ <framework src="AudioToolbox.framework" weak="true" />
+ </platform>
+
+ <!-- blackberry10 -->
+ <platform name="blackberry10">
+ <source-file src="src/blackberry10/index.js" target-dir="Notification" />
+ <config-file target="www/config.xml" parent="/widget">
+ <feature name="Notification" value="Notification"/>
+ </config-file>
+ <js-module src="www/blackberry10/beep.js" name="beep">
+ <clobbers target="window.navigator.notification.beep" />
+ </js-module>
+ </platform>
+
+ <!-- wp7 -->
+ <platform name="wp7">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Notification">
+ <param name="wp-package" value="Notification"/>
+ </feature>
+ </config-file>
+
+ <source-file src="src/wp/Notification.cs" />
+ <source-file src="src/wp/NotificationBox.xaml.cs" />
+ <source-file src="src/wp/NotificationBox.xaml" />
+ <source-file src="src/wp/notification-beep.wav" />
+ </platform>
+
+ <!-- wp8 -->
+ <platform name="wp8">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Notification">
+ <param name="wp-package" value="Notification"/>
+ </feature>
+ </config-file>
+
+ <source-file src="src/wp/Notification.cs" />
+ <source-file src="src/wp/NotificationBox.xaml.cs" />
+ <source-file src="src/wp/NotificationBox.xaml" />
+ <source-file src="src/wp/notification-beep.wav" />
+ </platform>
+
+ <!-- windows8 -->
+ <platform name="windows8">
+ <js-module src="src/windows8/NotificationProxy.js" name="NotificationProxy">
+ <merges target="" />
+ </js-module>
+ </platform>
+
+</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/src/ubuntu/notification.cpp
----------------------------------------------------------------------
diff --git a/src/ubuntu/notification.cpp b/src/ubuntu/notification.cpp
new file mode 100644
index 0000000..77c5e25
--- /dev/null
+++ b/src/ubuntu/notification.cpp
@@ -0,0 +1,81 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "notification.h"
+
+#include <QApplication>
+
+#include <QMediaPlayer>
+#include <QMessageBox>
+
+void Dialogs::beep(int scId, int ecId, int times) {
+ Q_UNUSED(scId)
+ Q_UNUSED(ecId)
+ Q_UNUSED(times)
+ QMediaPlayer* player = new QMediaPlayer;
+ player->setVolume(100);
+ player->setMedia(QUrl::fromLocalFile("/usr/share/sounds/ubuntu/stereo/bell.ogg"));
+ player->play();
+}
+
+void Dialogs::alert(int scId, int ecId, const QString &message, const QString &title, const QString &buttonLabel) {
+ QStringList list;
+ list.append(buttonLabel);
+
+ confirm(scId, ecId, message, title, list);
+}
+
+void Dialogs::confirm(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels) {
+ Q_UNUSED(ecId);
+
+ //FIXME:
+ assert(!_alertCallback);
+ _alertCallback = scId;
+
+ QString s1, s2, s3;
+ if (buttonLabels.size() > 0)
+ s1 = buttonLabels[0];
+ if (buttonLabels.size() > 1)
+ s2 = buttonLabels[1];
+ if (buttonLabels.size() > 2)
+ s3 = buttonLabels[2];
+
+ QString path = m_cordova->get_app_dir() + "/../qml/notification.qml";
+ //FIXME:
+ QString qml = QString("PopupUtils.open(\"%1\", root, { root: root, cordova: cordova, title: \"%2\", text: \"%3\", promptVisible: false, button1Text: \"%4\", button2Text: \"%5\", button3Text: \"%6\" })")
+ .arg(path).arg(title).arg(message).arg(s1).arg(s2).arg(s3);
+ m_cordova->execQML(qml);
+}
+
+void Dialogs::prompt(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels, const QString &defaultText) {
+ Q_UNUSED(ecId)
+
+ assert(!_alertCallback);
+ _alertCallback = scId;
+
+ QString s1, s2, s3;
+ if (buttonLabels.size() > 0)
+ s1 = buttonLabels[0];
+ if (buttonLabels.size() > 1)
+ s2 = buttonLabels[1];
+ if (buttonLabels.size() > 2)
+ s3 = buttonLabels[2];
+ QString path = m_cordova->get_app_dir() + "/../qml/notification.qml";
+ QString qml = QString("PopupUtils.open(\"%1\", root, { root: root, cordova: cordova, title: \"%2\", text: \"%3\", promptVisible: true, defaultPromptText: \"%7\", button1Text: \"%4\", button2Text: \"%5\", button3Text: \"%6\" })")
+ .arg(path).arg(title).arg(message).arg(s1).arg(s2).arg(s3).arg(defaultText);
+
+ qDebug() << qml;
+ m_cordova->execQML(qml);
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/src/ubuntu/notification.h
----------------------------------------------------------------------
diff --git a/src/ubuntu/notification.h b/src/ubuntu/notification.h
new file mode 100644
index 0000000..3173d99
--- /dev/null
+++ b/src/ubuntu/notification.h
@@ -0,0 +1,63 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_H
+#define NOTIFICATION_H
+
+#include <QtQuick>
+#include <cplugin.h>
+#include <cordova.h>
+
+class Dialogs: public CPlugin {
+ Q_OBJECT
+public:
+ explicit Dialogs(Cordova *cordova): CPlugin(cordova), _alertCallback(0) {
+ }
+
+ virtual const QString fullName() override {
+ return Dialogs::fullID();
+ }
+
+ virtual const QString shortName() override {
+ return "Notification";
+ }
+
+ static const QString fullID() {
+ return "Notification";
+ }
+public slots:
+ void beep(int scId, int ecId, int times);
+ void alert(int scId, int ecId, const QString &message, const QString &title, const QString &buttonLabel);
+ void confirm(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels);
+ void prompt(int scId, int ecId, const QString &message, const QString &title, const QStringList &buttonLabels, const QString &defaultText);
+
+ void notificationDialogButtonPressed(int buttonId, const QString &text) {
+ if (text.size()) {
+ QVariantMap res;
+ res.insert("buttonIndex", buttonId);
+ res.insert("input1", text);
+ this->cb(_alertCallback, res);
+ } else {
+ this->cb(_alertCallback, buttonId);
+ }
+ _alertCallback = 0;
+ }
+
+private:
+ QQmlComponent *_component;
+ int _alertCallback;
+};
+
+#endif
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/src/ubuntu/notification.qml
----------------------------------------------------------------------
diff --git a/src/ubuntu/notification.qml b/src/ubuntu/notification.qml
new file mode 100644
index 0000000..dc42b4b
--- /dev/null
+++ b/src/ubuntu/notification.qml
@@ -0,0 +1,44 @@
+import QtQuick 2.0
+import Ubuntu.Components.Popups 0.1
+import Ubuntu.Components 0.1
+
+Dialog {
+ id: dialogue
+ property string button1Text
+ property string button2Text
+ property string button3Text
+ property bool promptVisible
+ property string defaultPromptText
+ TextInput {// FIXME: swith to TextField(TextField should support visible property)
+ id: prompt
+ color: "white"
+ text: defaultPromptText
+ visible: promptVisible
+ focus: true
+ }
+ Button {
+ text: button1Text
+ color: "orange"
+ onClicked: {
+ root.exec("Notification", "notificationDialogButtonPressed", [1, prompt.text]);
+ PopupUtils.close(dialogue)
+ }
+ }
+ Button {
+ text: button2Text
+ visible: button2Text.length > 0
+ color: "orange"
+ onClicked: {
+ root.exec("Notification", "notificationDialogButtonPressed", [2, prompt.text]);
+ PopupUtils.close(dialogue)
+ }
+ }
+ Button {
+ text: button3Text
+ visible: button3Text.length > 0
+ onClicked: {
+ root.exec("Notification", "notificationDialogButtonPressed", [3, prompt.text]);
+ PopupUtils.close(dialogue)
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/55b096ac/www/notification.js
----------------------------------------------------------------------
diff --git a/www/notification.js b/www/notification.js
new file mode 100644
index 0000000..1c2c191
--- /dev/null
+++ b/www/notification.js
@@ -0,0 +1,109 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var exec = require('cordova/exec');
+var platform = require('cordova/platform');
+
+/**
+ * Provides access to notifications on the device.
+ */
+
+module.exports = {
+
+ /**
+ * Open a native alert dialog, with a customizable title and button text.
+ *
+ * @param {String} message Message to print in the body of the alert
+ * @param {Function} completeCallback The callback that is called when user clicks on a button.
+ * @param {String} title Title of the alert dialog (default: Alert)
+ * @param {String} buttonLabel Label of the close button (default: OK)
+ */
+ alert: function(message, completeCallback, title, buttonLabel) {
+ var _title = (title || "Alert");
+ var _buttonLabel = (buttonLabel || "OK");
+ exec(completeCallback, null, "Notification", "alert", [message, _title, _buttonLabel]);
+ },
+
+ /**
+ * Open a native confirm dialog, with a customizable title and button text.
+ * The result that the user selects is returned to the result callback.
+ *
+ * @param {String} message Message to print in the body of the alert
+ * @param {Function} resultCallback The callback that is called when user clicks on a button.
+ * @param {String} title Title of the alert dialog (default: Confirm)
+ * @param {Array} buttonLabels Array of the labels of the buttons (default: ['OK', 'Cancel'])
+ */
+ confirm: function(message, resultCallback, title, buttonLabels) {
+ var _title = (title || "Confirm");
+ var _buttonLabels = (buttonLabels || ["OK", "Cancel"]);
+
+ // Strings are deprecated!
+ if (typeof _buttonLabels === 'string') {
+ console.log("Notification.confirm(string, function, string, string) is deprecated. Use Notification.confirm(string, function, string, array).");
+ }
+
+ // Some platforms take an array of button label names.
+ // Other platforms take a comma separated list.
+ // For compatibility, we convert to the desired type based on the platform.
+ if (platform.id == "android" || platform.id == "ios" || platform.id == "windowsphone" || platform.id == "ubuntu") {
+ if (typeof _buttonLabels === 'string') {
+ var buttonLabelString = _buttonLabels;
+ _buttonLabels = _buttonLabels.split(","); // not crazy about changing the var type here
+ }
+ } else {
+ if (Array.isArray(_buttonLabels)) {
+ var buttonLabelArray = _buttonLabels;
+ _buttonLabels = buttonLabelArray.toString();
+ }
+ }
+ exec(resultCallback, null, "Notification", "confirm", [message, _title, _buttonLabels]);
+ },
+
+ /**
+ * Open a native prompt dialog, with a customizable title and button text.
+ * The following results are returned to the result callback:
+ * buttonIndex Index number of the button selected.
+ * input1 The text entered in the prompt dialog box.
+ *
+ * @param {String} message Dialog message to display (default: "Prompt message")
+ * @param {Function} resultCallback The callback that is called when user clicks on a button.
+ * @param {String} title Title of the dialog (default: "Prompt")
+ * @param {Array} buttonLabels Array of strings for the button labels (default: ["OK","Cancel"])
+ * @param {String} defaultText Textbox input value (default: "Default text")
+ */
+ prompt: function(message, resultCallback, title, buttonLabels, defaultText) {
+ var _message = (message || "Prompt message");
+ var _title = (title || "Prompt");
+ var _buttonLabels = (buttonLabels || ["OK","Cancel"]);
+ var _defaultText = (defaultText || "Default text");
+ exec(resultCallback, null, "Notification", "prompt", [_message, _title, _buttonLabels, _defaultText]);
+ },
+
+ /**
+ * Causes the device to beep.
+ * On Android, the default notification ringtone is played "count" times.
+ *
+ * @param {Integer} count The number of beeps.
+ */
+ beep: function(count) {
+ exec(null, null, "Notification", "beep", [count]);
+ }
+};