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

The following examples show how to use androidx.appcompat.app.AlertDialog#setOnShowListener() . 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: HostsActivity.java    From EhViewer with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_hosts, null, false);
  host = view.findViewById(R.id.host);
  ip = view.findViewById(R.id.ip);

  Bundle arguments = getArguments();
  if (savedInstanceState == null && arguments != null) {
    host.setText(arguments.getString(KEY_HOST));
    ip.setText(arguments.getString(KEY_IP));
  }

  AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setView(view);
  onCreateDialogBuilder(builder);
  AlertDialog dialog = builder.create();
  dialog.setOnShowListener(d -> onCreateDialog((AlertDialog) d));

  return dialog;
}
 
Example 2
Source File: HostsActivity.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
  View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_hosts, null, false);
  host = view.findViewById(R.id.host);
  ip = view.findViewById(R.id.ip);

  Bundle arguments = getArguments();
  if (savedInstanceState == null && arguments != null) {
    host.setText(arguments.getString(KEY_HOST));
    ip.setText(arguments.getString(KEY_IP));
  }

  AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).setView(view);
  onCreateDialogBuilder(builder);
  AlertDialog dialog = builder.create();
  dialog.setOnShowListener(d -> onCreateDialog((AlertDialog) d));

  return dialog;
}
 
Example 3
Source File: AppAlertDialog.java    From hash-checker with Apache License 2.0 5 votes vote down vote up
public static void show(
        @NonNull Context context,
        int titleResId,
        int messageResId,
        int positiveButtonTextResId,
        @Nullable DialogInterface.OnClickListener positiveClickListener
) {
    AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.AppAlertDialog)
            .setTitle(titleResId)
            .setMessage(messageResId)
            .setPositiveButton(
                    positiveButtonTextResId,
                    positiveClickListener
            )
            .setNegativeButton(
                    R.string.common_cancel,
                    (dialog, which) -> dialog.cancel()
            )
            .create();
    alertDialog.setOnShowListener(dialog -> {
        AlertDialog currentDialog = ((AlertDialog) dialog);

        int textColor = UIUtils.getAccentColor(context);
        currentDialog.getButton(
                DialogInterface.BUTTON_POSITIVE
        ).setTextColor(textColor);
        currentDialog.getButton(
                DialogInterface.BUTTON_NEGATIVE
        ).setTextColor(textColor);
    });
    alertDialog.show();
}
 
Example 4
Source File: BatchBackupDialogFragment.java    From SAI with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    AlertDialog alertDialog = new AlertDialog.Builder(requireContext())
            .setMessage(getExportPromptText())
            .setPositiveButton(R.string.yes, null)
            .setNegativeButton(R.string.cancel, null)
            .create();

    alertDialog.setOnShowListener(dialog -> bindDialog(alertDialog));

    return alertDialog;
}
 
Example 5
Source File: GenerateFileDialogFragment.java    From mcumgr-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ConstantConditions")
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final LayoutInflater inflater = requireActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.dialog_generate_file, null);
    final EditText fileSize = view.findViewById(R.id.file_size);

    final AlertDialog dialog = new AlertDialog.Builder(requireContext())
            .setTitle(R.string.files_upload_generate_title)
            .setView(view)
            // Setting the positive button listener here would cause the dialog to dismiss.
            // We have to validate the value before.
            .setPositiveButton(R.string.files_action_generate, null)
            .setNegativeButton(android.R.string.cancel, null)
            .create();
    dialog.setOnShowListener(d -> mImm.showSoftInput(fileSize, InputMethodManager.SHOW_IMPLICIT));
    dialog.show();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
        try {
            final int size = Integer.parseInt(fileSize.getText().toString());

            final FilesUploadFragment parent = (FilesUploadFragment) getParentFragment();
            parent.onGenerateFileRequested(size);
            dismiss();
        } catch (final NumberFormatException e) {
            fileSize.setError(getString(R.string.files_upload_generate_error));
        }
    });
    return 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: 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 8
