Example usage for android.app AlertDialog.Builder setCancelable

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

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.agustinprats.myhrv.MainActivity.java

/** Shows unable to init BLE message and exit app. */
private void showUnableToInitBleDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setCancelable(false);
    builder.setMessage(R.string.unable_init_ble);
    builder.setPositiveButton(R.string.exit, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {

            finish();//from   w w  w. j a  va2s.c  o  m
        }
    });
    builder.create().show();
}

From source file:com.semaphore.sm.MainActivity.java

private void resetDefault() {
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setMessage("All settings will be reset to default.\nDo you want to continue?");
    ad.setCancelable(false);
    ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            defaultTask dt = new defaultTask();
            dt.execute(sp);/*from  w w w.  j a v a2  s . c o m*/
        }
    });
    ad.setNegativeButton("Cancel", null);
    ad.show();
}

From source file:com.getkickbak.plugin.NotificationPlugin.java

/**
 * Builds and shows a native Android confirm dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons. Any labels after that will be ignored.
 * The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
 * /*from w ww. j a  v  a 2s  .  com*/
 * @param message
 *           The message the dialog should display
 * @param title
 *           The title of the dialog
 * @param buttonLabels
 *           A comma separated list of button labels (Up to 3 buttons)
 * @param callbackContext
 *           The callback context.
 */
public synchronized void confirm(final String message, final String title, String buttonLabels,
        final CallbackContext callbackContext) {

    final NotificationPlugin notification = this;
    final CordovaInterface cordova = this.cordova;
    final String[] fButtons = (buttonLabels != null) ? buttonLabels.split(",") : new String[0];

    Runnable runnable = new Runnable() {
        public void run() {
            AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity());
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable((fButtons.length > 0) ? true : false);

            // First button
            if (fButtons.length > 0) {
                dlg.setNegativeButton(fButtons[0], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 1));
                    }
                });
                dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                    public void onCancel(DialogInterface dialog) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                    }
                });
            }

            // Second button
            if (fButtons.length > 1) {
                dlg.setNeutralButton(fButtons[1], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 2));
                    }
                });
            }

            // Third button
            if (fButtons.length > 2) {
                dlg.setPositiveButton(fButtons[2], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        notification.dismiss(-1, dialog);
                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 3));
                    }
                });
            }
            /*
             * dlg.setOnDismissListener(new AlertDialog.OnDismissListener()
             * {
             * public void onDismiss(DialogInterface dialog)
             * {
             * }
             * });
             */

            dlg.create();
            Integer key = Integer.valueOf(((int) (Math.random() * 10000000)) + 10000);
            AlertDialog value = dlg.show();

            notification.dialogsIA.put(key, value);
            notification.dialogsAI.put(value, key);
            if (fButtons.length == 0) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, key.intValue()));
            }
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.qasp.diego.arsp.indice_localFrag.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    Coordenada GPSLocal = Global.GPS;/* w  w w .  j  a  v a2s.  c  o m*/
    ArrayList<Poluente> poluenteslocal = new ArrayList<>();
    final View rootview = inflater.inflate(R.layout.fragment_indice_local, container, false);
    Log.d("indice_localfrag", "OnCreateView");
    Log.d(String.valueOf(Global.GPS.getLatitude()), String.valueOf(Global.GPS.getLongitude()));

    if (Global.tabSelecionado == 1) {
        if (Global.tenhodados && PermissaodoGPS(getActivity())) {
            if (Global.GPSok) {
                DistanciasEstacaoGPS(Global.estacoes, GPSLocal);
                DeterminarPiorMedia(Global.estacoes, poluenteslocal);

                for (Poluente p : poluenteslocal) {
                    Log.d(p.getNome(), String.valueOf(p.getIndice()));
                }

                for (int i = poluenteslocal.size() - 1; i > 0
                        && poluenteslocal.get(i).getQualidade().equals("Boa"); i--)
                    poluenteslocal.remove(i);

                for (Poluente p : poluenteslocal) {
                    p.AtualizaImagem(Imagens.getFontedasImagens());
                }

                ImageView imagemindice = (ImageView) rootview.findViewById(R.id.indicelocal);
                imagemindice.setImageResource(poluenteslocal.get(0).getImagem());
                TextView indiceresultado = (TextView) rootview.findViewById(R.id.resutladodoindice);
                indiceresultado.setText(String.valueOf(poluenteslocal.get(0).getIndice()));
                TextView qualidaderesultado = (TextView) rootview.findViewById(R.id.resultadodaQualidade);
                qualidaderesultado.setText(String.valueOf(poluenteslocal.get(0).getQualidade()));
                TextView prevencao = (TextView) rootview.findViewById(R.id.prevencao);
                prevencao.setText(Prevencao.TextoDePrevencao(getActivity(), poluenteslocal.get(0)));
                TextView local = (TextView) rootview.findViewById(R.id.local);
                local.setText(EncontraLocalizacao());

                Log.d("indice_localfrag", "TabSelecionado");

                //DEBUG
                Log.d("Latitude: ", String.valueOf(GPSLocal.getLatitude()));
                Log.d("Longitude: ", String.valueOf(GPSLocal.getLongitude()));
                for (Estacao e : Global.estacoes) {
                    Log.d(e.getId(), String.valueOf(e.getDistanciaparaGPS()));
                }
                for (Poluente p : poluenteslocal) {
                    Log.d(p.getNome(), String.valueOf(p.getIndice()));
                }
            } else {
                // Leitura do GPS ainda no foi feita.
                AlertDialog.Builder aviso = new AlertDialog.Builder(rootview.getContext());
                aviso.setMessage(
                        "Leitura do GPS ainda no foi feita. Tente novamente saindo e voltando para essa aba.");
                aviso.setCancelable(true);
                aviso.setNeutralButton("OK", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
                AlertDialog alerta = aviso.create();
                alerta.show();
            }
        } else if (!PermissaodoGPS(getActivity())) {
            // Checo se eh uma issue de permissao e pergunto se quer ativar.
            AlertDialog.Builder bPERERR = new AlertDialog.Builder(getActivity());
            bPERERR.setTitle("Sem permisso");
            bPERERR.setMessage(
                    "Sem permisso no acesso ao GPS, atualizao impossvel. Deseja permitir? \n(Saia e volte para essa aba para atualizar.)");
            bPERERR.setCancelable(true);
            bPERERR.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    verifyGPSpermission(getActivity());
                }
            });
            bPERERR.setNegativeButton("No", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            AlertDialog alerta_permissao = bPERERR.create();
            alerta_permissao.show();
        }
    }
    return rootview;
}

