Example usage for android.app AlertDialog.Builder show

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

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.mhise.util.MHISEUtil.java

public static Dialog displayDialog(Context ctx, String message, String title) {

    AlertDialog.Builder alertDialogBuilder = null;
    try {/*ww w.  jav  a2s.  c  om*/
        if (!message.equals("") || !message.equals(null)) {

            alertDialogBuilder = new AlertDialog.Builder(ctx);

            alertDialogBuilder.setMessage(message);
            //alertDialogBuilder.setTitle(title);
            alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });
            // Showing Alert Message
            alertDialogBuilder.show();

        }
    } catch (NullPointerException e) {
        // TODO: handle exception

        Logger.debug("MHISEUtil-->Unable to display dialog message", "display dialog");

    }
    return alertDialogBuilder.create();
}

From source file:com.irccloud.android.activity.PastebinsActivity.java

public void onIRCEvent(int what, Object o) {
    IRCCloudJSONObject obj;//from w  w  w . j  a va2  s .c  o m
    switch (what) {
    case NetworkConnection.EVENT_SUCCESS:
        obj = (IRCCloudJSONObject) o;
        if (obj.getInt("_reqid") == reqid) {
            Log.d("IRCCloud", "Pastebin deleted successfully");
            reqid = -1;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    adapter.pastebins.remove(pasteToDelete);
                    adapter.notifyDataSetChanged();
                    checkEmpty();
                    pasteToDelete = null;
                }
            });
        }
        break;
    case NetworkConnection.EVENT_FAILURE_MSG:
        obj = (IRCCloudJSONObject) o;
        if (reqid != -1 && obj.getInt("_reqid") == reqid) {
            Crashlytics.log(Log.ERROR, "IRCCloud", "Delete failed: " + obj.toString());
            reqid = -1;
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    AlertDialog.Builder builder = new AlertDialog.Builder(PastebinsActivity.this);
                    builder.setTitle("Error");
                    builder.setMessage("Unable to delete this pastebin.  Please try again shortly.");
                    builder.setPositiveButton("Close", null);
                    builder.show();
                }
            });
        }
        break;
    default:
        break;
    }
}

From source file:com.intel.xdk.notification.Notification.java

public void confirm(String message, final String iden, String title, String ok, String cancel) {
    if (bConfirmBusy) {
        final String js = "javascript:var e = document.createEvent('Events');e.initEvent('intel.xdk.notification.confirm.busy',true,true);e.success=false;e.message='busy';e.id='"
                + iden + "';document.dispatchEvent(e);";
        activity.runOnUiThread(new Runnable() {

            public void run() {
                webView.loadUrl(js);//from w ww .j  a v a2s .  co  m
            }

        });
        return;
    }
    bConfirmBusy = true;

    if (title == null || title.length() == 0)
        title = "Please confirm";
    if (ok == null || ok.length() == 0)
        ok = "OK";
    if (cancel == null || cancel.length() == 0)
        cancel = "Cancel";

    AlertDialog.Builder alertBldr = new AlertDialog.Builder(activity);
    alertBldr.setCancelable(false);
    alertBldr.setMessage(message);
    alertBldr.setTitle(title);
    alertBldr.setPositiveButton(ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            processConfirm(true, iden);
        }
    });
    alertBldr.setNegativeButton(cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            processConfirm(false, iden);
        }
    });
    alertBldr.show();
}

From source file:com.jdom.get.stuff.done.android.AndroidApplicationContextFactory.java

public void displayProVersionPromo(String proAppName, String proVersionLink) {
    final String text = "For the cost of a soda, $0.99, you can enable the following features:\n"
            + "- No advertisements\n" + "- Sync frequency/action configuration\n"
            + "- Configure the fields displayed in the add/edit task page.\n\n"
            + "Click the OK button to load the pro version in the market viewer, or Cancel to stay with the free version.";

    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle("Upgrade");
    builder.setMessage(text);// w  w w .jav  a  2 s  .  co  m
    builder.setPositiveButton(OK_BUTTON_TEXT, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(Constants.PRO_VERSION_LINK));
            activity.startActivity(intent);
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
        }
    });

    builder.show();
}

