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

The following examples show how to use android.support.v7.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: ChangeSeedPasswordDialog.java    From android-wallet-app with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_change_seed_password, null, false);
    ButterKnife.bind(this, view);
    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setView(view)
            .setTitle(R.string.title_new_password)
            .setMessage(R.string.message_new_password)
            .setPositiveButton(R.string.buttons_save, null)
            .setNegativeButton(R.string.buttons_cancel, null)
            .create();


    alertDialog.setOnShowListener(dialog -> {
        Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(view1 -> changeSeedPassword());
    });

    alertDialog.show();
    return alertDialog;
}
 
Example 2
Source File: ButtonActivity.java    From android-md-core with Apache License 2.0 6 votes vote down vote up
@OnClick(R.id.btn_dialog_2)
protected void onBtnDialog2Click() {
  AlertDialog dialog = new AlertDialog.Builder(ButtonActivity.this)
      .setTitle(getString(R.string.text_custom_dialog))
      .setView(R.layout.custom_dialog)
      .setPositiveButton(R.string.text_ok, null)
      .setNegativeButton(R.string.text_cancel, null)
      .create();
  dialog.setOnShowListener(d -> {
    AlertDialog alertDialog = (AlertDialog) d;
    Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    CheckBox checkBox = (CheckBox) alertDialog.findViewById(R.id.checkbox);
    checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> positiveButton.setEnabled(isChecked));
    positiveButton.setEnabled(checkBox.isChecked());
  });
  dialog.show();
}
 
Example 3
Source File: DialogActivity.java    From android-md-core with Apache License 2.0 6 votes vote down vote up
@OnClick(R.id.btn_dialog_2)
protected void onBtnDialog2Click() {
  AlertDialog dialog = new AlertDialog.Builder(DialogActivity.this)
      .setTitle(getString(R.string.text_custom_dialog))
      .setView(R.layout.custom_dialog)
      .setPositiveButton(R.string.text_ok, null)
      .setNegativeButton(R.string.text_cancel, null)
      .create();
  dialog.setOnShowListener(d -> {
    AlertDialog alertDialog = (AlertDialog) d;
    Button positiveButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
    CheckBox checkBox = (CheckBox) alertDialog.findViewById(R.id.checkbox);
    checkBox.setOnCheckedChangeListener((buttonView, isChecked) -> positiveButton.setEnabled(isChecked));
    positiveButton.setEnabled(checkBox.isChecked());
  });
  dialog.show();
}
 
Example 4
Source File: VerifyPhoneDialog.java    From AccountBook with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setTitle(UiUtils.getString(R.string.verify_phone))
            .setCancelable(false)
            .setView(mContentView, 0, 50, 0, 0)
            .setNegativeButton(UiUtils.getString(R.string.dialog_cancel), null)
            .setPositiveButton(UiUtils.getString(R.string.dialog_finish), null)
            .create();

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(mCallback == null) return;

                    String code = mEdtCode.getText().toString();
                    if (!RegexUtils.checkCode(code)) {
                        mCallback.onVerifyFail(UiUtils.getString(R.string.hint_right_code));
                    } else {
                        mCallback.onVerifySuccess(code);
                    }
                }
            });
        }
    });
    return alertDialog;
}
 
Example 5
Source File: CopySeedDialog.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    generatedSeed = bundle.getString("generatedSeed");

    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.copy_seed)
            .setMessage(R.string.messages_copy_seed)
            .setCancelable(false)
            .setPositiveButton(R.string.buttons_ok, null)
            .setNegativeButton(R.string.buttons_cancel, null)
            .create();

    alertDialog.setOnShowListener(dialog -> {

        Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(view -> {
            ClipboardManager clipboard = (ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clip = ClipData.newPlainText(getActivity().getString(R.string.seed), generatedSeed);
            clipboard.setPrimaryClip(clip);
            dialog.dismiss();
        });
    });

    alertDialog.show();
    return alertDialog;
}
 
Example 6
Source File: EncryptSeedDialog.java    From android-wallet-app with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View view = inflater.inflate(R.layout.dialog_encrypt_seed_password, null, false);
    ButterKnife.bind(this, view);

    Bundle bundle = getArguments();
    seed = bundle.getString("seed");

    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setView(view)
            .setTitle(R.string.title_enter_password)
            .setMessage(R.string.message_enter_password)
            .setCancelable(false)
            .setPositiveButton(R.string.buttons_save, null)
            .setNegativeButton(R.string.buttons_cancel, null)
            .create();

    alertDialog.setOnShowListener(dialog -> {
        Button button = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        button.setOnClickListener(view1 -> encryptSeed());
    });

    alertDialog.show();
    return alertDialog;

}
 
