Search in sources :

Example 1 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project WordPress-Login-Flow-Android by wordpress-mobile.

the class LoginHttpAuthDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder alert = new MaterialAlertDialogBuilder(getActivity());
    alert.setTitle(R.string.http_authorization_required);
    if (!TextUtils.isEmpty(mMessage))
        alert.setMessage(mMessage);
    // noinspection InflateParams
    View httpAuth = getActivity().getLayoutInflater().inflate(R.layout.login_alert_http_auth, null);
    alert.setView(httpAuth);
    final EditText usernameEditText = (EditText) httpAuth.findViewById(R.id.login_http_username);
    final EditText passwordEditText = (EditText) httpAuth.findViewById(R.id.login_http_password);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            String username = EditTextUtils.getText(usernameEditText);
            String password = EditTextUtils.getText(passwordEditText);
            sendResult(username, password);
            dismiss();
            return true;
        }
    });
    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();
        }
    });
    alert.setPositiveButton(R.string.next, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String username = EditTextUtils.getText(usernameEditText);
            String password = EditTextUtils.getText(passwordEditText);
            sendResult(username, password);
        }
    });
    final AlertDialog alertDialog = alert.create();
    // update the Next button when username edit box changes
    usernameEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            updateButton(alertDialog, usernameEditText);
        }
    });
    // update the Next button on first appearance
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            updateButton(alertDialog, usernameEditText);
        }
    });
    return alertDialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) EditText(android.widget.EditText) DialogInterface(android.content.DialogInterface) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) NonNull(androidx.annotation.NonNull)

Example 2 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project WordPress-Login-Flow-Android by wordpress-mobile.

the class LoginEmailFragment method showErrorDialog.

private void showErrorDialog(String message) {
    AlertDialog dialog = new MaterialAlertDialogBuilder(getActivity()).setMessage(message).setPositiveButton(R.string.login_error_button, null).create();
    dialog.show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 3 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by WhisperSystems.

the class BaseRegistrationLockFragment method onViewCreated.

@Override
@CallSuper
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setDebugLogSubmitMultiTapView(view.findViewById(R.id.kbs_lock_pin_title));
    pinEntry = view.findViewById(R.id.kbs_lock_pin_input);
    pinButton = view.findViewById(R.id.kbs_lock_pin_confirm);
    errorLabel = view.findViewById(R.id.kbs_lock_pin_input_label);
    keyboardToggle = view.findViewById(R.id.kbs_lock_keyboard_toggle);
    forgotPin = view.findViewById(R.id.kbs_lock_forgot_pin);
    RegistrationLockFragmentArgs args = RegistrationLockFragmentArgs.fromBundle(requireArguments());
    timeRemaining = args.getTimeRemaining();
    forgotPin.setVisibility(View.GONE);
    forgotPin.setOnClickListener(v -> handleForgottenPin(timeRemaining));
    pinEntry.setImeOptions(EditorInfo.IME_ACTION_DONE);
    pinEntry.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_DONE) {
            ViewUtil.hideKeyboard(requireContext(), v);
            handlePinEntry();
            return true;
        }
        return false;
    });
    enableAndFocusPinEntry();
    pinButton.setOnClickListener((v) -> {
        ViewUtil.hideKeyboard(requireContext(), pinEntry);
        handlePinEntry();
    });
    keyboardToggle.setOnClickListener((v) -> {
        PinKeyboardType keyboardType = getPinEntryKeyboardType();
        updateKeyboard(keyboardType.getOther());
        keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
    });
    PinKeyboardType keyboardType = getPinEntryKeyboardType().getOther();
    keyboardToggle.setText(resolveKeyboardToggleText(keyboardType));
    disposables.bindTo(getViewLifecycleOwner().getLifecycle());
    viewModel = getViewModel();
    viewModel.getLockedTimeRemaining().observe(getViewLifecycleOwner(), t -> timeRemaining = t);
    TokenData keyBackupCurrentToken = viewModel.getKeyBackupCurrentToken();
    if (keyBackupCurrentToken != null) {
        int triesRemaining = keyBackupCurrentToken.getTriesRemaining();
        if (triesRemaining <= 3) {
            int daysRemaining = getLockoutDays(timeRemaining);
            new MaterialAlertDialogBuilder(requireContext()).setTitle(R.string.RegistrationLockFragment__not_many_tries_left).setMessage(getTriesRemainingDialogMessage(triesRemaining, daysRemaining)).setPositiveButton(android.R.string.ok, null).setNeutralButton(R.string.PinRestoreEntryFragment_contact_support, (dialog, which) -> sendEmailToSupport()).show();
        }
        if (triesRemaining < 5) {
            errorLabel.setText(requireContext().getResources().getQuantityString(R.plurals.RegistrationLockFragment__d_attempts_remaining, triesRemaining, triesRemaining));
        }
    }
}
Also used : CircularProgressButtonUtil.setSpinning(org.thoughtcrime.securesms.util.CircularProgressButtonUtil.setSpinning) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) R(org.thoughtcrime.securesms.R) Toast(android.widget.Toast) View(android.view.View) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) CircularProgressButton(com.dd.CircularProgressButton) CircularProgressButtonUtil.cancelSpinning(org.thoughtcrime.securesms.util.CircularProgressButtonUtil.cancelSpinning) PinKeyboardType(org.thoughtcrime.securesms.lock.v2.PinKeyboardType) RegistrationViewDelegate.setDebugLogSubmitMultiTapView(org.thoughtcrime.securesms.registration.fragments.RegistrationViewDelegate.setDebugLogSubmitMultiTapView) InputType(android.text.InputType) BaseRegistrationViewModel(org.thoughtcrime.securesms.registration.viewmodel.BaseRegistrationViewModel) CallSuper(androidx.annotation.CallSuper) TokenData(org.thoughtcrime.securesms.pin.TokenData) TimeUnit(java.util.concurrent.TimeUnit) Log(org.signal.core.util.logging.Log) AndroidSchedulers(io.reactivex.rxjava3.android.schedulers.AndroidSchedulers) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) Disposable(io.reactivex.rxjava3.disposables.Disposable) LoggingFragment(org.thoughtcrime.securesms.LoggingFragment) EditorInfo(android.view.inputmethod.EditorInfo) EditText(android.widget.EditText) Resources(android.content.res.Resources) PinKeyboardType(org.thoughtcrime.securesms.lock.v2.PinKeyboardType) TokenData(org.thoughtcrime.securesms.pin.TokenData) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) CallSuper(androidx.annotation.CallSuper)