From source file:com.andybotting.tramhunter.activity.StopDetailsActivity.java

/**
 * Show a dialog message for a given 'Special Event'
 * @param message/*from w w  w .j  a va  2  s. c o m*/
 */
private void showSpecialEvent(String message) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Special Event");
    dialogBuilder.setMessage(message);
    dialogBuilder.setPositiveButton("OK", null);
    dialogBuilder.setIcon(R.drawable.ic_dialog_alert);
    dialogBuilder.show();
}

From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java

/**
 * This method is used in the host application in the onRequestPermissionsResult method in case if a PUSH feedback is triggered.
 *
 * @param requestCode   the request code to be handled in the onRequestPermissionsResult method of the calling activity
 * @param permissions   the permissions/*from   www .jav a 2 s .  c o  m*/
 * @param grantResults  the granted results
 * @param activity      the activity from where the method is called
 * @param permission    the requested permission
 * @param dialogTitle   the dialog title for the rationale
 * @param dialogMessage the dialog message for the rationale
 */
public static void onRequestPermissionsResultCase(final int requestCode, @NonNull String[] permissions,
        @NonNull int[] grantResults, @NonNull final Activity activity, @NonNull final String permission,
        final int dialogTitle, final int dialogMessage, final long applicationId, @NonNull final String baseURL,
        @NonNull final String language) {
    final Intent intent = new Intent(activity, FeedbackActivity.class);
    intent.putExtra(FeedbackActivity.EXTRA_KEY_APPLICATION_ID, applicationId);
    intent.putExtra(FeedbackActivity.EXTRA_KEY_BASE_URL, baseURL);
    intent.putExtra(FeedbackActivity.EXTRA_KEY_LANGUAGE, language);
    if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
        // Permission was already granted. Taking a screenshot of the current screen automatically and open the FeedbackActivity from the feedback library
        startActivity(activity, intent, baseURL, true);
    } else {
        if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
            // The user denied the permission without checking 'Never ask again'. Show the rationale
            AlertDialog.Builder alertBuilder = new AlertDialog.Builder(activity);
            alertBuilder.setTitle(dialogTitle);
            alertBuilder.setMessage(dialogMessage);
            alertBuilder.setPositiveButton(R.string.supersede_feedbacklibrary_retry_string,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(activity, new String[] { permission },
                                    requestCode);
                        }
                    });
            alertBuilder.setNegativeButton(R.string.supersede_feedbacklibrary_not_now_text,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                            startActivity(activity, intent, baseURL, false);
                        }
                    });
            alertBuilder.setCancelable(false);
            alertBuilder.show();
        } else {
            // Open the FeedbackActivity from the feedback library without automatically taking a screenshot
            startActivity(activity, intent, baseURL, false);
        }
    }
}

From source file:br.com.GUI.perfil.HomePersonal.java

