Example usage for android.app AlertDialog.Builder create

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

Introduction

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

Prototype

public void create() 

Source Link

Document

Forces immediate creation of the dialog.

Usage

From source file:net.net76.lifeiq.TaskiQ.RegisterActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    inputFirstname = (EditText) findViewById(R.id.firstname);
    inputSurname = (EditText) findViewById(R.id.surname);
    inputUserID = (EditText) findViewById(R.id.userID);
    inputEmail = (EditText) findViewById(R.id.email);
    //1 inputPassword = (EditText) findViewById(R.id.password);
    //1inputPassword2 = (EditText) findViewById(R.id.password2);
    Spinner spinner = (Spinner) findViewById(R.id.spinner);
    EULA = (TextView) findViewById(R.id.EULA);

    SpannableString content = new SpannableString(EULA.getText().toString());
    content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
    EULA.setText(content);//from  w  ww.j a va2 s .co  m
    EULA.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            PackageInfo versionInfo = getPackageInfo();
            // EULA title
            String title = RegisterActivity.this.getString(R.string.app_name) + " v " + versionInfo.versionName;

            // EULA text
            String message = RegisterActivity.this.getString(R.string.eula_string);

            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(RegisterActivity.this)
                    .setTitle(title).setMessage(message).setCancelable(false)
                    .setPositiveButton(R.string.accept, new Dialog.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {

                            EULAAccept = true;
                            // Close dialog
                            dialogInterface.dismiss();

                        }
                    }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                            EULAAccept = false;

                        }

                    });
            builder.create().show();
        }

    });

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.Country_array,
            android.R.layout.simple_spinner_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            Log.v("item", (String) parent.getItemAtPosition(position));
            countryString = (String) parent.getItemAtPosition(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
        }
    });

    btnRegister = (Button) findViewById(R.id.btnRegister);
    btnLinkToLogin = (Button) findViewById(R.id.btnLinkToLoginScreen);

    // Progress dialog
    pDialog = new ProgressDialog(this);
    //pDialog.setCancelable(false);
    pDialog.setCanceledOnTouchOutside(false);

    // Session manager
    session = new SessionManager(getApplicationContext());

    // SQLite database handler
    db = new SQLiteHandler(getApplicationContext());

    // Check if user is already logged in or not
    if (session.isLoggedIn()) {
        // User is already logged in. Take him to main activity
        Intent intent = new Intent(RegisterActivity.this, MainActivity.class);
        startActivity(intent);
        finish();
    }

    // Register Button Click event
    btnRegister.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            String Firstname = inputFirstname.getText().toString();
            String Surname = inputSurname.getText().toString();
            String UserID = inputUserID.getText().toString();
            String email = inputEmail.getText().toString();
            //1    String password = inputPassword.getText().toString();
            //1   String password2 = inputPassword2.getText().toString();

            if (!Firstname.isEmpty() && !Surname.isEmpty() && !email.isEmpty() && !UserID.isEmpty()) {

                if (isEmailValid(email)) {

                    if (!UserID.contains(" ")) {

                        if (!countryString.equals("Select country of residence")) {
                            if (EULAAccept.equals(true)) {

                                if (isNetworkAvaliable(getApplicationContext())) {
                                    registerUser(Firstname, Surname, UserID, email, countryString);
                                } else {
                                    Toast.makeText(getApplicationContext(),
                                            "Currently there is no network. Please try later.",
                                            Toast.LENGTH_SHORT).show();
                                }
                            } else {
                                Toast.makeText(getApplicationContext(),
                                        "Please read and accept End User License Agreement.",
                                        Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(getApplicationContext(), "Please select a country of residence.",
                                    Toast.LENGTH_SHORT).show();
                        }

                    } else {
                        Toast.makeText(getApplicationContext(), "In the User ID no spaces are allowed.",
                                Toast.LENGTH_SHORT).show();
                    }

                } else {
                    Toast.makeText(getApplicationContext(), "Please enter a valid email address!",
                            Toast.LENGTH_SHORT).show();
                }

            } else {
                Toast.makeText(getApplicationContext(), "Please enter your details!", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    // Link to Login Screen
    btnLinkToLogin.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), LoginActivity.class);
            startActivity(i);
            finish();
        }
    });

}