From source file:com.otaupdater.utils.KernelInfo.java

public void showUpdateDialog(final Context ctx) {
    AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
    alert.setTitle(R.string.alert_update_title);
    alert.setMessage(ctx.getString(R.string.alert_update_kernel_to, kernelName, version));

    alert.setPositiveButton(R.string.alert_download, new DialogInterface.OnClickListener() {
        @Override/*from w ww .jav a2  s .  c om*/
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();

            final File file = new File(Config.KERNEL_DL_PATH_FILE, getDownloadFileName());
            if (file.exists()) {
                Log.v("OTA::Download", "Found old zip, checking md5");

                InputStream is = null;
                try {
                    is = new FileInputStream(file);
                    MessageDigest digest = MessageDigest.getInstance("MD5");
                    byte[] data = new byte[4096];
                    int nRead = -1;
                    while ((nRead = is.read(data)) != -1) {
                        digest.update(data, 0, nRead);
                    }
                    String oldMd5 = Utils.byteArrToStr(digest.digest());
                    Log.v("OTA::Download", "old zip md5: " + oldMd5);
                    if (!md5.equalsIgnoreCase(oldMd5)) {
                        file.delete();
                    } else {
                        //TODO show flash dialog
                        return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    file.delete();
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (Exception e) {
                        }
                    }
                }
            }

            final long dlID = fetchFile(ctx);

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setTitle(R.string.alert_downloading);
            builder.setMessage(ctx.getString(R.string.alert_downloading_changelog, changelog));
            builder.setCancelable(true);
            builder.setPositiveButton(R.string.alert_hide, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
                    dm.remove(dlID);
                }
            });
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alert.create().show();
}