Source File: Dialogs.java    From Aegis with GNU General Public License v3.0 5 votes vote down vote up
public static void showErrorDialog(Context context, @StringRes int message, CharSequence error, DialogInterface.OnClickListener listener) {
    View view = LayoutInflater.from(context).inflate(R.layout.dialog_error, null);
    TextView textDetails = view.findViewById(R.id.error_details);
    textDetails.setText(error);
    TextView textMessage = view.findViewById(R.id.error_message);
    textMessage.setText(message);

    AlertDialog dialog = new AlertDialog.Builder(context)
            .setTitle(R.string.error_occurred)
            .setView(view)
            .setPositiveButton(android.R.string.ok, (dialog1, which) -> {
                if (listener != null) {
                    listener.onClick(dialog1, which);
                }
            })
            .setNeutralButton(R.string.details, (dialog1, which) -> {
                textDetails.setVisibility(View.VISIBLE);
            })
            .create();

    dialog.setOnShowListener(d -> {
        Button button = dialog.getButton(AlertDialog.BUTTON_NEUTRAL);
        button.setOnClickListener(v -> {
            if (textDetails.getVisibility() == View.GONE) {
                textDetails.setVisibility(View.VISIBLE);
                button.setText(R.string.copy);
            } else {
                ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                if (clipboard != null) {
                    ClipData clip = ClipData.newPlainText("text/plain", error);
                    clipboard.setPrimaryClip(clip);
                }
            }
        });
    });

    Dialogs.showSecureDialog(dialog);
}
 
Example 9
Source File: FolderPickerActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.create_folder:
            final EditText et = new EditText(this);
            AlertDialog dialog = Util.getAlertDialogBuilder(this)
                    .setTitle(R.string.create_folder)
                    .setView(et)
                    .setPositiveButton(android.R.string.ok,
                            (dialogInterface, i) -> createFolder(et.getText().toString())
                    )
                    .setNegativeButton(android.R.string.cancel, null)
                    .create();
            dialog.setOnShowListener(dialogInterface -> ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .showSoftInput(et, InputMethodManager.SHOW_IMPLICIT));
            dialog.show();
            return true;
        case R.id.select:
            Intent intent = new Intent()
                    .putExtra(EXTRA_RESULT_DIRECTORY, Util.formatPath(mLocation.getAbsolutePath()));
            setResult(Activity.RESULT_OK, intent);
            finish();
            return true;
        case android.R.id.home:
            finish();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 10
Source File: QiscusBaseChatActivity.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
protected void deleteComments(List<QiscusComment> selectedComments) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this)
            .setMessage(getResources().getQuantityString(R.plurals.qiscus_delete_comments_confirmation,
                    selectedComments.size(), selectedComments.size()))
            .setNegativeButton(R.string.qiscus_cancel, (dialog, which) -> dialog.dismiss())
            .setCancelable(true);

    boolean ableToDeleteForEveryone = allMyComments(selectedComments);
    if (ableToDeleteForEveryone) {
        alertDialogBuilder.setNeutralButton(R.string.qiscus_delete_for_everyone, (dialog, which) -> {
            QiscusBaseChatFragment fragment = (QiscusBaseChatFragment) getSupportFragmentManager()
                    .findFragmentByTag(QiscusBaseChatFragment.class.getName());
            if (fragment != null) {
                fragment.deleteCommentsForEveryone(selectedComments);
            }
            dialog.dismiss();
        });
    }

    AlertDialog alertDialog = alertDialogBuilder.create();

    alertDialog.setOnShowListener(dialog -> {
        QiscusDeleteCommentConfig deleteConfig = chatConfig.getDeleteCommentConfig();
        alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setTextColor(deleteConfig.getCancelButtonColor());
        if (ableToDeleteForEveryone) {
            alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(deleteConfig.getDeleteForEveryoneButtonColor());
        }
    });

    alertDialog.show();
}
 
Example 11
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);
    });
}
 