From source file:eu.dirtyharry.androidopsiadmin.Main.java

public void getOPSIDepots() {

    final ProgressDialog dialog = ProgressDialog.show(Main.this, getString(R.string.gen_title_pleasewait),
            getString(R.string.pd_getdepots), true);
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dialog.dismiss();//from   ww  w . jav a 2s. c  o  m
            if (GlobalVar.getInstance().getError().equals("null")) {
                if (doit.equals("true")) {

                    JSONArray result = new JSONArray();
                    try {
                        result = opsiresult.getJSONArray("result");
                        depots = new String[result.length()];
                        for (int i = 0; i < result.length(); i++) {
                            depots[i] = result.getString(i);
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    AlertDialog.Builder builder = new AlertDialog.Builder(Main.this);
                    builder.setTitle(getString(R.string.gen_choose));
                    builder.setSingleChoiceItems(depots, -1, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            dialog.dismiss();
                            String depot = depots[item];
                            choosendepot = depot;

                            getOPSIDepotConfig(depot);

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

                } else if (doit.equals("serverdown")) {
                    Toast.makeText(Main.this, String.format(getString(R.string.to_servernotrechable), serverip),
                            // serverip + " "
                            // + getString(R.string.to_servernotrechable),
                            Toast.LENGTH_LONG).show();
                }
            } else {
                new Functions().msgBox(Main.this, getString(R.string.gen_title_error),
                        GlobalVar.getInstance().getError(), false);
            }

        }
    };
    Thread checkUpdate = new Thread() {
        public void run() {
            Looper.prepare();
            JSONArray JSONparams = new JSONArray();
            if (Networking.isServerUp(serverip, serverport, serverusername, serverpasswd)) {
                opsiresult = new JSONObject();
                opsiresult = eu.dirtyharry.androidopsiadmin.Networking.opsiGetJSONObject("rpc", serverip,
                        serverport, "getDepotIds_list", JSONparams, serverusername, serverpasswd);
                doit = "true";
            } else {
                doit = "serverdown";
                //
            }
            handler.sendEmptyMessage(0);
        }
    };
    checkUpdate.start();
}

From source file:info.snowhow.plugin.RecorderService.java

private void showNoGPSAlert() {
    Log.i(LOG_TAG, "No GPS available --- show Dialog");
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("GPS is disabled on your device. Would you like to enable it?")
            .setCancelable(false).setPositiveButton("GPS Settings", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent callGPSSettingIntent = new Intent(
                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    callGPSSettingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(callGPSSettingIntent);
                }/*w  ww  . ja  v a 2  s.c om*/
            });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            stopRecording();
            dialog.cancel();
        }
    });
    AlertDialog alert = alertDialogBuilder.create();
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alert.show();
}