Example 4 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by WhisperSystems.

the class ShakeToReport method showPostSubmitDialog.

private void showPostSubmitDialog(@NonNull Activity activity, @NonNull String url) {
    AlertDialog dialog = new MaterialAlertDialogBuilder(activity).setTitle(R.string.ShakeToReport_success).setMessage(url).setNegativeButton(android.R.string.cancel, (d, i) -> {
        d.dismiss();
        enableIfVisible();
    }).setPositiveButton(R.string.ShakeToReport_share, (d, i) -> {
        d.dismiss();
        enableIfVisible();
        activity.startActivity(new ShareIntents.Builder(activity).setText(url).build());
    }).show();
    ((TextView) dialog.findViewById(android.R.id.message)).setTextIsSelectable(true);
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShakeDetector(org.signal.core.util.ShakeDetector) SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) AlertDialog(androidx.appcompat.app.AlertDialog) SubmitDebugLogRepository(org.thoughtcrime.securesms.logsubmit.SubmitDebugLogRepository) NonNull(androidx.annotation.NonNull) SimpleProgressDialog(org.thoughtcrime.securesms.util.views.SimpleProgressDialog) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) ThreadUtil(org.signal.core.util.ThreadUtil) R(org.thoughtcrime.securesms.R) Tracer(org.signal.core.util.tracing.Tracer) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) TextView(android.widget.TextView) Application(android.app.Application) ShareIntents(org.thoughtcrime.securesms.sharing.ShareIntents) Toast(android.widget.Toast) WeakReference(java.lang.ref.WeakReference) Activity(android.app.Activity) ServiceUtil(org.thoughtcrime.securesms.util.ServiceUtil) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) TextView(android.widget.TextView) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder)

Example 5 with MaterialAlertDialogBuilder

