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.owncloud.android.ui.activity.Uploader.java

@Override
protected Dialog onCreateDialog(final int id) {
    final AlertDialog.Builder builder = new Builder(this);
    switch (id) {
    case DIALOG_WAITING:
        final ProgressDialog pDialog = new ProgressDialog(this, R.style.ProgressDialogTheme);
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);/*w  w  w.j a va 2s .  com*/
        pDialog.setMessage(getResources().getString(R.string.uploader_info_uploading));
        pDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ProgressBar v = (ProgressBar) pDialog.findViewById(android.R.id.progress);
                v.getIndeterminateDrawable().setColorFilter(getResources().getColor(R.color.color_accent),
                        android.graphics.PorterDuff.Mode.MULTIPLY);

            }
        });
        return pDialog;
    case DIALOG_NO_ACCOUNT:
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.uploader_wrn_no_account_title);
        builder.setMessage(
                String.format(getString(R.string.uploader_wrn_no_account_text), getString(R.string.app_name)));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.uploader_wrn_no_account_setup_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ECLAIR_MR1) {
                    // using string value since in API7 this
                    // constatn is not defined
                    // in API7 < this constatant is defined in
                    // Settings.ADD_ACCOUNT_SETTINGS
                    // and Settings.EXTRA_AUTHORITIES
                    Intent intent = new Intent(android.provider.Settings.ACTION_ADD_ACCOUNT);
                    intent.putExtra("authorities", new String[] { MainApp.getAuthTokenType() });
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                } else {
                    // since in API7 there is no direct call for
                    // account setup, so we need to
                    // show our own AccountSetupAcricity, get
                    // desired results and setup
                    // everything for ourself
                    Intent intent = new Intent(getBaseContext(), AccountAuthenticator.class);
                    startActivityForResult(intent, REQUEST_CODE_SETUP_ACCOUNT);
                }
            }
        });
        builder.setNegativeButton(R.string.uploader_wrn_no_account_quit_btn_text, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    case DIALOG_MULTIPLE_ACCOUNT:
        CharSequence ac[] = new CharSequence[mAccountManager
                .getAccountsByType(MainApp.getAccountType()).length];
        for (int i = 0; i < ac.length; ++i) {
            ac[i] = DisplayUtils.convertIdn(mAccountManager.getAccountsByType(MainApp.getAccountType())[i].name,
                    false);
        }
        builder.setTitle(R.string.common_choose_account);
        builder.setItems(ac, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                setAccount(mAccountManager.getAccountsByType(MainApp.getAccountType())[which]);
                onAccountSet(mAccountWasRestored);
                dialog.dismiss();
                mAccountSelected = true;
                mAccountSelectionShowing = false;
            }
        });
        builder.setCancelable(true);
        builder.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                mAccountSelectionShowing = false;
                dialog.cancel();
                finish();
            }
        });
        return builder.create();
    case DIALOG_NO_STREAM:
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.setTitle(R.string.uploader_wrn_no_content_title);
        builder.setMessage(R.string.uploader_wrn_no_content_text);
        builder.setCancelable(false);
        builder.setNegativeButton(R.string.common_cancel, new OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        return builder.create();
    default:
        throw new IllegalArgumentException("Unknown dialog id: " + id);
    }
}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

@Override
public void onResume() {
    super.onResume();
    initRecorderFragment();/*from www .  jav  a 2s  .  com*/
    final SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(this);
    if (!defaultPrefs.getBoolean("LICENSES_ACCEPTED", false)) {
        final AlertDialog.Builder acceptLicenses = new AlertDialog.Builder(this);
        View v = getLayoutInflater().inflate(R.layout.alertdialog_license_prompt, null);
        acceptLicenses.setView(v);

        WebView cpol = (WebView) v.findViewById(R.id.CPOL_view),
                apache = (WebView) v.findViewById(R.id.APACHE_2_0_view);
        cpol.loadUrl("file:///android_res/raw/cpol.html");
        cpol.getSettings().setLoadWithOverviewMode(true);
        cpol.getSettings().setBuiltInZoomControls(true);
        cpol.getSettings().setUseWideViewPort(true);
        apache.loadUrl("file:///android_res/raw/apache.html");
        apache.getSettings().setLoadWithOverviewMode(true);
        apache.getSettings().setBuiltInZoomControls(true);
        apache.getSettings().setUseWideViewPort(true);

        acceptLicenses.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                defaultPrefs.edit().putBoolean("LICENSES_ACCEPTED", true).apply();
                dialog.dismiss();

                PreferenceManager.setDefaultValues(MainMenuActivity.this, R.xml.data_viewer_phone_options,
                        false);
            }
        });

        acceptLicenses.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });

        acceptLicenses.setCancelable(false);
        acceptLicenses.show();
    }
}

