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.gh4a.IssueListActivity.java

private void showLabelsDialog() {
    String selectedLabels = mFilterData.get("labels");
    String[] checkedLabels = new String[] {};

    if (selectedLabels != null) {
        checkedLabels = selectedLabels.split(",");
    }/* w  ww  .ja va  2 s . c  o  m*/
    List<String> checkLabelStringList = Arrays.asList(checkedLabels);
    final boolean[] checkedItems = new boolean[mLabels.size()];

    final String[] allLabelArray = new String[mLabels.size()];

    for (int i = 0; i < mLabels.size(); i++) {
        Label l = mLabels.get(i);
        allLabelArray[i] = l.getName();
        if (checkLabelStringList.contains(l.getName())) {
            checkedItems[i] = true;
        } else {
            checkedItems[i] = false;
        }
    }

    int dialogTheme = Gh4Application.THEME == R.style.DefaultTheme ? R.style.Theme_Sherlock_Dialog
            : R.style.Theme_Sherlock_Light_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, dialogTheme));
    builder.setCancelable(true);
    builder.setTitle(R.string.issue_filter_by_labels);
    builder.setMultiChoiceItems(allLabelArray, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
        public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) {
            if (isChecked) {
                checkedItems[whichButton] = true;
            } else {
                checkedItems[whichButton] = false;
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
            String labels = "";
            for (int i = 0; i < allLabelArray.length; i++) {
                if (checkedItems[i]) {
                    labels += allLabelArray[i] + ",";
                }
            }
            mFilterData.put("labels", labels);
            reloadIssueList();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

From source file:com.cl.slack.gesture.GestureBuilderActivity.java

private Dialog createRenameDialog() {
    final View layout = View.inflate(this, R.layout.dialog_rename, null);
    mInput = (EditText) layout.findViewById(R.id.name);
    ((TextView) layout.findViewById(R.id.label)).setText(R.string.gestures_rename_label);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setIcon(0);// w  w  w.jav  a2 s  .  c om
    builder.setTitle(getString(R.string.gestures_rename_title));
    builder.setCancelable(true);
    builder.setOnCancelListener(new Dialog.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            cleanupRenameDialog();
        }
    });
    builder.setNegativeButton(getString(R.string.cancel_action), new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            cleanupRenameDialog();
        }
    });
    //        builder.setNeutralButton(getString(R.string.cancel_action),
    //                new Dialog.OnClickListener() {
    //                    public void onClick(DialogInterface dialog, int which) {
    //                        cleanupRenameDialog();
    //                    }
    //                }
    //        );
    builder.setPositiveButton(getString(R.string.rename_action), new Dialog.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            changeGestureName();
        }
    });
    builder.setView(layout);
    return builder.create();
}

From source file:com.example.moneymeterexample.AddExpenseActivity.java

protected Dialog onCreateDialog(int id) {

    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this, pDateSetListener, mYear, mMonth, mDay);

    case NEW_CATEGORY_ID:
        AlertDialog.Builder new_cat_dialog = new AlertDialog.Builder(this);
        new_cat_dialog.setMessage("Enter the name of new category");
        new_cat_dialog.setTitle("New Category");
        final EditText new_cat_txt = new EditText(this);
        new_cat_dialog.setView(new_cat_txt);
        new_cat_dialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

            @Override/*from   ww w  .j a va 2s. c  o m*/
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                String cat = new_cat_txt.getText().toString();

                String last = cat_list.remove((cat_list.size()) - 1);
                cat_list.add(cat);
                cat_list.add(last);
                ((BaseAdapter) category.getAdapter()).notifyDataSetChanged();

            }
        });
        new_cat_dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.cancel();

            }
        });

        return new_cat_dialog.create();

    case DELETE_CONFIRM_ID:
        AlertDialog.Builder delete_dialog = new AlertDialog.Builder(this);
        delete_dialog.setMessage("Are you sure you want to delete this entry?");
        delete_dialog.setTitle("Delete Confirmation");
        delete_dialog.setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                deleteRecord();
                amt.setText("");
                date.setText("");
                cat_list.remove(category.getSelectedItem().toString());
                ((BaseAdapter) category.getAdapter()).notifyDataSetChanged();
                notes.setText("");

            }
        });
        delete_dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                // TODO Auto-generated method stub
                dialog.cancel();

            }
        });

        return delete_dialog.create();

    }
    return null;
}

From source file:com.sakisds.icymonitor.activities.ConnectionActivity.java

