Search in sources :

Example 1 with CordovaInterface

use of org.apache.cordova.api.CordovaInterface in project cordova-android-chromeview by thedracle.

the class Notification method activityStart.

/**
     * 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);
}
Also used : CordovaInterface(org.apache.cordova.api.CordovaInterface) DialogInterface(android.content.DialogInterface)

Example 2 with CordovaInterface

use of org.apache.cordova.api.CordovaInterface in project cordova-android-chromeview by thedracle.

the class Notification method alert.

/**
     * 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);
}
Also used : AlertDialog(android.app.AlertDialog) CordovaInterface(org.apache.cordova.api.CordovaInterface) PluginResult(org.apache.cordova.api.PluginResult) DialogInterface(android.content.DialogInterface)

Example 3 with CordovaInterface

use of org.apache.cordova.api.CordovaInterface in project cordova-android-chromeview by thedracle.

the class Notification method progressStart.

/**
     * 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);
}
Also used : CordovaInterface(org.apache.cordova.api.CordovaInterface) DialogInterface(android.content.DialogInterface) ProgressDialog(android.app.ProgressDialog)

Example 4 with CordovaInterface

use of org.apache.cordova.api.CordovaInterface in project cordova-android-chromeview by thedracle.

the class Notification method confirm.

/**
     * 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);
}
Also used : AlertDialog(android.app.AlertDialog) CordovaInterface(org.apache.cordova.api.CordovaInterface) PluginResult(org.apache.cordova.api.PluginResult) DialogInterface(android.content.DialogInterface) JSONException(org.json.JSONException)

Example 5 with CordovaInterface

use of org.apache.cordova.api.CordovaInterface in project cordova-android-chromeview by thedracle.

the class Notification method prompt.

/**
     * 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);
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) PluginResult(org.apache.cordova.api.PluginResult) DialogInterface(android.content.DialogInterface) JSONException(org.json.JSONException) CordovaInterface(org.apache.cordova.api.CordovaInterface) JSONObject(org.json.JSONObject)

Aggregations

DialogInterface (android.content.DialogInterface)5 CordovaInterface (org.apache.cordova.api.CordovaInterface)5 AlertDialog (android.app.AlertDialog)3 PluginResult (org.apache.cordova.api.PluginResult)3 JSONException (org.json.JSONException)2 ProgressDialog (android.app.ProgressDialog)1 EditText (android.widget.EditText)1 JSONObject (org.json.JSONObject)1