From source file:com.github.mjdev.libaums.usbfileman.MainActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    final UsbFile entry = adapter.getItem((int) info.id);
    switch (item.getItemId()) {
    case R.id.delete_item:
        try {//from www .  j  a  v  a  2s .c  om
            entry.delete();
            adapter.refresh();
        } catch (IOException e) {
            Log.e(TAG, "error deleting!", e);
        }
        return true;
    case R.id.rename_item:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Rename");
        builder.setMessage("Please enter a name for renaming");
        final EditText input = new EditText(this);
        input.setText(entry.getName());
        builder.setView(input);

        builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                try {
                    entry.setName(input.getText().toString());
                    adapter.refresh();
                } catch (IOException e) {
                    Log.e(TAG, "error renaming!", e);
                }
            }

        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.dismiss();
            }
        });
        builder.setCancelable(false);
        builder.create().show();
        return true;
    case R.id.move_item:
        MoveClipboard cl = MoveClipboard.getInstance();
        cl.setFile(entry);
        return true;
    case R.id.start_http_server:
        startHttpServer(entry);
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

From source file:com.mibr.android.intelligentreminder.INeedToo.java

@Override
public Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_REMINDER_CONTACTS_SERVICE_FAILED_LICENSING:
        AlertDialog.Builder buildersvc = new AlertDialog.Builder(this);
        buildersvc.setMessage(//from  w w w  .  j a  v  a 2  s .  c om
                "The Reminder Contact Service add-on that you've got installed is not a licensed version");
        buildersvc.setCancelable(false)
                .setNeutralButton(R.string.msg_cus, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        String[] mailto = { "info@intelligentreminder.com", "" };
                        Intent sendIntent = new Intent(Intent.ACTION_SEND);
                        sendIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
                        sendIntent.putExtra(Intent.EXTRA_SUBJECT, "".toString());
                        sendIntent.putExtra(Intent.EXTRA_TEXT, "".toString());
                        sendIntent.setType("text/plain");
                        startActivity(Intent.createChooser(sendIntent, "Send EMail..."));
                    }
                }).setPositiveButton(R.string.msg_register, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {

                        if (INeedToo.IS_ANDROID_VERSION) {
                            String uri = getString(R.string.indeedtopayforservice);
                            Intent ii3 = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                            startActivity(ii3);
                        } else {
                            Uri uri = Uri.parse(
                                    "http://www.amazon.com/gp/mas/dl/android?p=com.mibr.android.remindercontacts");
                            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                            startActivity(intent);
                        }

                        isReminderContactsAvailable = true;
                        iDidReminderContacts = false;
                    }
                }).setNegativeButton(R.string.msg_cancel, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        AlertDialog alert = buildersvc.create();
        return alert;

    case DOING_SAMPLE_NEEDS_DIALOG:
        if (allItems == null) {
            return null;
        }
        dialogDoingSamples = new Dialog(this);
        dialogDoingSamples.setOwnerActivity(this);
        dialogDoingSamples.setContentView(R.layout.ineedvoiceprogress);
        dialogDoingSamples.setTitle("Working ...");
        ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_cancel)).setEnabled(true);
        ((Button) dialogDoingSamples.findViewById(R.id.needvoiceprogress_ok)).setEnabled(false);
        ;
        //         dialogDoingSamples.show();
        ArrayList stuff = new ArrayList();
        stuff.add(dialogDoingSamples);
        stuff.add(getApplicationContext());
        stuff.add(this);
        stuff.add(getLocationManager());
        stuff.add(getDbAdapter());
        stuff.add(allItems.get(whereImAtInAllItems));
        stuff.add(new Integer(1));
        new NeedByVoiceProgress().execute(stuff);
        return dialogDoingSamples;

    case DIALOG_SAMPLES:
        Dialog aDialog = null;
        AlertDialog.Builder builder2;
        LayoutInflater inflater2 = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout2 = inflater2.inflate(R.layout.ineedsamples, (ViewGroup) findViewById(R.id.hijklmnop));
        builder2 = new AlertDialog.Builder(this);
        builder2.setView(layout2);
        builder2.setTitle("Build Sample Data Set");
        builder2.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                allItems = new ArrayList<ArrayList<String>>();
                Boolean doit = false;
                StringBuilder sb = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();
                StringBuilder sb3 = new StringBuilder();
                int cnt = 0;
                Boolean dw = false;
                ArrayList<String> jdmatchesSS = null;
                ;
                sb.append("I need Print Cartridges description HP 28 and 48 ");
                if (mWalmart != null && mWalmart.isChecked()) {
                    sb.append(" location Walmart ");
                    dw = true;
                }
                if (mWalgreens != null && mWalgreens.isChecked()) {
                    sb.append(" location Walgreens ");
                    dw = true;
                }
                if (dw) { // they checked something
                    doit = true;
                    jdmatchesSS = new ArrayList<String>();
                    jdmatchesSS.add(sb.toString());
                    allItems.add(jdmatchesSS);
                    cnt++;
                }
                if (mSevenEleven != null && mSevenEleven.isChecked()) {
                    sb3.append("I need Energy Drink description Red Bull location 7-Eleven ");
                    ArrayList<String> jdmatches = new ArrayList<String>();
                    jdmatches.add(sb3.toString());
                    allItems.add(jdmatches);
                    cnt++;
                    doit = true;
                }

                if (mStarbucks != null && mStarbucks.isChecked()) {
                    sb2.append("I need Coffee description French Roast location Starbucks");
                    ArrayList<String> jdmatches = new ArrayList<String>();
                    jdmatches.add(sb2.toString());
                    allItems.add(jdmatches);
                    cnt++;
                    doit = true;
                }
                if (doit) {
                    whereImAtInAllItems = 0;
                    INeedToo.this.showDialog(DOING_SAMPLE_NEEDS_DIALOG);
                }

            }
        });
        mWalmart = (CheckBox) layout2.findViewById(R.id.BuildWalmart);
        mWalgreens = (CheckBox) layout2.findViewById(R.id.BuildWalgreens);
        mSevenEleven = (CheckBox) layout2.findViewById(R.id.Build7Eleven);
        mStarbucks = (CheckBox) layout2.findViewById(R.id.BuildStarbucks);

        aDialog = builder2.create();
        return aDialog;

    case DIALOG_SPLASH:
        /*
        jdd=new Dialog(mContext);
        jdd.setContentView(R.layout.ineed2splash);
        jdd.setTitle("W E L C O M E");
        */

        AlertDialog.Builder builder;
        LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.ineed2splashv2,
                (ViewGroup) findViewById(R.id.ScrollView01lmnop2));
        builder = new AlertDialog.Builder(this);

        builder.setPositiveButton("Okay", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                if (mWantSample != null) {
                    if (mWantSample.isChecked()) {
                        showDialog(DIALOG_SAMPLES);
                    }
                }
            }
        });
        builder.setTitle("W E L C O M E");
        if (getDbAdapter().thereAreSomeLocationsOnSystem()) {
            LinearLayout ll = (LinearLayout) layout.findViewById(R.id.CreateDefaultValues);
            ll.setVisibility(View.INVISIBLE);
        } else {
            mWantSample = (CheckBox) layout.findViewById(R.id.BuildDefaultValues);
        }
        builder.setView(layout);
        jdd = builder.create();
        //Button butt=(Button)jdd.findViewById(R.id.Button01);
        /*butt.setOnClickListener(new View.OnClickListener() {
                   
           @Override
           public void onClick(View v) {
              jdd.cancel();
           }
        });
        */
        break;
    default:
        return null;
    }
    return jdd;

}