void showErrorDialog(int title, int message) {
    AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
    dlgAlert.setTitle(getResources().getString(title));
    dlgAlert.setMessage(getResources().getString(message));
    dlgAlert.setPositiveButton("OK", null);
    dlgAlert.setCancelable(true);
    dlgAlert.create().show();/*from  ww w . j  a v a2 s .  c om*/
}

From source file:com.dsi.ant.antplus.pluginsampler.Activity_Dashboard.java

protected void onListItemClick(ListView l, View v, int position, long id) {
    int j = 0;/*from  ww w .j ava2  s. com*/

    if (position == j++) {
        Intent i = new Intent(this, Activity_SearchUiHeartRateSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_BikePowerSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_BikeCadenceSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_BikeSpeedDistanceSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_StrideSdmSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_WatchScanList.class);
        startActivity(i);
    } else if (position == j++) {
        // Settings must be configured before starting the FE Activity
        Dialog_ConfigSettings dialog = new Dialog_ConfigSettings();
        dialog.show(getSupportFragmentManager(), "Configure User Profile");
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_FitnessEquipmentSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_BloodPressureSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_WeightScaleSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_EnvironmentSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_GeoScanList.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_AudioControllableDeviceSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_AudioRemoteControlSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_VideoControllableDeviceSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_VideoRemoteControlSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_GenericControllableDeviceSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_GenericRemoteControlSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_AsyncScanHeartRateSampler.class);
        startActivity(i);
    } else if (position == j++) {
        Intent i = new Intent(this, Activity_MultiDeviceFilter.class);
        startActivity(i);
    } else if (position == j++) {
        /**
         * Launches the ANT+ Plugin Manager. The ANT+ Plugin Manager provides access to view and modify devices
         * saved in the plugin device database and control default plugin settings. It is also available as a
         * stand alone application, but the ability to launch it from your own application is useful in situations
         * where a user wants extra convenience or doesn't already have the stand alone launcher installed. For example,
         * you could place this launch command in your application's own settings menu.
         */
        if (!AntPluginPcc.startPluginManagerActivity(this)) {
            AlertDialog.Builder adlgBldr = new AlertDialog.Builder(this);
            adlgBldr.setTitle("Missing Dependency");
            adlgBldr.setMessage("This application requires the ANT+ Plugins, would you like to install them?");
            adlgBldr.setCancelable(true);
            adlgBldr.setPositiveButton("Go to Store", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent startStore = null;
                    startStore = new Intent(Intent.ACTION_VIEW,
                            Uri.parse("market://details?id=com.dsi.ant.plugins.antplus"));
                    startStore.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                    Activity_Dashboard.this.startActivity(startStore);
                }
            });
            adlgBldr.setNegativeButton("Cancel", new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

            final AlertDialog waitDialog = adlgBldr.create();
            waitDialog.show();
        }
    } else {
        Toast.makeText(this, "This menu item is not implemented", Toast.LENGTH_SHORT).show();
    }
}

