Example usage for android.app AlertDialog setCancelable

List of usage examples for android.app AlertDialog setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog setCancelable.

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:org.catrobat.catroid.ui.dialogs.TermsOfUseDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    Bundle fragmentDialogArguments = getArguments();
    boolean acceptTermsOfUse = false;
    if (fragmentDialogArguments != null) {
        acceptTermsOfUse = fragmentDialogArguments.getBoolean(DIALOG_ARGUMENT_TERMS_OF_USE_ACCEPT, false);
    }//from  w  w  w .j  a v a 2 s. co  m

    View view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_terms_of_use, null);

    final CheckBox checkBoxTermsOfUseAcceptedPermanently = (CheckBox) view
            .findViewById(R.id.dialog_terms_of_use_check_box_agree_permanently);

    TextView termsOfUseUrlTextView = (TextView) view.findViewById(R.id.dialog_terms_of_use_text_view_url);
    termsOfUseUrlTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String termsOfUseUrl = getString(R.string.terms_of_use_link_template, Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(R.string.dialog_terms_of_use_link_text));

    termsOfUseUrlTextView.setText(Html.fromHtml(termsOfUseUrl));

    AlertDialog.Builder termsOfUseDialogBuilder = new AlertDialog.Builder(getActivity()).setView(view)
            .setTitle(R.string.dialog_terms_of_use_title);

    if (!acceptTermsOfUse) {
        termsOfUseDialogBuilder.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
    } else {
        termsOfUseDialogBuilder.setNegativeButton(R.string.dialog_terms_of_use_do_not_agree,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        getActivity().finish();
                        dialog.dismiss();
                    }
                });
        termsOfUseDialogBuilder.setPositiveButton(R.string.dialog_terms_of_use_agree,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        if (checkBoxTermsOfUseAcceptedPermanently.isChecked()) {
                            SettingsActivity.setTermsOfServiceAgreedPermanently(getActivity(), true);
                        }
                        dialog.dismiss();
                        DroneInitializer droneInitializer = ((PreStageActivity) getActivity())
                                .getDroneInitializer();
                        if (droneInitializer != null) {
                            droneInitializer.initialiseDrone();
                        }
                    }
                });
        termsOfUseDialogBuilder.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                Log.d(TAG, "prevent canceling the dialog with back button");
                return true;
            }
        });

        checkBoxTermsOfUseAcceptedPermanently.setVisibility(CheckBox.VISIBLE);
        checkBoxTermsOfUseAcceptedPermanently.setText(R.string.dialog_terms_of_use_agree_permanent);
        termsOfUseDialogBuilder.setCancelable(false);
    }

    AlertDialog termsOfUseDialog = termsOfUseDialogBuilder.create();
    if (!acceptTermsOfUse) {
        termsOfUseDialog.setCanceledOnTouchOutside(true);
    } else {
        termsOfUseDialog.setCancelable(false);
        termsOfUseDialog.setCanceledOnTouchOutside(false);
    }

    return termsOfUseDialog;
}

From source file:com.bangalore.barcamp.activity.WebViewActivity.java

protected Dialog onCreateDialog(int id) {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    switch (id) {
    case SHOW_ERROR_DIALOG:
        alertDialog.setCancelable(false);
        alertDialog.setTitle(getString(R.string.error_title));
        alertDialog.setMessage(getString(R.string.connection_error_and_try_again));
        alertDialog.setButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

            @Override/*from   w ww  . j  a v a 2s. c  o  m*/
            public void onClick(DialogInterface dialog, int which) {
                dismissDialog(SHOW_ERROR_DIALOG);
                WebViewActivity.this.finish();
            }
        });
        break;
    }
    return alertDialog;
}

