Java Code Examples for android.content.DialogInterface.OnCancelListener

The following are Jave code examples for showing how to use OnCancelListener of the android.content.DialogInterface class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: JD-Test   File: DialogUtil.java   Source Code and License Vote up 6 votes
/**
 * 有取消回调的进度dialog
 * @param context
 * @param msg
 * @return
 */
public static Dialog createLoadingDialog(Activity context, String msg, DialogInterface.OnCancelListener listener) {
    final Dialog dialog = new Dialog(context , R.style.NoBackGroundDialog);
    dialog.show();
    dialog.setCanceledOnTouchOutside(false);
    if(listener != null) dialog.setOnCancelListener(listener);
    Window window = dialog.getWindow();
    assert window != null;
    window.setGravity(Gravity.CENTER);
    int width = ScreenUtil.getWidth(context) * 2 / 3;
    window.setLayout(width,
            android.view.WindowManager.LayoutParams.WRAP_CONTENT);
    View view = context.getLayoutInflater().inflate(
            R.layout.loading_dialog, null);
    TextView tipTextView = (TextView) view.findViewById(R.id.tipTextView);// 提示文字
    if(!TextUtils.isEmpty(msg)){
        tipTextView.setText(msg);// 设置加载信息
    }

    window.setContentView(view);//
    return dialog;

}
 
Example 2
Project: JD-Test   File: DialogUtil.java   Source Code and License Vote up 6 votes
/**
 * gif动画进度
 * @param context
 *
 * @return
 */
public static Dialog createJDLoadingDialog(Activity context, DialogInterface.OnCancelListener listener) {
    final Dialog dialog = new Dialog(context , R.style.NoBackGroundDialog);
    dialog.show();
    dialog.setCanceledOnTouchOutside(false);
    if(listener != null) dialog.setOnCancelListener(listener);
    Window window = dialog.getWindow();
    assert window != null;
    window.setGravity(Gravity.CENTER);
    window.setLayout(android.view.WindowManager.LayoutParams.WRAP_CONTENT,
            android.view.WindowManager.LayoutParams.WRAP_CONTENT);
    View view = context.getLayoutInflater().inflate(
            R.layout.jd_loading_dialog, null);
    window.setContentView(view);//
    return dialog;

}
 
Example 3
Project: BlackList   File: ProgressDialogHolder.java   Source Code and License Vote up 6 votes
public void show(Context context, @StringRes int titleId, @StringRes int messageId,
                 DialogInterface.OnCancelListener listener) {
    dismiss();
    DialogBuilder builder = new DialogBuilder(context);
    if (titleId > 0) {
        builder.setTitle(titleId);
    }
    LayoutInflater inflater = LayoutInflater.from(context);
    View itemView = inflater.inflate(R.layout.row_progress, null);
    messageTextView = (TextView) itemView.findViewById(R.id.text_progress);
    if (messageId > 0) {
        messageTextView.setText(messageId);
    }
    builder.addItem(itemView);
    builder.setOnCancelListener(listener);
    dialog = builder.show();
}
 
Example 4
Project: TripBuyer   File: MMAlert.java   Source Code and License Vote up 5 votes
public static AlertDialog showAlert(final Context context, final String title, final View view, final DialogInterface.OnCancelListener lCancel) {
	if (context instanceof Activity && ((Activity) context).isFinishing()) {
		return null;
	}

	final Builder builder = new AlertDialog.Builder(context);
	builder.setTitle(title);
	builder.setView(view);
	// builder.setCancelable(true);
	builder.setOnCancelListener(lCancel);
	final AlertDialog alert = builder.create();
	alert.show();
	return alert;
}
 
Example 5
Project: JD-Test   File: BaseActivity.java   Source Code and License Vote up 5 votes
protected void showProgressDialog(String msg , DialogInterface.OnCancelListener listener){
    if(loadingDialog == null){
        loadingDialog = DialogUtil.createLoadingDialog(this, msg, listener);
    }else if(!loadingDialog.isShowing()){
        loadingDialog.show();
    }

}
 
Example 6
Project: FlickLauncher   File: DialogUtils.java   Source Code and License Vote up 5 votes
/**
 * Calls cropTask.execute(), once the user has selected which wallpaper to set. On pre-N
 * devices, the prompt is not displayed since there is no API to set the lockscreen wallpaper.
 * <p>
 * TODO: Don't use CropAndSetWallpaperTask on N+, because the new API will handle cropping instead.
 */
public static void executeCropTaskAfterPrompt(
        Context context, final AsyncTask<Integer, ?, ?> cropTask,
        DialogInterface.OnCancelListener onCancelListener) {
    if (Utilities.isNycOrAbove()) {
        new AlertDialog.Builder(context)
                .setTitle(R.string.wallpaper_instructions)
                .setItems(R.array.which_wallpaper_options, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int selectedItemIndex) {
                        int whichWallpaper;
                        if (selectedItemIndex == 0) {
                            whichWallpaper = WallpaperManagerCompat.FLAG_SET_SYSTEM;
                        } else if (selectedItemIndex == 1) {
                            whichWallpaper = WallpaperManagerCompat.FLAG_SET_LOCK;
                        } else {
                            whichWallpaper = WallpaperManagerCompat.FLAG_SET_SYSTEM
                                    | WallpaperManagerCompat.FLAG_SET_LOCK;
                        }
                        cropTask.execute(whichWallpaper);
                    }
                })
                .setOnCancelListener(onCancelListener)
                .show();
    } else {
        cropTask.execute(WallpaperManagerCompat.FLAG_SET_SYSTEM);
    }
}
 
