Example usage for android.app AlertDialog.Builder setView

List of usage examples for android.app AlertDialog.Builder setView

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setView.

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:Main.java

/**
 * // w w  w. j  a  v  a  2s  .co m
 * Return an Alert Dialog with two buttons and a title.
 * @param context              - The Activity which needs this alert dialog.
 * @param message              - The message in the alert.
 * @param positiveBtnLabel     - The label of the positive button.
 * @param negetiveBtnLabel     - The label of the negative button.
 * @param positiveClickListener- The onClickListener of the positive button.
 * @param negativeClickListener- The onClickListener of the negative button.
 * @param input                - Edit text input.
 * @return - The generated Alert Dialog.
 */
public static AlertDialog.Builder getAlertDialogWithTwoButtonAndEditView(Context context, String message,
        String positiveBtnLabel, String negetiveBtnLabel, DialogInterface.OnClickListener positiveClickListener,
        DialogInterface.OnClickListener negativeClickListener, EditText input) {

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setPositiveButton(positiveBtnLabel, positiveClickListener)
            .setNegativeButton(negetiveBtnLabel, negativeClickListener);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    input.setLayoutParams(params);
    builder.setView(input);

    return builder;
}

From source file:com.frostwire.android.gui.util.UIUtils.java

/**
 * @param context                         -  containing Context.
 * @param showInstallationCompleteSection - true if you want to display "Your installation is now complete. Thank You" section
 * @param dismissListener                 - what happens when the dialog is dismissed.
 * @param referrerContextSuffix           - string appended at the end of social pages click urls's ?ref=_android_ parameter.
 *///from  ww  w  .  jav a 2s.com
public static void showSocialLinksDialog(final Context context, boolean showInstallationCompleteSection,
        DialogInterface.OnDismissListener dismissListener, String referrerContextSuffix) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    View customView = View.inflate(context, R.layout.view_social_buttons, null);
    builder.setView(customView);
    builder.setPositiveButton(context.getString(android.R.string.ok), (dialog, which) -> dialog.dismiss());
    final AlertDialog socialLinksDialog = builder.create();
    socialLinksDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    socialLinksDialog.setOnDismissListener(dismissListener);
    ImageButton fbButton = customView.findViewById(R.id.view_social_buttons_facebook_button);
    ImageButton twitterButton = customView.findViewById(R.id.view_social_buttons_twitter_button);
    ImageButton redditButton = customView.findViewById(R.id.view_social_buttons_reddit_button);
    final String referrerParam = "?ref=android_"
            + ((referrerContextSuffix != null) ? referrerContextSuffix.trim() : "");
    fbButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_FACEBOOK_PAGE + referrerParam));
    twitterButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_TWITTER_PAGE + referrerParam));
    redditButton.setOnClickListener(
            v -> UIUtils.openURL(v.getContext(), Constants.SOCIAL_URL_REDDIT_PAGE + referrerParam));
    if (showInstallationCompleteSection) {
        LinearLayout installationCompleteLayout = customView
                .findViewById(R.id.view_social_buttons_installation_complete_layout);
        installationCompleteLayout.setVisibility(View.VISIBLE);
        ImageButton dismissCheckButton = customView.findViewById(R.id.view_social_buttons_dismiss_check);
        dismissCheckButton.setOnClickListener(v -> socialLinksDialog.dismiss());
    }
    socialLinksDialog.show();
}

From source file:com.jamesgiang.aussnowcam.Utils.java

public static void About(Context c) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(c);
    dialogBuilder.setTitle(R.string.app_name);
    dialogBuilder.setIcon(R.drawable.icon);
    TextView textView = new TextView(c);
    SpannableString s = new SpannableString(c.getString(R.string.about_info));
    Linkify.addLinks(s, Linkify.WEB_URLS);
    textView.setText(s);/*w w  w  .j a va2  s. c o m*/
    textView.setGravity(Gravity.CENTER);
    textView.setMovementMethod(LinkMovementMethod.getInstance());
    dialogBuilder.setView(textView);
    dialogBuilder.show();
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog telling the user what to do before the QR code scanner is
 * displayed, and starts the QR code activity.
 * //from   ww  w .  j  a  v  a  2s  .co m
 * @param activity
 *            the caller activity
 */