From source file:hku.fyp14017.blencode.ui.dialogs.TermsOfUseDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle bundle) {
    Bundle fragmentDialogArguments = getArguments();
    boolean acceptTermsOfUse = false;
    if (fragmentDialogArguments != null) {
        acceptTermsOfUse = fragmentDialogArguments.getBoolean(DIALOG_ARGUMENT_TERMS_OF_USE_ACCEPT, false);
    }/*from ww w.jav a 2s.c  o m*/

    View view = LayoutInflater.from(getActivity()).inflate(hku.fyp14017.blencode.R.layout.dialog_terms_of_use,
            null);

    final CheckBox checkBoxTermsOfUseAcceptedPermanently = (CheckBox) view
            .findViewById(hku.fyp14017.blencode.R.id.dialog_terms_of_use_check_box_agree_permanently);

    TextView termsOfUseUrlTextView = (TextView) view
            .findViewById(hku.fyp14017.blencode.R.id.dialog_terms_of_use_text_view_url);
    termsOfUseUrlTextView.setMovementMethod(LinkMovementMethod.getInstance());

    String termsOfUseUrl = getString(hku.fyp14017.blencode.R.string.terms_of_use_link_template,
            Constants.CATROBAT_TERMS_OF_USE_URL,
            getString(hku.fyp14017.blencode.R.string.dialog_terms_of_use_link_text));

    termsOfUseUrlTextView.setText(Html.fromHtml(termsOfUseUrl));

    AlertDialog.Builder termsOfUseDialogBuilder = new AlertDialog.Builder(getActivity()).setView(view)
            .setTitle(hku.fyp14017.blencode.R.string.dialog_terms_of_use_title);

    if (!acceptTermsOfUse) {
        termsOfUseDialogBuilder.setNeutralButton(hku.fyp14017.blencode.R.string.ok,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
    } else {
        termsOfUseDialogBuilder.setNegativeButton(
                hku.fyp14017.blencode.R.string.dialog_terms_of_use_do_not_agree,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        getActivity().finish();
                        dialog.dismiss();
                    }
                });
        termsOfUseDialogBuilder.setPositiveButton(hku.fyp14017.blencode.R.string.dialog_terms_of_use_agree,
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        if (checkBoxTermsOfUseAcceptedPermanently.isChecked()) {
                            SettingsActivity.setTermsOfServiceAgreedPermanently(getActivity(), true);
                        }
                        dialog.dismiss();
                        DroneInitializer droneInitializer = ((PreStageActivity) getActivity())
                                .getDroneInitializer();
                        if (droneInitializer != null) {
                            droneInitializer.initialiseDrone();
                        }
                    }
                });
        termsOfUseDialogBuilder.setOnKeyListener(new OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                Log.d(TAG, "prevent canceling the dialog with back button");
                return true;
            }
        });

        checkBoxTermsOfUseAcceptedPermanently.setVisibility(CheckBox.VISIBLE);
        checkBoxTermsOfUseAcceptedPermanently
                .setText(hku.fyp14017.blencode.R.string.dialog_terms_of_use_agree_permanent);
        termsOfUseDialogBuilder.setCancelable(false);
    }

    AlertDialog termsOfUseDialog = termsOfUseDialogBuilder.create();
    if (!acceptTermsOfUse) {
        termsOfUseDialog.setCanceledOnTouchOutside(true);
    } else {
        termsOfUseDialog.setCancelable(false);
        termsOfUseDialog.setCanceledOnTouchOutside(false);
    }

    return termsOfUseDialog;
}

From source file:com.crystal.CrystalBeanWallpapers.Wallpaper.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final WallpaperLoader loader = new WallpaperLoader();
    switch (item.getItemId()) {
    case MENU_APPLY:
        if (mCustomizable) {
            final CharSequence[] items = getResources().getStringArray(R.array.customize_colors);
            int resId = mWallpapers.get(mCurrentFragment);
            Drawable d = mContext.getResources().getDrawable(resId);
            final Bitmap stockBitmap = ((BitmapDrawable) d).getBitmap();

            AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
            builder.setTitle(getString(R.string.pick_color));
            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override/* ww w. j av  a 2s . c  o  m*/
                public void onClick(DialogInterface dialog, int item) {
                    int color = Color.BLACK;
                    boolean setColor = true;
                    switch (item) {
                    case 0:
                        color = Color.RED;
                        break;
                    case 1:
                        color = Color.GREEN;
                        break;
                    case 2:
                        color = Color.BLUE;
                        break;
                    case 3:
                        setColor = false;
                        break;
                    }

                    loader.setBitmap(setColor ? getColoredBitmap(stockBitmap, color) : stockBitmap);
                    loader.execute();
                }
            });
            AlertDialog alert = builder.create();
            alert.setCancelable(false);
            alert.show();
        } else {
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), mWallpapers.get(mCurrentFragment));
            loader.setBitmap(bitmap);
            loader.execute();
        }
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.github.mobile.ui.ConfirmDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    AlertDialog dialog = LightAlertDialog.create(getActivity());
    dialog.setTitle(getTitle());//w w  w  .ja  v  a2s.  c o m
    dialog.setMessage(getMessage());
    dialog.setButton(BUTTON_POSITIVE, getResources().getString(android.R.string.yes), this);
    dialog.setButton(BUTTON_NEGATIVE, getResources().getString(android.R.string.no), this);
    dialog.setCancelable(true);
    dialog.setOnCancelListener(this);
    return dialog;
}

