Example usage for android.app AlertDialog show

List of usage examples for android.app AlertDialog show

Introduction

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

Prototype

public void show() 

Source Link

Document

Start the dialog and display it on screen.

Usage

From source file:com.appdupe.flamer.LoginUsingFacebook.java

/**
 * Showing an alert dialog to usre in case of any error.
 * /*from w w  w. j a  va  2  s .  co  m*/
 * @param title
 *            - title for the dialog.
 * @param message
 *            - error message.
 */
private void ErrorMessage(String title, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(LoginUsingFacebook.this);
    builder.setTitle(title);
    builder.setMessage(message);

    builder.setPositiveButton(getResources().getString(R.string.okbuttontext),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    dialog.dismiss();
                }
            });

    AlertDialog alert = builder.create();
    alert.setCancelable(false);
    alert.show();
}

From source file:se.lu.nateko.edca.BackboneSvc.java

/**
  * Method that displays an alert dialog to the user showing the string argument as the message text.
  * @param message Message to display in the alert dialog.
  * @param target The activity to display the AlertDialog in, pass null to default to the "active" Activity.
  *///  w w w. ja  v  a2 s.  co m
public void showAlertDialog(String message, Activity target) {
    Log.d(TAG, "showAlertDialog(String) called.");
    final String msg = message;
    final Activity tg = target;
    /*
      * By sending the code in "action" to the runOnUiThread() method from a separate thread,
      * its code will be placed in the UI Thread Message queue and thus happen after other
      * queued messages (such as displaying the layout).
      */
    new Thread(new Runnable() {
        public void run() {
            Runnable action = new Runnable() {
                public void run() {
                    /* The following is put on the Message queue. */
                    AlertDialog alertDialog = new AlertDialog.Builder((tg == null) ? getActiveActivity() : tg)
                            .create();
                    alertDialog.setMessage(msg);

                    /* Add a button to the dialog and set its text and button listener. */
                    alertDialog.setButton(
                            alertDialog.getContext().getString(R.string.service_alert_buttontext_ok),
                            new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            });
                    alertDialog.show(); // Display the dialog to the user.
                }
            };
            ((tg == null) ? getActiveActivity() : tg).runOnUiThread(action);
        }
    }).start();

}

From source file:devza.app.android.droidnetkey.FirewallAction.java

@Override
protected void onPostExecute(Integer result) {
    /*INVALID_CREDENTIALS = -1;
    TIMED_OUT = -2;//w  ww .  ja va  2 s  . co m
    GENERAL_ERROR = -3;*/
    if (!refresh) {
        d.dismiss();

        if (result < 0) {
            AlertDialog error = new AlertDialog.Builder(this.context).create();
            error.setTitle("Error");
            error.setButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface d, int id) {
                    d.cancel();
                }
            });

            String msg;

            switch (result) {
            case INVALID_CREDENTIALS:
                msg = "Invalid Username or Password";
                break;
            case TIMED_OUT:
                msg = "Connection Timed Out. Is your device connected to the internet?";
                break;
            case UNKNOWN_HOST:
                msg = "Could not connect. Is your device connected to the internet?";
                break;
            case GENERAL_ERROR:
                msg = "General Error.\n Please send some more information about this error to 15629368@sun.ac.za";
                break;
            default:
                msg = "General Error.\n Please send some more information about this error to 15629368@sun.ac.za";
                break;
            }
            error.setMessage(msg);
            error.show();
        } else {
            if (result == CONNECTED) {
                Intent usage = new Intent(this.context, UsageActivity.class);
                this.context.startActivity(usage);
                this.s.showNotification(true);
                this.s.startTimer();
            } else {
                Intent main = new Intent(this.context, MainActivity.class);
                this.context.startActivity(main);
                this.s.showNotification(false);
            }
        }
    }
}

From source file:com.android.quake.llvm.DownloaderActivity.java

