android.support.v7.app.AlertDialog.Builder Java Examples

The following examples show how to use android.support.v7.app.AlertDialog.Builder. 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: SettingsFragment.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 6 votes vote down vote up
@Nullable
@Override
public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container,
        final Bundle savedInstanceState) {
    final ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_settings, container, false);
    root.findViewById(R.id.clear_data_btn).setOnClickListener(view -> {
        new Builder(getActivity()).setTitle(R.string.title_confirm_clear)
                .setMessage(R.string.message_confirm_clear)
                .setPositiveButton(android.R.string.ok, (dialogInterface, i) -> clearData(true))
                .setNegativeButton(android.R.string.cancel, (dialogInterface, i) -> {
                })
                .show();
    });
    root.findViewById(R.id.clear_cache_btn).setOnClickListener(view -> clearData(false));
    return root;
}
 
Example #2
Source File: XmppActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
private void showAskForPresenceDialog(final Contact contact) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(contact.getJid().toString());
    builder.setMessage(R.string.request_presence_updates);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.request_now,
            (dialog, which) -> {
                if (xmppConnectionServiceBound) {
                    xmppConnectionService.sendPresencePacket(contact
                            .getAccount(), xmppConnectionService
                            .getPresenceGenerator()
                            .requestPresenceUpdatesFrom(contact));
                }
            });
    builder.create().show();
}
 
Example #3
Source File: PasswordResetActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
public void onPasswordResetClicked(View v) {
    SEGAnalytics.track("Auth: Request password reset");
    final String email = emailView.getText().toString();
    if (isEmailValid(email)) {
        performReset();
    } else {
        new Builder(this)
                .setTitle(getString(R.string.reset_password_dialog_title))
                .setMessage(getString(R.string.reset_paassword_dialog_please_enter_a_valid_email))
                .setPositiveButton(R.string.ok, (dialog, which) -> {
                    dialog.dismiss();
                    emailView.requestFocus();
                })
                .show();
    }
}
 
Example #4
Source File: EditAccountActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onPreferencesFetched(final Element prefs) {
    runOnUiThread(() -> {
        if (mFetchingMamPrefsToast != null) {
            mFetchingMamPrefsToast.cancel();
        }
        Builder builder = new Builder(EditAccountActivity.this);
        builder.setTitle(R.string.server_side_mam_prefs);
        String defaultAttr = prefs.getAttribute("default");
        final List<String> defaults = Arrays.asList("never", "roster", "always");
        final AtomicInteger choice = new AtomicInteger(Math.max(0, defaults.indexOf(defaultAttr)));
        builder.setSingleChoiceItems(R.array.mam_prefs, choice.get(), (dialog, which) -> choice.set(which));
        builder.setNegativeButton(R.string.cancel, null);
        builder.setPositiveButton(R.string.ok, (dialog, which) -> {
            prefs.setAttribute("default", defaults.get(choice.get()));
            xmppConnectionService.pushMamPreferences(mAccount, prefs);
        });
        builder.create().show();
    });
}
 
Example #5
Source File: DiscoverDeviceActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void onWifiDisabled() {
    log.d("Wi-Fi disabled; prompting user");
    new AlertDialog.Builder(this)
            .setTitle(R.string.wifi_required)
            .setPositiveButton(R.string.enable_wifi, (dialog, which) -> {
                dialog.dismiss();
                log.i("Enabling Wi-Fi at the user's request.");
                wifiFacade.setWifiEnabled(true);
                wifiListFragment.scanAsync();
            })
            .setNegativeButton(R.string.exit_setup, (dialog, which) -> {
                dialog.dismiss();
                finish();
            })
            .show();
}
 
Example #6
Source File: DiscoverDeviceActivity.java    From spark-setup-android with Apache License 2.0 6 votes vote down vote up
private void onMaxAttemptsReached() {
    if (!isResumed) {
        finish();
        return;
    }

    String errorMsg = Phrase.from(this, R.string.unable_to_connect_to_soft_ap)
            .put("device_name", getString(R.string.device_name))
            .format().toString();

    new AlertDialog.Builder(this)
            .setTitle(R.string.error)
            .setMessage(errorMsg)
            .setPositiveButton(R.string.ok, (dialog, which) -> {
                dialog.dismiss();
                startActivity(new Intent(DiscoverDeviceActivity.this, GetReadyActivity.class));
                finish();
            })
            .show();
}
 