Example 7
Source File: LoginActivity.java    From Saude-no-Mapa with MIT License 5 votes vote down vote up
@Override
public void showPasswordDialog(StringListener listener) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    View view = LayoutInflater.from(this).inflate(R.layout.dialog_reset_password_layout, null);
    EditText editText = (EditText) view.findViewById(R.id.email_edit_text);
    builder.setView(view);

    builder.setTitle("Recuperar Senha");
    builder.setPositiveButton("Ok", null);
    builder.setNegativeButton("Cancelar", null);

    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialogInterface -> {
        Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        Button negativeButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
        positiveButton.setOnClickListener(v -> {
            String email = editText.getText().toString();
            if (Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
                listener.onNext(email);
                dialogInterface.dismiss();
            } else {
                showToast(getString(R.string.invalid_email));
            }
        });
        negativeButton.setOnClickListener(v -> dialogInterface.dismiss());
    });

    alertDialog.show();
}
 
Example 8
Source File: GameMenuDialog.java    From settlers-remake with MIT License 5 votes vote down vote up
/**
 * Stops the system bars from showing when this dialog appears.
 */
private void applyFullscreenWorkaround(AlertDialog dialog) {
	dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
	dialog.setOnShowListener(x -> dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE));
	int activitySystemUiVisibility = getActivity().getWindow().getDecorView().getSystemUiVisibility();
	dialog.getWindow().getDecorView().setSystemUiVisibility(activitySystemUiVisibility);
}
 
Example 9
Source File: MainActivity.java    From blade-player with GNU General Public License v3.0 4 votes vote down vote up
private void checkPermission()
{
    if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.M)
    {
        if(checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)!= PackageManager.PERMISSION_GRANTED)
        {
            if(shouldShowRequestPermissionRationale(Manifest.permission.WRITE_EXTERNAL_STORAGE))
            {
                // Show an alert dialog
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setMessage(getString(R.string.please_grant_permission_msg));
                builder.setTitle(getString(R.string.please_grant_permission_title));
                builder.setPositiveButton("OK", new DialogInterface.OnClickListener()
                {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i)
                    {
                        ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXT_PERM_REQUEST_CODE);
                    }
                });
                AlertDialog dialog = builder.create();
                dialog.setOnShowListener(new DialogInterface.OnShowListener()
                {
                    @Override
                    public void onShow(DialogInterface arg0)
                    {
                        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setTextColor(Color.BLACK);
                    }
                });
                dialog.show();
            }
            else
            {
                // Request permission
                ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXT_PERM_REQUEST_CODE);
            }
        }
        else startLibService();
    }
    else startLibService();
}
 
Example 10
Source File: HomeFragment.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
private void sendDebugLogEmail(final StringBuilder body) {
    final LinearLayout layout = new LinearLayout(getContext());
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(32,16,32,16);


    final TextView title = new TextView(getContext());
    title.setText("Explain the problem below:");
    title.setTextSize(18);
    final EditText input = new EditText(getContext());
    layout.addView(title);
    layout.addView(input);

    final AlertDialog dialog = new AlertDialog.Builder(getContext())
            .setTitle("Send Logs: Step 1")
            .setView(layout)
            .setPositiveButton(android.R.string.ok, null)
            .setNegativeButton(android.R.string.cancel, null)
            .create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    String issue = input.getText().toString();
                    issue = issue.trim();
                    if (issue.isEmpty()) {
                        Toast.makeText(getContext(), "You must describe the problem you are facing to proceed!", Toast.LENGTH_SHORT).show();
                    } else {
                        body.insert(0, "\n\n------\n\n");
                        body.insert(0, issue);

                        DebugLog log = DebugLog.get(getActivity());
                        startActivity(log.emailLogIntent(getContext(), body.toString()));

                        mEnableLogs.setChecked(false);
                        dialog.dismiss();
                    }
                }
            });
        }
    });

    dialog.show();
}
 
