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

The following examples show how to use android.support.v7.app.AlertDialog#setCanceledOnTouchOutside() . 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: ProximityApiErrorDialogFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    alertDialogBuilder.setTitle("Error " +  mErrorCode);
    final View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_dialog_error, null);
    final TextView message = (TextView) view.findViewById(R.id.error_message);
    final TextView status = (TextView) view.findViewById(R.id.error_status);
    message.setText(mMessage);
    status.setText(mStatus);
    final AlertDialog alertDialog = alertDialogBuilder.setView(view).setPositiveButton(getString(R.string.ok), null).show();
    alertDialog.setCanceledOnTouchOutside(false);

    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ((OnHandleError)getParentFragment()).handleAuthorizationError(mErrorCode);
            dismiss();
        }
    });
    return alertDialog;
}
 
Example 2
Source File: NGActivity.java    From android_maplibui with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void requestPermissions(int title, int message, final int requestCode, final String... permissions) {
    boolean shouldShowDialog = false;
    for (String permission : permissions) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
            shouldShowDialog = true;
            break;
        }
    }

    if (shouldShowDialog) {
        final Activity activity = this;
        AlertDialog builder = new AlertDialog.Builder(this).setTitle(title)
                .setMessage(message)
                .setPositiveButton(android.R.string.ok, null).create();
        builder.setCanceledOnTouchOutside(false);
        builder.show();

        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                ActivityCompat.requestPermissions(activity, permissions, requestCode);
            }
        });
    } else
        ActivityCompat.requestPermissions(this, permissions, requestCode);
}
 
Example 3
Source File: UserDialog.java    From NanoIconPack with Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ViewGroup viewGroup = (ViewGroup) getActivity().getLayoutInflater()
            .inflate(R.layout.dialog_key, null);
    etUser = (EditText) viewGroup.findViewById(R.id.et_user);

    AlertDialog alertDialog = new AlertDialog.Builder(getContext())
            .setTitle(R.string.dlg_title_set_key)
            .setView(viewGroup)
            .setPositiveButton(R.string.dlg_bt_ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (onContinueListener != null) {
                        onContinueListener.onContinue(etUser.getText().toString().trim());
                    }
                }
            })
            .create();
    alertDialog.setCanceledOnTouchOutside(false);

    return alertDialog;
}
 
Example 4
Source File: BaseActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 提示对话框,带有“确定”按钮
 *
 * @param message 提示内容
 */
protected void showAlertDialog(int message) {
    AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message)
            .setPositiveButton(R.string.btn_confirm, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
Example 5
Source File: ChangeLogDialogFragment.java    From IslamicLibraryAndroid with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    View chgList = LayoutInflater.from(getContext()).inflate(R.layout.dialog_change_log, null);
    setUpBottomBar(chgList);
    AlertDialog alertDialog = new AlertDialog.Builder(getContext(), R.style.ThemeOverlay_AppCompat_Dialog_Alert)
            .setView(chgList)
            .setTitle(R.string.change_log)
            .create();
    alertDialog.setCanceledOnTouchOutside(true);
    return alertDialog;

}
 
Example 6
Source File: ViewUtil.java    From VBrowser-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 弹出一个带确认和取消的dialog
 * @param context
 * @param title
 * @param msg
 * @param okbutton
 * @param ok 点击确定事件
 * @param nobutton
 * @param no 点击取消事件
 * @return
 */
public static AlertDialog openConfirmDialog(Context context, String title,
                                            String msg, String okbutton, DialogInterface.OnClickListener ok, String nobutton,
                                            DialogInterface.OnClickListener no) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title);
    builder.setMessage("\n" + msg + "\n");
    builder.setNegativeButton(okbutton, ok);
    builder.setNeutralButton(nobutton, no);
    AlertDialog loadWaitDialog = builder.create();
    loadWaitDialog.setCanceledOnTouchOutside(false);
    loadWaitDialog.show();
    return loadWaitDialog;
}
 
Example 7
Source File: QuestionFragment.java    From triviums with MIT License 5 votes vote down vote up
private void showDialogForTimeout(){
    AlertDialog dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setMessage("Sorry, please check your internet connection")
            .setPositiveButton("OK", (dialog1, which) -> {
                getActivity().finish();
            });
    dialog = builder.create();
    //This disables clicking outside the dialog box
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
Example 8
Source File: StagesFragment.java    From triviums with MIT License 5 votes vote down vote up
private void showDialogForTimeout(){
    binding.loader.setVisibility(View.GONE);
    AlertDialog dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    builder.setMessage("Sorry, please check your internet connection")
            .setPositiveButton("OK", (dialog1, which) -> {
                getActivity().finish();
            });
    dialog = builder.create();

    //This disables clicking outside the dialog box
    dialog.setCanceledOnTouchOutside(false);

    dialog.show();
}
 
Example 9
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 10
Source File: LaunchFragment.java    From weMessage with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    int animationResource = args.getInt(weMessage.BUNDLE_DIALOG_ANIMATION);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final AnimationDialogLayout animationDialogLayout = (AnimationDialogLayout) getActivity().getLayoutInflater().inflate(R.layout.animation_dialog_layout, null);
    animationDialogLayout.setAnimationSource(animationResource);

    builder.setView(animationDialogLayout);

    final AlertDialog dialog = builder.create();

    animationDialogLayout.getVideoView().setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            animationDialogLayout.getVideoView().setZOrderOnTop(false);
            dialog.dismiss();
            if (runnable != null) {
                new Handler().postDelayed(runnable, 100L);
            }
        }
    });
    setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);
    this.dialogLayout = animationDialogLayout;

    return dialog;
}
 