Example 12
Source File: RegistrationLockV2Dialog.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static void showEnableDialog(@NonNull Context context, @NonNull Runnable onSuccess) {
    AlertDialog dialog = new AlertDialog.Builder(context)
                                        .setTitle(R.string.RegistrationLockV2Dialog_turn_on_registration_lock)
                                        .setView(R.layout.registration_lock_v2_dialog)
                                        .setMessage(R.string.RegistrationLockV2Dialog_if_you_forget_your_signal_pin_when_registering_again)
                                        .setNegativeButton(android.R.string.cancel, null)
                                        .setPositiveButton(R.string.RegistrationLockV2Dialog_turn_on, null)
                                        .create();
    dialog.setOnShowListener(d -> {
      ProgressBar progress       = Objects.requireNonNull(dialog.findViewById(R.id.reglockv2_dialog_progress));
      View        positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);

      positiveButton.setOnClickListener(v -> {
        progress.setIndeterminate(true);
        progress.setVisibility(View.VISIBLE);

        SimpleTask.run(SignalExecutors.UNBOUNDED, () -> {
          try {
            PinState.onEnableRegistrationLockForUserWithPin();
            Log.i(TAG, "Successfully enabled registration lock.");
            return true;
          } catch (IOException e) {
            Log.w(TAG, "Failed to enable registration lock setting.", e);
            return false;
          }
        }, (success) -> {
          progress.setVisibility(View.GONE);

          if (!success) {
            Toast.makeText(context, R.string.preferences_app_protection__failed_to_enable_registration_lock, Toast.LENGTH_LONG).show();
          } else {
            onSuccess.run();
          }

          dialog.dismiss();
        });
      });
    });

  dialog.show();
}
 
Example 13
Source File: WidgetsDialogFragment.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    FragmentWidgetsDialogBinding binding = FragmentWidgetsDialogBinding.inflate(requireActivity().getLayoutInflater());
    AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity(),
            R.style.WidgetDialogStyle);

    widgetsList = new ArrayList<>(PreferenceHelper.getWidgetList());

    appWidgetContainer = binding.widgetContainer;

    if (!widgetsList.isEmpty()) {
        for (String widgets : PreferenceHelper.getWidgetList()) {
            Intent widgetIntent = new Intent();
            widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    Integer.parseInt(widgets));
            addWidget(widgetIntent, appWidgetContainer.getChildCount(), false);
        }
    }

    builder.setView(binding.getRoot());
    builder.setTitle(R.string.dialog_title_widgets);
    builder.setNegativeButton(R.string.dialog_action_close, null);
    builder.setPositiveButton(R.string.dialog_action_add, null);

    final AlertDialog widgetDialog = builder.create();

    if (widgetDialog.getWindow() != null) {
        widgetDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
    }

    widgetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override public void onShow(DialogInterface dialogInterface) {
            Button button = widgetDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
                    pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                            appWidgetHost.allocateAppWidgetId());
                    startActivityForResult(pickIntent, WIDGET_CONFIG_START_CODE);
                }
            });
        }
    });

    return widgetDialog;
}
 
Example 14
Source File: CustomViewDialog.java    From SimpleDialogFragments with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getMessage();
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getTitle() == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}
 
Example 15
Source File: AccPersonalFragment.java    From tindroid with Apache License 2.0 4 votes vote down vote up
private void showAddCredential() {
    final Activity activity = getActivity();
    if (activity == null) {
        return;
    }

    final View editor = LayoutInflater.from(activity).inflate(R.layout.dialog_add_credential, null);
    final AlertDialog dialog = new AlertDialog.Builder(activity)
            .setView(editor).setTitle(R.string.add_credential_title)
            .setPositiveButton(android.R.string.ok, null)
            .setNegativeButton(android.R.string.cancel, null)
            .create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialogInterface) {
            dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View button) {
                    EditText credEditor = editor.findViewById(R.id.editCredential);
                    String cred = credEditor.getText().toString().trim().toLowerCase();
                    if (TextUtils.isEmpty(cred)) {
                        return;
                    }
                    Credential parsed = UiUtils.parseCredential(cred);
                    if (parsed != null) {
                        final MeTopic me = Cache.getTinode().getMeTopic();
                        // noinspection unchecked
                        me.setMeta(new MsgSetMeta(parsed))
                                .thenCatch(new UiUtils.ToastFailureListener(activity));

                        // Dismiss once everything is OK.
                        dialog.dismiss();
                    } else {
                        credEditor.setError(activity.getString(R.string.unrecognized_credential));
                    }
                }
            });
        }
    });

    dialog.show();
}
 
