Java Code Examples for android.support.v7.app.AlertDialog#setCancelable()

The following examples show how to use android.support.v7.app.AlertDialog#setCancelable() . 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: CrashHandler.java    From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param t 出现未捕获异常的线程
 * @param e 未捕获的异常
 */
@Override
public void uncaughtException(Thread t, Throwable e) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("出现异常");
    builder.setMessage(e.getMessage());
    builder.setPositiveButton("确定", new DialogInterface.OnClickListener(){

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.setCancelable(false);
    alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alertDialog.show();
}
 
Example 2
Source File: DialogUtils.java    From v9porn with MIT License 5 votes vote down vote up
public static AlertDialog initLoadingDialog(Context context, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.LoadingDialogStyle);
    View view = View.inflate(context, R.layout.loading_layout, null);
    if (!TextUtils.isEmpty(message)) {
        TextView textView = view.findViewById(R.id.textView);
        textView.setText(message);
    }
    builder.setView(view);
    builder.setCancelable(false);
    AlertDialog mAlertDialog = builder.create();
    mAlertDialog.setCanceledOnTouchOutside(false);
    mAlertDialog.setCancelable(false);

    return mAlertDialog;
}
 
Example 3
Source File: DialogUtils.java    From v9porn with MIT License 5 votes vote down vote up
public static AlertDialog initLoadingDialog(Context context, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.LoadingDialogStyle);
    View view = View.inflate(context, R.layout.loading_layout, null);
    if (!TextUtils.isEmpty(message)) {
        TextView textView = view.findViewById(R.id.textView);
        textView.setText(message);
    }
    builder.setView(view);
    builder.setCancelable(false);
    AlertDialog mAlertDialog = builder.create();
    mAlertDialog.setCanceledOnTouchOutside(false);
    mAlertDialog.setCancelable(false);

    return mAlertDialog;
}
 
Example 4
Source File: MyUtil.java    From Dainty with Apache License 2.0 5 votes vote down vote up
public static void createDialog(Context context, String title, String message, String positiveButtonText,
                                DialogInterface.OnClickListener onPositiveListener,
                                DialogInterface.OnClickListener onNegativeListener) {
    AlertDialog.Builder normalDialog = new AlertDialog.Builder(context);
    AlertDialog dialog=normalDialog.setIcon(android.R.drawable.ic_menu_info_details)
            .setTitle(title)
            .setMessage(message)
            .setPositiveButton(positiveButtonText, onPositiveListener)
            .setNegativeButton("取消", onNegativeListener).show();
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);
}
 
Example 5
Source File: UpdateAgent.java    From update with Apache License 2.0 4 votes vote down vote up
@Override
public void prompt(IUpdateAgent agent) {
    if (mContext instanceof Activity && ((Activity) mContext).isFinishing()) {
        return;
    }
    final UpdateInfo info = agent.getInfo();
    String size = Formatter.formatShortFileSize(mContext, info.size);
    String content = String.format("最新版本:%1$s\n新版本大小:%2$s\n\n更新内容\n%3$s", info.versionName, size, info.updateContent);

    final AlertDialog dialog = new AlertDialog.Builder(mContext).create();

    dialog.setTitle("应用更新");
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);


    float density = mContext.getResources().getDisplayMetrics().density;
    TextView tv = new TextView(mContext);
    tv.setMovementMethod(new ScrollingMovementMethod());
    tv.setVerticalScrollBarEnabled(true);
    tv.setTextSize(14);
    tv.setMaxHeight((int) (250 * density));

    dialog.setView(tv, (int) (25 * density), (int) (15 * density), (int) (25 * density), 0);


    DialogInterface.OnClickListener listener = new DefaultPromptClickListener(agent, true);

    if (info.isForce) {
        tv.setText("您需要更新应用才能继续使用\n\n" + content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", listener);
    } else {
        tv.setText(content);
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "立即更新", listener);
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "以后再说", listener);
        if (info.isIgnorable) {
            dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "忽略该版", listener);
        }
    }
    dialog.show();
}