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.inter.trade.ui.fragment.buylicensekey.BuyLicenseKeyPayConfirmFragment.java

/**
 * ???UIManagerActivity::onActivityResult???
 *///from   ww  w  . j  ava  2s .  c om
@Override
public void requestBuySuccess(final ResultData resultData, String msg) {
    resultData.putValue(ResultData.bkntno, mBkntno);

    /**
     * ??
     */
    //      new BuySuccessTask(getActivity(), resultData,"ApiQQRechangeInfo","checkRechaMoneyStatus").execute("");

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("");
    builder.setMessage(msg);
    builder.setInverseBackgroundForced(true);
    builder.setCancelable(false);
    //builder.setCustomTitle();
    builder.setNegativeButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            if (resultData.getValue(ResultData.result).equalsIgnoreCase("success")) {
                gotoPaySuccess();
            } else {
                //                   getActivity().finish();
                //                   gotoPaySuccess();
            }

        }
    });
    builder.create().show();
}

From source file:gr.scify.newsum.ui.SearchViewActivity.java

private void initTopicSpinner() {
    // Get topics in category. Null accepts all user sources. Modify
    // according to user selection
    final String[] saTopicIDs = SearchTopicActivity.saTopicIDs;
    final String[] saTitles = SearchTopicActivity.saTopicTitles;
    final String[] saDates = SearchTopicActivity.saTopicDates;
    // TODO add TopicInfo for SearchResults as well and parse accordingly

    // final String[] saTopicIDs = extras.getStringArray("searchresults");
    final TextView title = (TextView) findViewById(R.id.title);
    // Fill topic spinner
    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            android.R.layout.simple_spinner_item, saTitles);

    final TextView tx = (TextView) findViewById(R.id.textView1);
    // tx.setMovementMethod(LinkMovementMethod.getInstance());
    //      final float minm = tx.getTextSize();
    //      final float maxm = (minm + 24);

    // create an invisible spinner just to control the summaries of the
    // category (i will use it later on Swipe)
    Spinner spinner = (Spinner) findViewById(R.id.spinner1);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);/*from  w ww  .j a  v  a 2 s . com*/

    // Scroll view init
    final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1);
    // Add selection event
    spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {

            // Show waiting dialog
            showWaitingDialog();

            // Changing summary
            loading = true;
            // Update visibility of rating bar
            final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar);
            rb.setRating(0.0f);
            rb.setVisibility(View.VISIBLE);
            final TextView rateLbl = (TextView) findViewById(R.id.rateLbl);
            rateLbl.setVisibility(View.VISIBLE);

            scroll.scrollTo(0, 0);
            //            String[] saTopicIDs = sTopicIds.split(sSeparator);

            SharedPreferences settings = getSharedPreferences("urls", 0);
            // get user settings for sources
            String UserSources = settings.getString("UserLinks", "All");
            String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources);
            if (Summary.length == 0) { // WORK. Updated: CHECK
                // Close waiting dialog
                closeWaitingDialog();

                AlertDialog.Builder alert = new AlertDialog.Builder(SearchViewActivity.this);
                alert.setMessage(R.string.shouldReloadSummaries);
                alert.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface arg0, int arg1) {
                        startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class)
                                .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                    }
                });
                alert.setCancelable(false);
                alert.show();
                loading = false;
                return;
            }
            // track summary views per Search and topic title
            if (getAnalyticsPref()) {
                EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, "From Search",
                        saTitles[arg2] + ": " + saDates[arg2], 0l);
            }
            // Generate summary text
            sText = ViewActivity.generateSummaryText(Summary, SearchViewActivity.this);
            pText = ViewActivity.generatesummarypost(Summary, SearchViewActivity.this);
            tx.setText(Html.fromHtml(sText));
            tx.setMovementMethod(LinkMovementMethod.getInstance());
            title.setText(saTitles[arg2] + ": " + saDates[arg2]);
            float defSize = tx.getTextSize();
            SharedPreferences usersize = getSharedPreferences("textS", 0);
            float newSize = usersize.getFloat("size", defSize);
            tx.setTextSize(TypedValue.COMPLEX_UNIT_PX, newSize);
            // update the TopicActivity with viewed item
            TopicActivity.addVisitedTopicID(saTopicIDs[arg2]);

            // Close waiting dialog
            closeWaitingDialog();

        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }

    });

}

From source file:com.arkami.myidkey.activity.KeyCardEditActivity.java

private void setDeleteButton() {
    deleteButton = (Button) this.findViewById(R.id.delete_button);

    if (keyCard.getId() == null) {
        deleteButton.setVisibility(View.GONE);
    }/*from   w w w  .j  a  v a  2 s .  c o m*/

    deleteButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // XXX delete
            AlertDialog.Builder builder = new AlertDialog.Builder(KeyCardEditActivity.this);
            builder.setCancelable(true).setMessage(R.string.delete_message)
                    .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            deleteKeyCard();
                            KeyCardEditActivity.this.finish();
                        }
                    }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            // if this button is clicked, just close
                            // the dialog box and do nothing
                            dialog.cancel();
                        }
                    });

            // create alert dialog
            AlertDialog alertDialog = builder.create();
            // show it
            alertDialog.show();
        }
    });
}