Example #7
Source File: XmppActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
protected void showQrCode(final String uri) {
    if (uri == null || uri.isEmpty()) {
        return;
    }
    Point size = new Point();
    getWindowManager().getDefaultDisplay().getSize(size);
    final int width = (size.x < size.y ? size.x : size.y);
    Bitmap bitmap = BarcodeProvider.create2dBarcodeBitmap(uri, width);
    ImageView view = new ImageView(this);
    view.setBackgroundColor(Color.WHITE);
    view.setImageBitmap(bitmap);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(view);
    builder.create().show();
}
 
Example #8
Source File: XPermission.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public static void showTipsDialog(final Context context) {
    new Builder(context).setTitle((CharSequence) "提示信息").setMessage((CharSequence) "当前应用缺少必要权限,该功能暂时无法使用。如若需要,请单击【确定】按钮前往设置中心进行权限授权。").setNegativeButton((CharSequence) "取消", null).setPositiveButton((CharSequence) "确定", new OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            XPermission.startAppSettings(context);
        }
    }).show();
}
 
Example #9
Source File: XmppActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
protected void showAddToRosterDialog(final Contact contact) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(contact.getJid().toString());
    builder.setMessage(getString(R.string.not_in_roster));
    builder.setNegativeButton(getString(R.string.cancel), null);
    builder.setPositiveButton(getString(R.string.add_contact), (dialog, which) -> xmppConnectionService.createContact(contact, true));
    builder.create().show();
}
 
Example #10
Source File: XmppActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
protected void displayErrorDialog(final int errorCode) {
    runOnUiThread(() -> {
        Builder builder = new Builder(XmppActivity.this);
        builder.setIconAttribute(android.R.attr.alertDialogIcon);
        builder.setTitle(getString(R.string.error));
        builder.setMessage(errorCode);
        builder.setNeutralButton(R.string.accept, null);
        builder.create().show();
    });

}
 
Example #11
Source File: XmppActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void showInstallPgpDialog() {
    Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.openkeychain_required));
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setMessage(getText(R.string.openkeychain_required_long));
    builder.setNegativeButton(getString(R.string.cancel), null);
    builder.setNeutralButton(getString(R.string.restart),
            (dialog, which) -> {
                if (xmppConnectionServiceBound) {
                    unbindService(mConnection);
                    xmppConnectionServiceBound = false;
                }
                stopService(new Intent(XmppActivity.this,
                        XmppConnectionService.class));
                finish();
            });
    builder.setPositiveButton(getString(R.string.install),
            (dialog, which) -> {
                Uri uri = Uri
                        .parse("market://details?id=org.sufficientlysecure.keychain");
                Intent marketIntent = new Intent(Intent.ACTION_VIEW,
                        uri);
                PackageManager manager = getApplicationContext()
                        .getPackageManager();
                List<ResolveInfo> infos = manager
                        .queryIntentActivities(marketIntent, 0);
                if (infos.size() > 0) {
                    startActivity(marketIntent);
                } else {
                    uri = Uri.parse("http://www.openkeychain.org/");
                    Intent browserIntent = new Intent(
                            Intent.ACTION_VIEW, uri);
                    startActivity(browserIntent);
                }
                finish();
            });
    builder.create().show();
}
 
Example #12
Source File: EditAccountActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
public void showWipePepDialog() {
    Builder builder = new Builder(this);
    builder.setTitle(getString(R.string.clear_other_devices));
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setMessage(getString(R.string.clear_other_devices_desc));
    builder.setNegativeButton(getString(R.string.cancel), null);
    builder.setPositiveButton(getString(R.string.accept),
            (dialog, which) -> mAccount.getAxolotlService().wipeOtherPepDevices());
    builder.create().show();
}
 
Example #13
Source File: EditAccountActivity.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
private void showDeletePgpDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.unpublish_pgp);
    builder.setMessage(R.string.unpublish_pgp_message);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.confirm, (dialogInterface, i) -> {
        mAccount.setPgpSignId(0);
        mAccount.unsetPgpSignature();
        xmppConnectionService.databaseBackend.updateAccount(mAccount);
        xmppConnectionService.sendPresence(mAccount);
        refreshUiReal();
    });
    builder.create().show();
}
 