From source file:com.openatk.field_work.MainActivity.java

private void createOperation(final Callable<Void> myFunc) {
    // get prompts.xml view
    LayoutInflater li = LayoutInflater.from(this);
    View promptsView = li.inflate(R.layout.new_operation_dialog, null);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setView(promptsView);

    final EditText userInput = (EditText) promptsView.findViewById(R.id.new_operation_dialog_name);

    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            // Create the operation
            String name = userInput.getText().toString();
            if (name.isEmpty() == false) {

                Operation newOp = new Operation(name);
                TableOperations.updateOperation(dbHelper, newOp); //Add operation to db
                currentOperation = newOp;

                Log.d("MainActivity - createOperation", currentOperation.getName());

                dbHelper.close();/*w  w  w .j a  v  a 2 s .com*/
                //Add to operations list
                operationsList.add(0, newOp);
                if (spinnerMenuAdapter != null)
                    spinnerMenuAdapter.notifyDataSetChanged();
                selectCurrentOperationInSpinner();

                // Save this choice in preferences for next open
                SharedPreferences prefs = getApplicationContext().getSharedPreferences("com.openatk.field_work",
                        Context.MODE_PRIVATE);
                SharedPreferences.Editor editor = prefs.edit();
                editor.putInt("currentOperationId", currentOperation.getId());
                editor.commit();

                // Continue what we were doing with callback
                if (myFunc != null) {
                    try {
                        myFunc.call();
                    } catch (Exception e) {
                        Log.d("MainActivity - createOperation", "Failed to call return method");
                        e.printStackTrace();
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

protected void send() {
    final String text_orig = mEditText != null ? parseString(mEditText.getText()) : null;
    final String atext = mIsPhotoAttached || mIsImageAttached
            ? mUploadUseExtension ? getImageUploadStatus(this, FAKE_IMAGE_LINK, text_orig)
                    : text_orig + " " + FAKE_IMAGE_LINK
            : text_orig;//from   w  ww  .  j a va2 s.  com
    final int count = mValidator.getTweetLength(atext);
    if (!isNullOrEmpty(mUploadProvider) && (mIsPhotoAttached || mIsImageAttached)) {
        postMedia();
    } else if (count > 140) {
        if (mScheduleDate != null) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getString(R.string.schedule_tweet));
            builder.setMessage(getString(R.string.schedule_tweet_too_long));
            builder.setCancelable(true);
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getString(R.string.tweet_too_long));
            builder.setMessage(getString(R.string.confirm_twitlonger));
            builder.setCancelable(true);
            builder.setPositiveButton(getString(R.string.send_to_twitlonger),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            postTwitlonger();
                        }
                    });
            builder.setNeutralButton(getString(R.string.split_tweets), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    splitTweets();
                }
            });
            builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    //actuallyPost();
                }
            });
            //
            AlertDialog alert = builder.create();
            alert.show();
        }

    } else {
        if (mScheduleDate != null && isNullOrEmpty(mUploadProvider) && (mIsPhotoAttached || mIsImageAttached)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getString(R.string.schedule_tweet));
            builder.setMessage(getString(R.string.schedule_tweet_pic_twitter));
            builder.setCancelable(true);
            AlertDialog alert = builder.create();
            alert.show();
        } else if (mScheduleDate != null && mIsBuffer == true) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getString(R.string.schedule_tweet));
            builder.setMessage(getString(R.string.schedule_tweet_buffer));
            builder.setCancelable(true);
            AlertDialog alert = builder.create();
            alert.show();
        } else if (mIsBuffer == true && isNullOrEmpty(mUploadProvider)
                && (mIsPhotoAttached || mIsImageAttached)) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(getString(R.string.add_to_buffer));
            builder.setMessage(getString(R.string.buffer_pic_twitter));
            builder.setCancelable(true);
            AlertDialog alert = builder.create();
            alert.show();
        } else {
            actuallyPost();
        }
    }
}

