Java Code Examples for android.app.Dialog#setOnCancelListener()

The following examples show how to use android.app.Dialog#setOnCancelListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Util.java    From Track-My-Location with GNU General Public License v3.0 6 votes vote down vote up
public static boolean checkGooglePlayServicesAvailability(Activity activity) {
    GoogleApiAvailability api = GoogleApiAvailability.getInstance();
    int resultCode = api.isGooglePlayServicesAvailable(activity);
    if (resultCode != ConnectionResult.SUCCESS) {
        if (api.isUserResolvableError(resultCode)) {
            Dialog dialog = api.getErrorDialog(activity, resultCode, 1234);
            dialog.setCancelable(false);
            dialog.setOnCancelListener(dialogInterface -> activity.finish());
            dialog.show();
        } else {
            Toast.makeText(activity, "Device unsupported", Toast.LENGTH_LONG).show();
            activity.finish();
        }

        return false;
    }

    return true;
}
 
Example 2
Source File: Utils.java    From android with Apache License 2.0 6 votes vote down vote up
/**
 * A utility method to validate that the appropriate version of the Google Play Services is
 * available on the device. If not, it will open a dialog to address the issue. The dialog
 * displays a localized message about the error and upon user confirmation (by tapping on
 * dialog) will direct them to the Play Store if Google Play services is out of date or missing,
 * or to system settings if Google Play services is disabled on the device.
 *
 * @param activity
 * @return
 */
public static boolean checkGooglePlayServices(final Activity activity) {
    final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(
            activity);
    switch (googlePlayServicesCheck) {
        case ConnectionResult.SUCCESS:
            return true;
        default:
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck,
                    activity, 0);
            dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    activity.finish();
                }
            });
            dialog.show();
    }
    return false;
}
 
Example 3
Source File: ColorPickerDialogFragment.java    From color-picker with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
    Dialog result = super.onCreateDialog(savedInstanceState);
    result.requestWindowFeature(Window.FEATURE_NO_TITLE);
    result.setOnCancelListener(this);
    if (Build.VERSION.SDK_INT >= 21)
    {
        // set a background with round corners
        result.getWindow().setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.dmfs_colorpicker_dialog_background));
        // ensure we still have the right drop shadow in place
        ViewCompat.setElevation(result.getWindow().getDecorView(), 24);
    }
    // else: on ancient devices we'll just continue using default square corners
    return result;
}
 
Example 4
Source File: CastUtils.java    From UTubeTV with The Unlicense 6 votes vote down vote up
/**
 * A utility method to validate that the appropriate version of the Google Play Services is
 * available on the device. If not, it will open a dialog to address the issue. The dialog
 * displays a localized message about the error and upon user confirmation (by tapping on
 * dialog) will direct them to the Play Store if Google Play services is out of date or missing,
 * or to system settings if Google Play services is disabled on the device.
 */
public static boolean checkGooglePlayServices(final Activity activity) {
  final int googlePlayServicesCheck = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);
  switch (googlePlayServicesCheck) {
    case ConnectionResult.SUCCESS:
      return true;
    default:
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(googlePlayServicesCheck, activity, 0);
      dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogInterface) {
          activity.finish();
        }
      });
      dialog.show();
  }
  return false;
}
 
Example 5
Source File: LoadingDialogObserver.java    From SimpleAdapterDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param loadingDialog loading dialog
 * @param ifShowDialog  Show loadingDialog if true else not.
 */
public LoadingDialogObserver(Dialog loadingDialog, boolean ifShowDialog) {
    this.loadingDialog = loadingDialog;
    this.ifShowDialog = ifShowDialog;
    if (loadingDialog != null)
        loadingDialog.setOnCancelListener(this);
}
 
Example 6
Source File: LoadingDialogObserver.java    From CameraMaskDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param loadingDialog loading dialog
 * @param ifShowDialog  Show loadingDialog if true else not.
 */