Example 11
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 12
Source File: OtherFormsOfHistoryDialogFragment.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.other_forms_of_history_dialog, null);

    // Linkify the <link></link> span in the dialog text.
    TextView textView = (TextView) view.findViewById(R.id.text);
    final SpannableString textWithLink = SpanApplier.applySpans(
            textView.getText().toString(),
            new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                @Override
                public void onClick(View widget) {
                    new TabDelegate(false /* incognito */).launchUrl(
                            WEB_HISTORY_URL, TabLaunchType.FROM_CHROME_UI);
                }
            }));

    textView.setText(textWithLink);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    // Construct the dialog.
    AlertDialog dialog = new AlertDialog.Builder(getActivity(), R.style.AlertDialogTheme)
            .setView(view)
            .setTitle(R.string.clear_browsing_data_history_dialog_title)
            .setPositiveButton(
                    R.string.ok_got_it, this)
            .create();

    dialog.setCanceledOnTouchOutside(false);
    return dialog;
}
 
Example 13
Source File: BaseActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 提示对话框,带有“确定”和“取消”两个按钮
 *
 * @param title    标题
 * @param message  提示内容
 * @param listener “确定”按钮的点击监听器
 */
protected void showAlertDialog(String title, String message, DialogInterface.OnClickListener listener) {
    AlertDialog dialog = new AlertDialog.Builder(this).setTitle(title).setMessage(message)
            .setPositiveButton(R.string.btn_confirm, listener)
            .setNegativeButton(R.string.btn_cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
Example 14
Source File: BaseActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 提示对话框,带有“确定”和“取消”两个按钮
 *
 * @param message  提示内容
 * @param listener “确定”按钮的点击监听器
 */
protected void showAlertDialog(int message, DialogInterface.OnClickListener listener) {
    AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message)
            .setPositiveButton(R.string.btn_confirm, listener)
            .setNegativeButton(R.string.btn_cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
Example 15
Source File: BaseActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 提示对话框,带有“确定”和“取消”两个按钮
 *
 * @param message  提示内容
 * @param listener “确定”按钮的点击监听器
 */
protected void showAlertDialog(String message, DialogInterface.OnClickListener listener) {
    AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message)
            .setPositiveButton(R.string.btn_confirm, listener)
            .setNegativeButton(R.string.btn_cancel, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
Example 16
Source File: BaseActivity.java    From BlogDemo with Apache License 2.0 5 votes vote down vote up
/**
 * 提示对话框,带有“确定”按钮
 *
 * @param message 提示内容
 */
protected void showAlertDialog(String message) {
    AlertDialog dialog = new AlertDialog.Builder(this).setMessage(message)
            .setPositiveButton(R.string.btn_confirm, null).create();
    dialog.setCanceledOnTouchOutside(false);
    dialog.show();
}
 
Example 17
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();
}
 
Example 18
Source File: BroadcastCapabilitesDialogFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
    alertDialogBuilder.setTitle("Broadcast Capabilities");

    final View alertDialogView = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_broadcast_capabilities, null);
    mVersion = (TextView) alertDialogView.findViewById(R.id.version_value);
    final TextView totalSlots = (TextView) alertDialogView.findViewById(R.id.total_slots);
    final TextView totalEidSlots = (TextView) alertDialogView.findViewById(R.id.total_eid_slots);
    final TextView variableAdvertisingSupported = (TextView) alertDialogView.findViewById(R.id.variable_adv_supported);
    final TextView variableTxPowerSupported = (TextView) alertDialogView.findViewById(R.id.variable_tx_power_supported);
    final TextView supportedFrameTypes = (TextView) alertDialogView.findViewById(R.id.frame_types);
    final TextView supportedTxPower = (TextView) alertDialogView.findViewById(R.id.supported_tx_power);

    final AlertDialog alertDialog = alertDialogBuilder.setView(alertDialogView).setPositiveButton(getString(R.string.ok), null).show();
    alertDialog.setCanceledOnTouchOutside(false);

    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                dismiss();
        }
    });

    mVersion.setText(String.valueOf(ParserUtils.getIntValue(mBroadcastCapabilities, 0, BluetoothGattCharacteristic.FORMAT_UINT8)));
    totalSlots.setText(String.valueOf(ParserUtils.getIntValue(mBroadcastCapabilities, 1, BluetoothGattCharacteristic.FORMAT_UINT8)));
    totalEidSlots.setText(String.valueOf(ParserUtils.getIntValue(mBroadcastCapabilities, 2, BluetoothGattCharacteristic.FORMAT_UINT8)));


    final int capabilities = ParserUtils.getIntValue(mBroadcastCapabilities, 3, BluetoothGattCharacteristic.FORMAT_UINT8);
    final boolean variableAdvertising = (capabilities & IS_VARIABLE_ADV_SUPPORTED) > 0;
    if(variableAdvertising)
        variableAdvertisingSupported.setText("YES");
    else
        variableAdvertisingSupported.setText("NO");

    final boolean variableTxPower = (capabilities & IS_VARIABLE_TX_POWER_SUPPORTED) > 0;
    if(variableTxPower)
        variableTxPowerSupported.setText("YES");
    else
        variableTxPowerSupported.setText("NO");

    final int supportedEddystoneFrameTypes = ParserUtils.getIntValue(mBroadcastCapabilities, 4, ParserUtils.FORMAT_UINT16_BIG_INDIAN);

    final boolean typeUid = (supportedEddystoneFrameTypes & TYPE_UID) > 0;
    final boolean typeUrl = (supportedEddystoneFrameTypes & TYPE_URL) > 0;
    final boolean typeTlm = (supportedEddystoneFrameTypes & TYPE_TLM) > 0;
    final boolean typeEid = (supportedEddystoneFrameTypes & TYPE_EID) > 0;

    StringBuilder builder = new StringBuilder();

    if(typeUid)
        builder.append("UID, ");
    if(typeUrl)
        builder.append("URL, ");
    if(typeTlm)
        builder.append("TLM, ");
    if(typeEid)
        builder.append("EID");

    if(builder.toString().endsWith(",")) {
        builder.setLength(builder.length() - 2);
    }

    supportedFrameTypes.setText(builder.toString());

    builder = new StringBuilder();
    for(int i = 6; i < mBroadcastCapabilities.length; i++){
        builder.append(" " + ParserUtils.getIntValue(mBroadcastCapabilities, i , BluetoothGattCharacteristic.FORMAT_SINT8)).append(",");
    }

    if(builder.toString().endsWith(",")){
        builder.setLength(builder.length()-1);
    }
    builder.append(" dBm");
    supportedTxPower.setText(builder.toString());

    return alertDialog;
}
 