From source file:mp.paschalis.WatchBookActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    app = (App) getApplication();/*ww  w .  j  av  a2  s. c  o m*/

    setContentView(R.layout.activity_watch_book);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Get arguments, to determine who opened this activity
    final Bundle extras = getIntent().getExtras();

    try {
        isAvailable = extras.getBoolean(App.ExtrasForWatchBookActivityFromBookSearch);
    } catch (Exception e) {
        isAvailable = false;
    }

    // Set the layout's data
    // Get layout's Data
    bookISBN = (TextView) findViewById(R.id.textViewBookISBN);

    bookTitle = (TextView) findViewById(R.id.textViewBookTitle);
    bookAuthors = (TextView) findViewById(R.id.textViewBookAuthors);
    bookPublishedYear = (TextView) findViewById(R.id.textViewBookPublishedYear);
    bookPageCount = (TextView) findViewById(R.id.textViewBookPageCount);
    bookDateOfInsert = (TextView) findViewById(R.id.textViewBookDateOfInsert);

    bookCoverImage = (ImageView) findViewById(R.id.imageViewBookCover);

    bookLanguage = (TextView) findViewById(R.id.textViewBookLanguage);

    textViewWatchBookAvailable = (TextView) findViewById(R.id.textViewWatchBookAvailable);

    buttonRequestBook = (Button) findViewById(R.id.buttonRequestBook);

    buttonSendMessage = (Button) findViewById(R.id.buttonSendMessage);
    progressBarSendMessage = (ProgressBar) findViewById(R.id.progressBarSendMessage);

    buttonSendMessage.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            final DataClassRequestABook dataClassRequestABook = new DataClassRequestABook();

            dataClassRequestABook.username = app.user.username;
            dataClassRequestABook.isbn = app.selectedBook.isbn;

            ArrayList<String> userWhoLent = new ArrayList<String>();
            // Find all users who lent this book
            for (Book.DataClassUser u : app.selectedBook.owners) {
                if (u.status == 0) {
                    userWhoLent.add(u.username);
                }
            }

            final CharSequence[] owners = userWhoLent.toArray(new CharSequence[userWhoLent.size()]);

            AlertDialog.Builder builder = new AlertDialog.Builder(WatchBookActivity.this);
            builder.setTitle(R.string.msgPickBookOwner_);
            builder.setItems(owners, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int item) {

                    dataClassRequestABook.owner = (String) owners[item];

                    // Send message to owner
                    Intent intent = new Intent(WatchBookActivity.this, SendMessageActivity.class);

                    intent.putExtra(App.ExtrasForSendMessage_DestinationUser, dataClassRequestABook.owner);

                    startActivity(intent);

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

    });

    if (!isAvailable) {
        textViewWatchBookAvailable.setText(R.string.no);
        App.setStyleErrorDirection(textViewWatchBookAvailable);
        buttonRequestBook.setEnabled(false);
    } else {

        textViewWatchBookAvailable.setText(R.string.yes);
        App.setStyleSuccessDirection(textViewWatchBookAvailable);

        // Requests a book
        buttonRequestBook.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                {

                    final DataClassRequestABook dataClassRequestABook = new DataClassRequestABook();

                    dataClassRequestABook.username = app.user.username;
                    dataClassRequestABook.isbn = app.selectedBook.isbn;

                    ArrayList<String> userWhoLent = new ArrayList<String>();
                    // Find all users who lent this book
                    for (Book.DataClassUser u : app.selectedBook.owners) {
                        if (u.status == 0) {
                            userWhoLent.add(u.username);
                        }
                    }

                    final CharSequence[] owners = userWhoLent.toArray(new CharSequence[userWhoLent.size()]);

                    AlertDialog.Builder builder = new AlertDialog.Builder(WatchBookActivity.this);
                    builder.setTitle(R.string.msgPickBookOwner_);
                    builder.setItems(owners, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int item) {

                            dataClassRequestABook.owner = (String) owners[item];

                            // Request the book
                            new AsyncTaskRequestABook().execute(dataClassRequestABook);

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

            }
        });// End of Req Button!

    }

    TextView tvnc = (TextView) findViewById(R.id.textViewNoCover);
    ProgressBar pb = (ProgressBar) findViewById(R.id.progressBarLoadCover);

    // show The Image and save it to Library
    ImageLoader.DataClassDisplayBookCover bk = new ImageLoader.DataClassDisplayBookCover();
    bk.iv = bookCoverImage;
    bk.isCover = true;
    bk.tv = tvnc;
    bk.pb = pb;
    bk.book = app.selectedBook;
    App.imageLoader.DisplayCover(bk);

    bitmapBookCover = ((BitmapDrawable) bookCoverImage.getDrawable()).getBitmap();

    // new DownloadImageTask(bookCoverImage, bookInfo)
    // .execute(bookInfo.imgURL);

    // Assign the appropriate data from our alert object above
    bookISBN.setText(app.selectedBook.isbn);
    bookTitle.setText(app.selectedBook.title);
    bookAuthors.setText(app.selectedBook.authors);
    bookPublishedYear.setText(Integer.valueOf(app.selectedBook.publishedYear).toString());
    bookPageCount.setText(Integer.valueOf(app.selectedBook.pageCount).toString());
    bookDateOfInsert
            .setText(App.makeTimeStampHumanReadble(getApplicationContext(), app.selectedBook.dateOfInsert));
    bookLanguage.setText(app.selectedBook.lang);

    progressBarRequestBook = (ProgressBar) findViewById(R.id.progressBarRequestBook);

    buttonRequestBook = (Button) findViewById(R.id.buttonRequestBook);

}