From source file:org.ohthehumanity.carrie.CarrieActivity.java

/** Called when the activity is first created. */
@Override/*from   w w  w  .ja  v  a 2 s.  com*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mServerName = "";
    setContentView(R.layout.main);

    // instantiate our preferences backend
    mPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // set callback function when settings change
    mPreferences.registerOnSharedPreferenceChangeListener(this);

    if (mPreferences.getString("server", null) == null) {
        setStatus("Server not set");
    } else if (mPreferences.getString("port", null) == null) {
        setStatus("Port not configured");
    }

    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    if (cm.getActiveNetworkInfo().getType() != ConnectivityManager.TYPE_WIFI) {

        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setTitle("WiFi not active");
        dlgAlert.setMessage(
                "This application is usually used on a local network over a WiFi. Open WiFi settings?");
        dlgAlert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                switch (which) {
                case DialogInterface.BUTTON_POSITIVE:
                    //Yes button clicked
                    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    final ComponentName cn = new ComponentName("com.android.settings",
                            "com.android.settings.wifi.WifiSettings");
                    intent.setComponent(cn);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //Log.i(TAG, "Not opening wifi");
                    //No button clicked
                    break;
                }
            }
        });

        dlgAlert.setNegativeButton("No", null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }

    updateTitle();
    updateSkipLabels();
    updateServerName();
}

From source file:com.nutomic.syncthingandroid.util.BarcodeIntentIntegrator.java

@TargetApi(11)
private AlertDialog showDownloadDialog() {
    AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
    downloadDialog.setTitle(title);/*from   w ww  .  j a  v a  2 s .  co  m*/
    downloadDialog.setMessage(message);
    downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            String packageName;
            if (targetApplications.contains(BS_PACKAGE)) {
                // Prefer to suggest download of BS if it's anywhere in the list
                packageName = BS_PACKAGE;
            } else {
                // Otherwise, first option:
                packageName = targetApplications.get(0);
            }
            Uri uri = Uri.parse("market://details?id=" + packageName);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            try {
                if (fragment != null) {
                    fragment.startActivity(intent);
                } else if (fragmentV4 != null) {
                    fragmentV4.startActivity(intent);
                } else {
                    activity.startActivity(intent);
                }
            } catch (ActivityNotFoundException anfe) {
                // Hmm, market is not installed
                Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
            }
        }
    });
    downloadDialog.setNegativeButton(buttonNo, null);
    downloadDialog.setCancelable(true);
    return downloadDialog.show();
}

