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

The following are Jave code examples for showing how to use setOnShowListener() 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: CodeWatch   File: LanguageGoalFragment.java   Source Code and License Vote up 5 votes
@SuppressLint("InflateParams")
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater layoutInflater = getActivity().getLayoutInflater();
    View rootView = layoutInflater.inflate(R.layout.dialog_add_language_goal, null);
    unbinder = ButterKnife.bind(this, rootView);

    autoCompleteTextView.setAdapter(new ArrayAdapter<>(
            getActivity(), android.R.layout.simple_dropdown_item_1line, validLanguages));
    validator = new LanguageValidator(getActivity(), autoCompleteTextView, validLanguages);
    autoCompleteTextView.setValidator(validator);
    autoCompleteTextView.setOnFocusChangeListener(new FocusListener());
    autoCompleteTextView.setThreshold(1);
    autoCompleteTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            autoCompleteTextView.showDropDown();
        }
    });

    hoursPicker.setMinValue(1);
    hoursPicker.setMaxValue(24);
    hoursPicker.setValue(hoursPicked);


    builder.setView(rootView)
            .setPositiveButton(R.string.ok, null)
            .setNegativeButton(R.string.cancel, null);

    AlertDialog dialog = builder.create();
    dialog.setOnShowListener(this);

    return dialog;
}
 
Example 2
Project: home-automation   File: ScanActivity.java   Source Code and License Vote up 5 votes
private void showCredentialsDialog(final DeviceDAO deviceDAO) {
    final View content = View.inflate(this, R.layout.dialog_device_protected, null);
    final AlertDialog d = new AlertDialog.Builder(this)
            .setTitle(R.string.dialog_device_protected_title)
            .setPositiveButton(android.R.string.yes, null)
            .setNegativeButton(R.string.cancel, null)
            .setView(content).create();

    d.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) {
                    EditText username = content.findViewById(R.id.deviceUsername);
                    EditText password = content.findViewById(R.id.devicePassword);
                    if (TextUtils.isEmpty(username.getText())) {
                        username.setError(getString(R.string.dialog_error_field_required));
                        username.requestFocus();
                    } else if (TextUtils.isEmpty(password.getText())) {
                        password.setError(getString(R.string.dialog_error_field_required));
                        password.requestFocus();
                    } else {
                        dialog.dismiss();
                        deviceDAO.setUsername(username.getText().toString());
                        deviceDAO.setPassword(password.getText().toString());
                        checkCredentials(deviceDAO);
                    }
                }
            });
        }
    });
    d.show();
}
 
Example 3
Project: revolution-irc   File: ThemedAlertDialog.java   Source Code and License Vote up 5 votes
@Override
public AlertDialog create() {
    AlertDialog ret = super.create();
    ret.setOnShowListener((DialogInterface dialogInterface) -> {
        themeButton(ret.getButton(AlertDialog.BUTTON_POSITIVE));
        themeButton(ret.getButton(AlertDialog.BUTTON_NEGATIVE));
        themeButton(ret.getButton(AlertDialog.BUTTON_NEUTRAL));
    });
    return ret;
}
 
Example 4
Project: IelloAndroidAdminApp   File: DialogAPIKey.java   Source Code and License Vote up 5 votes
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // creazione 'manuale' del dialog
    int margin = getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin);

    LinearLayout rootView = new LinearLayout(getActivity());
    rootView.setOrientation(LinearLayout.VERTICAL);
    rootView.setPadding(margin, margin, margin, margin);
    mTxtInput = new TextInputLayout(getActivity());
    mTxtInput.addView(new EditText(getActivity()));
    mTxtInput.setHint(getString(R.string.api_key_title));
    if (mTxtInput.getEditText() != null) {
        mTxtInput.getEditText().setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        mTxtInput.getEditText().setHighlightColor(Color.YELLOW);
    }

    rootView.addView(mTxtInput);

    // Setto l'edit text con il testo dell'api key se presente
    String apiKey = SharedPrefsHelper.getInstance().getApiKey(getActivity());
    if(apiKey != null)
        mTxtInput.getEditText().setText(apiKey);

    AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setTitle(getString(R.string.title_insert_api_key))
            .setView(rootView)
            //.setCancelable(false)
            .setPositiveButton(getString(R.string.salva), null)
            .setNegativeButton(SharedPrefsHelper.getInstance()
                    .isApiKeyRegistered(getActivity()) ? getString(R.string.annulla) : getString(R.string.esci_app), this)
            .create();

    dialog.setOnShowListener(this);

    return dialog;
}
 
Example 5
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);
    });
}
 
Example 6
Project: fitnotifications   File: HomeFragment.java   Source Code and License Vote up 4 votes
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 7
Project: fitnotifications   File: HomeActivity.java   Source Code and License Vote up 4 votes
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("Enter your feedback below:");
    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("Send Feedback: 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 feedback = input.getText().toString();
                    feedback = feedback.trim();
                    if (feedback.isEmpty()) {
                        Toast.makeText(HomeActivity.this, "You must type some feedback to proceed!", 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, "Step 2: Select app to send feedback"));

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

    dialog.show();
}
 
Example 8
Project: SimpleDialogFragments   File: CustomViewDialog.java   Source Code and License Vote up 4 votes
@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 = getArgString(MESSAGE);
    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(getArgString(TITLE) == 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;
}