Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:air.com.snagfilms.cast.chromecast.utils.Utils.java

/**
 * A utility method to show a simple error dialog.
 * /*from w w w. j  a v a2  s.c  o m*/
 * @param context
 * @param message
 *            The message to be shown in the dialog
 */
public static final void showErrorDialog(Context context, String message) {
    if (context instanceof Activity && !(((Activity) context).isFinishing())) {
        new AlertDialog.Builder(context).setTitle(R.string.error).setMessage(message)
                .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).create().show();
    }
}

From source file:Main.java

public static void showWifiSettings(final Activity activity, final Runnable yes, final Runnable no) {
    // check for internet connection
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(activity);
    alertDialog.setTitle("No Internet Connection");
    alertDialog.setMessage("Would you like to change settings ?");
    // Setting Positive "Yes" Button
    alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
            if (yes != null)
                yes.run();//  w w  w  .  ja v  a 2 s  . co  m
        }
    });
    // Setting Negative "NO" Button
    alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            if (no != null)
                no.run();
        }
    });
    // Showing Alert Message
    alertDialog.show();
}

From source file:com.evozi.droidsniff.helper.DialogHelper.java

public static void clearBlacklist(Activity context) {
    DialogHelper.context = context;//  w w w  . j  a  va 2s.  c  o m
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(R.string.clear_blacklist).setCancelable(false)
            .setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    DBHelper.clearBlacklist(DialogHelper.context);
                    AuthHelper.clearBlacklist();
                }
            }).setNegativeButton(R.string.button_no, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.aleiacampo.oristanobus.util.NavigationDrawerUtil.java

public static void setFavourites(final AppCompatActivity appCompatActivity) {

    final Bundle bundle = new Bundle();
    final ArrayList<Stop> stopsList;

    SQLiteHelper db = new SQLiteHelper(appCompatActivity);
    stopsList = db.getAllStops();/*from   w w  w . j ava  2s .  co  m*/
    ArrayList<String> stopsNameList = new ArrayList<>();

    for (Stop stop : stopsList) {
        stopsNameList.add(stop.nameStop);
    }

    if (stopsList.isEmpty())
        stopsNameList.add("Nessuna fermata salvata");

    ListView favourites = (ListView) appCompatActivity.findViewById(R.id.favourite_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(),
            R.layout.text_view, stopsNameList);
    favourites.setAdapter(adapter);

    favourites.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            bundle.putInt("id_stop", stopsList.get(position).idStop);
            bundle.putInt("id_line", stopsList.get(position).idLine);
            bundle.putString("name_stop", stopsList.get(position).nameStop);
            bundle.putString("name_line", stopsList.get(position).nameLine);

            DrawerLayout drawer = (DrawerLayout) appCompatActivity.findViewById(R.id.drawer_left);
            drawer.closeDrawer(Gravity.LEFT);

            FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager();
            TimesFragment timesFragment = new TimesFragment();
            timesFragment.setArguments(bundle);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.home_frag, timesFragment, "Times");
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    });

    favourites.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View view, final int pos, long id) {

            AlertDialog.Builder alertDialog = new AlertDialog.Builder(appCompatActivity);
            alertDialog.setMessage("Rimuovere la fermata dai preferiti?");
            alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    SQLiteHelper db2 = new SQLiteHelper(appCompatActivity);
                    db2.deleteStop(stopsList.get(pos).id); // l'id della fermata caricato dal db
                    NavigationDrawerUtil.setFavourites(appCompatActivity);
                    dialog.cancel();
                }
            });
            alertDialog.setNegativeButton("Nope !", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            alertDialog.show();
            return true;
        }
    });

    favourites.setLongClickable(true);
}

From source file:ee.ioc.phon.android.speak.Utils.java

public static AlertDialog getYesNoDialog(Context context, String confirmationMessage, final Executable ex) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(confirmationMessage).setCancelable(false)
            .setPositiveButton(context.getString(R.string.buttonYes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ex.execute();//from www  .  jav  a 2s .  co m
                }
            }).setNegativeButton(context.getString(R.string.buttonNo), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    return builder.create();
}

From source file:ee.ioc.phon.android.speak.Utils.java

public static AlertDialog getTextEntryDialog(Context context, String title, String initialText,
        final ExecutableString ex) {
    final View textEntryView = LayoutInflater.from(context).inflate(R.layout.alert_dialog_text_entry, null);
    final EditText et = (EditText) textEntryView.findViewById(R.id.url_edit);
    et.setText(initialText);//w  w w . j  a  v  a  2  s .  c  o m
    return new AlertDialog.Builder(context).setTitle(title).setView(textEntryView)
            .setPositiveButton(R.string.buttonOk, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    ex.execute(et.getText().toString());
                }
            }).setNegativeButton(R.string.buttonCancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            }).create();
}

From source file:com.pdftron.pdf.utils.Utils.java

public static void showAlertDialogWithLink(Context context, String message, String title) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);

    builder.setMessage(Html.fromHtml(message)).setCancelable(true).setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {

                @Override/*w ww  .j  av  a 2s  .c  o  m*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
    if (title.length() > 0) {
        builder.setTitle(title);
    }
    final AlertDialog d = builder.create();
    d.show();

    // Make the textview clickable. Must be called after show()
    ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}

From source file:com.spoiledmilk.ibikecph.util.Util.java

public static void showLanguageDialog(final Activity activity) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(IbikeApplication.getString("choose_language"));
    builder.setItems(IbikePreferences.getLanguageNames(), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            ((IbikeApplication) activity.getApplication()).changeLanguage(Language.values()[item + 1]);
            ((iLanguageListener) activity).reloadStrings();
            dialog.dismiss();//from   w ww.java  2 s.c o  m
        }
    });
    builder.setPositiveButton(IbikeApplication.getString("Cancel"), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    builder.show();
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.NotificationsFragment.java

/**
 * Alert button clicked; shows alert//from  w ww.ja v a2  s .co m
 */
@OnClick(R.id.notifications_alert_button)
public void onAlertButton() {
    new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.alert_title))
            .setMessage(getString(R.string.alert_message))
            .setPositiveButton(getString(R.string.alert_button), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).show();

}

From source file:com.ivan.autosms.MainActivity.java

public void openErrorDialog(String errorMessage) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setMessage(errorMessage);
    dialogBuilder.setCancelable(true);/*from w  ww.j a  va 2 s. c  o  m*/

    dialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    AlertDialog errorDialog = dialogBuilder.create();
    errorDialog.show();
}