List of usage examples for android.app AlertDialog.Builder show
public void show()
From source file:com.phonegap.DroidGap.java
/** * Display an error dialog and optionally exit application. * //from w ww . j ava 2 s .co m * @param title * @param message * @param button * @param exit */ public void displayError(final String title, final String message, final String button, final boolean exit) { final DroidGap me = this; me.runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder dlg = new AlertDialog.Builder(me); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); dlg.setPositiveButton(button, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); if (exit) { me.finish(); } } }); dlg.create(); dlg.show(); } }); }
From source file:ch.hearc.drunksum.DrunkSumActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { /*// ww w . j av a 2 s . c om Gre le clic sur un lment du menu */ if (item.getItemId() == R.id.reinit) { // remet la somme 0 Toast.makeText(this, "Sum reinitialized", Toast.LENGTH_SHORT).show(); mSum = 0; setTitle("Sum: " + formatter.format(mSum)); } else if (item.getItemId() == R.id.divide) { // propose de divisier la somme AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("Divide sum by:"); final EditText input = new EditText(this); // n'afficher que les chiffres input.setInputType(InputType.TYPE_CLASS_NUMBER); alert.setView(input); alert.setPositiveButton("Divide", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { double div = 0; try { // une exception survient si le texte est vide // si c'est 0, div vaut infinity div = mSum / Double.parseDouble(input.getText().toString()); } catch (Exception e) { } final Snackbar snackBar = Snackbar.make(mGraphicOverlay, "Divided sum: " + formatter.format(div), Snackbar.LENGTH_INDEFINITE); snackBar.setAction("OK", new View.OnClickListener() { @Override public void onClick(View v) { snackBar.dismiss(); } }); snackBar.show(); } }); alert.show(); } return true; }
From source file:ch.uzh.supersede.feedbacklibrary.FeedbackActivity.java
private void onRequestPermissionsResultDenied(final int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults, @NonNull final String permission, int dialogMessage, @NonNull String dialogInstructions) { if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { // The user denied without checking 'Never ask again'. Show again the rationale AlertDialog.Builder alertBuilder = new AlertDialog.Builder(this); alertBuilder.setTitle(R.string.supersede_feedbacklibrary_permission_request_title); alertBuilder.setMessage(dialogMessage); alertBuilder.setPositiveButton(R.string.supersede_feedbacklibrary_retry_string, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions(FeedbackActivity.this, new String[] { permission }, requestCode); }//from w ww . ja v a 2s . c om }); alertBuilder.setNegativeButton(R.string.supersede_feedbacklibrary_not_now_text, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertBuilder.setCancelable(false); alertBuilder.show(); } else { // The user denied and checked the 'Never ask again' option. Show a short explanation dialog DialogUtils.showInformationDialog(this, new String[] { dialogInstructions }, false); } }
From source file:com.corporatetaxi.TaxiArrived_Acitivity.java
public void caceldialog() { AlertDialog.Builder builder = new AlertDialog.Builder(TaxiArrived_Acitivity.this); AppPreferences.setApprequestTaxiScreen(TaxiArrived_Acitivity.this, false); LayoutInflater inflater = getLayoutInflater(); View header = inflater.inflate(R.layout.dialog_heading, null); TextView textView = (TextView) header.findViewById(R.id.text); ImageView icon = (ImageView) header.findViewById(R.id.icon); icon.setImageResource(R.drawable.ic_launcher); textView.setText("Taxi Has Arrived"); builder.setCustomTitle(header);//ww w . jav a 2s. c o m builder.setCancelable(false); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); builder.show(); }
From source file:palamarchuk.smartlife.app.RegisterActivity.java
private void startRegisterProcess(String deviceKey) { String url = ServerRequest.DOMAIN + "/users"; MultipartEntity multipartEntity;/* w w w .ja v a 2 s .c o m*/ // collect data try { multipartEntity = collectData(); multipartEntity.addPart("token", new StringBody(deviceKey)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); throw new RuntimeException(e); } QueryMaster queryMaster = new QueryMaster(RegisterActivity.this, url, QueryMaster.QUERY_POST, multipartEntity); queryMaster.setProgressDialog(); queryMaster.setOnCompleteListener(new QueryMaster.OnCompleteListener() { @Override public void complete(String serverResponse) { try { JSONObject jsonObject = new JSONObject(serverResponse); String status = jsonObject.getString("status"); if (status.equalsIgnoreCase(ServerRequest.STATUS_SUCCESS)) { Toast.makeText(RegisterActivity.this, "?? ?", Toast.LENGTH_SHORT).show(); SharedPreferences.Editor editor = sharedPreferences.edit(); editor.putString(SHARED_PREF_PHONE, phone.getText().toString()); editor.putString(SHARED_PREF_PASSWORD, password.getText().toString()); editor.apply(); AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this); builder.setMessage( "? ?? ?, "); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // startLoginActivityAutoStart(RegisterActivity.this); Intent loginActivity = new Intent(RegisterActivity.this, LoginActivity.class); loginActivity.putExtra(LoginActivity.SMS_VERIFICATION, true); loginActivity.putExtra(LoginActivity.AUTOLOGIN, true); startActivity(loginActivity); finish(); } }); builder.show(); } else if (status.equalsIgnoreCase(ServerRequest.STATUS_ERROR)) { if (jsonObject.has(ServerRequest.SMS_VERIFICATION_ERROR)) { int verificationErrorCode = jsonObject.getInt(ServerRequest.SMS_VERIFICATION_ERROR); if (verificationErrorCode == 1) { AlertDialog.Builder pleaseTryLogin = new AlertDialog.Builder(RegisterActivity.this); pleaseTryLogin.setMessage(jsonObject.getString("message")); pleaseTryLogin.setPositiveButton("Ok", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startLoginActivityAutoStart(RegisterActivity.this); } }); pleaseTryLogin.show(); } } else { Toast.makeText(RegisterActivity.this, jsonObject.getString("message"), Toast.LENGTH_SHORT).show(); } } } catch (JSONException ex) { ex.printStackTrace(); throw new RuntimeException("Server response cannot be cast to JSONObject"); } } @Override public void error(int errorCode) { Toast.makeText(RegisterActivity.this, " ?! ? !", Toast.LENGTH_SHORT).show(); } }); queryMaster.start(); }
From source file:com.ccxt.whl.activity.SettingsFragment.java
/** * ?/* w w w . j a v a 2s. c o m*/ */ public void change_headurl() { /*//SDcard if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)){ //SDcardTestSyncListView IMAGE_FILE_LOCATION = Environment.getExternalStorageDirectory()+Constant.CACHE_DIR_IMAGE+"/temp.jpg"; imageUri = Uri.parse(IMAGE_FILE_LOCATION); //File cutFile = new File(Constant.CACHE_DIR_IMAGE,"temp.jpg"); //cutFile.getParentFile().mkdirs(); File dir = new File(IMAGE_FILE_LOCATION); if (!dir.exists()) { try { // dir.createNewFile(); } catch (Exception e) { //println(e); } } }else{ Toast.makeText(getActivity(), "SD????", 0).show(); return; }*/ /*-?*/ if (!CommonUtils.isExitsSdcard()) { Toast.makeText(getActivity(), "SD????", 0).show(); return; } cameraFile = new File(PathUtil.getInstance().getImagePath(), DemoApplication.getInstance().getUser() + System.currentTimeMillis() + ".jpg"); if (cameraFile == null && !cameraFile.exists()) {//? cameraFile.getParentFile().mkdirs(); } AlertDialog.Builder builder = new Builder(getActivity()); String[] strarr = { "?", "" }; builder.setItems(strarr, new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // TODO ? if (arg1 == 0) {//? selectPicFromCamera(); } else {// selectPicFromLocal(); } } }); builder.show(); }
From source file:com.sssemil.sonyirremote.ir.ir.java
public boolean prepBISpinner() { try {/*from www.j a va2s . com*/ spinner = (Spinner) findViewById(R.id.spinner); item = spinner.getSelectedItem().toString(); result = true; } catch (NullPointerException ex) { AlertDialog.Builder adb = new AlertDialog.Builder(this); adb.setTitle(getString(R.string.error)); adb.setMessage(getString(R.string.you_need_to_select)); adb.setIcon(android.R.drawable.ic_dialog_alert); adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result = false; } }); adb.show(); } return result; }
From source file:com.example.android.rowanparkingpass.Activities.CreateVehicleActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent myIntent;//from w w w . jav a 2s . c om switch (item.getItemId()) { // action with ID action_delete was selected case R.id.action_delete: AlertDialog.Builder alertDialog = new AlertDialog.Builder(CreateVehicleActivity.this); alertDialog.setTitle("Delete Driver?"); alertDialog.setMessage(vehicle.getCarInfo()); alertDialog.setPositiveButton("Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent myIntent = new Intent(CreateVehicleActivity.this, VehiclesActivity.class); myIntent.putExtra(MODE, mode.VEHICLES_LIST.name()); if (SaveData.getSync()) { SendInfoVehicle s = new SendInfoVehicle(); s.deleteVehicle(String.valueOf(vehicle.getVehicleId())); } // delete driver from database db.deleteVehicle(String.valueOf(vehicle.getVehicleId())); new DatabaseHandlerPasses(context) .deleteRequestVehicleID(String.valueOf(vehicle.getVehicleId())); startActivity(myIntent); finish(); } }); alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); alertDialog.show(); break; default: break; } return true; }
From source file:com.sssemil.sonyirremote.ir.ir.java
public void doOnDown() { spinner6 = ((Spinner) findViewById(R.id.spinner6)); try {// ww w .j av a2 s . c o m test = spinner6.getSelectedItem().toString(); lastWord = test.substring(test.lastIndexOf(" ") + 1); cont = true; } catch (NullPointerException ex) { cont = false; AlertDialog.Builder adb = new AlertDialog.Builder(this); adb.setTitle(getString(R.string.error)); adb.setMessage(getString(R.string.you_need_to_select)); adb.setIcon(android.R.drawable.ic_dialog_alert); adb.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); adb.show(); } if (cont) { // execute this when the downloader must be fired final DownloadTask downloadTask = new DownloadTask(ir.this); try { downloadTask.execute(lastWord).get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } if (!resp.equals("ok")) { AlertDialog.Builder adb1 = new AlertDialog.Builder(this); adb1.setTitle(getString(R.string.download)); adb1.setMessage(getString(R.string.ser3)); adb1.setIcon(android.R.drawable.ic_dialog_alert); adb1.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { doOnDown(); } }); adb1.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //finish(); } }); adb1.show(); } else { AlertDialog.Builder adb1 = new AlertDialog.Builder(this); adb1.setTitle(getString(R.string.downloadT)); adb1.setMessage(getString(R.string.done)); adb1.setIcon(android.R.drawable.ic_dialog_alert); adb1.setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); adb1.show(); } resp = "ko"; } cont = false; }
From source file:gc.david.dfm.ui.MainActivity.java
/** * Shows an AlertDialog with the Google Play Services License. *///from www . j av a 2 s . c o m private void showGooglePlayServiceLicenseDialog() { Mint.leaveBreadcrumb("MainActivity::showGooglePlayServiceLicenseDialog"); final String LicenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext()); final AlertDialog.Builder LicenseDialog = new AlertDialog.Builder(MainActivity.this); LicenseDialog.setTitle(R.string.menu_legal_notices_title); LicenseDialog.setMessage(LicenseInfo); LicenseDialog.show(); }