public LoadingDialogObserver(Dialog loadingDialog, boolean ifShowDialog) {
    this.loadingDialog = loadingDialog;
    this.ifShowDialog = ifShowDialog;
    if (loadingDialog != null)
        loadingDialog.setOnCancelListener(this);
}
 
Example 7
Source File: LoadingDialogObserver.java    From WheelViewDemo with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param loadingDialog loading dialog
 * @param ifShowDialog  Show loadingDialog if true else not.
 */
public LoadingDialogObserver(Dialog loadingDialog, boolean ifShowDialog) {
    this.loadingDialog = loadingDialog;
    this.ifShowDialog = ifShowDialog;
    if (loadingDialog != null)
        loadingDialog.setOnCancelListener(this);
}
 
Example 8
Source File: ActionSheet4WeChat.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @Title showSheet
 * @param activity
 *            上下文环境
 * @param actionSheetConfig
 *            ActionSheet配置项
 * @param actionSheetItemSelected
 *            ActionSheet Item选中监听
 * @param cancelListener
 *            取消按钮的监听,无需监听可传null
 * @return Dialog 返回类型
 */
@SuppressLint("NewApi")
public Dialog show(final Activity activity,
		ActionSheetConfig actionSheetConfig,
		final OnActionSheetItemSelected actionSheetItemSelected,
		OnCancelListener cancelListener) {
	final Dialog dlg = new Dialog(activity, R.style.ActionSheet);
	LinearLayout layout = this.getLayout(activity, dlg, actionSheetConfig,
			actionSheetItemSelected);

	TextView mCancel = (TextView) layout.findViewById(R.id.cancel);

	mCancel.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			actionSheetItemSelected.onActionSheetItemSelected(activity, 0);
			dlg.dismiss();
		}
	});

	Window w = dlg.getWindow();
	WindowManager.LayoutParams lp = w.getAttributes();
	lp.x = 0;
	final int cMakeBottom = -1000;
	lp.y = cMakeBottom;
	lp.gravity = Gravity.BOTTOM;
	dlg.onWindowAttributesChanged(lp);
	dlg.setCanceledOnTouchOutside(false);
	if (cancelListener != null)
		dlg.setOnCancelListener(cancelListener);

	dlg.setContentView(layout);
	dlg.show();

	// 设置点击弹窗外部取消actionsheet
	dlg.setCanceledOnTouchOutside(true);

	return dlg;
}
 
Example 9
Source File: PlayServicesUtils.java    From android-gradle-java-app-template with Apache License 2.0 5 votes vote down vote up
/**
 * Check if device has the correct Google Play Services version.
 *
 * @param activity     Current activity.
 * @param availability New instance of GoogleApiAvailability.
 * @return True if there was a successful connection ot Google Play Services.
 */
public static boolean hasGooglePlayServices(@NonNull Activity activity, @NonNull GoogleApiAvailability availability) {
    final int result = availability.isGooglePlayServicesAvailable(activity);

    if (result == ConnectionResult.SUCCESS) {
        return true;
    } else {
        final Dialog dialog = availability.getErrorDialog(activity, result, 0);
        // Let user use the application
        dialog.setOnCancelListener(DialogInterface::cancel);
        dialog.show();
    }
    return false;
}
 
Example 10
Source File: SearchPrinterDialog.java    From esc-pos-android with Apache License 2.0 5 votes vote down vote up
public SearchPrinterDialog(Activity activity, BTService service) {
  this.activity = activity;
  this.service = service;
  deviceItems = new HashMap<>();

  @SuppressLint("InflateParams")
  View view = LayoutInflater.from(activity).inflate(R.layout.serach_dialog_layout, null, false);

  insets = dpToPx(16);
  activity.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_FOUND));
  activity.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_CLASS_CHANGED));
  activity.registerReceiver(receiver, new IntentFilter(BluetoothDevice.ACTION_NAME_CHANGED));
  activity.registerReceiver(receiver, new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED));

  Set<BluetoothDevice> pairedDevices = service.getBondedDevices();

  availableDevicesContainer = (LinearLayout) view.findViewById(R.id.available_devices_container);
  progress = view.findViewById(R.id.search_devices_progress);
  if (pairedDevices.size() > 0) {
    fillPairedDevices(pairedDevices, (LinearLayout) view.findViewById(R.id.paired_devices_container));
  } else {
    view.findViewById(R.id.paired_devices).setVisibility(View.GONE);
  }

  service.startDiscovery();

  dialog = new Dialog(activity);
  dialog.setCancelable(true);
  dialog.setContentView(view);
  dialog.setTitle(R.string.pos_title_choose_printer);
  dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialogInterface) {
      SearchPrinterDialog.this.onCancel();
    }
  });
  dialog.show();
}
 
