Example usage for android.app AlertDialog dismiss

List of usage examples for android.app AlertDialog dismiss

Introduction

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

Prototype

@Override
public void dismiss() 

Source Link

Document

Dismiss this dialog, removing it from the screen.

Usage

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

/**
 * Send a bug report either with email or with Vector.
 *//*from   ww w.  j a v  a  2  s .co 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:ti.modules.titanium.ui.widget.TiUIDialog.java

public void hide(KrollDict options) {
    AlertDialog dialog = dialogWrapper.getDialog();
    if (dialog != null) {
        dialog.dismiss();
        dialogWrapper.getActivity().removeDialog(dialog);
    }/*from w ww .  j  a va2 s.c  o m*/

    if (view != null) {
        view.getProxy().releaseViews();
        view = null;
    }
}

From source file:com.mrchandler.disableprox.ui.TaskerSensorSettingsActivity.java

private void initInAppBilling() {
    final IabHelper helper = new IabHelper(this, getString(R.string.google_billing_public_key));
    //Has the user purchased the Tasker IAP?
    if (!ProUtil.isPro(this)) {
        helper.startSetup(new IabHelper.OnIabSetupFinishedListener() {
            @Override/*  w  w  w. ja va2s . c o  m*/
            public void onIabSetupFinished(IabResult result) {
                if (result.isFailure()) {
                    Log.d(TAG, "Unable to get up In-App Billing. Oh well.");
                    return;
                }
                helper.queryInventoryAsync(new IabHelper.QueryInventoryFinishedListener() {
                    @Override
                    public void onQueryInventoryFinished(IabResult result, Inventory inv) {
                        if (result.isFailure()) {
                            ProUtil.setProStatus(TaskerSensorSettingsActivity.this, false);
                            return;
                        }
                        if (inv.hasPurchase(Constants.SKU_TASKER)) {
                            ProUtil.setProStatus(TaskerSensorSettingsActivity.this, true);
                        } else {
                            ProUtil.setProStatus(TaskerSensorSettingsActivity.this, false);
                            if (!ProUtil.isFreeloaded(TaskerSensorSettingsActivity.this)) {
                                AlertDialog dialog = new AlertDialog.Builder(TaskerSensorSettingsActivity.this)
                                        .setTitle(R.string.iap_dialog_title)
                                        .setMessage(R.string.iap_dialog_message)
                                        .setNegativeButton("Not Right Now",
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        doNotSave = true;
                                                        finish();
                                                    }
                                                })
                                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {
                                                helper.launchPurchaseFlow(TaskerSensorSettingsActivity.this,
                                                        Constants.SKU_TASKER, PURCHASE_RESULT_CODE,
                                                        new IabHelper.OnIabPurchaseFinishedListener() {
                                                            @Override
                                                            public void onIabPurchaseFinished(IabResult result,
                                                                    Purchase info) {
                                                                if (result.isFailure()) {
                                                                    Toast.makeText(
                                                                            TaskerSensorSettingsActivity.this,
                                                                            "Error getting purchase details.",
                                                                            Toast.LENGTH_SHORT).show();
                                                                    doNotSave = true;
                                                                    finish();
                                                                    return;
                                                                }
                                                                if (info.getSku()
                                                                        .equals(Constants.SKU_TASKER)) {
                                                                    ProUtil.setProStatus(
                                                                            TaskerSensorSettingsActivity.this,
                                                                            true);
                                                                }
                                                            }
                                                        });
                                            }
                                        }).setNeutralButton("More Information",
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int which) {
                                                        AlertDialog oldDialog = (AlertDialog) dialog;
                                                        oldDialog.dismiss();
                                                        AlertDialog newDialog = new AlertDialog.Builder(
                                                                TaskerSensorSettingsActivity.this).setTitle(
                                                                        getString(R.string.iap_dialog_title))
                                                                        .setMessage(getString(
                                                                                R.string.iap_dialog_more_information))
                                                                        .setOnCancelListener(
                                                                                new DialogInterface.OnCancelListener() {
                                                                                    @Override
                                                                                    public void onCancel(
                                                                                            DialogInterface dialog) {
                                                                                        doNotSave = true;
                                                                                        finish();
                                                                                    }
                                                                                })
                                                                        .setCancelable(true).create();
                                                        newDialog.setCanceledOnTouchOutside(true);
                                                        newDialog.show();
                                                    }
                                                })
                                        .setOnCancelListener(new DialogInterface.OnCancelListener() {
                                            @Override
                                            public void onCancel(DialogInterface dialog) {
                                                doNotSave = true;
                                                finish();
                                            }
                                        }).setCancelable(true).create();
                                dialog.setCanceledOnTouchOutside(true);
                                dialog.show();
                            }
                        }
                    }
                });
            }
        });
    }
}

From source file:com.jonathongrigg.apps.spark.MainActivity.java

public void showAboutDialog() {
    final AlertDialog aboutDialog = new AlertDialog.Builder(this).create();
    aboutDialog.setTitle(this.getText(R.string.dialog_title));
    aboutDialog.setMessage(this.getText(R.string.dialog_text));
    aboutDialog.setIcon(R.drawable.ic_menu_info_details);

    aboutDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            aboutDialog.dismiss();
        }/*w  w  w .  j a va 2 s  .c o m*/
    });

    aboutDialog.show();
}

From source file:github.daneren2005.dsub.util.Util.java