From source file:com.speed.traquer.app.Feedback_rate_taxi.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        if (actv_comp_taxi.length() != 0 || inputTaxi.length() != 0) {
            final AlertDialog.Builder alertBox = new AlertDialog.Builder(Feedback_rate_taxi.this);
            alertBox.setIcon(R.drawable.info_icon);
            alertBox.setCancelable(false);
            alertBox.setTitle("Do you want to cancel feedback?");
            alertBox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // finish used for destroyed activity
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (Yes)",
                            "Feedback taxi event", null).build());
                    finish();/*from   ww w  .j  av a  2  s . c  o m*/
                    Intent intent = new Intent(Feedback_rate_taxi.this, Speedometer.class);
                    Feedback_rate_taxi.this.startActivity(intent);
                }
            });

            alertBox.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (No)",
                            "Feedback taxi event", null).build());
                    dialog.cancel();
                }
            });

            alertBox.show();
        } else {
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:com.gh4a.IssueCreateActivity.java

private void showAssigneesDialog() {
    final String[] assignees = new String[mAllAssignee.size() + 1];
    assignees[0] = getResources().getString(R.string.issue_clear_assignee);

    int checkedItem = 0;

    for (int i = 1; i <= mAllAssignee.size(); i++) {
        User u = mAllAssignee.get(i - 1);
        assignees[i] = u.getLogin();/*  ww  w .j a v  a  2  s  .  co m*/
        if (mSelectedAssignee != null && u.getLogin().equalsIgnoreCase(mSelectedAssignee.getLogin())) {
            checkedItem = i;
        }
    }

    int dialogTheme = Gh4Application.THEME == R.style.DefaultTheme ? R.style.Theme_Sherlock_Dialog
            : R.style.Theme_Sherlock_Light_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, dialogTheme));
    builder.setCancelable(true);
    builder.setTitle(R.string.issue_assignee);
    builder.setSingleChoiceItems(assignees, checkedItem, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                mSelectedAssignee = null;
            } else {
                mSelectedAssignee = mAllAssignee.get(which - 1);
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (mSelectedAssignee != null) {
                mTvSelectedAssignee
                        .setText(IssueCreateActivity.this.getResources().getString(R.string.issue_assignee)
                                + " : " + mSelectedAssignee.getLogin());
            } else {
                mTvSelectedAssignee.setText(null);
            }
            dialog.dismiss();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

From source file:com.gh4a.IssueCreateActivity.java

private void showMilestonesDialog() {
    final String[] milestones = new String[mAllMilestone.size() + 1];

    milestones[0] = getResources().getString(R.string.issue_clear_milestone);

    int checkedItem = 0;
    if (mSelectedMilestone != null) {
        checkedItem = mSelectedMilestone.getNumber();
    }//from  w w  w  .j a va  2s  .c  o  m

    for (int i = 1; i <= mAllMilestone.size(); i++) {
        Milestone m = mAllMilestone.get(i - 1);
        milestones[i] = m.getTitle();
        if (m.getNumber() == checkedItem) {
            checkedItem = i;
        }
    }

    int dialogTheme = Gh4Application.THEME == R.style.DefaultTheme ? R.style.Theme_Sherlock_Dialog
            : R.style.Theme_Sherlock_Light_Dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, dialogTheme));
    builder.setCancelable(true);
    builder.setTitle(R.string.issue_milestone);
    builder.setSingleChoiceItems(milestones, checkedItem, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == 0) {
                mSelectedMilestone = null;
            } else {
                mSelectedMilestone = mAllMilestone.get(which - 1);
            }
        }
    });

    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (mSelectedMilestone != null) {
                mTvSelectedMilestone
                        .setText(IssueCreateActivity.this.getResources().getString(R.string.issue_milestone)
                                + " : " + mSelectedMilestone.getTitle());
            } else {
                mTvSelectedMilestone.setText(null);
            }
            dialog.dismiss();
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    }).create();

    builder.show();
}

From source file:com.google.zxing.client.android.history.HistoryActivity.java

@Override
protected void onListItemClick(ListView l, View v, final int positionItemList, long id) {
    progDialog = new ProgressDialog(this);

    if (adapter.getItem(positionItemList).getResult() != null) {
        Intent intent = new Intent(this, CaptureActivity.class);
        intent.putExtra(Intents.History.ITEM_NUMBER, positionItemList);
        setResult(Activity.RESULT_OK, intent);

        AlertDialog.Builder builder2 = new AlertDialog.Builder(this, 3);
        builder2.setMessage(getBaseContext().getResources().getString(R.string.alerta_enviar_dado));
        builder2.setCancelable(true);
        builder2.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
            @Override/*from  ww  w .j  a v a 2 s.  co m*/
            public void onClick(DialogInterface dialog, int i2) {

                /*
                 * mandando somente um dado para o servidor
                 */
                boolean conectado = verificaConexao();
                if (conectado) {
                    try {
                        progDialog.setTitle(
                                getBaseContext().getResources().getString(R.string.alerta_enviando_dado));
                        progDialog.setMessage(
                                getBaseContext().getResources().getString(R.string.alerta_dado_sendo_enviado));
                        progDialog.setIcon(android.R.drawable.ic_menu_upload);
                        progDialog.show();

                        String dado = adapter.getItem(positionItemList).getDisplay();
                        enviarItemHistorico(dado);

                    } catch (Exception ex) {
                        // TODO: handle exception
                        ex.printStackTrace();
                    }
                }
                dialog.dismiss();
                reloadHistoryItems();
            }
        });
        builder2.setNegativeButton(R.string.button_cancel, null);
        builder2.show();

    }

}

From source file:com.webileapps.fragments.CordovaFragment.java

/**
 * Display an error dialog and optionally exit application.
 *///from  ww  w  .java 2s .c o m
public void displayError(final String title, final String message, final String button, final boolean exit) {
    final CordovaFragment me = this;
    me.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            try {
                AlertDialog.Builder dlg = new AlertDialog.Builder(me.getActivity());
                dlg.setMessage(message);
                dlg.setTitle(title);
                dlg.setCancelable(false);
                dlg.setPositiveButton(button, new AlertDialog.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        if (exit) {
                            getActivity().finish();
                        }
                    }
                });
                dlg.create();
                dlg.show();
            } catch (Exception e) {
                getActivity().finish();
            }
        }
    });
}