From source file:com.google.zxing.integration.android.SupportIntentIntegrator.java

private AlertDialog showDownloadDialog() {
    AlertDialog.Builder downloadDialog = new AlertDialog.Builder(activity);
    downloadDialog.setTitle(title);//w w  w  .  jav  a2 s  .c o m
    downloadDialog.setMessage(message);
    downloadDialog.setPositiveButton(buttonYes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            String packageName;
            if (targetApplications.contains(BS_PACKAGE)) {
                // Prefer to suggest download of BS if it's anywhere in the list
                packageName = BS_PACKAGE;
            } else {
                // Otherwise, first option:
                packageName = targetApplications.get(0);
            }
            Uri uri = Uri.parse("market://details?id=" + packageName);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            try {
                if (fragment != null) {
                    fragment.startActivity(intent);
                } else if (fragmentV4 != null) {
                    fragmentV4.startActivity(intent);
                } else {
                    activity.startActivity(intent);
                }
            } catch (ActivityNotFoundException anfe) {
                // Hmm, market is not installed
                Log.w(TAG, "Google Play is not installed; cannot install " + packageName);
            }
        }
    });
    downloadDialog.setNegativeButton(buttonNo, null);
    downloadDialog.setCancelable(true);
    return downloadDialog.show();
}

From source file:cgeo.geocaching.cgeocaches.java

public void handleCachesLoaded() {
    try {/*from  w  ww  .j a  v  a2 s. c o  m*/
        setAdapter();

        updateTitle();

        setDateComparatorForEventList();

        showFooterMoreCaches();

        if (search != null && search.getError() == StatusCode.UNAPPROVED_LICENSE) {
            AlertDialog.Builder dialog = new AlertDialog.Builder(this);
            dialog.setTitle(res.getString(R.string.license));
            dialog.setMessage(res.getString(R.string.err_license));
            dialog.setCancelable(true);
            dialog.setNegativeButton(res.getString(R.string.license_dismiss),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            Cookies.clearCookies();
                            dialog.cancel();
                        }
                    });
            dialog.setPositiveButton(res.getString(R.string.license_show),
                    new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int id) {
                            Cookies.clearCookies();
                            startActivity(new Intent(Intent.ACTION_VIEW,
                                    Uri.parse("http://www.geocaching.com/software/agreement.aspx?ID=0")));
                        }
                    });

            AlertDialog alert = dialog.create();
            alert.show();
        } else if (search != null && search.getError() != null) {
            showToast(res.getString(R.string.err_download_fail) + ' ' + search.getError().getErrorString(res)
                    + '.');

            hideLoading();
            showProgress(false);

            finish();
            return;
        }

        setAdapterCurrentCoordinates(false);
    } catch (Exception e) {
        showToast(res.getString(R.string.err_detail_cache_find_any));
        Log.e("cgeocaches.loadCachesHandler", e);

        hideLoading();
        showProgress(false);

        finish();
        return;
    }

    try {
        hideLoading();
        showProgress(false);
    } catch (Exception e2) {
        Log.e("cgeocaches.loadCachesHandler.2", e2);
    }

    adapter.setSelectMode(false);
}