public static void pairInboundInstructions(final FragmentActivity activity) {
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getBuilder(activity);
            View layout = View.inflate(getContext(), R.layout.pair_inbound_instructions, null);
            builder.setView(layout);
            ((TextView) layout.findViewById(R.id.instructions))
                    .setText(getResources().getString(R.string.new_inbound_instructions));
            builder.setPositiveButton(android.R.string.ok, new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent("com.google.zxing.client.android.SCAN");
                    intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
                    getActivity().startActivityForResult(intent, MainActivity.QR_CODE_SCANNED);
                }
            });
            return builder.create();
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "instruction");
}

From source file:net.naonedbus.utils.InfoDialogUtils.java

/**
 * Afficher une dialog avec un contenu au format HTML
 * //from   w w w  .  jav a  2s.  c om
 * @param context
 * @param html
 */
public static void showHtml(final Context context, final String html) {
    AlertDialog.Builder moreDetailsDialog = null;
    final WebView webView = new WebView(context);
    final ScrollView scrollView = new ScrollView(context);

    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(Color.WHITE);
    webView.loadDataWithBaseURL("fake://not/needed", html, "text/html", "UTF-8", null); // Encoding
    // fix
    // for
    // Android
    // 3.x
    // /
    // 4.x
    scrollView.addView(webView);

    moreDetailsDialog = new AlertDialog.Builder(context);
    moreDetailsDialog.setIcon(android.R.drawable.ic_dialog_info);
    moreDetailsDialog.setTitle("Informations");
    moreDetailsDialog.setView(scrollView);
    moreDetailsDialog.setPositiveButton(android.R.string.ok, null);
    moreDetailsDialog.show();
}

From source file:im.vector.util.BugReporter.java

/**
 * Send a bug report either with email or with Vector.
 *//*from  w w  w  . j av a2  s.  c  o  m*/
public static void sendBugReport() {
    final Activity currentActivity = VectorApp.getCurrentActivity();

    // no current activity so cannot display an alert
    if (null == currentActivity) {
        sendBugReport(VectorApp.getInstance().getApplicationContext(), true, true, "", null);
        return;
    }

    final Context appContext = currentActivity.getApplicationContext();
    LayoutInflater inflater = currentActivity.getLayoutInflater();
    View dialogLayout = inflater.inflate(R.layout.dialog_bug_report, null);

    final AlertDialog.Builder dialog = new AlertDialog.Builder(currentActivity);
    dialog.setTitle(R.string.send_bug_report);
    dialog.setView(dialogLayout);

    final EditText bugReportText = (EditText) dialogLayout.findViewById(R.id.bug_report_edit_text);
    final CheckBox includeLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_logs);
    final CheckBox includeCrashLogsButton = (CheckBox) dialogLayout
            .findViewById(R.id.bug_report_button_include_crash_logs);

    final ProgressBar progressBar = (ProgressBar) dialogLayout.findViewById(R.id.bug_report_progress_view);
    final TextView progressTextView = (TextView) dialogLayout.findViewById(R.id.bug_report_progress_text_view);

    dialog.setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            // will be overridden to avoid dismissing the dialog while displaying the progress
        }
    });

    //
    final AlertDialog bugReportDialog = dialog.show();
    final Button cancelButton = bugReportDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
    final Button sendButton = bugReportDialog.getButton(AlertDialog.BUTTON_POSITIVE);

    if (null != cancelButton) {
        cancelButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // check if there is no upload in progress
                if (includeLogsButton.isEnabled()) {
                    bugReportDialog.dismiss();
                } else {
                    mIsCancelled = true;
                    cancelButton.setEnabled(false);
                }
            }
        });
    }

    if (null != sendButton) {
        sendButton.setEnabled(false);

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // disable the active area while uploading the bug report
                bugReportText.setEnabled(false);
                sendButton.setEnabled(false);
                includeLogsButton.setEnabled(false);
                includeCrashLogsButton.setEnabled(false);

                progressTextView.setVisibility(View.VISIBLE);
                progressTextView.setText(appContext.getString(R.string.send_bug_report_progress, 0 + ""));

                progressBar.setVisibility(View.VISIBLE);
                progressBar.setProgress(0);

                sendBugReport(VectorApp.getInstance(), includeLogsButton.isChecked(),
                        includeCrashLogsButton.isChecked(), bugReportText.getText().toString(),
                        new IMXBugReportListener() {
                            @Override
                            public void onUploadFailed(String reason) {
                                try {
                                    if (null != VectorApp.getInstance() && !TextUtils.isEmpty(reason)) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance()
                                                        .getString(R.string.send_bug_report_failed, reason),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to display the toast "
                                            + e.getMessage());
                                }

                                try {
                                    // restore the dialog if the upload failed
                                    bugReportText.setEnabled(true);
                                    sendButton.setEnabled(true);
                                    includeLogsButton.setEnabled(true);
                                    includeCrashLogsButton.setEnabled(true);
                                    cancelButton.setEnabled(true);

                                    progressTextView.setVisibility(View.GONE);
                                    progressBar.setVisibility(View.GONE);
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadFailed() : failed to restore the dialog button "
                                            + e.getMessage());

                                    try {
                                        bugReportDialog.dismiss();
                                    } catch (Exception e2) {
                                        Log.e(LOG_TAG, "## onUploadFailed() : failed to dismiss the dialog "
                                                + e2.getMessage());
                                    }
                                }

                                mIsCancelled = false;
                            }

                            @Override
                            public void onUploadCancelled() {
                                onUploadFailed(null);
                            }

                            @Override
                            public void onProgress(int progress) {
                                if (progress > 100) {
                                    Log.e(LOG_TAG, "## onProgress() : progress > 100");
                                    progress = 100;
                                } else if (progress < 0) {
                                    Log.e(LOG_TAG, "## onProgress() : progress < 0");
                                    progress = 0;
                                }

                                progressBar.setProgress(progress);
                                progressTextView.setText(
                                        appContext.getString(R.string.send_bug_report_progress, progress + ""));
                            }

                            @Override
                            public void onUploadSucceed() {
                                try {
                                    if (null != VectorApp.getInstance()) {
                                        Toast.makeText(VectorApp.getInstance(),
                                                VectorApp.getInstance().getString(
                                                        R.string.send_bug_report_sent),
                                                Toast.LENGTH_LONG).show();
                                    }
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the toast "
                                            + e.getMessage());
                                }

                                try {
                                    bugReportDialog.dismiss();
                                } catch (Exception e) {
                                    Log.e(LOG_TAG, "## onUploadSucceed() : failed to dismiss the dialog "
                                            + e.getMessage());
                                }
                            }
                        });
            }
        });
    }

    bugReportText.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) {
            if (null != sendButton) {
                sendButton.setEnabled(bugReportText.getText().toString().length() > 10);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    });
}

