List of usage examples for android.app AlertDialog setTitle
@Override public void setTitle(CharSequence title)
From source file:ch.bfh.instacircle.NetworkActiveActivity.java
/** * Checks whether the current network configuration is how it is supposed to * be/*from w w w.ja v a 2s .c om*/ */ public void checkNetworkState() { ConnectivityManager conn = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0); final String configuredSsid = preferences.getString("SSID", "N/A"); final String password = preferences.getString("password", "N/A"); NetworkInfo nInfo = conn.getNetworkInfo(ConnectivityManager.TYPE_WIFI); String ssid = wifi.getConnectionInfo().getSSID(); Log.d(TAG, "Currently active SSID: " + ssid); // Only check the state if this device is not an access point if (!wifiapmanager.isWifiAPEnabled(wifi)) { Log.d(TAG, "Configured SSID: " + configuredSsid); if (!(nInfo.getDetailedState() == NetworkInfo.DetailedState.CONNECTED && nInfo.getState() == NetworkInfo.State.CONNECTED && ssid.equals(configuredSsid))) { if (repairInitiated == false && repairTime + 6000 < System.currentTimeMillis()) { repairInitiated = true; repairTime = System.currentTimeMillis(); // create a dialog that ask whether you want to repair the // network connection AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - Network Connection Lost"); alertDialog.setMessage( "The connection to the network " + configuredSsid + " has been lost. Try to repair?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Repair", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); adhoc.connectToNetwork(configuredSsid, password, NetworkActiveActivity.this, false); repairInitiated = false; } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Leave", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); WifiManager wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE); new AdhocWifiManager(wifiman).restoreWifiConfiguration(getBaseContext()); new WifiAPManager().disableHotspot(wifiman, getBaseContext()); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); Intent stopIntent = new Intent(NetworkActiveActivity.this, NetworkService.class); stopService(stopIntent); Intent intent = new Intent(NetworkActiveActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }); alertDialog.show(); } } else { repairInitiated = false; } } }
From source file:com.microsoft.band.sdk.heartrate.BandHeartRateAppActivity.java
private void createAlert() { // Make an alert! AlertDialog alertDialog = new AlertDialog.Builder(BandHeartRateAppActivity.this).create(); alertDialog.setTitle("You are stressed!"); alertDialog.setMessage("Comedy has been shown to decrease stress, so watch a video!"); alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss();//www . j a v a 2 s . c om } }); alertDialog.show(); // End Make an Alert }
From source file:org.odk.collect.android.activities.MainMenuActivity.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case PASSWORD_DIALOG: AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog passwordDialog = builder.create(); passwordDialog.setTitle(getString(R.string.enter_admin_password)); LayoutInflater inflater = this.getLayoutInflater(); View dialogView = inflater.inflate(R.layout.dialogbox_layout, null); passwordDialog.setView(dialogView, 20, 10, 20, 10); final CheckBox checkBox = (CheckBox) dialogView.findViewById(R.id.checkBox); final EditText input = (EditText) dialogView.findViewById(R.id.editText); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override/* w w w.jav a 2s. co m*/ public void onCheckedChanged(CompoundButton compoundButton, boolean b) { if (!checkBox.isChecked()) { input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); } else { input.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD); } } }); passwordDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); String pw = adminPreferences.getString(AdminKeys.KEY_ADMIN_PW, ""); if (pw.compareTo(value) == 0) { Intent i = new Intent(getApplicationContext(), AdminPreferencesActivity.class); startActivity(i); input.setText(""); passwordDialog.dismiss(); } else { ToastUtils.showShortToast(R.string.admin_password_incorrect); Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog", "PASSWORD_INCORRECT"); } } }); passwordDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Collect.getInstance().getActivityLogger().logAction(this, "adminPasswordDialog", "cancel"); input.setText(""); return; } }); passwordDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); return passwordDialog; } return null; }
From source file:goo.TeaTimer.TimerActivity.java
/** { @inheritDoc} */ @Override/* www. j a v a2s .co m*/ public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case PREF: startActivity(new Intent(this, TimerPrefActivity.class)); break; case ABOUT: //new TimerAboutDialog(this).show(); //break; LayoutInflater li = LayoutInflater.from(this); View view = li.inflate(R.layout.about, null); Builder p = new AlertDialog.Builder(this).setView(view); final AlertDialog alrt = p.create(); alrt.setIcon(R.drawable.icon); alrt.setTitle(mImgUrl); alrt.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.close), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }); alrt.show(); return true; default: return false; } return true; }
From source file:com.swetha.easypark.GetIndividualParkingSpotDetails.java
public void displayalertdialog(double latitude, double longitude, String address, int success) { final double lat = latitude; final double lng = longitude; if (success == 1) { final AlertDialog alertDialog = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this).create(); // Setting Dialog Title alertDialog.setTitle("Congratulations!"); // Setting Dialog Message alertDialog.setMessage("Your parking spot has been blocked"); // Setting Icon to Dialog // alertDialog.setIcon(R.drawable.tick); // Setting OK Button alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { alertDialog.dismiss();/*from w w w . ja v a 2 s . c o m*/ AlertDialog alertDialog1 = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this) .create(); // Setting Dialog Title alertDialog1.setTitle("Do you want to get directions?"); alertDialog1.setButton2("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.e("GetIndividualParkingSpots", "Inside Yes"); Intent yesintent = new Intent(GetIndividualParkingSpotDetails.this, GoogleDirectionsActivity.class); yesintent.putExtra(GetParkingLots.LATITUDE, lat); yesintent.putExtra(GetParkingLots.LONGITUDE, lng); startActivity(yesintent); Log.e("GetIndividualParkingSpots", "After Calling Intent"); } }); alertDialog1.setButton3("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Write your code here to execute after dialog closed Intent nointent = new Intent(GetIndividualParkingSpotDetails.this, GetParkingLots.class); startActivity(nointent); } }); alertDialog1.show(); } }); // Showing Alert Message alertDialog.show(); if (chk_default.isChecked()) { Log.i("GetIndividualParkingSpotDetails", "Inside Checkbox if "); Log.i("GetIndividualParkingSpotDetails", " Spot has been blocked till long " + toTime); Log.i("GetIndividualParkingSpotDetails", " Spot has been blocked till DateTime" + DateTimeHelpers.convertToTimeFromLong(toTime)); Log.i("GetIndividualParkingSpotDetails", "Inside if checkbox address" + address); scheduleNotification(getNotification( "You parked the car in" + address + "Your parking spot id is " + theParkingSpotName)); } } else { AlertDialog alertDialog = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this).create(); // Setting Dialog Title alertDialog.setTitle("Sorry!"); // Setting Dialog Message alertDialog.setMessage("There was a problem processing your request"); // Setting Icon to Dialog // alertDialog.setIcon(R.drawable.tick); // Setting OK Button alertDialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Write your code here to execute after dialog closed Intent intent = new Intent(GetIndividualParkingSpotDetails.this, GetParkingLots.class); startActivity(intent); } }); // Showing Alert Message alertDialog.show(); } }
From source file:nl.mpcjanssen.simpletask.AddTask.java
private void showPrioMenu() { AlertDialog.Builder builder = new AlertDialog.Builder(this); final Priority[] priorities = Priority.values(); ArrayList<String> priorityCodes = new ArrayList<String>(); for (Priority prio : priorities) { priorityCodes.add(prio.getCode()); }//from w w w . ja va2 s. c o m builder.setItems(priorityCodes.toArray(new String[priorityCodes.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface arg0, int which) { replacePriority(priorities[which].getCode()); } }); // Create the AlertDialog AlertDialog dialog = builder.create(); dialog.setTitle(R.string.priority_prompt); dialog.show(); }
From source file:edu.rutgers.winlab.crowdpp.ui.HomeFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.home_fragment_layout, container, false); tb_cal = (ToggleButton) view.findViewById(R.id.tb_home_calibration); tb_service = (ToggleButton) view.findViewById(R.id.tb_home_service); tb_test = (ToggleButton) view.findViewById(R.id.tb_home_test); tv_cal_content = (TextView) view.findViewById(R.id.tv_home_calibration_content); tv_cal_text = (TextView) view.findViewById(R.id.tv_home_calibration_text); tv_debug = (TextView) view.findViewById(R.id.tv_home_test_debug); tv_record = (TextView) view.findViewById(R.id.tv_home_test_record); timer_cal = (Chronometer) view.findViewById(R.id.timer_calibration); timer_test = (Chronometer) view.findViewById(R.id.timer_test); rl_service = (RelativeLayout) view.findViewById(R.id.rl_home_service); rl_test = (RelativeLayout) view.findViewById(R.id.rl_home_test); if (isMyServiceRunning() == true) tb_service.setChecked(true);/*from w w w . j a v a2 s . c om*/ if (Constants.calibration()) tv_cal_content.setText("You are all set for the calibration."); if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { Toast.makeText(getActivity(), "Can not find SD card ...", Toast.LENGTH_SHORT).show(); getActivity().finish(); } crowdppDir = new File(Constants.crowdppPath); if (!crowdppDir.exists() || !crowdppDir.isDirectory()) { crowdppDir.mkdir(); } testDir = new File(Constants.testPath); if (!testDir.exists() || !testDir.isDirectory()) { testDir.mkdir(); } calWavFile = crowdppDir + "/" + Constants.PHONE_ID + ".wav"; timer_cal.setVisibility(View.INVISIBLE); timer_test.setVisibility(View.INVISIBLE); mDatabase = new DataBaseHelper(getActivity().getApplicationContext()); mDB = mDatabase.getWritableDatabase(); gps = new LocationTracker(getActivity().getApplicationContext()); s3Client = new AmazonS3Client(new BasicAWSCredentials(Constants.ACCESS_KEY_ID, Constants.SECRET_KEY)); s3Client.setRegion(Region.getRegion(Regions.US_WEST_2)); tb_cal.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prevent the calibration button being pressed when either and test or service is running if (tb_service.isChecked()) { Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show(); tb_cal.setChecked(false); } else if (tb_test.isChecked()) { Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show(); tb_cal.setChecked(false); } // calibration else { if (isChecked) { tv_cal_text.setText(Constants.cal_text); rl_service.setVisibility(View.INVISIBLE); rl_test.setVisibility(View.INVISIBLE); timer_cal.setVisibility(View.VISIBLE); AlertDialog dialog = new AlertDialog.Builder(getActivity()).create(); dialog.setTitle("Calibration"); dialog.setMessage(Constants.cal_dialog); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { timer_cal.setBase(SystemClock.elapsedRealtime()); timer_cal.start(); tv_cal_content.setText("Recording your voice..."); Bundle mbundle = new Bundle(); mbundle.putString("audiopath", calWavFile); Log.i("HomeFragment", "start audio recording service"); // delete the existing calibration data before the recalibration FileProcess.deleteFile(calWavFile); FileProcess.deleteFile(calWavFile + ".jstk.mfcc.txt"); FileProcess.deleteFile(calWavFile + ".YIN.pitch.txt"); // start audio recording Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); recordIntent.putExtras(mbundle); getActivity().startService(recordIntent); } }); dialog.show(); dialog.getButton(DialogInterface.BUTTON_POSITIVE).setTextSize(20); } else { // stop audio recording Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); getActivity().stopService(recordIntent); timer_cal.stop(); tb_cal.setClickable(false); tv_cal_content.setText("Calibrating...."); // start calibration new Calibration().execute(); tb_cal.setClickable(true); tv_cal_text.setText(""); rl_service.setVisibility(View.VISIBLE); rl_test.setVisibility(View.VISIBLE); timer_cal.setVisibility(View.INVISIBLE); } } } }); tb_service.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prevent the service button being pressed when either and test or calibration is running if (tb_cal.isChecked()) { Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show(); tb_service.setChecked(false); } else if (tb_test.isChecked()) { Toast.makeText(getActivity(), "Please turn off the test...", Toast.LENGTH_SHORT).show(); tb_service.setChecked(false); } // speaker counting service else { Intent countIntent = new Intent(getActivity(), SpeakerCountService.class); if (isChecked) { getActivity().startService(countIntent); } else { getActivity().stopService(countIntent); } } } }); tb_test.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prevent the test button being pressed when either and service or calibration is running if (tb_cal.isChecked()) { Toast.makeText(getActivity(), "Please turn off the calibration...", Toast.LENGTH_SHORT).show(); tb_test.setChecked(false); } else if (tb_service.isChecked()) { Toast.makeText(getActivity(), "Please turn off the service...", Toast.LENGTH_SHORT).show(); tb_test.setChecked(false); } // perform the speaker counting test else { if (isChecked) { // get location information gps.getLocation(); if (gps.canGetLocation()) { latitude = gps.getLatitude(); longitude = gps.getLongitude(); } else { latitude = -1; longitude = -1; } gps.stopUsingGPS(); timer_test.setBase(SystemClock.elapsedRealtime()); timer_test.start(); tv_debug.setText("Recording..."); testWavFile = testDir + "/" + FileProcess.newFileOnTime("wav"); // start audio recording Bundle mbundle = new Bundle(); mbundle.putString("audiopath", testWavFile); Log.i("HomeFragment", "start audio recording service"); Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); recordIntent.putExtras(mbundle); date = Now.getDate(); start = Now.getTimeOfDay(); getActivity().startService(recordIntent); timer_test.setVisibility(View.VISIBLE); } else { // stop audio recording Intent recordIntent = new Intent(getActivity(), AudioRecordService.class); getActivity().stopService(recordIntent); timer_test.stop(); end = Now.getTimeOfDay(); tb_test.setClickable(false); // start speaker counting test new Test().execute(); timer_test.setVisibility(View.INVISIBLE); tb_test.setClickable(true); } } } }); return view; }
From source file:cm.aptoide.pt.RemoteInSearch.java
@Override protected void onListItemClick(ListView l, View v, final int position, long id) { super.onListItemClick(l, v, position, id); Vector<String> tmp_get = db.getApk(apk_lst.get(position).apkid); String tmp_path = this.getString(R.string.icons_path) + apk_lst.get(position).apkid; File test_icon = new File(tmp_path); LayoutInflater li = LayoutInflater.from(this); View view = li.inflate(R.layout.alertscroll, null); Builder alrt = new AlertDialog.Builder(this).setView(view); final AlertDialog p = alrt.create(); if (test_icon.exists() && test_icon.length() > 0) { p.setIcon(new BitmapDrawable(tmp_path)); } else {//from w ww . j a va 2 s . c om p.setIcon(android.R.drawable.sym_def_app_icon); } p.setTitle(apk_lst.get(position).name); TextView t1 = (TextView) view.findViewById(R.id.n11); t1.setText(tmp_get.firstElement()); TextView t2 = (TextView) view.findViewById(R.id.n22); t2.setText(tmp_get.get(1)); TextView t3 = (TextView) view.findViewById(R.id.n33); t3.setText(tmp_get.get(2)); TextView t4 = (TextView) view.findViewById(R.id.n44); t4.setText(tmp_get.get(3)); TextView t5 = (TextView) view.findViewById(R.id.n55); String tmpi = db.getDescript(apk_lst.get(position).apkid); if (!(tmpi == null)) { t5.setText(tmpi); } else { t5.setText("No info availale on server. Search market by pressing the button below for more info."); } p.setButton2("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); if (tmp_get.get(2).equalsIgnoreCase("\tno\n")) { p.setButton(getString(R.string.install), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); new Thread() { public void run() { String apk_pkg = downloadFile(position); if (apk_pkg == null) { Message msg = new Message(); msg.arg1 = 1; download_handler.sendMessage(msg); download_error_handler.sendEmptyMessage(0); } else { installApk(apk_pkg, position); } } }.start(); } }); p.setButton3("Search Market", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + apk_lst.get(position).apkid)); startActivity(intent); } }); } else { p.setButton(getString(R.string.rem), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String apk_pkg = apk_lst.get(position).apkid; removeApk(apk_pkg, position); } }); if (apk_lst.get(position).status == 2) { p.setButton3(getString(R.string.update), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); new Thread() { public void run() { String apk_pkg = downloadFile(position); if (apk_pkg == null) { //Toast.makeText(RemoteInSearch.this, "Could not connect to server!", Toast.LENGTH_LONG).show(); Message msg = new Message(); msg.arg1 = 1; download_handler.sendMessage(msg); download_error_handler.sendEmptyMessage(0); } else { installApk(apk_pkg, position); } } }.start(); } }); } else { p.setButton3("Search Market", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + apk_lst.get(position).apkid)); startActivity(intent); } }); } } p.show(); }
From source file:com.ushahidi.android.app.ui.phone.AddCheckinActivity.java
/** * Create various dialog//www. ja v a 2 s . com */ @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ERROR_NETWORK: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.network_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_ERROR_SAVING: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.network_error)); dialog.setMessage(getString(R.string.file_system_error_msg)); dialog.setButton2(getString(R.string.ok), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_CHOOSE_IMAGE_METHOD: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.choose_method)); dialog.setMessage(getString(R.string.how_to_select_pic)); dialog.setButton(getString(R.string.gallery_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_PICK); intent.setData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(intent, REQUEST_CODE_IMAGE); dialog.dismiss(); } }); dialog.setButton2(getString(R.string.cancel), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton3(getString(R.string.camera_option), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, PhotoUtils.getPhotoUri(photoName, AddCheckinActivity.this)); startActivityForResult(intent, REQUEST_CODE_CAMERA); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } case DIALOG_SHOW_MESSAGE: AlertDialog.Builder messageBuilder = new AlertDialog.Builder(this); messageBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showDialog = messageBuilder.create(); showDialog.show(); break; case DIALOG_SHOW_REQUIRED: AlertDialog.Builder requiredBuilder = new AlertDialog.Builder(this); requiredBuilder.setTitle(R.string.required_fields); requiredBuilder.setMessage(mErrorMessage).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog showRequiredDialog = requiredBuilder.create(); showRequiredDialog.show(); break; // prompt for unsaved changes case DIALOG_SHOW_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.unsaved_changes)); dialog.setMessage(getString(R.string.want_to_cancel)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } // prompt for report deletion case DIALOG_SHOW_DELETE_PROMPT: { AlertDialog dialog = (new AlertDialog.Builder(this)).create(); dialog.setTitle(getString(R.string.delete_report)); dialog.setMessage(getString(R.string.want_to_delete)); dialog.setButton(getString(R.string.no), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog.setButton2(getString(R.string.yes), new Dialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // delete checkin deleteCheckins(); dialog.dismiss(); } }); dialog.setCancelable(false); return dialog; } } return null; }
From source file:ch.bfh.instacircle.NetworkActiveActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent = null;//from ww w . j ava 2 s . c o m switch (item.getItemId()) { case R.id.display_qrcode: // displaying the QR code SharedPreferences preferences = getSharedPreferences(PREFS_NAME, 0); String config = preferences.getString("SSID", "N/A") + "||" + preferences.getString("password", "N/A"); try { intent = new Intent("com.google.zxing.client.android.ENCODE"); intent.putExtra("ENCODE_TYPE", "TEXT_TYPE"); intent.putExtra("ENCODE_DATA", config); intent.putExtra("ENCODE_FORMAT", "QR_CODE"); intent.putExtra("ENCODE_SHOW_CONTENTS", false); startActivity(intent); } catch (ActivityNotFoundException e) { // if the "Barcode Scanner" application is not installed ask the // user if he wants to install it AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - Barcode Scanner Required"); alertDialog.setMessage( "In order to use this feature, the Application \"Barcode Scanner\" must be installed. Install now?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); // redirect to Google Play try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.zxing.client.android"))); } catch (Exception e) { Log.d(TAG, "Unable to find market. User will have to install ZXing himself"); } } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } return true; case R.id.leave_network: // Display a confirm dialog asking whether really to leave AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Leave Network?"); builder.setMessage("Do you really want to leave this conversation?"); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { if (isServiceRunning()) { String identification = getSharedPreferences(PREFS_NAME, 0).getString("identification", "N/A"); Message message = new Message(identification, Message.MSG_MSGLEAVE, identification, NetworkDbHelper.getInstance(NetworkActiveActivity.this).getNextSequenceNumber()); Intent intent = new Intent("messageSend"); intent.putExtra("message", message); LocalBroadcastManager.getInstance(NetworkActiveActivity.this).sendBroadcast(intent); } else { NetworkDbHelper.getInstance(NetworkActiveActivity.this).closeConversation(); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); notificationManager.cancelAll(); Intent intent = new Intent(NetworkActiveActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } } }); builder.setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); AlertDialog dialog = builder.create(); dialog.show(); return true; case R.id.write_nfc_tag: if (!nfcAdapter.isEnabled()) { // if nfc is available but deactivated ask the user whether he // wants to enable it. If yes, redirect to the settings. AlertDialog alertDialog = new AlertDialog.Builder(this).create(); alertDialog.setTitle("InstaCircle - NFC needs to be enabled"); alertDialog.setMessage("In order to use this feature, NFC must be enabled. Enable now?"); alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); } }); alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); alertDialog.show(); } else { // display a progress dialog waiting for the NFC tag to be // tapped writeNfcEnabled = true; writeNfcTagDialog = new ProgressDialog(this); writeNfcTagDialog.setTitle("InstaCircle - Share Networkconfiguration with NFC Tag"); writeNfcTagDialog.setMessage("Please tap a writeable NFC Tag on the back of your device..."); writeNfcTagDialog.setCancelable(false); writeNfcTagDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { writeNfcEnabled = false; dialog.dismiss(); } }); writeNfcTagDialog.show(); } default: return super.onOptionsItemSelected(item); } }