Example 11
Source File: HomeActivity.java    From fitnotifications with Apache License 2.0 4 votes vote down vote up
private void sendFeedback() {
    final LinearLayout layout = new LinearLayout(HomeActivity.this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setPadding(32,16,32,16);

    final TextView title = new TextView(HomeActivity.this);
    title.setText(R.string.feedback_step1_message);
    title.setTextSize(18);
    final EditText input = new EditText(HomeActivity.this);
    layout.addView(title);
    layout.addView(input);

    final AlertDialog dialog = new AlertDialog.Builder(HomeActivity.this)
        .setTitle(R.string.feedback_step1_title)
        .setView(layout)
        .setPositiveButton(android.R.string.ok, null)
        .setNegativeButton(android.R.string.cancel, null)
        .create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    String feedback = input.getText().toString();
                    feedback = feedback.trim();
                    if (feedback.isEmpty()) {
                        Toast.makeText(HomeActivity.this, R.string.no_feedback_message, Toast.LENGTH_SHORT).show();
                    } else {
                        feedback += "\n\n";
                        String uriText =
                                "mailto:[email protected]" +
                                        "?subject=" + Uri.encode(getString(R.string.email_subject)) +
                                        "&body=" + Uri.encode(feedback);

                        Uri uri = Uri.parse(uriText);

                        Intent sendIntent = new Intent(Intent.ACTION_SENDTO);
                        sendIntent.setData(uri);
                        startActivity(Intent.createChooser(sendIntent, getString(R.string.select_send_feedback_app)));

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

    dialog.show();
}
 
Example 12
Source File: SettingActivity.java    From AccountBook with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 显示修改密码 Dialog
 */
private void showUpdatePwdDialog() {
    final AppCompatEditText editText = new AppCompatEditText(mContext);
    editText.setHint(UiUtils.getString(R.string.hint_input_new_pwd));
    final AlertDialog alertDialog = new AlertDialog.Builder(mContext)
            .setTitle(UiUtils.getString(R.string.dialog_title_update_pwd))
            .setCancelable(false)
            .setView(editText, DimenUtils.dp2px(16f), DimenUtils.dp2px(16f), DimenUtils.dp2px(16f), DimenUtils.dp2px(16f))
            .setNegativeButton(UiUtils.getString(R.string.dialog_cancel), null)
            .setPositiveButton(UiUtils.getString(R.string.dialog_finish), null)
            .create();

    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(final DialogInterface dialog) {
            Button button = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    String newPwd = editText.getText().toString();
                    if(!RegexUtils.checkPassword(newPwd)){
                        ToastUtils.show(mContext, UiUtils.getString(R.string.toast_right_password));
                    }else{
                        User user = UserUtils.getUser();
                        user.setPassword(newPwd);
                        ProgressUtils.show(mContext, UiUtils.getString(R.string.load_update));
                        mRepository.saveUserInfo(user, new UserDataSource.SaveUserInfoCallback() {
                            @Override
                            public void saveSuccess() {
                                ProgressUtils.dismiss();
                                alertDialog.dismiss();
                                ToastUtils.show(mContext, UiUtils.getString(R.string.toast_update_success));
                            }

                            @Override
                            public void saveFail(Error e) {
                                ProgressUtils.dismiss();
                                ToastUtils.show(mContext, e.getMessage());
                            }
                        });
                    }
                }
            });
        }
    });
    alertDialog.show();
}
 
Example 13
Source File: ShowSeedDialog.java    From android-wallet-app with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View dialogView = inflater.inflate(R.layout.dialog_show_seed, null, false);
    ButterKnife.bind(this, dialogView);

    final AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
            .setView(dialogView)
            .setTitle(R.string.title_enter_password)
            .setPositiveButton(R.string.buttons_show, null)
            .setNegativeButton(R.string.buttons_cancel, null)
            .create();

    alertDialog.setOnShowListener(dialog -> {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());

        final Button bPositive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
        final Button bNegative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);

        // if seed is not password protected
        if (prefs.getString(Constants.PREFERENCE_ENC_SEED, "").isEmpty()) {

            textInputLayoutPassword.setVisibility(View.GONE);

            if (IOTA.seed != null)
                textViewSeed.setText(String.valueOf(IOTA.seed));

            // update the dialog
            alertDialog.setTitle(getString(R.string.title_current_seed));
            bNegative.setText(R.string.buttons_ok);
            bPositive.setEnabled(false);
        }

        bPositive.setOnClickListener(view -> {
            showPassword();
            if (!textViewSeed.getText().toString().isEmpty()) {

                textInputLayoutPassword.setVisibility(View.GONE);

                // update the dialog
                alertDialog.setTitle(getString(R.string.title_current_seed));
                bNegative.setText(R.string.buttons_ok);
                bPositive.setEnabled(false);
            }
        });
    });

    alertDialog.show();
    return alertDialog;
}
 
Example 14
Source File: ColorOMaticDialog.java    From Color-O-Matic with GNU General Public License v3.0 4 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    if (savedInstanceState == null) {
        colorOMaticView = new ColorOMaticView(
                getArguments().getInt(ARG_INITIAL_COLOR),
                getArguments().getBoolean(ARG_SHOW_COLOR_INDICATOR),
                ColorMode.values()[
                        getArguments().getInt(ARG_COLOR_MODE_ID)],
                IndicatorMode.values()[
                        getArguments().getInt(ARG_INDICATOR_MODE)],
                getActivity());
    } else {
        colorOMaticView = new ColorOMaticView(
                savedInstanceState.getInt(ARG_INITIAL_COLOR, ColorOMaticView.DEFAULT_COLOR),
                savedInstanceState.getBoolean(ARG_SHOW_COLOR_INDICATOR),
                ColorMode.values()[
                        savedInstanceState.getInt(ARG_COLOR_MODE_ID)],
                IndicatorMode.values()[
                        savedInstanceState.getInt(ARG_INDICATOR_MODE)],
                getActivity());
    }

    colorOMaticView.enableButtonBar(new ColorOMaticView.ButtonBarListener() {
        @Override
        public void onPositiveButtonClick(int color) {
            if (listener != null) listener.onColorSelected(color);
            dismiss();
        }

        @Override
        public void onNegativeButtonClick() {
            dismiss();
        }
    });

    final AlertDialog ad = new AlertDialog.Builder(getActivity(), getTheme()).setView(colorOMaticView).create();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        ad.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                measureLayout(ad);
            }
        });
    } else {
        measureLayout(ad);
    }

    return ad;
}
 
Example 15
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);
    });
}