Example 16
Source File: WidgetsDialogFragment.java    From HgLauncher with GNU General Public License v3.0 4 votes vote down vote up
@NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    FragmentWidgetsDialogBinding binding = FragmentWidgetsDialogBinding.inflate(requireActivity().getLayoutInflater());
    AlertDialog.Builder builder = new AlertDialog.Builder(requireActivity(),
            R.style.WidgetDialogStyle);

    widgetsList = new ArrayList<>(PreferenceHelper.getWidgetList());

    appWidgetContainer = binding.widgetContainer;

    if (!widgetsList.isEmpty()) {
        for (String widgets : PreferenceHelper.getWidgetList()) {
            Intent widgetIntent = new Intent();
            widgetIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    Integer.parseInt(widgets));
            addWidget(widgetIntent, appWidgetContainer.getChildCount(), false);
        }
    }

    builder.setView(binding.getRoot());
    builder.setTitle(R.string.dialog_title_widgets);
    builder.setNegativeButton(R.string.dialog_action_close, null);
    builder.setPositiveButton(R.string.dialog_action_add, null);

    final AlertDialog widgetDialog = builder.create();

    if (widgetDialog.getWindow() != null) {
        widgetDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
    }

    widgetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override public void onShow(DialogInterface dialogInterface) {
            Button button = widgetDialog.getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
                    pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                            appWidgetHost.allocateAppWidgetId());
                    startActivityForResult(pickIntent, WIDGET_CONFIG_START_CODE);
                }
            });
        }
    });

    return widgetDialog;
}
 
Example 17
Source File: CustomViewDialog.java    From SimpleDialogFragments with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog = (AlertDialog) super.onCreateDialog(savedInstanceState);

    layoutInflater = dialog.getLayoutInflater();

    View content = onCreateContentView(savedInstanceState);

    // Intermediate view with custom message TextView
    View intermediate = inflate(R.layout.simpledialogfragment_custom_view);
    TextView textView = (TextView) intermediate.findViewById(R.id.customMessage);
    View topSpacer = intermediate.findViewById(R.id.textSpacerNoTitle);
    ViewGroup container = (ViewGroup) intermediate.findViewById(R.id.customView);
    container.addView(content);

    dialog.setView(intermediate);


    String msg = getMessage();
    if (msg != null) {
        CharSequence message;
        if (getArguments().getBoolean(HTML)) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                message = Html.fromHtml(msg, 0);
            } else {
                //noinspection deprecation
                message = Html.fromHtml(msg);
            }
        } else {
            message = msg;
        }
        textView.setText(message);

    } else {
        textView.setVisibility(View.GONE);
    }
    dialog.setMessage(null);

    topSpacer.setVisibility(getTitle() == null && msg != null ? View.VISIBLE : View.GONE);


    dialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface d) {
            positiveButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    pressPositiveButton();
                }
            });
            onDialogShown();

        }
    });

    return dialog;
}
 
Example 18
Source File: PartitionDialogFragment.java    From mcumgr-android with Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    final LayoutInflater inflater = requireActivity().getLayoutInflater();
    final View view = inflater.inflate(R.layout.dialog_files_settings, null);
    final EditText partition = view.findViewById(R.id.partition);
    partition.setText(mFsUtils.getPartitionString());
    partition.selectAll();

    final AlertDialog dialog = new AlertDialog.Builder(requireContext())
            .setTitle(R.string.files_settings_title)
            .setView(view)
            // Setting the positive button listener here would cause the dialog to dismiss.
            // We have to validate the value before.
            .setPositiveButton(R.string.files_settings_action_save, null)
            .setNegativeButton(android.R.string.cancel, null)
            // Setting the neutral button listener here would cause the dialog to dismiss.
            .setNeutralButton(R.string.files_settings_action_restore, null)
            .create();
    dialog.setOnShowListener(d -> mImm.showSoftInput(partition, InputMethodManager.SHOW_IMPLICIT));

    // The neutral button should not dismiss the dialog.
    // We have to overwrite the default OnClickListener.
    // This can be done only after the dialog was shown.
    dialog.show();
    dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(v -> {
        final String defaultPartition = mFsUtils.getDefaultPartition();
        partition.setText(defaultPartition);
        partition.setSelection(defaultPartition.length());
    });
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> {
        final String newPartition = partition.getText().toString().trim();
        if (!TextUtils.isEmpty(newPartition)) {
            mFsUtils.setPartition(newPartition);
            dismiss();
        } else {
            partition.setError(getString(R.string.files_settings_error));
        }
    });
    return dialog;
}
 
