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:id.nci.stm_9.LookupUnknownKeyDialogFragment.java

/**
 * Creates dialog/*from   ww  w  .ja v  a2 s .  c  o 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_unknown_signature_key);
    alert.setMessage(getString(R.string.lookup_unknown_key, PgpKeyHelper.convertKeyIdToHex(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);
            startActivityForResult(intent, 0x00007006);
        }
    });
    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:org.catrobat.catroid.ui.fragment.ScriptFragment.java

private void showConfirmDeleteDialog(boolean fromContextMenu) {
    this.deleteScriptFromContextMenu = fromContextMenu;
    int titleId;//www. java2s  . co m
    if ((deleteScriptFromContextMenu && scriptToEdit.getBrickList().size() == 0)
            || adapter.getAmountOfCheckedItems() == 1) {
        titleId = R.string.dialog_confirm_delete_brick_title;
    } else {
        titleId = R.string.dialog_confirm_delete_multiple_bricks_title;
    }

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());
    builder.setTitle(titleId);
    builder.setMessage(R.string.dialog_confirm_delete_brick_message);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (deleteScriptFromContextMenu) {
                adapter.handleScriptDelete(sprite, scriptToEdit);
            } else {
                deleteCheckedBricks();
                clearCheckedBricksAndEnableButtons();
            }
        }
    });
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (!deleteScriptFromContextMenu) {
                clearCheckedBricksAndEnableButtons();
            }
        }
    });

    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:hku.fyp14017.blencode.ui.fragment.ScriptFragment.java

private void showConfirmDeleteDialog(boolean fromContextMenu) {
    this.deleteScriptFromContextMenu = fromContextMenu;
    int titleId;//  w  ww.ja v a  2 s. com
    if ((deleteScriptFromContextMenu && scriptToEdit.getBrickList().size() == 0)
            || adapter.getAmountOfCheckedItems() == 1) {
        titleId = hku.fyp14017.blencode.R.string.dialog_confirm_delete_brick_title;
    } else {
        titleId = hku.fyp14017.blencode.R.string.dialog_confirm_delete_multiple_bricks_title;
    }

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());
    builder.setTitle(titleId);
    builder.setMessage(hku.fyp14017.blencode.R.string.dialog_confirm_delete_brick_message);
    builder.setPositiveButton(hku.fyp14017.blencode.R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (deleteScriptFromContextMenu) {
                adapter.handleScriptDelete(sprite, scriptToEdit);
            } else {
                deleteCheckedBricks();
                clearCheckedBricksAndEnableButtons();
            }
        }
    });
    builder.setNegativeButton(hku.fyp14017.blencode.R.string.no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();

        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (!deleteScriptFromContextMenu) {
                clearCheckedBricksAndEnableButtons();
            }
        }
    });

    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:com.googlecode.android_scripting.ZipExtractorTask.java

private Replace showDialog(final String name) {
    final FutureResult<Replace> mResult = new FutureResult<Replace>();

    MainThread.run(mContext, new Runnable() {
        @Override/*from   w w w.j  a  v a2  s .  c o  m*/
        public void run() {
            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(String.format("Script \"%s\" already exist.", name));
            builder.setMessage(String.format("Do you want to replace script \"%s\" ?", name));

            DialogInterface.OnClickListener buttonListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Replace result = Replace.SKIPALL;
                    switch (which) {
                    case DialogInterface.BUTTON_POSITIVE:
                        result = Replace.YES;
                        break;
                    case DialogInterface.BUTTON_NEGATIVE:
                        result = Replace.NO;
                        break;
                    case DialogInterface.BUTTON_NEUTRAL:
                        result = Replace.YESTOALL;
                        break;
                    }
                    mResult.set(result);
                    dialog.dismiss();
                }
            };
            builder.setNegativeButton("Skip", buttonListener);
            builder.setPositiveButton("Replace", buttonListener);
            builder.setNeutralButton("Replace All", buttonListener);

            builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    mResult.set(Replace.SKIPALL);
                    dialog.dismiss();
                }
            });
            builder.show();
        }
    });

    try {
        return mResult.get();
    } catch (InterruptedException e) {
        Log.e(e);
    }
    return null;
}

From source file:hku.fyp14017.blencode.ui.fragment.LookFragment.java

private void showConfirmDeleteDialog() {
    int titleId;/*from   w  w w.j  ava 2  s  . com*/
    if (adapter.getAmountOfCheckedItems() == 1) {
        titleId = hku.fyp14017.blencode.R.string.dialog_confirm_delete_look_title;
    } else {
        titleId = hku.fyp14017.blencode.R.string.dialog_confirm_delete_multiple_looks_title;
    }

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());
    builder.setTitle(titleId);
    builder.setMessage(hku.fyp14017.blencode.R.string.dialog_confirm_delete_look_message);
    builder.setPositiveButton(hku.fyp14017.blencode.R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            LookController.getInstance().deleteCheckedLooks(adapter, lookDataList, getActivity());
            clearCheckedLooksAndEnableButtons();
        }
    });
    builder.setNegativeButton(hku.fyp14017.blencode.R.string.no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

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

    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:org.catrobat.catroid.ui.fragment.LookFragment.java

private void showConfirmDeleteDialog() {
    int titleId;//w w  w  . j  a v  a2 s . c  o  m
    if (adapter.getAmountOfCheckedItems() == 1) {
        titleId = R.string.dialog_confirm_delete_look_title;
    } else {
        titleId = R.string.dialog_confirm_delete_multiple_looks_title;
    }

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());
    builder.setTitle(titleId);
    builder.setMessage(R.string.dialog_confirm_delete_look_message);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            LookController.getInstance().deleteCheckedLooks(adapter, lookDataList, getActivity());
            clearCheckedLooksAndEnableButtons();
        }
    });
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

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

    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:com.efithealth.app.activity.MainActivity.java

