Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder 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:com.nikhilnayak.games.octoshootar.ui.dialogfragments.InventoryItemEntryDetailDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mInventoryItemEntry = getArguments().getParcelable(EXTRA_INVENTORY_ITEM_ENTRY);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    mInventoryItemEntryViewDetailView = new InventoryItemEntryDetailView(getActivity());
    mInventoryItemEntryViewDetailView.setModel(mInventoryItemEntry);
    mInventoryItemEntryViewDetailView.setCraftRequestListener(this);
    builder.setView(mInventoryItemEntryViewDetailView);

    builder.setCancelable(true);
    builder.setPositiveButton(R.string.craft_dialog_fragment_ok_response, null);

    AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override/*from w  w  w  .  j a va  2s.  c  o  m*/
        public void onShow(DialogInterface dialog) {
            Button positiveButton = ((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE);
            positiveButton.setBackgroundResource(R.drawable.button_dialog);
        }
    });
    return alertDialog;
}

From source file:com.twolinessoftware.smarterlist.fragment.NotesEntryDialogFragment.java

@NonNull
@Override/* ww w  . j  a v a  2  s . c om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    LayoutInflater li = LayoutInflater.from(getActivity());
    View noteView = li.inflate(R.layout.fragment_noteentry, null);

    ButterKnife.inject(this, noteView);

    m_editNotes.setText(m_smartListItem.getNotes());

    builder.setView(noteView);

    builder.setCancelable(true).setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            onAdd(null);
        }
    });

    return builder.create();
}

From source file:com.oddsoft.tpetrash2.view.activity.MainActivity.java

protected final Dialog onCreateDialog(final int id) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setIcon(ContextCompat.getDrawable(this, R.drawable.ic_exclamation_sign));

    builder.setCancelable(true);
    builder.setPositiveButton(android.R.string.ok, null);

    //final Context context = this;

    switch (id) {
    case DIALOG_WELCOME:
        builder.setTitle(getResources().getString(R.string.welcome_title));
        builder.setMessage(getResources().getString(R.string.welcome_message));
        break;/* www.  j av a2  s .  c om*/
    case DIALOG_UPDATE:
        builder.setTitle(getString(R.string.changelog_title));
        final String[] changes = getResources().getStringArray(R.array.updates);
        final StringBuilder buf = new StringBuilder();
        for (int i = 0; i < changes.length; i++) {
            buf.append("\n\n");
            buf.append(changes[i]);
        }
        builder.setMessage(buf.toString().trim());
        break;
    }
    return builder.create();
}

From source file:com.njlabs.amrita.aid.gpms.ui.GpmsActivity.java

public void openApply(View v) {
    final String[] items = { "Day Pass", "Home Pass" };
    AlertDialog.Builder builder = new AlertDialog.Builder(baseContext);
    builder.setCancelable(true);
    builder.setTitle("Pass type ?");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialogList, int item) {
            Intent intent = new Intent(baseContext, PassApplyActivity.class);
            intent.putExtra("pass_type", items[item]);
            if (relays != null && relays.size() > 0 && identifier != null) {
                intent.putParcelableArrayListExtra("relays", relays);
                intent.putExtra("identifier", identifier);
            }/*  w w  w  .ja  v a 2 s.  c o  m*/
            startActivity(intent);
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:com.njlabs.amrita.aid.aums.AumsActivity.java

private void semesterPicker(final StringCallback stringCallback) {
    final String[] items = { "1", "2", "Vacation 1", "3", "4", "Vacation 2", "5", "6", "Vacation 3", "7", "8",
            "Vacation 4", "9", "10", "Vacation 5", "11", "12", "Vacation 6", "13", "14", "15" };
    AlertDialog.Builder builder = new AlertDialog.Builder(baseContext);
    builder.setCancelable(true);
    builder.setTitle("Select a Semester");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        @Override//from  w  ww .  j av a 2  s . c om
        public void onClick(DialogInterface dialog, int which) {
            stringCallback.onFinish(items[which]);
        }
    });
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
}