From source file:com.otaupdater.utils.RomInfo.java

public void showUpdateDialog(final Context ctx) {
    AlertDialog.Builder alert = new AlertDialog.Builder(ctx);
    alert.setTitle(R.string.alert_update_title);
    alert.setMessage(ctx.getString(R.string.alert_update_rom_to, romName, version));

    alert.setPositiveButton(R.string.alert_download, new DialogInterface.OnClickListener() {
        @Override/*w  w  w  . j ava2 s.  c  o m*/
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();

            final File file = new File(Config.ROM_DL_PATH_FILE, getDownloadFileName());
            if (file.exists()) {
                Log.v("OTA::Download", "Found old zip, checking md5");

                InputStream is = null;
                try {
                    is = new FileInputStream(file);
                    MessageDigest digest = MessageDigest.getInstance("MD5");
                    byte[] data = new byte[4096];
                    int nRead = -1;
                    while ((nRead = is.read(data)) != -1) {
                        digest.update(data, 0, nRead);
                    }
                    String oldMd5 = Utils.byteArrToStr(digest.digest());
                    Log.v("OTA::Download", "old zip md5: " + oldMd5);
                    if (!md5.equalsIgnoreCase(oldMd5)) {
                        file.delete();
                    } else {
                        //TODO show flash dialog
                        return;
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    file.delete();
                } finally {
                    if (is != null) {
                        try {
                            is.close();
                        } catch (Exception e) {
                        }
                    }
                }
            }

            final long dlID = fetchFile(ctx);

            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setTitle(R.string.alert_downloading);
            builder.setMessage(ctx.getString(R.string.alert_downloading_changelog, changelog));
            builder.setCancelable(true);
            builder.setPositiveButton(R.string.alert_hide, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                    DownloadManager dm = (DownloadManager) ctx.getSystemService(Context.DOWNLOAD_SERVICE);
                    dm.remove(dlID);
                }
            });
        }
    });

    alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    alert.create().show();
}

From source file:com.semaphore.sm.MainActivity.java

private void clearInitd() {
    AlertDialog.Builder ad = new AlertDialog.Builder(this);
    ad.setMessage("All files in init.d directory will be deleted.\nDo you want to continue?");
    ad.setCancelable(false);
    ad.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            int ret = Commander.getInstance().run("rm -r /system/etc/init.d/*", true);
            if (ret == 0) {
                Toast toast = Toast.makeText(getApplicationContext(), "init.d cleared successfully",
                        Toast.LENGTH_LONG);
                toast.show();/* w  ww .j  a v  a2 s .  c o m*/
            }
        }
    });
    ad.setNegativeButton("Cancel", null);
    ad.show();
}

From source file:com.osama.cryptofm.filemanager.ui.FilemanagerTabs.java

private void getExternalStoragePermissions() {
    Log.d(TAG, "getExternalStoragePermissions: Getting permissions");
    //inform user what to do
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setCancelable(false);
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override/*from w w w.  j  a v a 2  s  .c  o  m*/
        public void onClick(DialogInterface dialogInterface, int i) {
            Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
            startActivityForResult(intent, GET_PERMISSION_CODE);
        }
    });
    dialog.setMessage("Looks like you have external sdcard. "
            + "Please choose it in next screen to enable read and write on it. "
            + "Otherwise I will not be able to use it");
    dialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            mStorageTitles[0] = mStorageTitles[1];
            Toast.makeText(FilemanagerTabs.this, "I wont be able to perform any operation on external sdcard",
                    Toast.LENGTH_LONG).show();

        }
    });
    dialog.setTitle("Need permission");
    dialog.show();

}

