List of usage examples for android.app AlertDialog.Builder setOnDismissListener
public void setOnDismissListener(@Nullable OnDismissListener listener)
From source file:cc.metapro.openct.utils.ActivityUtils.java
public static AlertDialog addViewToAlertDialog(@NonNull final AlertDialog.Builder builder, @NonNull final View view) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) { parent.removeView(view);/*from www . ja va 2s . c om*/ } ScrollView scrollView = new ScrollView(builder.getContext()); scrollView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); scrollView.addView(view); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { InputMethodManager imm = (InputMethodManager) builder.getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(view.getWindowToken(), 0); } }); AlertDialog dialog = builder.setView(scrollView).create(); Window window = dialog.getWindow(); if (window != null) { window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); } return dialog; }
From source file:com.outsystemscloud.andrevieira.secureDevice.java
/** * Builds and shows a native Android alert with given Strings * @param message The message the alert should display * @param buttonLabel The label of the button * @param callbackContext The callback context *//* www .j av a 2s . c o m*/ private synchronized void alert(final String message, final String buttonLabel) { final CordovaInterface cordova = this.cordova; final Activity activity = cordova.getActivity(); Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = createDialog(cordova); dlg.setMessage(message); dlg.setCancelable(true); dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); System.exit(0); } }); dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { public void onDismiss(final DialogInterface dialog) { System.exit(0); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.upstack.materialcamerasample.MainActivity.java
public void showDialog(Context context, String title, String[] btnText, DialogInterface.OnClickListener listener) { final CharSequence[] items = { "160x120", "320x240" }; if (listener == null) { listener = new DialogInterface.OnClickListener() { @Override//from w ww .jav a 2 s.co m public void onClick(DialogInterface paramDialogInterface, int paramInt) { paramDialogInterface.dismiss(); } }; } AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(title); final DialogInterface.OnClickListener finalListener = listener; builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { finalListener.onClick(dialog, item); } }); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { finalListener.onClick(dialog, -1); } }); builder.show(); }
From source file:it.prof.iotsemplicedemo.DeviceScanActivity.java
@Override public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { case PERMISSION_REQUEST_COARSE_LOCATION: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d("", "Coarse location permission granted"); } else {//from w w w . j a v a2s . com final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.perm_error_title); builder.setMessage(R.string.perm_error_msg); builder.setPositiveButton(android.R.string.ok, null); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { } }); builder.show(); } } } }
From source file:com.thenextplateau.ubristlebotcontroller.DeviceScanActivity.java
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { switch (requestCode) { case PERMISSION_REQUEST_COARSE_LOCATION: { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "coarse location permission granted"); } else {//from www .j a v a2 s. co m final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Functionality limited"); builder.setMessage( "Since location access has not been granted, this app will not be able to discover beacons when in the background."); builder.setPositiveButton(android.R.string.ok, null); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { } }); builder.show(); } } } }
From source file:com.example.linhdq.test.documents.creation.crop.CropImageActivity.java
private void showCropOnBoarding(final CropData cropData) { PreferencesUtils.setFirstScan(this, false); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.crop_onboarding_title); builder.setMessage(R.string.crop_onboarding_message); builder.setPositiveButton(R.string.got_it, new DialogInterface.OnClickListener() { @Override/*from w w w . jav a 2 s .co m*/ public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { handleBlurResult(cropData); } }); builder.show(); }
From source file:ac.robinson.bettertogether.ConnectionSetupActivity.java
private boolean checkSettingsAccess() { // TODO: by default, applications are not granted access, but the settings switch shows access is allowed - need to // TODO: toggle this switch to actually grant access. Need to improve this interaction generally if (!canWriteSettings()) { AlertDialog.Builder builder = new AlertDialog.Builder(ConnectionSetupActivity.this); builder.setTitle(R.string.title_settings_access); builder.setMessage(R.string.hint_enable_settings_access); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override/* www . ja v a2s . com*/ public void onDismiss(DialogInterface dialog) { // note: dismiss rather than cancel so we always take this action (pos or neg result) if (checkSettingsAccess()) { if (mConnectionMode == ConnectionMode.CONNECTION_INITIATED_HOTSPOT) { createHotspot(); return; } } mConnectionMode = ConnectionMode.SCANNING; setupDefaultUI(); } }); builder.setPositiveButton(R.string.hint_edit_settings_access, new DialogInterface.OnClickListener() { @TargetApi(Build.VERSION_CODES.M) @Override public void onClick(DialogInterface dialog, int which) { try { Intent settingsIntent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS); settingsIntent.setData(Uri.parse("package:" + PluginIntent.HOST_PACKAGE)); startActivity(settingsIntent); } catch (ActivityNotFoundException e) { Toast.makeText(ConnectionSetupActivity.this, R.string.error_editing_settings, Toast.LENGTH_LONG).show(); // TODO: reset ui? } dialog.dismiss(); } }); builder.setNeutralButton(R.string.button_done, null); builder.show(); return false; } return true; }
From source file:com.zuluindia.watchpresenter.MainActivity.java
public void launchChooseAccount() { AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(getString(R.string.chooseAnAccount)) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { }/*from w w w . j a v a 2 s .com*/ }).setMessage(R.string.beforeAccountChooseMessage).setIcon(android.R.drawable.ic_dialog_alert); builder.setCancelable(false); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { chooseAccount(); } }); builder.show(); }
From source file:com.b44t.ui.Components.PasscodeView.java
private void checkFingerprint() { Activity parentActivity = (Activity) getContext(); if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint && !ApplicationLoader.mainInterfacePaused) { try {/*from w w w .j a va2 s .c om*/ if (fingerprintDialog != null && fingerprintDialog.isShowing()) { return; } } catch (Exception e) { FileLog.e("messenger", e); } try { FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat .from(ApplicationLoader.applicationContext); if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) { RelativeLayout relativeLayout = new RelativeLayout(getContext()); relativeLayout.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(16), AndroidUtilities.dp(8)); fingerprintStatusTextView = new TextView(getContext()); fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL); fingerprintStatusTextView .setText(ApplicationLoader.applicationContext.getString(R.string.FingerprintInfo)); fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead); relativeLayout.addView(fingerprintStatusTextView); RelativeLayout.LayoutParams layoutParams = LayoutHelper .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT); fingerprintStatusTextView.setLayoutParams(layoutParams); AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setView(relativeLayout); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (cancellationSignal != null) { selfCancelled = true; cancellationSignal.cancel(); cancellationSignal = null; } } }); if (fingerprintDialog != null) { try { if (fingerprintDialog.isShowing()) { fingerprintDialog.dismiss(); } } catch (Exception e) { FileLog.e("messenger", e); } } fingerprintDialog = builder.show(); cancellationSignal = new CancellationSignal(); selfCancelled = false; fingerprintManager.authenticate(null, 0, cancellationSignal, new FingerprintManagerCompat.AuthenticationCallback() { @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { if (!selfCancelled) { showFingerprintError(errString); } } @Override public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { showFingerprintError(helpString); } @Override public void onAuthenticationFailed() { showFingerprintError(LocaleController.getString("FingerprintNotRecognized", R.string.FingerprintNotRecognized)); } @Override public void onAuthenticationSucceeded( FingerprintManagerCompat.AuthenticationResult result) { try { if (fingerprintDialog.isShowing()) { fingerprintDialog.dismiss(); } } catch (Exception e) { FileLog.e("messenger", e); } fingerprintDialog = null; processDone(true); } }, null); } } catch (Throwable e) { //ignore } } }
From source file:ir.besteveryeverapp.ui.Components.PasscodeView.java
private void checkFingerprint() { Activity parentActivity = (Activity) getContext(); if (Build.VERSION.SDK_INT >= 23 && parentActivity != null && UserConfig.useFingerprint && !ApplicationLoader.mainInterfacePaused) { try {/*from www . j a va 2s. co m*/ if (fingerprintDialog != null && fingerprintDialog.isShowing()) { return; } } catch (Exception e) { FileLog.e("tmessages", e); } try { FingerprintManagerCompat fingerprintManager = FingerprintManagerCompat .from(ApplicationLoader.applicationContext); if (fingerprintManager.isHardwareDetected() && fingerprintManager.hasEnrolledFingerprints()) { RelativeLayout relativeLayout = new RelativeLayout(getContext()); relativeLayout.setPadding(AndroidUtilities.dp(24), AndroidUtilities.dp(16), AndroidUtilities.dp(24), AndroidUtilities.dp(8)); TextView fingerprintTextView = new TextView(getContext()); fingerprintTextView.setTypeface(FontManager.instance().getTypeface()); fingerprintTextView.setTextColor(0xff939393); fingerprintTextView.setId(id_fingerprint_textview); fingerprintTextView.setTextAppearance(android.R.style.TextAppearance_Material_Subhead); fingerprintTextView .setText(LocaleController.getString("FingerprintInfo", R.string.FingerprintInfo)); relativeLayout.addView(fingerprintTextView); RelativeLayout.LayoutParams layoutParams = LayoutHelper .createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START); fingerprintTextView.setLayoutParams(layoutParams); fingerprintImageView = new ImageView(getContext()); fingerprintImageView.setImageResource(R.drawable.ic_fp_40px); fingerprintImageView.setId(id_fingerprint_imageview); relativeLayout.addView(fingerprintImageView, LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 0, 20, 0, 0, RelativeLayout.ALIGN_PARENT_START, RelativeLayout.BELOW, id_fingerprint_textview)); fingerprintStatusTextView = new TextView(getContext()); fingerprintStatusTextView.setTypeface(FontManager.instance().getTypeface()); fingerprintStatusTextView.setGravity(Gravity.CENTER_VERTICAL); fingerprintStatusTextView .setText(LocaleController.getString("FingerprintHelp", R.string.FingerprintHelp)); fingerprintStatusTextView.setTextAppearance(android.R.style.TextAppearance_Material_Body1); fingerprintStatusTextView.setTextColor(0x42000000); relativeLayout.addView(fingerprintStatusTextView); layoutParams = LayoutHelper.createRelative(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT); layoutParams.setMarginStart(AndroidUtilities.dp(16)); layoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, id_fingerprint_imageview); layoutParams.addRule(RelativeLayout.ALIGN_TOP, id_fingerprint_imageview); layoutParams.addRule(RelativeLayout.END_OF, id_fingerprint_imageview); fingerprintStatusTextView.setLayoutParams(layoutParams); AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setView(relativeLayout); builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); builder.setOnDismissListener(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { if (cancellationSignal != null) { selfCancelled = true; cancellationSignal.cancel(); cancellationSignal = null; } } }); if (fingerprintDialog != null) { try { if (fingerprintDialog.isShowing()) { fingerprintDialog.dismiss(); } } catch (Exception e) { FileLog.e("tmessages", e); } } fingerprintDialog = builder.show(); cancellationSignal = new CancellationSignal(); selfCancelled = false; fingerprintManager.authenticate(null, 0, cancellationSignal, new FingerprintManagerCompat.AuthenticationCallback() { @Override public void onAuthenticationError(int errMsgId, CharSequence errString) { if (!selfCancelled) { showFingerprintError(errString); } } @Override public void onAuthenticationHelp(int helpMsgId, CharSequence helpString) { showFingerprintError(helpString); } @Override public void onAuthenticationFailed() { showFingerprintError(LocaleController.getString("FingerprintNotRecognized", R.string.FingerprintNotRecognized)); } @Override public void onAuthenticationSucceeded( FingerprintManagerCompat.AuthenticationResult result) { try { if (fingerprintDialog.isShowing()) { fingerprintDialog.dismiss(); } } catch (Exception e) { FileLog.e("tmessages", e); } fingerprintDialog = null; processDone(true); } }, null); } } catch (Throwable e) { //ignore } } }