@Override
protected void onResume() {
    super.onResume();
    if (MyApplication.getInstance().getMemid().equals("")) {
        AlertDialog.Builder builder = new Builder(MainActivity.this);
        builder.setTitle("????");
        builder.setMessage("???");
        builder.setPositiveButton("", new OnClickListener() {

            @Override// ww w . j a v  a  2 s . co m
            public void onClick(DialogInterface arg0, int arg1) {
                showWarning();
            }
        });
        builder.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(DialogInterface arg0) {
                showWarning();
            }
        });
        builder.create();
        builder.show();
    }
    if (!isConflict && !isCurrentAccountRemoved) {
        updateUnreadLabel();
        // updateUnreadAddressLable();
        EMChatManager.getInstance().activityResumed();
    }

    // unregister this event listener when this activity enters the
    // background
    DemoHXSDKHelper sdkHelper = (DemoHXSDKHelper) DemoHXSDKHelper.getInstance();
    sdkHelper.pushActivity(this);

    // register the event listener when enter the foreground
    EMChatManager.getInstance().registerEventListener(this,
            new EMNotifierEvent.Event[] { EMNotifierEvent.Event.EventNewMessage,
                    EMNotifierEvent.Event.EventOfflineMessage,
                    EMNotifierEvent.Event.EventConversationListChanged });
}

From source file:hku.fyp14017.blencode.ui.fragment.SoundFragment.java

private void showConfirmDeleteDialog() {
    int titleId;/*from   w  w  w  .  j a  va2 s .  c o m*/
    if (adapter.getAmountOfCheckedItems() == 1) {
        titleId = hku.fyp14017.blencode.R.string.dialog_confirm_delete_sound_title;
    } else {
        titleId = hku.fyp14017.blencode.R.string.dialog_confirm_delete_multiple_sounds_title;
    }

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());
    builder.setTitle(titleId);
    builder.setMessage(hku.fyp14017.blencode.R.string.dialog_confirm_delete_sound_message);
    builder.setPositiveButton(hku.fyp14017.blencode.R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            SoundController.getInstance().deleteCheckedSounds(getActivity(), adapter, soundInfoList,
                    mediaPlayer);
            clearCheckedSoundsAndEnableButtons();
        }
    });
    builder.setNegativeButton(hku.fyp14017.blencode.R.string.no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();

        }
    });

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {

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

    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

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

/**
 * @return a Dialog with a list of items, one of them possibly pre-selected.
 *//*from  w w  w  .  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();
    builder.setTitle(arguments.getString(DialogFragmentFactory.EXTRA_TITLE));
    final int actionId = arguments.getInt(DialogFragmentFactory.EXTRA_ACTION_ID);
    int selectedItem = arguments.getInt(DialogFragmentFactory.EXTRA_SELECTED_ITEM);
    final CharSequence[] choices = arguments.getCharSequenceArray(DialogFragmentFactory.EXTRA_CHOICES);
    OnClickListener listener = null;
    final AtomicBoolean hasClicked = new AtomicBoolean(false);
    if (getActivity() instanceof DialogItemListener) {
        listener = 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 if (hasClicked.get()) {
                    Log.w(TAG, "User already clicked once on this dialog! Monkey?");
                } else {
                    hasClicked.set(true);
                    ((DialogItemListener) activity).onItemSelected(actionId, choices, which);
                }
            }
        };
    }
    // If one item is to be pre-selected, use the single choice items layout.
    if (selectedItem >= 0)
        builder.setSingleChoiceItems(choices, selectedItem, listener);
    // If no particular item is to be pre-selected, use the default list item layout.
    else
        builder.setItems(choices, listener);

    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:de.langerhans.wallet.ui.ImportKeysQrFragment.java

private void importPrivateKeys(final List<ECKey> keys) {
    final int numKeysToImport = keys.size();
    final int numKeysImported = wallet.addKeys(keys);

    final AlertDialog.Builder dialog = new AlertDialog.Builder(activity);
    dialog.setInverseBackgroundForced(true);
    final StringBuilder message = new StringBuilder();
    if (numKeysImported > 0)
        message.append(getString(R.string.import_keys_dialog_success_imported, numKeysImported));
    if (numKeysImported < numKeysToImport) {
        if (message.length() > 0)
            message.append('\n');
        message.append(/*from   w w  w .ja v  a2 s . c  o  m*/
                getString(R.string.import_keys_dialog_success_existing, numKeysToImport - numKeysImported));
    }
    if (numKeysImported > 0) {
        if (message.length() > 0)
            message.append("\n\n");
        message.append(getString(R.string.import_keys_dialog_success_reset));
    }
    dialog.setMessage(message);
    if (numKeysImported > 0) {
        dialog.setPositiveButton(R.string.import_keys_dialog_button_reset_blockchain,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        application.resetBlockchain();
                        activity.finish();
                    }
                });
        dialog.setNegativeButton(R.string.button_dismiss, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int id) {
                activity.finish();
            }
        });
    } else {
        dialog.setNeutralButton(R.string.button_dismiss, null);
    }
    dialog.setOnCancelListener(null);
    dialog.show();

    log.info("imported " + numKeysImported + " of " + numKeysToImport + " private keys");
}