private static void showDialog(Context context, int icon, String title, String message) {
    SpannableString ss = new SpannableString(message);
    Linkify.addLinks(ss, Linkify.ALL);/*w  ww  .j  a  va2 s  . c  o  m*/

    AlertDialog dialog = new AlertDialog.Builder(context).setIcon(icon).setTitle(title).setMessage(ss)
            .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int i) {
                    dialog.dismiss();
                }
            }).show();

    ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:org.brandroid.openmanager.fragments.DialogHandler.java

/**
 * Show a warning message with option to "Always Remember" choice
 * @param context Context.//from   www.ja v  a  2 s.  c om
 * @param text Message to show.
 * @param title Title of Dialog.
 * @param preferences Preferences object from which to pull pref_key. This will be placed in the "warn" SharedPreference.
 * @param pref_key Preference Key holding whether or not to show warning.
 * @param onYes Callback for when Yes is chosen. This will be called automatically if "Do not ask again" is selected.
 */
public static void showConfirmationDialog(Context context, String text, String title,
        final Preferences preferences, final String pref_key, final DialogInterface.OnClickListener onYes) {
    final View layout = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.confirm_view, null);

    final AlertDialog dialog = new AlertDialog.Builder(context).setTitle(title).setView(layout).create();

    if (!preferences.getBoolean("warn", pref_key, false)) {
        ViewUtils.setText(layout, text, R.id.confirm_message);

        ViewUtils.setOnClicks(layout, new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v.getId() == R.id.confirm_remember) {
                    CheckBox me = (CheckBox) v;
                    preferences.setSetting("warn", pref_key, me.isChecked());
                    ViewUtils.setViewsEnabled(layout, !me.isChecked(), R.id.confirm_no);
                } else if (v.getId() == R.id.confirm_no) {
                    preferences.setSetting("warn", pref_key, false);
                    dialog.dismiss();
                } else if (v.getId() == R.id.confirm_yes) {
                    onYes.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                }
            }
        }, R.id.confirm_remember, R.id.confirm_yes, R.id.confirm_no);

        dialog.show();
    } else
        onYes.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
}

From source file:org.cloudfoundry.android.cfdroid.services.ServiceEditDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    LayoutInflater inflater = LayoutInflater.from(getActivity());
    final View v = inflater.inflate(R.layout.service_edit, null);
    choices = (Spinner) v.findViewById(R.id.type);
    name = (EditText) v.findViewById(R.id.name);
    getLoaderManager().initLoader(0, null, this);

    name.setOnEditorActionListener(new OnEditorActionListener() {

        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == IME_ACTION_DONE && ready()) {
                createService();/* w w  w.  jav  a2  s.  c o m*/
                return true;
            }
            return false;
        }

    });

    name.addTextChangedListener(new BaseTextWatcher() {
        @Override
        public void afterTextChanged(Editable s) {
            updateEnablement();
        }
    });

    final AlertDialog dialog = new AlertDialog.Builder(getActivity())
            .setTitle(R.string.edit_service_dialog_title).setView(v).setCancelable(true)
            .setPositiveButton(R.string.create, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    createService();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).create();
    // workaround for http://code.google.com/p/android/issues/detail?id=6360
    // ...
    dialog.setOnShowListener(new OnShowListener() {
        @Override
        public void onShow(DialogInterface di) {
            okButton = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
            updateEnablement();
        }
    });

    return dialog;
}

From source file:com.coinblesk.client.backup.BackupActivity.java

private void showPermissionRationale() {
    AlertDialog dialog = new AlertDialog.Builder(this, R.style.AlertDialogAccent)
            .setTitle(R.string.backup_storage_permissions_title)
            .setMessage(R.string.backup_storage_permissions_rationale)
            .setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
                @Override/*w w  w .j a v  a  2  s  .  com*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setCancelable(true).create();
    dialog.show();
}

From source file:it.polimi.spf.app.fragments.contacts.PeopleFragment.java

private void onRequestReview(final PersonInfo entry) {
    final ContactConfirmDialogView dialogView = new ContactConfirmDialogView(getActivity(), entry);
    final AlertDialog dialog = new AlertDialog.Builder(getActivity()).setTitle("Confirm contact request")
            .setView(dialogView).setPositiveButton("Accept", null)
            .setNeutralButton("Cancel", new DialogInterface.OnClickListener() {

                @Override/*from ww  w  .  j  a v  a 2s.co  m*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setNegativeButton("Refuse", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    mPersonRegistry.deleteRequest(entry);
                    onRefresh();
                }

            }).show();

    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                mPersonRegistry.confirmRequest(entry, dialogView.getPassphrase(),
                        dialogView.getSelectedCircles());
            } catch (WrongPassphraseException e) {
                Toast.makeText(getActivity(), "Wrong passphrase", Toast.LENGTH_SHORT).show();
                return;
            }

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

From source file:net.coding.program.project.init.create.ProjectCreateFragment.java

private void showWarningDialog() {
    LayoutInflater factory = LayoutInflater.from(getActivity());
    final View textEntryView = factory.inflate(R.layout.init_dialog_text_entry2, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    AlertDialog dialog = builder.setTitle("??").setView(textEntryView)
            .setPositiveButton("", new DialogInterface.OnClickListener() {
                @Override/* w  ww . jav a 2s . com*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).show();
    CustomDialog.dialogTitleLineColor(getActivity(), dialog);
}