From source file:com.jonbanjo.cupsprint.CertificateActivity.java

private void removeCert(final String alias) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Remove Certificate?").setMessage(alias)
            .setPositiveButton("Remove", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    try {
                        trustStore.deleteEntry(alias);
                        FileOutputStream outputStream = openFileOutput(JfSSLScheme.trustfile, MODE_PRIVATE);
                        trustStore.store(outputStream, JfSSLScheme.password.toCharArray());
                        outputStream.flush();
                        outputStream.close();
                        certListAdaptor.remove(alias);
                    } catch (Exception e) {
                        System.out.println(e.toString());
                    }/*from   ww w  . j a va 2s . c om*/
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog dialog = builder.create();
    dialog.show();

}

From source file:se.anyro.tagtider.TransferActivity.java

private AlertDialog createSmsDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.sms_dialog_title);
    if (mPhoneNumber == null) {
        builder.setMessage(R.string.sms_dialog_message);
    } else {/*from   w w  w  . j  a va2 s.c  o  m*/
        builder.setMessage(String.format(getString(R.string.sms_dialog_message_free), mPhoneNumber));
    }
    builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (mPhoneNumber == null) {
                sendSms("0730121096", mTrain + " " + mStationId);
            } else {
                new StartSubscriptionTask().execute(mPhoneNumber, TYPE_SMS);
            }
        }
    });
    builder.setNegativeButton("Avbryt", null);
    final AlertDialog smsDialog = builder.create();
    return smsDialog;
}

From source file:it.mb.whatshare.Dialogs.java

/**
 * Shows a dialog informing the user that Whatsapp is not installed on the
 * device, and gives an option to hide the dialog in the future.
 * /*  w  ww. jav  a  2s  .  co m*/
 * @param activity
 *            the caller activity
 * @param intent
 *            the intent containing the content to be shared
 */
public static void whatsappMissing(final SendToWhatsappActivity activity, final Intent intent) {
    // @formatter:off
    DialogFragment dialog = new PatchedDialogFragment() {
        public Dialog onCreateDialog(Bundle savedInstanceState) {
            AlertDialog.Builder builder = getNoUiBuilder(activity)
                    .setTitle(activity.getString(R.string.whatsapp_not_installed_title))
                    .setMessage(activity.getString(R.string.whatsapp_not_installed)).setPositiveButton(
                            activity.getString(android.R.string.ok), new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    activity.startActivity(SendToAppActivity
                                            .createPlainIntent(intent.getStringExtra("message")));
                                }
                            })
                    .setNegativeButton(activity.getString(R.string.whatsapp_not_installed_dont_mind),
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    SharedPreferences pref = activity.getSharedPreferences("it.mb.whatshare",
                                            Context.MODE_PRIVATE);
                                    pref.edit()
                                            .putBoolean(SendToWhatsappActivity.HIDE_MISSING_WHATSAPP_KEY, true)
                                            .commit();
                                    activity.startActivity(SendToAppActivity
                                            .createPlainIntent(intent.getStringExtra("message")));
                                }
                            });
            Dialog dialog = builder.create();
            dialog.setCanceledOnTouchOutside(false);
            return dialog;
        }
    };
    dialog.show(activity.getSupportFragmentManager(), "whatsapp_missing");
    // @formatter:on
}