Example 19
Source File: FListCharSelectionPopup.java    From AndFChat with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();    //Call show on default first so we can override the handlers

    final AlertDialog dialog = (AlertDialog) getDialog();
    if (dialog == null) {
        return;
    }

    final Button button = dialog.getButton(AlertDialog.BUTTON_POSITIVE);
    button.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            String characterName = ((ArrayAdapter<String>)charSelector.getAdapter()).getItem(charSelector.getSelectedItemPosition());

            sessionData.clear();

            // Reset data only when new character connects
            if (sessionData.getCharacterName() == null || !sessionData.getCharacterName().equals(characterName)) {
                chatroomManager.clear();
                characterManager.clear();

                sessionData.setCharacterName(characterName);
            }
            // Websocket is connected?
            if (connection.isConnected()) {

                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        button.setEnabled(false);
                        button.setText(R.string.connecting);
                    }
                };

                Ln.i("Connected to WebSocket!");
                Ln.d("loading logs");
                historyManager.loadHistory();
                // Identify the character
                connection.identify();
            }
        }
    });

    // Cant close dialog
    dialog.setCanceledOnTouchOutside(false);
}
 
Example 20
Source File: XmppActivity.java    From Conversations with GNU General Public License v3.0 4 votes vote down vote up
@SuppressLint("InflateParams")
private void quickEdit(final String previousValue,
                       final OnValueEdited callback,
                       final @StringRes int hint,
                       boolean password,
                       boolean permitEmpty) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    DialogQuickeditBinding binding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.dialog_quickedit, null, false);
    if (password) {
        binding.inputEditText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    }
    builder.setPositiveButton(R.string.accept, null);
    if (hint != 0) {
        binding.inputLayout.setHint(getString(hint));
    }
    binding.inputEditText.requestFocus();
    if (previousValue != null) {
        binding.inputEditText.getText().append(previousValue);
    }
    builder.setView(binding.getRoot());
    builder.setNegativeButton(R.string.cancel, null);
    final AlertDialog dialog = builder.create();
    dialog.setOnShowListener(d -> SoftKeyboardUtils.showKeyboard(binding.inputEditText));
    dialog.show();
    View.OnClickListener clickListener = v -> {
        String value = binding.inputEditText.getText().toString();
        if (!value.equals(previousValue) && (!value.trim().isEmpty() || permitEmpty)) {
            String error = callback.onValueEdited(value);
            if (error != null) {
                binding.inputLayout.setError(error);
                return;
            }
        }
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
        dialog.dismiss();
    };
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener((v -> {
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
        dialog.dismiss();
    }));
    dialog.setCanceledOnTouchOutside(false);
    dialog.setOnDismissListener(dialog1 -> {
        SoftKeyboardUtils.hideSoftKeyboard(binding.inputEditText);
    });
}