src/android/Notification.java
/**
     * 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.
     */
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.
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;
        Runnable runnable = new Runnable() {
            public void run() {
                final EditText promptInput =  new EditText(cordova.getActivity());
                /* CB-11677 - By default, prompt input text color is set according current theme.
                But for some android versions is not visible (for example 5.1.1).
                android.R.color.primary_text_light will make text visible on all versions. */
                Resources resources = cordova.getActivity().getResources();
                int promptInputTextColor = resources.getColor(android.R.color.primary_text_dark);
                promptInput.setTextColor(promptInputTextColor);
                promptInput.setText(defaultText);
                Builder dlg = createDialog(cordova); 
                dlg.setMessage(message);
                dlg.setTitle(title);
                dlg.setCancelable(true);
                dlg.setView(promptInput);
                final JSONObject result = new JSONObject();
                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) {
                                        LOG.d(LOG_TAG,"JSONException on first button.", e);
                                    }
                                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                                }
                            });
                    } catch (JSONException e) {
                        LOG.d(LOG_TAG,"JSONException on first 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) {
                                        LOG.d(LOG_TAG,"JSONException on second button.", e);
                                    }
                                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                                }
                            });
                    } catch (JSONException e) {
                        LOG.d(LOG_TAG,"JSONException on second 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) {
                                        LOG.d(LOG_TAG,"JSONException on third button.", e);
                                    }
                                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result));
                                }
                            });
                    } catch (JSONException e) {
                        LOG.d(LOG_TAG,"JSONException on third button.");
                    }
                }
                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));
                    }
                });
                changeTextDirection(dlg);
            };
        };
        this.cordova.getActivity().runOnUiThread(runnable);
    }
public synchronized void prompt ( final String message , final String title , final JSONArray buttonLabels , final String defaultText , final CallbackContext callbackContext ) { final CordovaInterface cordova = this . cordova ; Runnable runnable = new Runnable ( ) { public void run ( ) { final EditText promptInput = new EditText ( cordova . getActivity ( ) ) ; /* CB-11677 - By default, prompt input text color is set according current theme.
                But for some android versions is not visible (for example 5.1.1).
                android.R.color.primary_text_light will make text visible on all versions. */ Resources resources = cordova . getActivity ( ) . getResources ( ) ; int promptInputTextColor = resources . getColor ( android . R . color . primary_text_dark ) ; promptInput . setTextColor ( promptInputTextColor ) ; promptInput . setText ( defaultText ) ; Builder dlg = createDialog ( cordova ) ; dlg . setMessage ( message ) ; dlg . setTitle ( title ) ; dlg . setCancelable ( true ) ; dlg . setView ( promptInput ) ; final JSONObject result = new JSONObject ( ) ; 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 ) { LOG . d ( LOG_TAG , "JSONException on first button." , e ) ; } callbackContext . sendPluginResult ( new PluginResult ( PluginResult . Status . OK , result ) ) ; } } ) ; } catch ( JSONException e ) { LOG . d ( LOG_TAG , "JSONException on first 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 ) { LOG . d ( LOG_TAG , "JSONException on second button." , e ) ; } callbackContext . sendPluginResult ( new PluginResult ( PluginResult . Status . OK , result ) ) ; } } ) ; } catch ( JSONException e ) { LOG . d ( LOG_TAG , "JSONException on second 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 ) { LOG . d ( LOG_TAG , "JSONException on third button." , e ) ; } callbackContext . sendPluginResult ( new PluginResult ( PluginResult . Status . OK , result ) ) ; } } ) ; } catch ( JSONException e ) { LOG . d ( LOG_TAG , "JSONException on third button." ) ; } } 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 ) ) ; } } ) ; changeTextDirection ( dlg ) ; } ; } ; this . cordova . getActivity ( ) . runOnUiThread ( runnable ) ; }
Builds and shows a native Android prompt dialog with given title, message, buttons.
Builds and shows a native Android prompt dialog with given title message buttons .
// new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_DARK); // First button // Second button // Third button