Example 11
Source File: VKOpenAuthDialog.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
public void show(@NonNull Activity activity, Bundle bundle, int reqCode, @Nullable VKError vkError) {
	mVkError = vkError;
	mBundle = bundle;
	mReqCode = reqCode;
	mView = View.inflate(activity, R.layout.vk_open_auth_dialog, null);

	mProgress = mView.findViewById(R.id.progress);
	mWebView = (WebView) mView.findViewById(R.id.copyUrl);

	final Dialog dialog = new Dialog(activity, R.style.VKAlertDialog);
	dialog.setContentView(mView);
	dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
		@Override
		public void onCancel(DialogInterface dialogInterface) {
			dialog.dismiss();
		}
	});
	dialog.setOnDismissListener(this);
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
		dialog.getWindow().setStatusBarColor(Color.TRANSPARENT);
	}

	mDialog = dialog;
	mDialog.show();

	loadPage();
}
 
Example 12
Source File: UI.java    From green_android with GNU General Public License v3.0 4 votes vote down vote up
private static void setDialogCloseHandler(final Dialog d, final Runnable callback, final boolean cancelOnly) {
    final DialogCloseHandler handler = new DialogCloseHandler(callback, cancelOnly);
    d.setOnCancelListener(handler);
    d.setOnDismissListener(handler);
}
 
Example 13
Source File: ActionSheet4IOS.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
 * 
 * @Title showSheet
 * @Description TODO(这里用一句话描述这个方法的作用)
 * @param activity
 *            上下文环境
 * @param actionSheetConfig
 *            ActionSheet配置项
 * @param actionSheetItemSelected
 *            ActionSheet Item选中监听
 * @param cancelListener
 *            取消按钮的监听,无需监听可传null
 * @return Dialog 返回类型
 */
@SuppressLint("NewApi")
public Dialog show(final Activity activity,
		ActionSheetConfig actionSheetConfig,
		final OnActionSheetItemSelected actionSheetItemSelected,
		OnCancelListener cancelListener) {
	final Dialog dlg = new Dialog(activity, R.style.ActionSheet);
	LinearLayout layout = this.getLayout(activity, dlg, actionSheetConfig,
			actionSheetItemSelected);

	TextView mCancel = (TextView) layout.findViewById(R.id.cancel);

	mCancel.setOnClickListener(new OnClickListener() {

		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			actionSheetItemSelected.onActionSheetItemSelected(activity, 0);
			dlg.dismiss();
		}
	});

	Window w = dlg.getWindow();
	WindowManager.LayoutParams lp = w.getAttributes();
	lp.x = 0;
	final int cMakeBottom = -1000;
	lp.y = cMakeBottom;
	lp.gravity = Gravity.BOTTOM;
	dlg.onWindowAttributesChanged(lp);
	dlg.setCanceledOnTouchOutside(false);
	if (cancelListener != null)
		dlg.setOnCancelListener(cancelListener);

	dlg.setContentView(layout);
	dlg.show();

	// 设置点击弹窗外部取消actionsheet
	dlg.setCanceledOnTouchOutside(true);

	return dlg;
}
 
Example 14
Source File: UI.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public static void setDialogCloseHandler(final Dialog d, final Runnable callback, final boolean cancelOnly) {
    final DialogCloseHandler handler = new DialogCloseHandler(callback, cancelOnly);
    d.setOnCancelListener(handler);
    d.setOnDismissListener(handler);
}