From source file:com.javielinux.dialogs.CreateDefaultColumnsUserDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    userId = getArguments().getLong("user_id");

    userEntity = new Entity("users", userId);

    CharSequence[] choices = new CharSequence[3];
    choices[0] = getString(R.string.timeline);
    choices[1] = getString(R.string.mentions);
    choices[2] = getString(R.string.direct_messages);

    final boolean[] isChoices = new boolean[] { true, true, true };

    LinearLayout llTitle = new LinearLayout(getActivity());
    llTitle.setOrientation(LinearLayout.VERTICAL);
    final CheckBox boxInvite = new CheckBox(getActivity());
    boxInvite.setText(R.string.follow_tweettopics);
    boxInvite.setChecked(true);//w  w  w  . j ava2s . co  m
    llTitle.addView(boxInvite);
    TextView txtTitle = new TextView(getActivity());
    txtTitle.setText(R.string.create_columns);
    txtTitle.setTextSize(25);
    llTitle.addView(txtTitle);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setCustomTitle(llTitle);
    builder.setMultiChoiceItems(choices, isChoices, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            isChoices[whichButton] = isChecked;
        }
    });
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // choices
            int count = DataFramework.getInstance().getEntityListCount("columns", "") + 1;
            if (isChoices[0]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_TIMELINE);
                Entity timeline = new Entity("columns");
                timeline.setValue("description", type.getString("description"));
                timeline.setValue("type_id", type);
                timeline.setValue("position", count);
                timeline.setValue("user_id", userEntity.getId());
                timeline.save();
                count++;
            }
            if (isChoices[1]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_MENTIONS);
                Entity mentions = new Entity("columns");
                mentions.setValue("description", type.getString("description"));
                mentions.setValue("type_id", type);
                mentions.setValue("position", count);
                mentions.setValue("user_id", userEntity.getId());
                mentions.save();
                count++;
            }
            if (isChoices[2]) {
                Entity type = new Entity("type_columns", (long) TweetTopicsUtils.COLUMN_DIRECT_MESSAGES);
                Entity dms = new Entity("columns");
                dms.setValue("description", type.getString("description"));
                dms.setValue("type_id", type);
                dms.setValue("position", count);
                dms.setValue("user_id", userEntity.getId());
                dms.save();
            }

            ((TweetTopicsActivity) getActivity()).refreshColumns();

            // create friend
            if (boxInvite.isChecked()) {
                Utils.showMessage(getActivity(), getActivity().getString(R.string.thanks));
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            ConnectionManager.getInstance().getTwitter(userEntity.getId())
                                    .createFriendship("tweettopics_app");
                        } catch (TwitterException e1) {
                            e1.printStackTrace();
                        } catch (IllegalArgumentException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }

    });

    return builder.create();

}

From source file:edu.cwru.apo.Home.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();/*from w w  w  .  j  ava2  s.com*/
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    JSONArray caseID = result.getJSONArray("caseID");
                    JSONArray first = result.getJSONArray("first");
                    JSONArray last = result.getJSONArray("last");
                    JSONArray phone = result.getJSONArray("phone");
                    JSONArray family = result.getJSONArray("family");
                    ContentValues values;
                    for (int i = 0; i < numbros; i++) {
                        values = new ContentValues();
                        values.put("_id", caseID.getString(i));
                        values.put("first", first.getString(i));
                        values.put("last", last.getString(i));
                        values.put("phone", phone.getString(i));
                        values.put("family", family.getString(i));
                        database.replace("phoneDB", null, values);
                    }
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    } else if (method == Methods.checkAppVersion) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    String appVersion = result.getString("version");
                    String appDate = result.getString("date");
                    final String appUrl = result.getString("url");
                    PackageInfo pinfo = this.getPackageManager().getPackageInfo(getPackageName(), 0);
                    ;
                    if (appVersion.compareTo(pinfo.versionName) != 0) {
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.setTitle("Upgrade");
                        builder.setMessage("Update available, ready to upgrade?");
                        builder.setIcon(R.drawable.icon);
                        builder.setCancelable(false);
                        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                Intent promptInstall = new Intent("android.intent.action.VIEW",
                                        Uri.parse("https://apo.case.edu:8090/app/" + appUrl));
                                startActivity(promptInstall);
                            }
                        });
                        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });
                        AlertDialog alert = builder.create();
                        alert.show();
                    } else {
                        Toast msg = Toast.makeText(this, "No updates found", Toast.LENGTH_LONG);
                        msg.show();
                    }
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (NameNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}