Example #14
Source File: PermissionsFragment.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
public void ensurePermission(final @NonNull String permission) {
    Builder dialogBuilder = new AlertDialog.Builder(getActivity())
            .setCancelable(false);

    // FIXME: stop referring to these location permission-specific strings here,
    // try to retrieve them from the client
    if (ActivityCompat.checkSelfPermission(getActivity(), permission) != PERMISSION_GRANTED ||
            ActivityCompat.shouldShowRequestPermissionRationale(getActivity(), permission)) {
        dialogBuilder.setTitle(R.string.location_permission_dialog_title)
                .setMessage(R.string.location_permission_dialog_text)
                .setPositiveButton(R.string.got_it, (dialog, which) -> {
                    dialog.dismiss();
                    requestPermission(permission);
                });
    } else {
        // user has explicitly denied this permission to setup.
        // show a simple dialog and bail out.
        dialogBuilder.setTitle(R.string.location_permission_denied_dialog_title)
                .setMessage(R.string.location_permission_denied_dialog_text)
                .setPositiveButton(R.string.settings, (dialog, which) -> {
                    dialog.dismiss();
                    Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                    String pkgName = getActivity().getApplicationInfo().packageName;
                    intent.setData(Uri.parse("package:" + pkgName));
                    startActivity(intent);
                })
                .setNegativeButton(R.string.exit_setup, (dialog, which) -> {
                    Client client = (Client) getActivity();
                    client.onUserDeniedPermission(permission);
                });
    }

    dialogBuilder.show();
}
 
Example #15
Source File: DiscoverDeviceActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void onDeviceClaimedByOtherUser() {
    String dialogMsg = getString(R.string.dialog_title_owned_by_another_user,
            getString(R.string.device_name), sparkCloud.getLoggedInUsername());

    new Builder(this)
            .setTitle(getString(R.string.change_owner_question))
            .setMessage(dialogMsg)
            .setPositiveButton(getString(R.string.change_owner),
                    (dialog, which) -> {
                        dialog.dismiss();
                        log.i("Changing owner to " + sparkCloud.getLoggedInUsername());
                        // FIXME: state mutation from another class.  Not pretty.
                        // Fix this by breaking DiscoverProcessWorker down into Steps
                        resetWorker();
                        discoverProcessWorker.needToClaimDevice = true;
                        discoverProcessWorker.gotOwnershipInfo = true;
                        discoverProcessWorker.isDetectedDeviceClaimed = false;

                        showProgressDialog();
                        startConnectWorker();
                    })
            .setNegativeButton(R.string.cancel,
                    (dialog, which) -> {
                        dialog.dismiss();
                        startActivity(new Intent(DiscoverDeviceActivity.this, GetReadyActivity.class));
                        finish();
                    })
            .show();
}
 
Example #16
Source File: DiscoverDeviceActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void onLocationDisabled() {
    log.d("Location disabled; prompting user");
    new Builder(this).setTitle(R.string.location_required)
            .setMessage(R.string.location_required_message)
            .setPositiveButton(R.string.enable_location, ((dialog, which) -> {
                dialog.dismiss();
                log.i("Sending user to enabling Location services.");
                startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
            }))
            .setNegativeButton(R.string.exit_setup, ((dialog, which) -> {
                dialog.dismiss();
                finish();
            }))
            .show();
}
 
Example #17
Source File: PasswordResetActivity.java    From spark-setup-android with Apache License 2.0 5 votes vote down vote up
private void onResetAttemptFinished(String content) {
    new AlertDialog.Builder(this)
            .setMessage(content)
            .setPositiveButton(R.string.ok, (dialog, which) -> {
                dialog.dismiss();
                finish();
            })
            .show();
}
 
Example #18
Source File: CredentialsDialogFragment.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Create field for username
    mUsernameET = new EditText(getActivity());
    mUsernameET.setHint(getActivity().getText(R.string.auth_username));

    // Create field for password
    mPasswordET = new EditText(getActivity());
    mPasswordET.setHint(getActivity().getText(R.string.auth_password));
    mPasswordET.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);

    // Prepare LinearLayout for dialog
    LinearLayout ll = new LinearLayout(getActivity());
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(mUsernameET);
    ll.addView(mPasswordET);
    
    ll.requestFocus();
    
    setRetainInstance(true);

    Builder authDialog = new AlertDialog
            .Builder(getActivity())
            .setTitle(getActivity().getText(R.string.saml_authentication_required_text))
            .setView(ll)
            .setCancelable(false)
            .setPositiveButton(R.string.common_ok, this)
            .setNegativeButton(R.string.common_cancel, this);

    Dialog d = authDialog.create();
    d.getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    return d;
}
 
