Java Code Examples for androidx.appcompat.app.AlertDialog#setOnDismissListener()

The following examples show how to use androidx.appcompat.app.AlertDialog#setOnDismissListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GroupMembersDialog.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
public void display() {
  AlertDialog dialog = new AlertDialog.Builder(fragmentActivity)
                                      .setTitle(R.string.ConversationActivity_group_members)
                                      .setIconAttribute(R.attr.group_members_dialog_icon)
                                      .setCancelable(true)
                                      .setView(R.layout.dialog_group_members)
                                      .setPositiveButton(android.R.string.ok, null)
                                      .show();

  GroupMemberListView memberListView = dialog.findViewById(R.id.list_members);

  LiveGroup                                   liveGroup   = new LiveGroup(groupRecipient.requireGroupId());
  LiveData<List<GroupMemberEntry.FullMember>> fullMembers = liveGroup.getFullMembers();

  //noinspection ConstantConditions
  fullMembers.observe(fragmentActivity, memberListView::setMembers);

  dialog.setOnDismissListener(d -> fullMembers.removeObservers(fragmentActivity));

  memberListView.setRecipientClickListener(recipient -> {
    dialog.dismiss();
    contactClick(recipient);
  });
}
 
Example 2
Source File: CrashReportActivity.java    From Easy_xkcd with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);

    ThemePrefs themePrefs = new ThemePrefs(this);

    setTheme(themePrefs.getNewTheme());

    final AlertDialog dialog = new AlertDialog.Builder(this)
            .setTitle(R.string.crash_dialog_title)
            .setView(R.layout.crash_report_dialog)
            .setPositiveButton(R.string.crash_ok, this)
            .setNegativeButton(R.string.crash_cancel, this)
            .create();

    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnDismissListener(this);
    dialog.show();

    comment = dialog.findViewById(android.R.id.input);
    if (savedInstanceState != null) {
        comment.setText(savedInstanceState.getString(STATE_COMMENT));
    }
}
 
Example 3
Source File: CheckConnectionDialogFragment.java    From PresencePublisher with MIT License 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
    builder.setTitle(R.string.dialog_check_connection_title)
            .setMessage(R.string.dialog_check_connection_summary_waiting)
            .setNeutralButton(R.string.dialog_cancel, null);

    AlertDialog alertDialog = builder.create();
    Future<?> future = executorService.submit(new ConnectionTestWorker(alertDialog));
    alertDialog.setOnDismissListener(dialog -> future.cancel(true));
    return alertDialog;
}
 
Example 4
Source File: GalleryPreviewsScene.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
public void setDialog(@NonNull AlertDialog dialog) {
    mDialog = dialog;

    ((TextView) ViewUtils.$$(dialog, R.id.start)).setText(String.format(Locale.US, "%d", 1));
    ((TextView) ViewUtils.$$(dialog, R.id.end)).setText(String.format(Locale.US, "%d", mPages));
    mSlider = (Slider) ViewUtils.$$(dialog, R.id.slider);
    mSlider.setRange(1, mPages);
    mSlider.setProgress(mCurrentPage + 1);

    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this);
    dialog.setOnDismissListener(this);
}
 
Example 5
Source File: DialogPreference.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the dialog associated with this Preference. This is normally initiated
 * automatically on clicking on the preference. Call this method if you need to
 * show the dialog on some other event.
 *
 * @param state Optional instance state to restore on the dialog
 */
protected void showDialog(Bundle state) {
    Context context = getContext();

    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;

    mBuilder = new AlertDialog.Builder(context)
            .setTitle(mDialogTitle)
            .setIcon(mDialogIcon)
            .setPositiveButton(mPositiveButtonText, this)
            .setNegativeButton(mNegativeButtonText, this);

    View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        mBuilder.setView(contentView);
    }

    onPrepareDialogBuilder(mBuilder);

    PreferenceUtils.registerOnActivityDestroyListener(this, this);

    // Create the dialog
    final AlertDialog dialog = mDialog = mBuilder.create();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    if (needInputMethod()) {
        requestInputMethod(dialog);
    }
    dialog.setOnDismissListener(this);
    dialog.show();

    onDialogCreated(dialog);
}
 
Example 6
Source File: AppCompatDialogManager.java    From AndroidRate with MIT License 5 votes vote down vote up
/**
 * <p>Creates Rate Dialog.</p>
 *
 * @return created dialog
 */
@Nullable
@Override
@RequiresApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public Dialog createDialog() {

    AlertDialog.Builder builder = getAppCompatDialogBuilder(context, dialogOptions.getThemeResId());
    Context dialogContext = builder.getContext();

    final View view = dialogOptions.getView(dialogContext);

    if ((dialogOptions.getType() == CLASSIC) || (view == null)) {
        if (dialogOptions.getType() != CLASSIC) {
            builder = getAppCompatDialogBuilder(context, 0);
            dialogContext = builder.getContext();
        }
        supplyAppCompatClassicDialogArguments(builder, dialogContext);
    } else {
        supplyNonClassicDialogArguments(view, dialogContext);
    }

    final AlertDialog alertDialog = builder
            .setCancelable(dialogOptions.getCancelable())
            .setView(view)
            .create();

    alertDialog.setOnShowListener(showListener);
    alertDialog.setOnDismissListener(dismissListener);

    return alertDialog;
}
 