From source file:es.uja.photofirma.android.SignUpActivity.java

/**
 * Advertencia a cerca de la privacidad del usuario, el usuario ser notificado
 * /*from   www .j  av  a2  s.  co  m*/
 */
public void onTermsOfUse(View view) {
    final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle("Terminos de uso");
    alertDialog.setMessage(getString(R.string.terms_of_use));
    alertDialog.setCancelable(false);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            alertDialog.dismiss();
        }
    });
    alertDialog.show();

}

From source file:com.offsec.nethunter.AppNavHomeActivity.java

public void showLicense() {
    // @binkybear here goes the changelog etc... \n\n%s
    String readmeData = String.format("%s\n\n%s", getResources().getString(R.string.licenseInfo),
            getResources().getString(R.string.nhwarning));

    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    adb.setTitle("README INFO").setMessage(readmeData).setNegativeButton("Close",
            new DialogInterface.OnClickListener() {
                @Override/*  www  . j a  v a 2s.  com*/
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }); //nhwarning
    AlertDialog ad = adb.create();
    ad.setCancelable(false);
    ad.getWindow().getAttributes().windowAnimations = R.style.DialogStyle;
    ad.show();
}

From source file:com.metinkale.prayerapp.vakit.fragments.SortFragment.java

public void onItemDismiss(final int position) {
    final Times times = Times.getTimesAt(position);

    AlertDialog dialog = new AlertDialog.Builder(getActivity()).create();
    dialog.setTitle(R.string.delete);//from   ww w .ja  va 2 s.  c o m
    dialog.setMessage(getString(R.string.delConfirm, times.getName()));
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.yes),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int buttonId) {
                    times.delete();
                    mAdapter.notifyItemRemoved(position);
                }
            });
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.no),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int buttonId) {
                    dialog.cancel();
                    mAdapter.notifyDataSetChanged();
                }
            });
    dialog.show();
}

From source file:com.aikidonord.Intervenant.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_intervenant);

    View rlLoading = findViewById(R.id.loadingPanel);
    View listView = findViewById(R.id.list);

    ActionBar actionBar = this.getSupportActionBar();

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(getResources().getString(R.string.actionbar_titre_intervenant));

    if (VerifConnexion.isOnline(this)) {

        rlLoading.setVisibility(View.VISIBLE);
        listView.setVisibility(View.GONE);

        new QueryForAnimateurTask().execute(this, this.getApplicationContext());
    } else {//from w ww  . j a  va 2 s.co m

        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle(getResources().getString(R.string.app_name));
        alertDialog.setMessage(getResources().getString(R.string.no_network));
        alertDialog.setIcon(R.drawable.ic_launcher);
        alertDialog.setCancelable(false);
        alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getResources().getString(R.string.close),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // if this button is clicked, close
                        // current activity
                        Intervenant.this.finish();
                    }
                });
        alertDialog.show();
    }

}

From source file:com.sck.maininterface.PaymentInfo.java

@SuppressWarnings("deprecation")
@Override/*from  www .  j  a  v a 2  s .c  o  m*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_PAYMENT) {

        if (resultCode == Activity.RESULT_OK) {

            PaymentConfirmation confirm = data.getParcelableExtra(PaymentActivity.EXTRA_RESULT_CONFIRMATION);

            if (confirm != null) {

                try {
                    Log.i(TAG, confirm.toJSONObject().toString(4));
                    Log.i(TAG, confirm.getPayment().toJSONObject().toString(4));

                    /*   Toast.makeText(
                             getApplicationContext(),
                             "Payment Confirmation info received from PayPal",
                             Toast.LENGTH_LONG).show();*/

                    AlertDialog ad = new AlertDialog.Builder(this).create();
                    ad.setCancelable(false); // This blocks the 'BACK' button  
                    ad.setMessage("Payment Confirmation info received from PayPal");
                    ad.setButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    ad.show();
                    //new updateExpiryDate().execute();
                    //paymentSuccess=true;
                    saveExpDate(renewedDate);

                } catch (JSONException e) {
                    Log.e(TAG, "an extremely unlikely failure occurred: ", e);
                }
            }
        }

        else if (resultCode == Activity.RESULT_CANCELED) {
            Log.i(TAG, "The user canceled.");
        }

        else if (resultCode == PaymentActivity.RESULT_EXTRAS_INVALID) {
            Log.i(TAG, "An invalid Payment or PayPalConfiguration was submitted. Please see the docs.");
        }
    }

    // /

}