Example #19
Source File: DialogFactory.java    From QuickNote with Apache License 2.0 5 votes vote down vote up
public static void showInputDialog(Context context, String title, View contentView, DialogInterface.OnClickListener positiveListener) {
    Builder builder = new Builder(context);
    builder.setTitle(title);
    builder.setMessage(null);
    builder.setView(contentView, 3 * PADDING, PADDING, 3 * PADDING, PADDING);
    builder.setNegativeButton(QuickNote.getString(R.string.popup_window_cancel), null);
    builder.setPositiveButton(QuickNote.getString(R.string.popup_window_sure), positiveListener);
    builder.show();
}
 
Example #20
Source File: DialogFactory.java    From QuickNote with Apache License 2.0 5 votes vote down vote up
public static EditText showInputDialog(Context context, String title, String content, DialogInterface.OnClickListener positiveListener) {
    Builder builder = new Builder(context);
    builder.setTitle(title);
    builder.setMessage(content);
    AppCompatEditText input = new AppCompatEditText(context);
    builder.setView(input, PADDING, PADDING, PADDING, PADDING);
    builder.setNegativeButton(CANCEL_TIP, null);
    builder.setPositiveButton(SURE_TIP, positiveListener);
    builder.show();
    return input;
}
 
Example #21
Source File: DialogFactory.java    From QuickNote with Apache License 2.0 5 votes vote down vote up
public static void createAndShowDialog(Context context, String title, String content,
                                       String negativeButtonTip, DialogInterface.OnClickListener negativeListener,
                                       String positiveButtonTip, DialogInterface.OnClickListener positiveListener) {
    Builder builder = new Builder(context);
    builder.setTitle(title);
    builder.setMessage(content);
    builder.setNegativeButton(negativeButtonTip, negativeListener);
    builder.setPositiveButton(positiveButtonTip, positiveListener);
    builder.show();
}
 
Example #22
Source File: SettingsFragment.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
private void clearData(final boolean clearFavorites) {
    final AlertDialog dialog = new ProgressDialog.Builder(getActivity())
            .setTitle(R.string.title_clearing)
            .setMessage(R.string.message_clearing)
            .setCancelable(false).create();

    final String msgClearingFmt = getString(R.string.message_clearing_fmt);

    final Consumer<Integer> onNextConsumer = ret -> {
        // onNext
        if (ret != 0) {
            dialog.setMessage(String.format(msgClearingFmt, getString(ret)));
        }
    };

    final Consumer<Throwable> onErrorConsumer = err -> { // Failed
        Log.d(TAG, "Failed!" + err.getLocalizedMessage());
        dialog.dismiss();
    };

    final Action onComplete = () -> { // onComplete
        Log.d(TAG, "Dismiss");
        dialog.dismiss();
    };

    compositeDisposable.add(settingsViewModel.clearData(clearFavorites)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(onNextConsumer, onErrorConsumer, onComplete));
    dialog.show();
}
 
Example #23
Source File: EditAccountActivity.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCaptchaRequested(final Account account, final String id, final Data data, final Bitmap captcha) {
    runOnUiThread(() -> {
        if (mCaptchaDialog != null && mCaptchaDialog.isShowing()) {
            mCaptchaDialog.dismiss();
        }
        final Builder builder = new Builder(EditAccountActivity.this);
        final View view = getLayoutInflater().inflate(R.layout.captcha, null);
        final ImageView imageView = view.findViewById(R.id.captcha);
        final EditText input = view.findViewById(R.id.input);
        imageView.setImageBitmap(captcha);

        builder.setTitle(getString(R.string.captcha_required));
        builder.setView(view);

        builder.setPositiveButton(getString(R.string.ok),
                (dialog, which) -> {
                    String rc = input.getText().toString();
                    data.put("username", account.getUsername());
                    data.put("password", account.getPassword());
                    data.put("ocr", rc);
                    data.submit();

                    if (xmppConnectionServiceBound) {
                        xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, id, data);
                    }
                });
        builder.setNegativeButton(getString(R.string.cancel), (dialog, which) -> {
            if (xmppConnectionService != null) {
                xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
            }
        });

        builder.setOnCancelListener(dialog -> {
            if (xmppConnectionService != null) {
                xmppConnectionService.sendCreateAccountWithCaptchaPacket(account, null, null);
            }
        });
        mCaptchaDialog = builder.create();
        mCaptchaDialog.show();
        input.requestFocus();
    });
}
 
Example #24
Source File: XmppActivity.java    From Conversations 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) {
    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);
    });
}