List of usage examples for android.app Dialog setCanceledOnTouchOutside
public void setCanceledOnTouchOutside(boolean cancel)
From source file:org.onepf.trivialdrive.ui.fragment.ProviderPickerDialogFragment.java
@NonNull @Override/*from ww w. ja v a 2s .com*/ public Dialog onCreateDialog(final Bundle savedInstanceState) { if (listener == null) { throw new IllegalStateException(); } final OnProviderPickerListener listener = this.listener; final Adapter adapter = new Adapter(); final Dialog dialog = new AlertDialog.Builder(getActivity()).setCancelable(true) .setTitle(R.string.dialog_providers_title) .setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { final Provider provider = adapter.getItem(which); listener.onProviderPicked(provider); dialog.dismiss(); } }).create(); dialog.setCanceledOnTouchOutside(true); return dialog; }
From source file:org.catrobat.catroid.ui.dialogs.LegoNXTSensorConfigInfoDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { View dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_lego_nxt_sensor_config_info, null);//from ww w. j a v a 2s. c om disableShowInfoDialog = (CheckBox) dialogView .findViewById(R.id.lego_nxt_sensor_config_info_disable_show_dialog); NXTSensor.Sensor[] sensorMapping = SettingsActivity.getLegoMindstormsNXTSensorMapping(this.getActivity()); String[] sensorMappingStrings = getResources().getStringArray(R.array.nxt_sensor_chooser); TextView mapping1 = (TextView) dialogView.findViewById(R.id.lego_nxt_sensor_config_info_port_1_mapping); TextView mapping2 = (TextView) dialogView.findViewById(R.id.lego_nxt_sensor_config_info_port_2_mapping); TextView mapping3 = (TextView) dialogView.findViewById(R.id.lego_nxt_sensor_config_info_port_3_mapping); TextView mapping4 = (TextView) dialogView.findViewById(R.id.lego_nxt_sensor_config_info_port_4_mapping); mapping1.setText(sensorMappingStrings[sensorMapping[0].ordinal()]); mapping2.setText(sensorMappingStrings[sensorMapping[1].ordinal()]); mapping3.setText(sensorMappingStrings[sensorMapping[2].ordinal()]); mapping4.setText(sensorMappingStrings[sensorMapping[3].ordinal()]); Dialog dialog = new AlertDialog.Builder(getActivity()).setView(dialogView) .setTitle(R.string.lego_nxt_sensor_config_info_title) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (disableShowInfoDialog.isChecked()) { SettingsActivity.disableLegoMindstormsSensorInfoDialog( LegoNXTSensorConfigInfoDialog.this.getActivity()); } } }).create(); dialog.setCanceledOnTouchOutside(true); return dialog; }
From source file:com.ternup.caddisfly.fragment.LocationFragment.java
/** * Invoked by the "Start Updates" button * Sends a request to start location updates * * @param v The view object associated with this method, in this case a Button. *///from w w w. java 2 s. c o m public void startUpdates(View v) { // Get Location Manager and check for GPS & Network location services LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // Build the alert dialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges the alert dialog Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } else { mUpdatesRequested = true; if (servicesConnected()) { // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); mLocationButton.setVisibility(View.GONE); startPeriodicUpdates(); } } }
From source file:com.nttec.everychan.http.recaptcha.Recaptcha2fallback.java
@Override public void handle(final Activity activity, final CancellableTask task, final Callback callback) { try {//from w w w.j a v a 2s .c o m final HttpClient httpClient = ((HttpChanModule) MainApplication.getInstance().getChanModule(chanName)) .getHttpClient(); final String usingURL = scheme + RECAPTCHA_FALLBACK_URL + publicKey + (sToken != null && sToken.length() > 0 ? ("&stoken=" + sToken) : ""); String refererURL = baseUrl != null && baseUrl.length() > 0 ? baseUrl : usingURL; Header[] customHeaders = new Header[] { new BasicHeader(HttpHeaders.REFERER, refererURL) }; String htmlChallenge; if (lastChallenge != null && lastChallenge.getLeft().equals(usingURL)) { htmlChallenge = lastChallenge.getRight(); } else { htmlChallenge = HttpStreamer.getInstance().getStringFromUrl(usingURL, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task, false); } lastChallenge = null; Matcher challengeMatcher = Pattern.compile("name=\"c\" value=\"([\\w-]+)").matcher(htmlChallenge); if (challengeMatcher.find()) { final String challenge = challengeMatcher.group(1); HttpResponseModel responseModel = HttpStreamer.getInstance().getFromUrl( scheme + RECAPTCHA_IMAGE_URL + challenge + "&k=" + publicKey, HttpRequestModel.builder().setGET().setCustomHeaders(customHeaders).build(), httpClient, null, task); try { InputStream imageStream = responseModel.stream; final Bitmap challengeBitmap = BitmapFactory.decodeStream(imageStream); final String message; Matcher messageMatcher = Pattern.compile("imageselect-message(?:.*?)>(.*?)</div>") .matcher(htmlChallenge); if (messageMatcher.find()) message = RegexUtils.removeHtmlTags(messageMatcher.group(1)); else message = null; final Bitmap candidateBitmap; Matcher candidateMatcher = Pattern .compile("fbc-imageselect-candidates(?:.*?)src=\"data:image/(?:.*?);base64,([^\"]*)\"") .matcher(htmlChallenge); if (candidateMatcher.find()) { Bitmap bmp = null; try { byte[] imgData = Base64.decode(candidateMatcher.group(1), Base64.DEFAULT); bmp = BitmapFactory.decodeByteArray(imgData, 0, imgData.length); } catch (Exception e) { } candidateBitmap = bmp; } else candidateBitmap = null; activity.runOnUiThread(new Runnable() { final int maxX = 3; final int maxY = 3; final boolean[] isSelected = new boolean[maxX * maxY]; @SuppressLint("InlinedApi") @Override public void run() { LinearLayout rootLayout = new LinearLayout(activity); rootLayout.setOrientation(LinearLayout.VERTICAL); if (candidateBitmap != null) { ImageView candidateView = new ImageView(activity); candidateView.setImageBitmap(candidateBitmap); int picSize = (int) (activity.getResources().getDisplayMetrics().density * 50 + 0.5f); candidateView.setLayoutParams(new LinearLayout.LayoutParams(picSize, picSize)); candidateView.setScaleType(ImageView.ScaleType.FIT_XY); rootLayout.addView(candidateView); } if (message != null) { TextView textView = new TextView(activity); textView.setText(message); CompatibilityUtils.setTextAppearance(textView, android.R.style.TextAppearance); textView.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); rootLayout.addView(textView); } FrameLayout frame = new FrameLayout(activity); frame.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); final ImageView imageView = new ImageView(activity); imageView.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); imageView.setScaleType(ImageView.ScaleType.FIT_XY); imageView.setImageBitmap(challengeBitmap); frame.addView(imageView); final LinearLayout selector = new LinearLayout(activity); selector.setLayoutParams(new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)); AppearanceUtils.callWhenLoaded(imageView, new Runnable() { @Override public void run() { selector.setLayoutParams(new FrameLayout.LayoutParams(imageView.getWidth(), imageView.getHeight())); } }); selector.setOrientation(LinearLayout.VERTICAL); selector.setWeightSum(maxY); for (int y = 0; y < maxY; ++y) { LinearLayout subSelector = new LinearLayout(activity); subSelector.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f)); subSelector.setOrientation(LinearLayout.HORIZONTAL); subSelector.setWeightSum(maxX); for (int x = 0; x < maxX; ++x) { FrameLayout switcher = new FrameLayout(activity); switcher.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); switcher.setTag(new int[] { x, y }); switcher.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { int[] coord = (int[]) v.getTag(); int index = coord[1] * maxX + coord[0]; isSelected[index] = !isSelected[index]; v.setBackgroundColor(isSelected[index] ? Color.argb(128, 0, 255, 0) : Color.TRANSPARENT); } }); subSelector.addView(switcher); } selector.addView(subSelector); } frame.addView(selector); rootLayout.addView(frame); Button checkButton = new Button(activity); checkButton.setLayoutParams( new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); checkButton.setText(android.R.string.ok); rootLayout.addView(checkButton); ScrollView dlgView = new ScrollView(activity); dlgView.addView(rootLayout); final Dialog dialog = new Dialog(activity); dialog.setTitle("Recaptcha"); dialog.setContentView(dlgView); dialog.setCanceledOnTouchOutside(false); dialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (!task.isCancelled()) { callback.onError("Cancelled"); } } }); dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); dialog.show(); checkButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.dismiss(); if (task.isCancelled()) return; Async.runAsync(new Runnable() { @Override public void run() { try { List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("c", challenge)); for (int i = 0; i < isSelected.length; ++i) if (isSelected[i]) pairs.add(new BasicNameValuePair("response", Integer.toString(i))); HttpRequestModel request = HttpRequestModel.builder() .setPOST(new UrlEncodedFormEntity(pairs, "UTF-8")) .setCustomHeaders(new Header[] { new BasicHeader(HttpHeaders.REFERER, usingURL) }) .build(); String response = HttpStreamer.getInstance().getStringFromUrl( usingURL, request, httpClient, null, task, false); String hash = ""; Matcher matcher = Pattern.compile( "fbc-verification-token(?:.*?)<textarea[^>]*>([^<]*)<", Pattern.DOTALL).matcher(response); if (matcher.find()) hash = matcher.group(1); if (hash.length() > 0) { Recaptcha2solved.push(publicKey, hash); activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onSuccess(); } }); } else { lastChallenge = Pair.of(usingURL, response); throw new RecaptchaException( "incorrect answer (hash is empty)"); } } catch (final Exception e) { Logger.e(TAG, e); if (task.isCancelled()) return; handle(activity, task, callback); } } }); } }); } }); } finally { responseModel.release(); } } else throw new Exception("can't parse recaptcha challenge answer"); } catch (final Exception e) { Logger.e(TAG, e); if (!task.isCancelled()) { activity.runOnUiThread(new Runnable() { @Override public void run() { callback.onError(e.getMessage() != null ? e.getMessage() : e.toString()); } }); } } }
From source file:org.catrobat.catroid.ui.dialogs.DeleteLookDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final int selectedPosition = getArguments().getInt(BUNDLE_ARGUMENTS_SELECTED_POSITION); Dialog dialog = new CustomAlertDialogBuilder(getActivity()).setTitle(R.string.delete_look_dialog) .setNegativeButton(R.string.cancel_button, new OnClickListener() { @Override/*w ww.j av a 2 s .co m*/ public void onClick(DialogInterface dialog, int which) { dismiss(); } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleDeleteLook(selectedPosition); } }).create(); dialog.setCanceledOnTouchOutside(true); return dialog; }
From source file:org.deviceconnect.android.observer.fragment.WarningDialogFragment.java
@SuppressLint("InflateParams") @Override//from w w w.j av a2s.co m public Dialog onCreateDialog(final Bundle savedInstanceState) { String packageName = getActivity().getIntent() .getStringExtra(DConnectObservationService.PARAM_PACKAGE_NAME); int port = getActivity().getIntent().getIntExtra(DConnectObservationService.PARAM_PORT, -1); LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View view = inflater.inflate(R.layout.activity_warning_dialog, null); final TextView appNameView = (TextView) view.findViewById(R.id.alert_message); final ImageView appIconView = (ImageView) view.findViewById(R.id.alert_icon); String appName = getAppName(packageName); Drawable icon = null; try { icon = getActivity().getPackageManager().getApplicationIcon(packageName); } catch (NameNotFoundException e) { icon = getActivity().getResources().getDrawable(R.drawable.icon); } appNameView.setText(appName); appIconView.setImageDrawable(icon); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); Dialog dialog = builder.setTitle(getString(R.string.activity_warning)) .setMessage(getString(R.string.activity_warning_mess)).setView(view) .setPositiveButton(R.string.activity_warning_ok, new OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { CheckBox box = (CheckBox) view.findViewById(R.id.disable_observer); mDisableFlg = box.isChecked(); dismiss(); } }).create(); dialog.setCanceledOnTouchOutside(false); return dialog; }
From source file:org.catrobat.catroid.ui.dialogs.DeleteSoundDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final int selectedPosition = getArguments().getInt(BUNDLE_ARGUMENTS_SELECTED_POSITION); Dialog dialog = new CustomAlertDialogBuilder(getActivity()).setTitle(R.string.delete_sound_dialog) .setNegativeButton(R.string.cancel_button, new OnClickListener() { @Override//from w w w . j a v a2s . co m public void onClick(DialogInterface dialog, int which) { dismiss(); } }).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { handleDeleteSound(selectedPosition); } }).create(); dialog.setCanceledOnTouchOutside(true); return dialog; }
From source file:com.gunz.carrental.Fragments.CarsFragment.java
private void addCar(final boolean isAddCar, final int position) { final Dialog dialog = new Dialog(getActivity()); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog_car); dialog.setCanceledOnTouchOutside(false); dialog.setCancelable(false);//from w w w . j av a 2 s . c om TextView lblTitle = (TextView) dialog.findViewById(R.id.lblTitle); final MaterialEditText txBrand = (MaterialEditText) dialog.findViewById(R.id.txBrand); final MaterialEditText txModel = (MaterialEditText) dialog.findViewById(R.id.txModel); final MaterialEditText txLicense = (MaterialEditText) dialog.findViewById(R.id.txLicense); final MaterialEditText txFare = (MaterialEditText) dialog.findViewById(R.id.txFare); Button btnSave = (Button) dialog.findViewById(R.id.btnSave); ImageView imgClose = (ImageView) dialog.findViewById(R.id.imgClose); dialog.show(); clearErrorMsg(dialog); if (!isAddCar) { lblTitle.setText(getActivity().getResources().getString(R.string.update_car_title)); txBrand.setText(cars.get(position).brand); txModel.setText(cars.get(position).type); txLicense.setText(cars.get(position).licensePlat); txFare.setText(String.valueOf((int) cars.get(position).farePerDay)); } else { lblTitle.setText(getActivity().getResources().getString(R.string.add_new_car_title)); } btnSave.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { if (TextUtils.isEmpty(txBrand.getText().toString().trim())) { txBrand.setText(""); txBrand.setError(getActivity().getResources().getString(R.string.validation_required)); txBrand.requestFocus(); } else if (TextUtils.isEmpty(txModel.getText().toString().trim())) { txModel.setText(""); txModel.setError(getActivity().getResources().getString(R.string.validation_required)); txModel.requestFocus(); } else if (TextUtils.isEmpty(txLicense.getText().toString().trim())) { txLicense.setText(""); txLicense.setError(getActivity().getResources().getString(R.string.validation_required)); txLicense.requestFocus(); } else if (TextUtils.isEmpty(txFare.getText().toString().trim())) { txFare.setText(""); txFare.setError(getActivity().getResources().getString(R.string.validation_required)); txFare.requestFocus(); } else { String confirmText; if (isAddCar) { confirmText = getActivity().getResources().getString(R.string.dialog_add_car_question); } else { confirmText = getActivity().getResources().getString(R.string.dialog_update_car_question); } new SweetAlertDialog(getActivity(), SweetAlertDialog.NORMAL_TYPE) .setTitleText(getActivity().getResources().getString(R.string.dialog_confirmation)) .setContentText(confirmText) .setCancelText(getActivity().getResources().getString(R.string.btn_cancel)) .setConfirmText(getActivity().getResources().getString(R.string.btn_save)) .showCancelButton(true) .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sweetAlertDialog) { if (isAddCar) { saveNewCar(dialog, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } else { updateCar(dialog, cars.get(position).id, txBrand.getText().toString().trim(), txModel.getText().toString().trim(), Integer.parseInt(txFare.getText().toString().trim()), txLicense.getText().toString().trim()); } sweetAlertDialog.dismiss(); } }).show(); } } }); imgClose.setOnClickListener(new OnOneClickListener() { @Override public void onOneClick(View v) { Animation animation = AnimationUtils.loadAnimation(getActivity(), R.anim.bounce); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { dialog.dismiss(); } @Override public void onAnimationRepeat(Animation animation) { } }); v.startAnimation(animation); } }); }
From source file:com.neighbor.ex.tong.ui.activity.MainActivity2Activity.java
private void chkGpsService() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getResources().getString(R.string.set_gps_title)); builder.setMessage(getResources().getString(R.string.set_gps_message)); builder.setPositiveButton(getResources().getString(R.string.info_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); }/*from www . j a v a2s. c om*/ }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); }
From source file:group.pals.android.lib.ui.filechooser.utils.ui.bookmark.BookmarkFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (BuildConfig.DEBUG) Log.d(_ClassName, "onCreateDialog()"); Dialog dialog = new Dialog(getActivity(), R.style.Afc_Theme_Dialog_Dark); dialog.setCanceledOnTouchOutside(true); dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON); dialog.setTitle(R.string.afc_title_bookmark_manager); dialog.setContentView(initContentView(dialog.getLayoutInflater(), null)); dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.afc_bookmarks_dark); return dialog; }