From source file:net.reichholf.dreamdroid.activities.MovieListActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final Dialog dialog;
    AlertDialog.Builder builder;

    switch (id) {
    case (DIALOG_DELETE_MOVIE_CONFIRM_ID):
        builder = new AlertDialog.Builder(this);
        builder.setTitle(mMovie.getString(Movie.TITLE)).setMessage(getText(R.string.delete_confirm))
                .setCancelable(false)/*from www.j  a va2 s .  co m*/
                .setPositiveButton(getText(android.R.string.yes), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        deleteMovie();
                        dialog.dismiss();
                    }
                }).setNegativeButton(getText(android.R.string.no), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.dismiss();
                        removeDialog(DIALOG_PICK_LOCATION_ID);
                    }
                });
        dialog = builder.create();
        break;

    case (DIALOG_PICK_LOCATION_ID):
        CharSequence[] locations = new CharSequence[DreamDroid.LOCATIONS.size()];

        int selectedIndex = 0;
        int lc = 0;
        for (String location : DreamDroid.LOCATIONS) {
            locations[lc] = location;
            if (location.equals(mCurrentLocation)) {
                selectedIndex = lc;
            }
            lc++;
        }

        builder = new AlertDialog.Builder(this);
        builder.setTitle(getText(R.string.choose_location));

        builder.setSingleChoiceItems(locations, selectedIndex, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String selectedLoc = DreamDroid.LOCATIONS.get(which);
                if (!selectedLoc.equals(mCurrentLocation)) {
                    mCurrentLocation = DreamDroid.LOCATIONS.get(which);
                    reload();
                }
                dialog.dismiss();
            }
        });

        dialog = builder.create();
        break;

    case (DIALOG_PICK_TAGS_ID):
        CharSequence[] tags = new CharSequence[DreamDroid.TAGS.size()];
        boolean[] selectedTags = new boolean[DreamDroid.TAGS.size()];

        int tc = 0;
        for (String tag : DreamDroid.TAGS) {
            tags[tc] = tag;

            if (mSelectedTags.contains(tag)) {
                selectedTags[tc] = true;
            } else {
                selectedTags[tc] = false;
            }

            tc++;
        }

        mTagsChanged = false;
        mOldTags = new ArrayList<String>();
        mOldTags.addAll(mSelectedTags);

        builder = new AlertDialog.Builder(this);
        builder.setTitle(getText(R.string.choose_tags));

        builder.setMultiChoiceItems(tags, selectedTags, new OnMultiChoiceClickListener() {
            /*
             * (non-Javadoc)
             * 
             * @see android.content.DialogInterface.
             * OnMultiChoiceClickListener
             * #onClick(android.content.DialogInterface, int, boolean)
             */
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                String tag = DreamDroid.TAGS.get(which);
                mTagsChanged = true;
                if (isChecked) {
                    if (!mSelectedTags.contains(tag)) {
                        mSelectedTags.add(tag);
                    }
                } else {
                    int idx = mSelectedTags.indexOf(tag);
                    if (idx >= 0) {
                        mSelectedTags.remove(idx);
                    }
                }
            }

        });

        builder.setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (mTagsChanged) {
                    reload();
                }
                dialog.dismiss();
                removeDialog(DIALOG_PICK_TAGS_ID);
            }

        });

        builder.setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mSelectedTags.clear();
                mSelectedTags.addAll(mOldTags);
                dialog.dismiss();
                removeDialog(DIALOG_PICK_TAGS_ID);
            }

        });

        dialog = builder.create();
        break;
    default:
        dialog = super.onCreateDialog(id);
    }

    return dialog;
}

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();/* w ww .  j  a v  a2  s . co  m*/
                    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();
            }
        }
    }
}

From source file:com.openerp.addons.note.EditNoteFragment.java

public void createNotetag() {

    AlertDialog.Builder builder = new Builder(scope.context());
    final EditText tag = new EditText(scope.context());
    builder.setTitle("Tag Name").setMessage("Enter new Tag").setView(tag);

    builder.setPositiveButton("Create", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int i) {
            // do something with onClick
            if (tag.getText().length() > 0) {
                LinkedHashMap<String, String> newTag = db.writeNoteTags(tag.getText().toString());
                noteTags.addObject(/*  w w  w  .ja v  a 2 s  .com*/
                        new TagsItems(Integer.parseInt(newTag.get("newID")), newTag.get("tagName"), ""));
            } else {
                Toast.makeText(scope.context(), "Enter Tag First", Toast.LENGTH_LONG).show();
            }
        }
    });

    builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface di, int i) {
        }
    });

    builder.create().show();
}