Example 7
Source File: DCCManager.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
private void showDialog(AlertDialog dialog) {
    if (mCurrentDialog != null)
        mCurrentDialog.dismiss();
    mCurrentDialog = dialog;
    dialog.setOnDismissListener((DialogInterface i) -> {
        mCurrentDialog = null;
        showDialogsIfNeeded();
    });
    dialog.show();
}
 
Example 8
Source File: RxAlertDialog.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public RxAlertDialog build() {
  final AlertDialog dialog = builder.create();
  final CancelEvent cancelEvent = new CancelEvent(PublishRelay.create());
  final DismissEvent dismissEvent = new DismissEvent(PublishRelay.create());
  dialog.setOnCancelListener(cancelEvent);
  dialog.setOnDismissListener(dismissEvent);
  return new RxAlertDialog(dialog, view, positiveClick, negativeClick, cancelEvent,
      dismissEvent);
}
 
Example 9
Source File: GalleryPreviewsScene.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
public void setDialog(@NonNull AlertDialog dialog) {
    mDialog = dialog;

    ((TextView) ViewUtils.$$(dialog, R.id.start)).setText(String.format(Locale.US, "%d", 1));
    ((TextView) ViewUtils.$$(dialog, R.id.end)).setText(String.format(Locale.US, "%d", mPages));
    mSlider = (Slider) ViewUtils.$$(dialog, R.id.slider);
    mSlider.setRange(1, mPages);
    mSlider.setProgress(mCurrentPage + 1);

    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(this);
    dialog.setOnDismissListener(this);
}
 
Example 10
Source File: DialogPreference.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
/**
 * Shows the dialog associated with this Preference. This is normally initiated
 * automatically on clicking on the preference. Call this method if you need to
 * show the dialog on some other event.
 *
 * @param state Optional instance state to restore on the dialog
 */
protected void showDialog(Bundle state) {
    Context context = getContext();

    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;

    mBuilder = new AlertDialog.Builder(context)
            .setTitle(mDialogTitle)
            .setIcon(mDialogIcon)
            .setPositiveButton(mPositiveButtonText, this)
            .setNegativeButton(mNegativeButtonText, this);

    View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        mBuilder.setView(contentView);
    }

    onPrepareDialogBuilder(mBuilder);

    PreferenceUtils.registerOnActivityDestroyListener(this, this);

    // Create the dialog
    final AlertDialog dialog = mDialog = mBuilder.create();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    if (needInputMethod()) {
        requestInputMethod(dialog);
    }
    dialog.setOnDismissListener(this);
    dialog.show();

    onDialogCreated(dialog);
}
 
Example 11
Source File: LicensesDialog.java    From LicensesDialog with Apache License 2.0 5 votes vote down vote up
public Dialog create() {
    //Get resources
    final WebView webView = createWebView(mContext);
    webView.loadDataWithBaseURL(null, mLicensesText, "text/html", "utf-8", null);
    final AlertDialog.Builder builder;
    if (mThemeResourceId != 0) {
        builder = new AlertDialog.Builder(new ContextThemeWrapper(mContext, mThemeResourceId));
    } else {
        builder = new AlertDialog.Builder(mContext);
    }
    builder.setTitle(mTitleText)
        .setView(webView)
        .setPositiveButton(mCloseText, (dialogInterface, i) -> dialogInterface.dismiss());
    final AlertDialog dialog = builder.create();
    dialog.setOnDismissListener(dialog1 -> {
        if (mOnDismissListener != null) {
            mOnDismissListener.onDismiss(dialog1);
        }
    });
    dialog.setOnShowListener(dialogInterface -> {
        if (mDividerColor != 0) {
            // Set title divider color
            final int titleDividerId = mContext.getResources().getIdentifier("titleDivider", "id", "android");
            final View titleDivider = dialog.findViewById(titleDividerId);
            if (titleDivider != null) {
                titleDivider.setBackgroundColor(mDividerColor);
            }
        }
    });
    return dialog;
}
 
Example 12
Source File: XmppActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("InflateParams")
private void quickEdit(final String previousValue,
                       final OnValueEdited callback,
                       final @StringRes int hint,
                       boolean password,
                       boolean permitEmpty) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_quickedit, null, false);
    if (password) {
        binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    builder.setPositiveButton(R.string.accept, null);
    if (hint != 0) {
        binding.inputLayout.setHint(getString(hint));
    }
    binding.inputEditText.requestFocus();
    if (previousValue != null) {
        binding.inputEditText.getText().append(previousValue);
    }
    builder.setView(binding.getRoot());
    builder.setNegativeButton(R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(binding.inputEditText));
    dialog.show();
    View.OnClickListener clickListener = v -> {
        String value = binding.inputEditText.getText().toString();
        if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) {
            String error = callback.onValueEdited(value);
            if (error != null) {
                binding.inputLayout.setError(error);
                return;
            }
        }
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
        dialog.dismiss();
    };
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener((v -> {
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
        dialog.dismiss();
    }));
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnDismissListener(dialog1 -> {
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
    });
}