From source file:at.maui.cheapcast.fragment.DonationsFragment.java

/**
 * Open dialog// w  ww .  ja v  a2 s  .c o  m
 *
 * @param icon
 * @param title
 * @param message
 */
void openDialog(int icon, int title, String message) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
    dialog.setIcon(icon);
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setCancelable(true);
    dialog.setNeutralButton(R.string.donations__button_close, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    dialog.show();
}

From source file:com.phonegap.Notification.java

/**
 * Builds and shows a native Android confirm dialog with given title, message, buttons.
 * This dialog only shows up to 3 buttons.  Any labels after that will be ignored.
 * The index of the button pressed will be returned to the JavaScript callback identified by callbackId.
 * //from w w  w .j  a  v  a2s.co  m
 * @param message       The message the dialog should display
 * @param title       The title of the dialog
 * @param buttonLabels    A comma separated list of button labels (Up to 3 buttons)
 * @param callbackId   The callback id
 */
public synchronized void confirm(final String message, final String title, String buttonLabels,
        final String callbackId) {

    final PhonegapActivity ctx = this.ctx;
    final Notification notification = this;
    final String[] fButtons = buttonLabels.split(",");

    Runnable runnable = new Runnable() {
        public void run() {
            AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);

            // First button
            if (fButtons.length > 0) {
                dlg.setPositiveButton(fButtons[0], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 1), callbackId);
                    }
                });
            }

            // Second button
            if (fButtons.length > 1) {
                dlg.setNeutralButton(fButtons[1], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 2), callbackId);
                    }
                });
            }

            // Third button
            if (fButtons.length > 2) {
                dlg.setNegativeButton(fButtons[2], new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        notification.success(new PluginResult(PluginResult.Status.OK, 3), callbackId);
                    }
                });
            }

            dlg.create();
            dlg.show();
        };
    };
    this.ctx.runOnUiThread(runnable);
}

From source file:at.jclehner.rxdroid.SplashScreenActivity.java

@SuppressWarnings("deprecation")
@Override//from   www.ja  v  a  2  s .  c  o m
protected Dialog onCreateDialog(int id, Bundle args) {
    if (id == R.id.db_error_dialog) {
        final AlertDialog.Builder ab = new AlertDialog.Builder(SplashScreenActivity.this);
        ab.setTitle(R.string._title_error);
        ab.setIcon(android.R.drawable.ic_dialog_alert);
        ab.setCancelable(false);
        ab.setNegativeButton(R.string._btn_exit, SplashScreenActivity.this);
        ab.setPositiveButton(R.string._btn_reset, SplashScreenActivity.this);
        ab.setMessage("");

        return ab.create();
    }
    return super.onCreateDialog(id, args);
}

From source file:com.csipsimple.ui.favorites.FavAdapter.java

private void showDialogForSipData(final Context context, final Long profileId, final String groupName,
        final String domain) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(R.string.set_android_group);
    builder.setCancelable(true);
    builder.setItems(R.array.sip_data_sources, new DialogInterface.OnClickListener() {
        @Override/*  w ww . jav a  2 s  .c  o  m*/
        public void onClick(DialogInterface dialog, int which) {
            applyNumbersToCSip(groupName, 1 << which, domain, profileId);
        }
    });

    final Dialog dialog = builder.create();
    dialog.show();
}

From source file:com.microblink.ocr.ScanActivity.java

@Override
public void onError(Throwable ex) {
    // This method will be called when opening of camera resulted in exception or
    // recognition process encountered an error.
    // The error details will be given in exc parameter.
    Log.e(this, ex, "Error");
    AlertDialog.Builder ab = new AlertDialog.Builder(this);
    ab.setCancelable(false).setTitle("Error").setMessage(ex.getMessage())
            .setNeutralButton("OK", new DialogInterface.OnClickListener() {
                @Override//from   w ww .  ja v  a  2  s . c o m
                public void onClick(DialogInterface dialog, int which) {
                    if (dialog != null)
                        dialog.dismiss();
                    finish();
                }
            }).create().show();
    finish();
}