Example usage for android.app AlertDialog.Builder setOnCancelListener

List of usage examples for android.app AlertDialog.Builder setOnCancelListener

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setOnCancelListener.

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:com.remobile.dialogs.Notification.java

/**
 * 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
 *//*  w w  w .  ja v a2s . c  o m*/
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {
    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = createDialog(); // new AlertDialog.Builder(this.cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);
            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));
                }
            });

            changeTextDirection(dlg);
        }

        ;
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.abc.driver.PersonalActivity.java

private void doCrop() {
    Log.d(TAG, "doCrop()");
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0);

    int size = list.size();

    if (size == 0) {
        Log.d(TAG, " Crop activity is not found.  List size is zero.");
        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        app.setPortaritBitmap(Bitmap.createScaledBitmap(tmpBmp, CellSiteConstants.IMAGE_WIDTH,
                CellSiteConstants.IMAGE_HEIGHT, false));

        mUserPortraitIv.setImageBitmap(app.getPortaritBitmap());
        isPortraitChanged = true;//from  w  ww . j  a va  2s .com

        Log.d(TAG, "set bitmap");

        return;
    } else {
        Log.d(TAG, "found the crop activity.");
        intent.setData(imageUri);

        intent.putExtra("outputX", CellSiteConstants.IMAGE_WIDTH);
        intent.putExtra("outputY", CellSiteConstants.IMAGE_HEIGHT);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Log.d(TAG, "Just one as choose it as crop activity.");
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);
            i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CellSiteConstants.CROP_PICTURE);
        } else {
            Log.d(TAG, "More that one activity for crop  is found . will chooose one");
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");

            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE);
                }
            });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                // @Override
                public void onCancel(DialogInterface dialog) {
                    if (imageUri != null) {
                        getContentResolver().delete(imageUri, null, null);
                        imageUri = null;
                        isPortraitChanged = false;
                    }
                }
            });
            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}

From source file:loon.LGame.java

/**
 * /*from w  ww. j  a v  a  2s  . c  o  m*/
 * 
 * @param listener
 * @param title
 * @param message
 */
public void showAndroidTextInput(final TextEvent listener, final String title, final String message) {
    if (listener == null) {
        return;
    }
    final AndroidViewTools.ClickAndroid OK = new AndroidViewTools.ClickAndroid(listener, 0);
    final AndroidViewTools.ClickAndroid CANCEL = new AndroidViewTools.ClickAndroid(listener, 1);
    android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(LGame.this);
    builder.setTitle(title);
    final android.widget.EditText input = new android.widget.EditText(LGame.this);
    input.setText(message);
    input.setSingleLine();
    OK.setInput(input);
    builder.setView(input);
    builder.setPositiveButton("Ok", OK);
    builder.setOnCancelListener(CANCEL);
    builder.show();
}

From source file:com.abc.driver.TruckActivity.java

private void doCrop() {
    Log.d(TAG, "doCrop()");
    final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();

    Intent intent = new Intent("com.android.camera.action.CROP");
    intent.setType("image/*");

    List<ResolveInfo> list = this.getPackageManager().queryIntentActivities(intent, 0);

    int size = list.size();

    if (size == 0) {
        Log.d(TAG, " Crop activity is not found.  List size is zero.");
        Bitmap tmpBmp = BitmapFactory.decodeFile(imageUri.getPath(), null);
        trcukLicenseBmp = Bitmap.createScaledBitmap(tmpBmp, IMAGE_WIDTH, IMAGE_HEIGHT, false);

        mTLPiv.setImageBitmap(trcukLicenseBmp);
        isPortraitChanged = true;/*from   w  w  w.  j  av  a  2 s  .co  m*/

        Log.d(TAG, "set bitmap");

        return;
    } else {
        Log.d(TAG, "found the crop activity.");
        intent.setData(imageUri);

        intent.putExtra("outputX", IMAGE_WIDTH);
        intent.putExtra("outputY", IMAGE_HEIGHT);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);

        if (size == 1) {
            Log.d(TAG, "Just one as choose it as crop activity.");
            Intent i = new Intent(intent);
            ResolveInfo res = list.get(0);
            i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

            startActivityForResult(i, CellSiteConstants.CROP_PICTURE);
        } else {
            Log.d(TAG, "More that one activity for crop  is found . will chooose one");
            for (ResolveInfo res : list) {
                final CropOption co = new CropOption();

                co.title = getPackageManager().getApplicationLabel(res.activityInfo.applicationInfo);
                co.icon = getPackageManager().getApplicationIcon(res.activityInfo.applicationInfo);
                co.appIntent = new Intent(intent);

                co.appIntent
                        .setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));

                cropOptions.add(co);
            }

            CropOptionAdapter adapter = new CropOptionAdapter(getApplicationContext(), cropOptions);

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Choose Crop App");

            builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    startActivityForResult(cropOptions.get(item).appIntent, CellSiteConstants.CROP_PICTURE);
                }
            });

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                // @Override
                public void onCancel(DialogInterface dialog) {
                    if (imageUri != null) {
                        getContentResolver().delete(imageUri, null, null);
                        imageUri = null;
                        isPortraitChanged = false;
                    }
                }
            });
            AlertDialog alert = builder.create();

            alert.show();
        }
    }
}

From source file:com.gsma.rcs.ri.messaging.OneToOneTalkView.java