private void onDownloadFailed(String reason) {
    Log.e(LOG_TAG, "Download stopped: " + reason);
    String shortReason;/*from   w  ww.  j a va 2 s .co  m*/
    int index = reason.indexOf('\n');
    if (index >= 0) {
        shortReason = reason.substring(0, index);
    } else {
        shortReason = reason;
    }
    AlertDialog alert = new Builder(this).create();
    alert.setTitle(R.string.download_activity_download_stopped);

    if (!mSuppressErrorMessages) {
        alert.setMessage(shortReason);
    }

    alert.setButton(getString(R.string.download_activity_retry), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            startDownloadThread();
        }

    });
    alert.setButton2(getString(R.string.download_activity_quit), new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }

    });
    try {
        alert.show();
    } catch (WindowManager.BadTokenException e) {
        // Happens when the Back button is used to exit the activity.
        // ignore.
    }
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void requestPin() {
    final String email = mEnterEmailAutoCompleteTextView.getText().toString().toLowerCase().trim();

    // Validate input
    if (!RegexPatterns.EMAIL.matcher(email).matches()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
        builder.setMessage(R.string.registration_email_not_valid);
        builder.setPositiveButton(R.string.rogerthat, null);
        AlertDialog dialog = builder.create();
        dialog.show();
        return;//w w  w . j a  v a  2s .c o m
    }
    // Check network connectivity
    if (!mService.getNetworkConnectivityManager().isConnected()) {
        UIUtils.showNoNetworkDialog(this);
        return;
    }
    UIUtils.hideKeyboard(this, mEnterEmailAutoCompleteTextView);
    sendRegistrationRequest(email);
}

From source file:org.csp.everyaware.offline.Map.java

/************************ ALERT DIALOG NO INTERNET AVAILABLE *************************************/

public void noConnectivityDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.alert_dialog_no_internet).setIcon(android.R.drawable.ic_dialog_info)
            .setTitle(R.string.app_name).setCancelable(false)
            .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }//  ww  w  . j  a  v  a  2s.com
            });

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:activities.PaintActivity.java

@Override
public void LayerMenuItem_LongPressed(int index) {
    //Button Agregar
    if (index == -1)
        return;//from   w  ww .j  a v a  2s  .  c o m

    /** S+olo se puede eliminar un color si hay ms de uno en la bandeja**/
    if (painter.numLayers() > 2) {
        AlertDialog.Builder builder = new AlertDialog.Builder(PaintActivity.this);
        final int _index = index;
        builder.setMessage("Eliminar color?").setCancelable(true)
                .setPositiveButton("Si", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        Log.d("LayerMenuItem", "Eliminando : " + _index);
                        deleteLayer(_index);
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.cancel();
                    }
                });

        AlertDialog alertDialog = builder.create();
        alertDialog.show();
    }

}

From source file:fm.smart.r1.ItemActivity.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it/*from w  ww. ja v  a2 s. co  m*/
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.getId());
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport,
                            Main.default_study_goal_id, item.getId(), null));

                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default goal

                        ItemActivity.add_sentence_goal_result = new AddSentenceResult(
                                Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id,
                                        item.getId(), sentence_id, null));

                        result = ItemActivity.add_sentence_goal_result;
                        if (ItemActivity.add_sentence_goal_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.getId(), Main.default_study_goal_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this, item.getId().toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:org.csp.everyaware.offline.Map.java

public void closeAppDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(R.string.alert_dialog_close_app).setIcon(android.R.drawable.ic_dialog_info)
            .setTitle(R.string.app_name).setCancelable(false)
            .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    closeApp();/* w w  w  . j a  va 2 s .  c  o m*/
                }
            }).setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.google.example.eightbitartist.DrawingActivity.java

private boolean checkConfiguration(boolean showDialog) {
    int[] ids = new int[] { R.string.app_id, R.string.achievement_5_turns, R.string.achievement_10_turns,
            R.string.achievement_got_one_wrong, R.string.achievement_guessed_correctly,
            R.string.achievement_started_a_game };

    // Check all of the resource IDs
    boolean correctlyConfigured = true;
    for (int id : ids) {
        if ("REPLACE_ME".equals(getString(id))) {
            correctlyConfigured = false;
        }/*from w  ww .  j  av  a 2 s  .  c  o  m*/
    }

    if (!correctlyConfigured) {
        Log.e(TAG, "Error: res/values/ids.xml contains invalid values.");
        if (showDialog) {
            // Show a dialog warning the developer
            AlertDialog ad = new AlertDialog.Builder(this).setTitle("Configuration Error")
                    .setMessage("One or more of your IDs is not configured correctly, "
                            + "please correctly configure res/values/ids.xml")
                    .setPositiveButton("OK", null).create();

            ad.show();
        }
    }

    return correctlyConfigured;
}