From source file:com.safecell.HomeScreenActivity.java

public void showGPSStatusAlert(String provider) {

    // Log.v("Safecell", "" + provider);

    String title = "";
    String message = "";

    if (LocationManager.GPS_PROVIDER.equals(provider)) {
        return;// w w w  .j  a v a 2  s.c o  m
    }

    if (provider == null) {
        title = "GPS is not enabled.";
        message = "GPS is not enabled. Please enable it.";
    } else {
        title = "GPS is not enabled.";
        message = "GPS is not enabled. Please enable it. \nMeanwhile, background trip tracking will be disabled.";
    }

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

    builder.setTitle(title);
    builder.setMessage(message);
    builder.setCancelable(false);

    builder.setPositiveButton("Launch Settings", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            launchGPSOptions();
        }
    });

    if (LocationManager.NETWORK_PROVIDER.equals(provider)) {
        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });
    }

    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.abcvoipsip.ui.account.AccountsEditListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.add(R.string.add_account).setIcon(android.R.drawable.ic_menu_add)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override/* ww  w  .  j  a  va2 s .  c o  m*/
                public boolean onMenuItemClick(MenuItem item) {
                    startActivityForResult(new Intent(getActivity(), WizardChooser.class), CHOOSE_WIZARD);
                    return true;
                }
            }).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    menu.add(R.string.reorder).setIcon(android.R.drawable.ic_menu_sort_by_size)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AccountsEditListAdapter ad = (AccountsEditListAdapter) getListAdapter();
                    ad.toggleDraggable();
                    return true;
                }
            }).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    menu.add(R.string.backup_restore).setIcon(android.R.drawable.ic_menu_save)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {

                    // Populate choice list
                    List<String> items = new ArrayList<String>();
                    items.add(getResources().getString(R.string.backup));
                    final File backupDir = PreferencesWrapper.getConfigFolder(getActivity());
                    if (backupDir != null) {
                        String[] filesNames = backupDir.list();
                        for (String fileName : filesNames) {
                            items.add(fileName);
                        }
                    }

                    final String[] fItems = (String[]) items.toArray(new String[0]);
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle(R.string.backup_restore);
                    builder.setItems(fItems, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            if (item == 0) {
                                SipProfileJson.saveSipConfiguration(getActivity());
                            } else {
                                File fileToRestore = new File(backupDir + File.separator + fItems[item]);
                                SipProfileJson.restoreSipConfiguration(getActivity(), fileToRestore);
                            }
                        }
                    });
                    builder.setCancelable(true);
                    AlertDialog backupDialog = builder.create();
                    backupDialog.show();
                    return true;
                }
            });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.aniruddhc.acemusic.player.Dialogs.GooglePlayMusicAuthenticationDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    parentActivity = getActivity();//from  w  w  w.  ja va  2  s .c om
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    sharedPreferences = parentActivity.getSharedPreferences("com.aniruddhc.acemusic.player",
            Context.MODE_PRIVATE);
    View rootView = parentActivity.getLayoutInflater().inflate(R.layout.dialog_google_authentication_layout,
            null);

    //Check if this dialog was called from the Welcome sequence.
    mFirstRun = getArguments().getBoolean(Common.FIRST_RUN);

    infoText = (TextView) rootView.findViewById(R.id.google_authentication_dialog_text);
    infoText.setTypeface(TypefaceHelper.getTypeface(getActivity(), "RobotoCondensed-Light"));
    infoText.setPaintFlags(infoText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    final AccountManager accountManager = AccountManager.get(getActivity().getApplicationContext());
    final Account[] accounts = accountManager.getAccountsByType("com.google");
    final int size = accounts.length;
    String[] accountNames = new String[size];

    for (int i = 0; i < size; i++) {
        accountNames[i] = accounts[i].name;
    }

    //Set the dialog title.
    builder.setTitle(R.string.sign_in_google_play_music);
    builder.setCancelable(false);
    builder.setItems(accountNames, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            account = accounts[which];
            sharedPreferences.edit().putString("GOOGLE_PLAY_MUSIC_ACCOUNT", account.name).commit();
            AsyncGoogleMusicAuthenticationTask task = new AsyncGoogleMusicAuthenticationTask(
                    parentActivity.getApplicationContext(), parentActivity, mFirstRun, account.name);

            task.execute();

        }

    });

    return builder.create();
}

From source file:com.filemanager.free.fragments.preference_fragments.Preffrag.java