private AlertDialog popUpDeliveryExpiration(Context ctx, String title, String msg,
        DialogInterface.OnClickListener onPositiveClickListener,
        DialogInterface.OnClickListener onNegativeClickListener,
        DialogInterface.OnCancelListener onCancelListener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setMessage(msg);/*from   www  . ja v  a2  s  .  c o  m*/
    builder.setTitle(title);
    if (onNegativeClickListener != null) {
        builder.setNegativeButton(R.string.label_cancel, onNegativeClickListener);
    }
    builder.setPositiveButton(R.string.label_ok, onPositiveClickListener);
    builder.setOnCancelListener(onCancelListener);
    return builder.show();
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

private String getInputFromAlertDialog(final String title, final String message, final boolean password) {
    final FutureActivityTask<String> task = new FutureActivityTask<String>() {
        @Override/*from www .j  ava2s .  c  o m*/
        public void onCreate() {
            super.onCreate();
            final EditText input = new EditText(getActivity());
            if (password) {
                input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
                input.setTransformationMethod(new PasswordTransformationMethod());
            }
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setTitle(title);
            alert.setMessage(message);
            alert.setView(input);
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.dismiss();
                    setResult(input.getText().toString());
                    finish();
                }
            });
            alert.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    setResult(null);
                    finish();
                }
            });
            alert.show();
        }
    };
    mTaskQueue.execute(task);

    try {
        return task.getResult();
    } catch (Exception e) {
        Log.e("Failed to display dialog.", e);
        throw new RuntimeException(e);
    }
}

From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java

/**
 * ??Select/*  ww  w  .ja  va  2  s.com*/
 * 
 * @param title
 * @param text
 * @return
 */
public int showAndroidSelect(final String title, final String text[]) {
    Runnable showSelect = new Runnable() {
        public void run() {
            final AlertDialog.Builder builder = new AlertDialog.Builder(LGameAndroid2DActivity.this);
            builder.setTitle(title);
            builder.setItems(text, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {
                    androidSelect = item;
                }
            });
            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    androidSelect = -1;
                }
            });
            AlertDialog alert = builder.create();
            alert.show();
        }
    };
    runOnUiThread(showSelect);
    return androidSelect;
}

From source file:org.sufficientlysecure.keychain.ui.dialog.LookupUnknownKeyDialogFragment.java

/**
 * Creates dialog//from   w ww .  ja v  a  2 s . co  m
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    final long unknownKeyId = getArguments().getLong(ARG_UNKNOWN_KEY_ID);
    mMessenger = getArguments().getParcelable(ARG_MESSENGER);

    AlertDialog.Builder alert = new AlertDialog.Builder(activity);

    alert.setIcon(android.R.drawable.ic_dialog_alert);
    alert.setTitle(R.string.title_unknownSignatureKey);
    alert.setMessage(getString(R.string.lookupUnknownKey, PgpHelper.getSmallFingerPrint(unknownKeyId)));

    alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();

            sendMessageToHandler(MESSAGE_OKAY);

            Intent intent = new Intent(activity, KeyServerQueryActivity.class);
            intent.setAction(KeyServerQueryActivity.ACTION_LOOK_UP_KEY_ID);
            intent.putExtra(KeyServerQueryActivity.EXTRA_KEY_ID, unknownKeyId);
            startActivityForResult(intent, Id.request.look_up_key_id);
        }
    });
    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int id) {
            dismiss();

            sendMessageToHandler(MESSAGE_CANCEL);
        }
    });
    alert.setCancelable(true);
    alert.setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            sendMessageToHandler(MESSAGE_CANCEL);
        }
    });

    return alert.create();
}

From source file:ca.rmen.android.networkmonitor.app.dialog.InfoDialogFragment.java

/**
 * @return a Dialog with a title, message, and single button to dismiss the dialog.
 *//*from   www .j a v  a  2 s  .  c  o  m*/
@Override
@NonNull
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Log.v(TAG, "onCreateDialog: savedInstanceState = " + savedInstanceState);
    Context context = getActivity();
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    Bundle arguments = getArguments();
    final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID);
    final int iconId = arguments.getInt(DialogFragmentFactory.EXTRA_ICON_ID);
    if (iconId > 0)
        builder.setIcon(iconId);
    final Bundle extras = arguments.getBundle(DialogFragmentFactory.EXTRA_EXTRAS);
    builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE))
            .setMessage(arguments.getString(DialogFragmentFactory.EXTRA_MESSAGE));
    if (getActivity() instanceof InfoDialogListener) {
        OnClickListener neutralListener = new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                FragmentActivity activity = getActivity();
                if (activity == null)
                    Log.w(TAG, "User clicked on dialog after it was detached from activity. Monkey?");
                else
                    ((InfoDialogListener) activity).onNeutralClicked(actionId, extras);
            }
        };
        builder.setNeutralButton(android.R.string.ok, neutralListener);
    }
    if (getActivity() instanceof OnCancelListener)
        builder.setOnCancelListener((OnCancelListener) getActivity());
    final Dialog dialog = builder.create();
    if (getActivity() instanceof OnDismissListener)
        dialog.setOnDismissListener((OnDismissListener) getActivity());
    return dialog;
}

From source file:hu.fnf.devel.atlas.Atlas.java

private void configureAtlasFirst() {
    AlertDialog.Builder confwindow = new AlertDialog.Builder(this);

    confwindow.setTitle(getResources().getString(R.string.atlas_configuiration));
    confwindow.setMessage(getResources().getString(R.string.please_provide_data));

    View input = getLayoutInflater().inflate(R.layout.config_view, null);

    confwindow.setView(input);/*w  ww. jav  a  2s .  c om*/
    confwindow.setOnCancelListener(AtlasData.getCancelListener(this));
    dialog = confwindow.create();
    dialog.show();
}