From source file:cc.metapro.openct.utils.ActivityUtils.java

public static AlertDialog addViewToAlertDialog(@NonNull final AlertDialog.Builder builder,
        @NonNull final View view) {
    ViewGroup parent = (ViewGroup) view.getParent();
    if (parent != null) {
        parent.removeView(view);/*from w w w .ja  v  a  2  s  .  com*/
    }

    ScrollView scrollView = new ScrollView(builder.getContext());
    scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    scrollView.addView(view);

    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            InputMethodManager imm = (InputMethodManager) builder.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
    });

    AlertDialog dialog = builder.setView(scrollView).create();
    Window window = dialog.getWindow();
    if (window != null) {
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
    }
    return dialog;
}

From source file:alphadelete.aguaconsciente.ui.fragments.AboutFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater dialogInflater = getActivity().getLayoutInflater();
    View openSourceLicensesView = dialogInflater.inflate(R.layout.fragment_about, null);

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    dialogBuilder.setView(openSourceLicensesView).setTitle((getString(R.string.action_about)))
            .setNeutralButton(android.R.string.ok, null);

    return dialogBuilder.create();
}

From source file:nf.frex.android.FrexActivity.java

public static void showYesNoDialog(Context context, int titleId, String message,
        DialogInterface.OnClickListener yesListener, DialogInterface.OnClickListener noListener,
        DialogInterface.OnCancelListener cancelListener) {

    TextView textView = new TextView(context);
    textView.setSingleLine(false);//from  www .ja  v  a2 s .  c  o  m
    textView.setPadding(10, 10, 10, 10);
    textView.setText(message);

    AlertDialog.Builder b = new AlertDialog.Builder(context);
    b.setTitle(titleId);
    b.setView(textView);
    b.setCancelable(true);
    if (yesListener != null) {
        b.setPositiveButton(android.R.string.yes, yesListener);
    }
    if (noListener != null) {
        b.setNegativeButton(android.R.string.no, noListener);
    }
    if (cancelListener != null) {
        b.setOnCancelListener(cancelListener);
    }
    b.show();
}

From source file:com.bonganimbigi.soundrecorder.fragments.LicensesFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater dialogInflater = getActivity().getLayoutInflater();
    View openSourceLicensesView = dialogInflater.inflate(R.layout.fragment_licenses, null);

    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
    dialogBuilder.setView(openSourceLicensesView).setTitle((getString(R.string.dialog_title_licenses)))
            .setNeutralButton(android.R.string.ok, null);

    return dialogBuilder.create();
}