Example 7
Project: OSchina_resources_android   File: CommonDialog.java   Source Code and License Vote up 5 votes
protected CommonDialog(Context context, boolean flag,
                       DialogInterface.OnCancelListener listener) {
    super(context, flag, listener);
    contentPadding = (int) getContext().getResources().getDimension(
            R.dimen.global_dialog_padding);
    init(context);
}
 
Example 8
Project: google-speech-api-android   File: MainActivity.java   Source Code and License Vote up 5 votes
private void showProgressDialog(
        @Nullable final String message,
        final boolean cancelable,
        @Nullable final DialogInterface.OnCancelListener cancelListener) {
    final ProgressDialog prevDialog = dialogAtomicReference.getAndSet(null);
    if (prevDialog != null && prevDialog.isShowing()) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                prevDialog.dismiss();
            }
        });
    }

    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            final ProgressDialog newDialog = ProgressDialog.show(
                    // Context
                    MainActivity.this,
                    // Title
                    null,
                    // Message
                    message,
                    // Indeterminate
                    true,
                    // Cancelable
                    cancelable,
                    // CancelListener
                    cancelListener
            );
            if (!dialogAtomicReference.compareAndSet(null, newDialog)) {
                newDialog.dismiss();
            }
        }
    });
}
 
Example 9
Project: CompatAlertDialog   File: AlertDialog.java   Source Code and License Vote up 4 votes
public Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
    builder.setOnCancelListener(onCancelListener);
    return this;
}
 
Example 10
Project: AssistantBySDK   File: TimePickerDialog.java   Source Code and License Vote up 4 votes
public void setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
    mOnCancelListener = onCancelListener;
}
 
Example 11
Project: AssistantBySDK   File: DatePickerDialog.java   Source Code and License Vote up 4 votes
@SuppressWarnings("unused")
public void setOnCancelListener(DialogInterface.OnCancelListener onCancelListener) {
    mOnCancelListener = onCancelListener;
}
 
Example 12
Project: JD-Test   File: BaseActivity.java   Source Code and License Vote up 4 votes
protected void showProgressDialog(DialogInterface.OnCancelListener listener){
    this.showProgressDialog(null ,listener);
}
 
Example 13
Project: BlackList   File: DialogBuilder.java   Source Code and License Vote up 4 votes
public DialogBuilder setOnCancelListener(DialogInterface.OnCancelListener listener) {
    getDialog().setOnCancelListener(listener);
    return this;
}
 
Example 14
Project: HutHelper   File: LoadingDialog.java   Source Code and License Vote up 4 votes
public void setOnCancelListener(DialogInterface.OnCancelListener listener){
    dialog.setOnCancelListener(listener);
}
 
Example 15
Project: FlickLauncher   File: WallpaperCropActivity.java   Source Code and License Vote up 4 votes
public DialogInterface.OnCancelListener getOnDialogCancelListener() {
    return mOnDialogCancelListener;
}
 
Example 16
Project: keepass2android   File: Dlg.java   Source Code and License Vote up 3 votes
/**
 * Shows an error message.
 * 
 * @param context
 *            {@link Context}
 * @param msg
 *            the message.
 * @param listener
 *            will be called after the user cancelled the dialog.
 */
public static void showError(Context context, CharSequence msg,
        DialogInterface.OnCancelListener listener) {
    AlertDialog dlg = newAlertDlg(context);
    dlg.setIcon(android.R.drawable.ic_dialog_alert);
    dlg.setTitle(R.string.afc_title_error);
    dlg.setMessage(msg);
    dlg.setOnCancelListener(listener);
    dlg.show();
}
 
Example 17
Project: keepass2android   File: Dlg.java   Source Code and License Vote up 3 votes
/**
 * Shows an unknown error.
 * 
 * @param context
 *            {@link Context}
 * @param t
 *            the {@link Throwable}
 * @param listener
 *            will be called after the user cancelled the dialog.
 */
public static void showUnknownError(Context context, Throwable t,
        DialogInterface.OnCancelListener listener) {
    showError(
            context,
            String.format(
                    context.getString(R.string.afc_pmsg_unknown_error), t),
            listener);
}
 
Example 18
Project: keepass2android   File: Dlg.java   Source Code and License Vote up 3 votes
/**
 * Shows a confirmation dialog.
 * 
 * @param context
 *            {@link Context}
 * @param msg
 *            the message.
 * @param onYes
 *            will be called if the user selects positive answer (a
 *            <i>Yes</i> or <i>OK</i>).
 * @param onNo
 *            will be called after the user cancelled the dialog.
 */
public static void confirmYesno(Context context, CharSequence msg,
        DialogInterface.OnClickListener onYes,
        DialogInterface.OnCancelListener onNo) {
    AlertDialog dlg = newAlertDlg(context);
    dlg.setIcon(android.R.drawable.ic_dialog_alert);
    dlg.setTitle(R.string.afc_title_confirmation);
    dlg.setMessage(msg);
    dlg.setButton(DialogInterface.BUTTON_POSITIVE,
            context.getString(android.R.string.yes), onYes);
    dlg.setOnCancelListener(onNo);
    dlg.show();
}
 
Example 19
Project: keepass2android   File: Dlg.java   Source Code and License Vote up 2 votes
/**
 * Shows an error message.
 * 
 * @param context
 *            {@link Context}
 * @param msgId
 *            the resource ID of the message.
 * @param listener
 *            will be called after the user cancelled the dialog.
 */
public static void showError(Context context, int msgId,
        DialogInterface.OnCancelListener listener) {
    showError(context, context.getString(msgId), listener);
}
 
Example 20
Project: CompatAlertDialog   File: AlertDialog.java   Source Code and License Vote up 0 votes
Builder setOnCancelListener(DialogInterface.OnCancelListener onCancelListener);