@Override
public boolean onPreferenceClick(final Preference preference) {
    if (preferences != null)
        preferences.changed = 1;/*  w w w.ja v  a2  s  .c  o m*/
    final MaterialDialog.Builder a = new MaterialDialog.Builder(getActivity());
    a.positiveText(R.string.cancel);
    a.title(R.string.choose_color);
    if (theme == 1)
        a.theme(Theme.DARK);

    a.autoDismiss(true);
    int fab_skin_pos = sharedPref.getInt("fab_skin_color_position", 1);
    int fab_skin = Color.parseColor(PreferenceUtils.getFabColor(fab_skin_pos));
    a.positiveColor(fab_skin);
    a.neutralColor(fab_skin);
    a.neutralText(R.string.defualt);
    a.onNeutral(new MaterialDialog.SingleButtonCallback() {
        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            sharedPref.edit().remove(preference.getKey());
            sharedPref.edit().apply();
        }
    });
    ColorAdapter adapter = null;
    String[] colors = PreferenceUtils.colors;
    List<String> arrayList = Arrays.asList(colors);
    switch (preference.getKey()) {
    case "skin":
        adapter = new ColorAdapter(getActivity(), arrayList, "skin_color_position",
                sharedPref.getInt("skin_color_position", 9));
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle(getResources().getString(R.string.confirm));
        builder.setMessage(getResources().getString(R.string.themeRestart));
        builder.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                restartPC(getActivity());
            }
        });
        builder.setNegativeButton(getResources().getString(R.string.cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
        builder.setCancelable(true);
        builder.show();
        break;
    case "fab_skin":
        adapter = new ColorAdapter(getActivity(), arrayList, "fab_skin_color_position", fab_skin_pos);
        break;
    case "icon_skin":
        adapter = new ColorAdapter(getActivity(), arrayList, "icon_skin_color_position",
                sharedPref.getInt("icon_skin_color_position", 9));
        break;
    case "zippath":
        zipPath();
        break;
    case "extractpath":
        zipPath();
        break;
    default:
        break;
    }
    if (!preference.getKey().equals("zippath") && !preference.getKey().equals("extractpath")) {
        @SuppressLint("InflateParams")
        GridView v = (GridView) getActivity().getLayoutInflater().inflate(R.layout.dialog_grid, null);
        v.setAdapter(adapter);
        a.customView(v, false);
        MaterialDialog x = a.build();
        assert (adapter) != null;
        adapter.updateMatDialog(x);
        x.show();
    }

    return false;
}

From source file:com.phonegap.DroidGap.java

/**
 * Display an error dialog and optionally exit application.
 * /*from  w w  w.  j a  va2 s .co m*/
 * @param title
 * @param message
 * @param button
 * @param exit
 */
public void displayError(final String title, final String message, final String button, final boolean exit) {
    final DroidGap me = this;
    me.runOnUiThread(new Runnable() {
        public void run() {
            AlertDialog.Builder dlg = new AlertDialog.Builder(me);
            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) {
                        me.finish();
                    }
                }
            });
            dlg.create();
            dlg.show();
        }
    });
}

From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java

/**
 * Gets the alert builder.//from   ww  w  . j  a  va  2  s  . co  m
 *
 * @param title the title
 * @param list the list
 * @param layout the layout
 * @return the alert builder
 */
private AlertDialog.Builder getAlertBuilder(String title, final ArrayList<String> list, int layout) {
    AlertDialog.Builder singleChoiceListDialog = new AlertDialog.Builder(getActivity());
    singleChoiceListDialog.setTitle(title);
    final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(), layout, list);
    singleChoiceListDialog.setPositiveButton(R.string.cancel, new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dismiss();

        }
    });
    singleChoiceListDialog.setAdapter(arraySingleChoiceAdapter, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            selectedChoice = list.get(which);
            listDialogListener.onListItemSelected(identifier, selectedChoice);
        }
    });
    singleChoiceListDialog.setCancelable(false);
    return singleChoiceListDialog;
}

From source file:com.csipsimple.ui.account.AccountsEditListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.add(R.string.add_account).setIcon(android.R.drawable.ic_menu_add)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override/*from   w  w  w.  j  a  v  a2s  . com*/
                public boolean onMenuItemClick(MenuItem item) {
                    onClickAddAccount();
                    return true;
                }
            }).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    menu.add(R.string.reorder).setIcon(android.R.drawable.ic_menu_sort_by_size)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    AccountsEditListAdapter ad = (AccountsEditListAdapter) getListAdapter();
                    ad.toggleDraggable();
                    return true;
                }
            }).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);

    menu.add(R.string.backup_restore).setIcon(android.R.drawable.ic_menu_save)
            .setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {

                    // Populate choice list
                    List<String> items = new ArrayList<String>();
                    items.add(getResources().getString(R.string.backup));
                    final File backupDir = PreferencesWrapper.getConfigFolder(getActivity());
                    if (backupDir != null) {
                        String[] filesNames = backupDir.list();
                        for (String fileName : filesNames) {
                            items.add(fileName);
                        }
                    }

                    final String[] fItems = (String[]) items.toArray(new String[0]);
                    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setTitle(R.string.backup_restore);
                    builder.setItems(fItems, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int item) {
                            if (item == 0) {
                                SipProfileJson.saveSipConfiguration(getActivity(), "");
                            } else {
                                File fileToRestore = new File(backupDir + File.separator + fItems[item]);
                                SipProfileJson.restoreSipConfiguration(getActivity(), fileToRestore, "");
                            }
                        }
                    });
                    builder.setCancelable(true);
                    AlertDialog backupDialog = builder.create();
                    backupDialog.show();
                    return true;
                }
            });

    super.onCreateOptionsMenu(menu, inflater);
}