use of com.google.android.material.dialog.MaterialAlertDialogBuilder in project Signal-Android by WhisperSystems.

the class BlockUnblockDialog method buildBlockFor.

@WorkerThread
private static AlertDialog.Builder buildBlockFor(@NonNull Context context, @NonNull Recipient recipient, @NonNull Runnable onBlock, @Nullable Runnable onBlockAndReportSpam) {
    recipient = recipient.resolve();
    AlertDialog.Builder builder = new MaterialAlertDialogBuilder(context);
    Resources resources = context.getResources();
    if (recipient.isGroup()) {
        if (SignalDatabase.groups().isActive(recipient.requireGroupId())) {
            builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_and_leave_s, recipient.getDisplayName(context)));
            builder.setMessage(R.string.BlockUnblockDialog_you_will_no_longer_receive_messages_or_updates);
            builder.setPositiveButton(R.string.BlockUnblockDialog_block_and_leave, ((dialog, which) -> onBlock.run()));
            builder.setNegativeButton(android.R.string.cancel, null);
        } else {
            builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_s, recipient.getDisplayName(context)));
            builder.setMessage(R.string.BlockUnblockDialog_group_members_wont_be_able_to_add_you);
            builder.setPositiveButton(R.string.RecipientPreferenceActivity_block, ((dialog, which) -> onBlock.run()));
            builder.setNegativeButton(android.R.string.cancel, null);
        }
    } else if (recipient.isReleaseNotes()) {
        builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_s, recipient.getDisplayName(context)));
        builder.setMessage(R.string.BlockUnblockDialog_block_getting_signal_updates_and_news);
        builder.setPositiveButton(R.string.BlockUnblockDialog_block, ((dialog, which) -> onBlock.run()));
        builder.setNegativeButton(android.R.string.cancel, null);
    } else {
        builder.setTitle(resources.getString(R.string.BlockUnblockDialog_block_s, recipient.getDisplayName(context)));
        builder.setMessage(R.string.BlockUnblockDialog_blocked_people_wont_be_able_to_call_you_or_send_you_messages);
        if (onBlockAndReportSpam != null) {
            builder.setNeutralButton(android.R.string.cancel, null);
            builder.setNegativeButton(R.string.BlockUnblockDialog_report_spam_and_block, (d, w) -> onBlockAndReportSpam.run());
            builder.setPositiveButton(R.string.BlockUnblockDialog_block, (d, w) -> onBlock.run());
        } else {
            builder.setPositiveButton(R.string.BlockUnblockDialog_block, ((dialog, which) -> onBlock.run()));
            builder.setNegativeButton(android.R.string.cancel, null);
        }
    }
    return builder;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) Lifecycle(androidx.lifecycle.Lifecycle) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Nullable(androidx.annotation.Nullable) AlertDialog(androidx.appcompat.app.AlertDialog) NonNull(androidx.annotation.NonNull) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WorkerThread(androidx.annotation.WorkerThread) Recipient(org.thoughtcrime.securesms.recipients.Recipient) SimpleTask(org.thoughtcrime.securesms.util.concurrent.SimpleTask) Resources(android.content.res.Resources) Resources(android.content.res.Resources) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) WorkerThread(androidx.annotation.WorkerThread)

Aggregations

MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)69 NonNull (androidx.annotation.NonNull)36 View (android.view.View)32 AlertDialog (androidx.appcompat.app.AlertDialog)32 Bundle (android.os.Bundle)29 Nullable (androidx.annotation.Nullable)24 R (org.thoughtcrime.securesms.R)22 Context (android.content.Context)20 TextView (android.widget.TextView)18 Log (org.signal.core.util.logging.Log)16 LayoutInflater (android.view.LayoutInflater)15 Toast (android.widget.Toast)15 DialogInterface (android.content.DialogInterface)14 Intent (android.content.Intent)14 R (org.odk.collect.android.R)14 Dialog (android.app.Dialog)11 DialogFragment (androidx.fragment.app.DialogFragment)11 Resources (android.content.res.Resources)10 SignalStore (org.thoughtcrime.securesms.keyvalue.SignalStore)10 ViewUtil (org.thoughtcrime.securesms.util.ViewUtil)10