Java Code Examples for android.support.v7.app.AlertDialog.setOnDismissListener()

The following are Jave code examples for showing how to use setOnDismissListener() of the android.support.v7.app.AlertDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: mobile-store   File: CrashReportActivity.java   Source Code and License Vote up 6 votes
@Override
protected void init(Bundle savedInstanceState) {
    super.init(savedInstanceState);

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

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

    comment = (EditText) dialog.findViewById(android.R.id.input);
    if (savedInstanceState != null) {
        comment.setText(savedInstanceState.getString(STATE_COMMENT));
    }
}
 
Example 2
Project: Companion-For-PUBG-Android   File: ItemFragment.java   Source Code and License Vote up 6 votes
private void showDisclaimerForFirstTime() {
    final SharedPreferences preferences = getActivity().getSharedPreferences("temp", Context.MODE_PRIVATE);
    final String hasShown = "hasShown";
    if (preferences.getBoolean(hasShown, false)) {
        return;
    }

    AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setTitle("This is still in beta!")
            .setMessage("Data is not yet finished nor complete. Please help us via Github. Links available in the drawer.")
            .setPositiveButton("Ok no problem!", null)
            .show();
    alertDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            preferences.edit().putBoolean(hasShown, true).apply();
        }
    });
}
 
Example 3
Project: android_nextgis_mobile   File: PermissionUtil.java   Source Code and License Vote up 5 votes
public static void requestPermissions(
        final Activity activity,
        int title,
        int message,
        final int requestCode,
        final String... permissions)
{
    boolean shouldShowDialog = false;
    for (String permission : permissions) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
            shouldShowDialog = true;
            break;
        }
    }

    if (shouldShowDialog) {
        AlertDialog builder = new AlertDialog.Builder(activity).setTitle(title)
                .setMessage(message)
                .setPositiveButton(android.R.string.ok, null)
                .create();
        builder.setCanceledOnTouchOutside(false);
        builder.show();

        builder.setOnDismissListener(new DialogInterface.OnDismissListener()
        {
            @Override
            public void onDismiss(DialogInterface dialog)
            {
                ActivityCompat.requestPermissions(activity, permissions, requestCode);
            }
        });
    } else {
        ActivityCompat.requestPermissions(activity, permissions, requestCode);
    }
}
 
Example 4
Project: Phoenix-for-VK   File: InputTextDialog.java   Source Code and License Vote up 4 votes
public void show() {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(titleRes);
    View view = View.inflate(context, R.layout.dialog_enter_text, null);

    final EditText input = (EditText) view.findViewById(R.id.editText);
    input.setText(value);
    input.setSelection(input.getText().length());

    if (hint != null) {
        input.setHint(hint);
    }

    input.setInputType(inputType);
    builder.setView(view);
    builder.setPositiveButton(R.string.button_ok, null);
    builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> dialog.cancel());

    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> {
        Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);

        b.setOnClickListener(view1 -> {
            input.setError(null);
            String newValue = input.getText().toString().trim();

            if (TextUtils.isEmpty(newValue) && !allowEmpty) {
                input.setError(context.getString(R.string.field_is_required));
                input.requestFocus();
            } else {
                try {
                    if (validator != null) {
                        validator.validate(newValue);
                    }

                    if (callback != null) {
                        callback.onChanged(newValue);
                    }

                    if (target != null) {
                        target.setText(newValue);
                    }

                    alertDialog.dismiss();
                } catch (IllegalArgumentException e) {
                    input.setError(e.getMessage());
                    input.requestFocus();
                }
            }
        });
    });

    alertDialog.setOnDismissListener(onDismissListener);
    alertDialog.show();

    input.post(() -> {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
    });
}