public boolean onOptionsItemSelected(MenuItem item) {
    // Take appropriate action for each action item click
    switch (item.getItemId()) {

    case R.id.actSolicitacoesDeAmizadePersonal:
        ArrayList<Aluno> solicitacoes = new Aluno().buscarAlunoNaoConfirmadoPorPersonalWeb("",
                pref.getString("usuario", null));
        if (!solicitacoes.isEmpty()) {
            Intent i = new Intent(this, SolicitacoesDeAmizade.class);
            startActivity(i);/* w w w  .j a v  a2 s  .  com*/
        } else {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
            alertDialog.setTitle("Ops...");
            alertDialog.setMessage(R.string.label_voce_nao_possui_solicitacoes_de_amizade);
            alertDialog.setIcon(R.drawable.profile);
            alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            // Showing Alert Message
            alertDialog.show();
        }

        return true;
    case R.id.actLogoutPersonal:
        finish();
        Intent login = new Intent(this, Login.class);
        login.putExtra("logout", true);
        editor.clear();
        editor.commit();
        startActivity(login);
        return true;
    case R.id.actAdicionarAlunos:
        Intent adicionarAlunos = new Intent(this, BuscarUsuario.class);
        startActivity(adicionarAlunos);
        return true;
    case R.id.actAlterarDadosPessoaisPersonal:
        if (pref.getBoolean("isFacebookUser", false)) {
            AlertDialog.Builder alertDialog = new AlertDialog.Builder(HomePersonal.this);
            alertDialog.setTitle("Erro");
            alertDialog.setMessage(
                    "Seu cadastro est vinculado ao Facebook, sendo assim, no  possivel alterao de informaes pessoais");
            alertDialog.setIcon(R.drawable.profile);
            alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            // Showing Alert Message
            alertDialog.show();
        } else {
            Intent alterarDados = new Intent(this, AlterarDadosPessoais.class);
            startActivity(alterarDados);
        }

        return true;
    case R.id.actPerfil:
        Intent perfilIntent = new Intent(this, PerfilPersonal.class);
        startActivity(perfilIntent);
        return true;

    case R.id.actNovaAvaliacao:
        Intent avaliacoesIntent = new Intent(this, AvaliarGorduraCorporal.class);
        startActivity(avaliacoesIntent);
        return true;
    case R.id.actNovoTreinamento:

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("Ops...");
        alertDialog.setMessage("Digite um nome para o novo treinamento");
        alertDialog.setIcon(R.drawable.critical);

        // Set an EditText view to get user input 
        final EditText input = new EditText(this);
        alertDialog.setView(input);

        alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                Treinamento t = new Treinamento(0, input.getText().toString(), null, null,
                        pref.getString("usuario", null), null);

                //Log.i("interface: treinamento", t.toString());
                try {
                    int resultado = t.salvarTreinamentoWeb(b);
                    if (resultado > 0) {
                        Log.i("interface: salvei web", "salvei web");
                        t.setCodTreinamento(resultado);
                        if (t.salvarTreinamento(b, pref.getString("usuario", null))) {
                            Log.i("interface: salvei local", "salvei local");
                            Toast.makeText(HomePersonal.this, "Salvo com sucesso!", Toast.LENGTH_SHORT).show();
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                    Toast.makeText(HomePersonal.this, "Erro ao salvar!", Toast.LENGTH_SHORT).show();
                }
            }
        });
        alertDialog.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();

            }
        });
        // Showing Alert Message
        alertDialog.show();

    }

    return false;
}

From source file:com.google.zxing.client.android.CaptureActivity.java

private void displayFrameworkBugMessageAndExit() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(EUExUtil.getResStringID("app_name")));
    builder.setMessage(getString(EUExUtil.getResStringID("plugin_uexscanner_msg_camera_framework_bug")));
    builder.setPositiveButton(EUExUtil.getResStringID("confirm"), new FinishListener(this));
    builder.setOnCancelListener(new FinishListener(this));
    builder.show();
}

From source file:com.t2.androidspineexample.AndroidSpineExampleActivity.java

/**
 * Validates sensors, makes sure that bluetooth is on and each sensor has a parameter associated with it
 *//*from w ww .  j a  va 2s.  co m*/
void validateBioSensors() {

    // First make sure that bluetooth is enabled
    if (!mBluetoothEnabled) {
        AlertDialog.Builder alert1 = new AlertDialog.Builder(this);

        alert1.setMessage("Bluetooth is not enabled on your device.");

        alert1.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
            }
        });
        alert1.show();
    }
    String badSensorName = null;
}

From source file:com.android.applications.todoist.views.SupportForm.java

private void showAlert(String title, String message, String button_text, Boolean finish) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this).setTitle(title).setMessage(message);
    if (finish) {
        dialog.setNeutralButton(button_text, new DialogInterface.OnClickListener() {
            @Override//  ww  w .  ja va  2s .c om
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
    } else {
        dialog.setNeutralButton(button_text, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //Do nothing                  
            }
        });
    }

    dialog.show();
}