Example 19
Source File: QrReaderFragment.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void promtForEventWORegistrationMoreQr() {

    // IDENTIFICATION
    String message = getString(R.string.qr_id) + ":\n";
    if (eventUid != null) {
        message = message + eventUid + "\n\n";
    } else {
        message = message + getString(R.string.qr_no_data) + "\n\n";
    }

    // ATTRIBUTES
    message = message + getString(R.string.qr_data_values) + ":\n";

    if (eventData != null && !eventData.isEmpty()) {
        for (Trio<TrackedEntityDataValue, String, Boolean> attribute : eventData) {
            message = message + attribute.val1() + ":\n" + attribute.val0().value() + "\n\n";
        }
        message = message + "\n";
    } else {
        message = message + getString(R.string.qr_no_data) + "\n\n";
    }


    // READ MORE
    message = message + "\n\n" + getString(R.string.read_more_qr);

    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.CustomDialog)
            .setTitle(getString(R.string.QR_SCANNER))
            .setMessage(message)
            .setPositiveButton(getString(R.string.action_accept), (dialog, which) -> {
                dialog.dismiss();
                mScannerView.resumeCameraPreview(this);
            })
            .setNegativeButton(getString(R.string.save_qr), (dialog, which) -> {
                presenter.downloadEventWORegistration();
                dialog.dismiss();
            });
    AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialogInterface -> {
        alertDialog.getButton(Dialog.BUTTON_POSITIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
        alertDialog.getButton(Dialog.BUTTON_NEGATIVE).setTextColor(getResources().getColor(R.color.colorPrimary));
    });
    alertDialog.show();
}
 
Example 20
Source File: BackupDialog.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
public static void showEnableBackupDialog(@NonNull Context context, @NonNull SwitchPreferenceCompat preference) {
  String[]    password = BackupUtil.generateBackupPassphrase();
  AlertDialog dialog   = new AlertDialog.Builder(context)
                                        .setTitle(R.string.BackupDialog_enable_local_backups)
                                        .setView(R.layout.backup_enable_dialog)
                                        .setPositiveButton(R.string.BackupDialog_enable_backups, null)
                                        .setNegativeButton(android.R.string.cancel, null)
                                        .create();

  dialog.setOnShowListener(created -> {
    Button button = ((AlertDialog) created).getButton(AlertDialog.BUTTON_POSITIVE);
    button.setOnClickListener(v -> {
      CheckBox confirmationCheckBox = dialog.findViewById(R.id.confirmation_check);
      if (confirmationCheckBox.isChecked()) {
        BackupPassphrase.set(context, Util.join(password, " "));
        TextSecurePreferences.setBackupEnabled(context, true);
        LocalBackupListener.schedule(context);

        preference.setChecked(true);
        created.dismiss();
      } else {
        Toast.makeText(context, R.string.BackupDialog_please_acknowledge_your_understanding_by_marking_the_confirmation_check_box, Toast.LENGTH_LONG).show();
      }
    });
  });

  dialog.show();

  CheckBox checkBox = dialog.findViewById(R.id.confirmation_check);
  TextView textView = dialog.findViewById(R.id.confirmation_text);

  ((TextView)dialog.findViewById(R.id.code_first)).setText(password[0]);
  ((TextView)dialog.findViewById(R.id.code_second)).setText(password[1]);
  ((TextView)dialog.findViewById(R.id.code_third)).setText(password[2]);

  ((TextView)dialog.findViewById(R.id.code_fourth)).setText(password[3]);
  ((TextView)dialog.findViewById(R.id.code_fifth)).setText(password[4]);
  ((TextView)dialog.findViewById(R.id.code_sixth)).setText(password[5]);

  textView.setOnClickListener(v -> checkBox.toggle());

  dialog.findViewById(R.id.number_table).setOnClickListener(v -> {
    ((ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE)).setPrimaryClip(ClipData.newPlainText("text", Util.join(password, " ")));
    Toast.makeText(context, R.string.BackupDialog_copied_to_clipboard, Toast.LENGTH_LONG).show();
  });


}