Example usage for android.content DialogInterface cancel

List of usage examples for android.content DialogInterface cancel

Introduction

In this page you can find the example usage for android.content DialogInterface cancel.

Prototype

void cancel();

Source Link

Document

Cancels the dialog, invoking the OnCancelListener .

Usage

From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java

private void showAnnouncementDialogIfNeeded(Intent intent) {
    final String title = intent.getStringExtra(EXTRA_DIALOG_TITLE);
    final String message = intent.getStringExtra(EXTRA_DIALOG_MESSAGE);

    if (!mShowedAnnouncementDialog && !TextUtils.isEmpty(title) && !TextUtils.isEmpty(message)) {
        LOGD(TAG, "showAnnouncementDialogIfNeeded, title: " + title);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, message: " + message);
        final String yes = intent.getStringExtra(EXTRA_DIALOG_YES);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, yes: " + yes);
        final String no = intent.getStringExtra(EXTRA_DIALOG_NO);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, no: " + no);
        final String url = intent.getStringExtra(EXTRA_DIALOG_URL);
        LOGD(TAG, "showAnnouncementDialogIfNeeded, url: " + url);
        final SpannableString spannable = new SpannableString(message == null ? "" : message);
        Linkify.addLinks(spannable, Linkify.WEB_URLS);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (!TextUtils.isEmpty(title)) {
            builder.setTitle(title);/*from  w w w  .j av  a 2 s  . c o m*/
        }
        builder.setMessage(spannable);
        if (!TextUtils.isEmpty(no)) {
            builder.setNegativeButton(no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
        }
        if (!TextUtils.isEmpty(yes)) {
            builder.setPositiveButton(yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(intent);
                }
            });
        }
        final AlertDialog dialog = builder.create();
        dialog.show();
        final TextView messageView = (TextView) dialog.findViewById(android.R.id.message);
        if (messageView != null) {
            // makes the embedded links in the text clickable, if there are any
            messageView.setMovementMethod(LinkMovementMethod.getInstance());
        }
        mShowedAnnouncementDialog = true;
    }
}

From source file:app.CT.BTCCalculator.fragments.BreakevenFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    // Register Bus Provider instance.
    BusProvider.getInstance().register(this);

    View view = getView();//ww  w . ja  v  a 2 s .  c om

    // Initialize text fields.
    assert view != null;
    btcBought = (EditText) view.findViewById(R.id.btcBought);
    btcBoughtPrice = (EditText) view.findViewById(R.id.btcBoughtPrice);
    btcSold = (EditText) view.findViewById(R.id.btcSold);
    btcSoldPrice = (EditText) view.findViewById(R.id.btcSoldPrice);
    optimalBTCPrice = (EditText) view.findViewById(R.id.optimalBTCPrice);
    optimalBTC = (EditText) view.findViewById(R.id.optimalBTC);
    resultText = (TextView) view.findViewById(R.id.resultText);

    Button buttonCalculate = (Button) view.findViewById(R.id.buttonCalculate);

    // Checks whether the first visible EditText element is focused in order to enable
    // and show the keyboard to the user. The corresponding XML element has android:imeOptions="actionNext".
    // All EditText elements below are now programmed to show keyboard when pressed.
    btcBought.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcBoughtPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcSold.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    btcSoldPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    optimalBTCPrice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    optimalBTC.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showSoftKeyboard(v);
        }
    });

    optimalBTCPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            try {
                float result = ((Float.valueOf(btcSold.getText().toString()))
                        * Float.valueOf(btcSoldPrice.getText().toString()))
                        / Float.valueOf(optimalBTCPrice.getText().toString());
                optimalBTC.setText(String.valueOf(result));
            } catch (Exception ignored) {
            }

        }
    });

    btcBoughtPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            containsCurrentRate[0] = false;
        }
    });

    btcSoldPrice.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            containsCurrentRate[1] = false;
        }
    });

    buttonCalculate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            float buyAmount, buyCost, sellAmount, sellPrice, optimalBTCCost, optimalBTCAmount, remainder,
                    totalCost, totalAmount, finalPrice;
            boolean didItWork = true;
            boolean validTransaction = true;

            // Error checking to prevent crashes.
            try {
                // Gets the input entered from the user.
                buyAmount = Float.valueOf(btcBought.getText().toString());
                buyCost = Float.valueOf(btcBoughtPrice.getText().toString());
                sellAmount = Float.valueOf(btcSold.getText().toString());
                sellPrice = Float.valueOf(btcSoldPrice.getText().toString());
                optimalBTCCost = Float.valueOf(optimalBTCPrice.getText().toString());
                optimalBTCAmount = Float.valueOf(optimalBTC.getText().toString());

                // Calculates remainder from the buying and selling.
                remainder = Math.abs((buyAmount - sellAmount));

                // User cannot sell more than they own.
                if (roundTwoDecimals(optimalBTCAmount * optimalBTCCost) > roundTwoDecimals(
                        sellAmount * sellPrice)) {
                    final android.support.v7.app.AlertDialog.Builder alertDialog = new android.support.v7.app.AlertDialog.Builder(
                            getActivity());
                    alertDialog.setTitle("Error");
                    alertDialog.setMessage(getString(R.string.optimalBTCErrorMsg));
                    alertDialog.setCancelable(false);
                    alertDialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
                    alertDialog.show();
                    validTransaction = false;
                }

                // Checks if the user typed in a greater selling amount than buying.
                if (sellAmount > buyAmount) {
                    // Create new dialog popup.
                    final android.support.v7.app.AlertDialog.Builder alertDialog = new android.support.v7.app.AlertDialog.Builder(
                            getActivity());

                    alertDialog.setTitle("Error");
                    alertDialog.setMessage("You cannot sell more than you own.");
                    alertDialog.setCancelable(false);
                    alertDialog.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // If this button is clicked, close current dialog.
                            dialog.cancel();
                        }
                    });
                    alertDialog.show();

                    // Invalidates transaction since selling amount > buying amount.
                    validTransaction = false;
                }

                // Calculations to output.
                totalCost = buyAmount * buyCost;
                totalAmount = optimalBTCAmount + remainder;
                finalPrice = totalCost / totalAmount;

                if (validTransaction) {
                    resultText.setText(String.format(getString(R.string.resultText),
                            String.valueOf(totalAmount), String.valueOf(roundTwoDecimals(finalPrice))));
                }
            } catch (Exception e) {
                // Sets bool to false in order to execute "finally" block below.
                didItWork = false;
            } finally {
                if (!didItWork) {
                    // Creates new dialog popup.
                    final AlertDialog.Builder alertDialog2 = new AlertDialog.Builder(getActivity());

                    alertDialog2.setTitle("Error");
                    alertDialog2.setMessage("Please fill in all fields.");
                    alertDialog2.setCancelable(false);
                    alertDialog2.setNeutralButton("Ok", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            // If this button is clicked, close current dialog.
                            dialog.cancel();
                        }
                    });

                    // Show the dialog.
                    alertDialog2.show();
                }
            }

        }
    });
}

From source file:com.example.mohamed.a3qaqer.RegisterActvity.java

private void buildAlertMessageNoGps() {

    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("? ?  GPS,  ?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(@SuppressWarnings("unused") final DialogInterface dialog,
                        @SuppressWarnings("unused") final int id) {
                    startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }/* w  w  w.  ja va 2s .  c o m*/
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.honeycomb.cocos2dx.Soccer.java

public void askForRate(JSONObject prms) {
    AlertDialog.Builder exitbuilder = new AlertDialog.Builder(this);
    exitbuilder.setTitle("Rate 2 Planes").setMessage(com.honeycomb.cocos2dx.R.string.Rate).setCancelable(false)
            .setPositiveButton("Rate It Now", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    rateButtonClicked(getDict());
                }// w  w  w. j  ava 2s .c  o  m
            }).setNegativeButton("No,Thanks", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                    AndroidNDKHelper.SendMessageWithParameters("rated", getDict());
                }
            });
    AlertDialog stopalert = exitbuilder.create();
    stopalert.show();
}

From source file:com.jesjimher.bicipalma.MesProperesActivity.java

/**
 * //from  ww w. j  a v a2s.c  o m
 */
private void mostrarEstadisticas() {
    int bTot = 0;
    int bAver = 0;
    int aAver = 0;
    int bLib = 0;
    int aLib = 0;
    int noBicis = 0;

    for (Estacion e : estaciones) {
        bTot += e.getAnclajesAveriados() + e.getAnclajesLibres() + e.getAnclajesUsados();
        bAver += e.getBicisAveriadas();
        aAver += e.getAnclajesAveriados();
        bLib += e.getBicisLibres();
        aLib += e.getAnclajesLibres();
        if (e.getBicisLibres() == 0)
            noBicis++;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    // Si el n de bicis es negativo, es q an no se han descargado los datos
    if (bLib < 0) {
        builder.setMessage(R.string.sinDescargaTodavia).setCancelable(true).setPositiveButton(R.string.cerrar,
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    } else {
        String mensBicis = String.format(getString(R.string.estadisticasBicis), bLib, bAver);
        String mensAnclajes = String.format(getString(R.string.estadisticasAnclajes), bTot,
                bTot - (aLib + aAver), 100 * (1 - aLib / (0.0 + bTot - aAver)), aLib,
                100 * aLib / (0.0 + bTot - aAver), aAver, 100 * aAver / Double.valueOf(bTot));

        String mensVacias = String.format(getString(R.string.estadisticasVacias), noBicis, estaciones.size());

        builder.setMessage(mensBicis + mensAnclajes + mensVacias).setTitle(R.string.estadoservicio)
                .setCancelable(true).setPositiveButton(R.string.cerrar, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
        AlertDialog alert = builder.create();
        alert.show();
    }
}

From source file:com.anton.gavel.GavelMain.java

public void createDialog(int id) {
    if (progressDialog != null) {
        progressDialog.dismiss();//from   w  w  w .  jav a2s  .co  m
    }
    // handles creation of any dialogs by other actions
    switch (id) {
    case DIALOG_PI:
        //call custom dialog for collecting Personal Info
        PersonalInfoDialogFragment personalInfoDialog = new PersonalInfoDialogFragment();
        personalInfoDialog.setPersonalInfo(mPersonalInfo);
        personalInfoDialog.show(getSupportFragmentManager(), "PersonalInfoDialogFragment");
        break;
    case DIALOG_ABOUT:
        //construct a simple dialog to show text

        //get about text
        TextView aboutView = new TextView(this);
        aboutView.setText(R.string.about_text);
        aboutView.setMovementMethod(LinkMovementMethod.getInstance());//enable links
        aboutView.setPadding(50, 30, 50, 30);

        //build dialog
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
        alertDialog.setTitle("About")//title
                .setView(aboutView)//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).create() //build
                .show(); //display
        break;

    case DIALOG_SUBMISSION_ERR:
        AlertDialog.Builder submissionErrorDialog = new AlertDialog.Builder(this);
        submissionErrorDialog.setTitle("Submission Error")//title
                .setMessage("There was a problem submitting your complaint on the City's website.")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;

    case DIALOG_OTHER_COMPLAINT:
        final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        final EditText input = new EditText(this);
        input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_CLASS_TEXT);
        // capitalize letters + seperate words
        AlertDialog.Builder getComplaintDialog = new AlertDialog.Builder(this);
        getComplaintDialog.setTitle("Other...").setView(input)
                .setMessage("Give a categorical title for your complaint:")
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String value = input.getText().toString();
                        // add the item to list and make it selected
                        complaintsAdapter.insert(value, 0);
                        complaintSpinner.setSelection(0);
                        complaintsAdapter.notifyDataSetChanged();
                        addToSubmitValues(value);

                        imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard   
                        dialog.cancel();

                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        imm.toggleSoftInput(InputMethodManager.RESULT_HIDDEN, 0);//hide keyboard              
                        dialog.cancel();
                    }
                }).create();

        input.requestFocus();
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);// show keyboard

        getComplaintDialog.show();//show dialog
        break;
    case DIALOG_NO_GEOCODING:
        AlertDialog.Builder noGeoCoding = new AlertDialog.Builder(this);
        noGeoCoding.setTitle("Not Available")//title
                .setMessage(
                        "Your version of Android does not support location-based address lookup. This feature is only supported on Gingerbread and above.")//insert textview from above
                .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;
    case DIALOG_INCOMPLETE_PERSONAL_INFORMATION:
        AlertDialog.Builder incompleteInfo = new AlertDialog.Builder(this);
        incompleteInfo.setTitle("Incomplete")//title
                .setMessage(
                        "Your personal information is incomplete. Select 'Edit Personal Information' from the menu and fill in all required fields")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display         
        break;
    case DIALOG_NO_COMPLAINT:
        AlertDialog.Builder noComplaint = new AlertDialog.Builder(this);
        noComplaint.setTitle("No Comlaint Specified")//title
                .setMessage("You must specify a complaint (e.g. barking dog).")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display
        break;
    case DIALOG_NO_LOCATION:
        AlertDialog.Builder incompleteComplaint = new AlertDialog.Builder(this);
        incompleteComplaint.setTitle("No Location Specified")//title
                .setMessage("You must specify a location (approximate street address) of the complaint.")//insert textview from above
                .setPositiveButton("Done", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                }).setIcon(R.drawable.ic_launcher).show(); //display         
    }

}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

private void setRandomList() {

    if (isFABOpen) {
        closeFABMenu();/* ww  w. j  a  v  a  2  s .c o m*/
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "random_title", "random_content", "random_creation" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            iv_icon.setVisibility(View.GONE);

            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String random_content = row2.getString(row2.getColumnIndexOrThrow("random_content"));
            final String random_title = row2.getString(row2.getColumnIndexOrThrow("random_title"));

            if (random_content.isEmpty()) {
                Snackbar.make(lv, getActivity().getString(R.string.number_enterData), Snackbar.LENGTH_LONG)
                        .show();
            } else {
                getActivity().setTitle(random_title);
                lv.setVisibility(View.GONE);
                lvItems.setVisibility(View.VISIBLE);

                try {
                    FileOutputStream fOut = new FileOutputStream(newFile());
                    OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
                    myOutWriter.append(random_content);
                    myOutWriter.close();

                    fOut.flush();
                    fOut.close();
                } catch (IOException e) {
                    Log.e("Exception", "File write failed: " + e.toString());
                }

                items = new ArrayList<>();
                readItems();

                setAdapter(1000);

                fab.setVisibility(View.GONE);
                fab_dice.setVisibility(View.VISIBLE);
            }
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String random_title = row2.getString(row2.getColumnIndexOrThrow("random_title"));
            final String random_content = row2.getString(row2.getColumnIndexOrThrow("random_content"));
            final String random_icon = row2.getString(row2.getColumnIndexOrThrow("random_icon"));
            final String random_attachment = row2.getString(row2.getColumnIndexOrThrow("random_attachment"));
            final String random_creation = row2.getString(row2.getColumnIndexOrThrow("random_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark) };
            new android.app.AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {

                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(random_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);
                                edit_cont.setText(random_content);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTitle, inputCont,
                                                        random_icon, random_attachment, random_creation);
                                                setRandomList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setRandomList();
                                            }
                                        });
                                snackbar.show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.example.testapplication.DialogLocation.java

@SuppressLint("InlinedApi")
@Override//from   w w  w. j a va  2s.  c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    mProgressBar = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv = new ProgressBar(getActivity(), null, android.R.attr.progressBarStyleLarge);
    mProgressBarInv.setVisibility(ProgressBar.GONE);

    mLocationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);

    mCriteria = new Criteria();
    int criteria = (mGpsPref) ? Criteria.POWER_HIGH : Criteria.POWER_MEDIUM;
    mCriteria.setPowerRequirement(criteria);

    mProvider = mLocationManager.getBestProvider(mCriteria, true);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    ConnectivityManager cm = (ConnectivityManager) getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    TelephonyManager tm = (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
    int telephonyInfo = tm.getNetworkType();

    boolean networkAvailable = true;

    if ((telephonyInfo == TelephonyManager.NETWORK_TYPE_UNKNOWN && !networkInfo.isConnected())
            || !mLocationManager.isProviderEnabled("network")) {
        networkAvailable = false;
    }

    int locationMode = -1;
    int locationType = -1;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        try {
            locationMode = Settings.Secure.getInt(getActivity().getContentResolver(),
                    Settings.Secure.LOCATION_MODE);
        } catch (SettingNotFoundException e) {
            e.printStackTrace();
        }

        if (locationMode == Settings.Secure.LOCATION_MODE_OFF
                || (!networkAvailable && (mProvider.matches("network"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mGpsPref && (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = (locationMode == Settings.Secure.LOCATION_MODE_SENSORS_ONLY || !networkAvailable)
                    ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network") && (locationMode == Settings.Secure.LOCATION_MODE_BATTERY_SAVING
                || locationMode == Settings.Secure.LOCATION_MODE_HIGH_ACCURACY))
            locationType = USING_NETWORK_LOCATION;

    } else {
        if (mProvider.matches("passive") || !networkAvailable
                && (mProvider.matches("network") || (!mGpsPref && mProvider.matches("gps"))))
            locationType = NO_LOCATION_SERVICES;
        else if (mProvider.matches("gps") && mGpsPref)
            locationType = ((mProvider.matches("gps")) || !networkAvailable) ? USING_ONLY_GPS_LOCATION
                    : USING_GPS_LOCATION_NETWORK_AVAILABLE;
        else if (mProvider.matches("network"))
            locationType = USING_NETWORK_LOCATION;
    }

    switch (locationType) {
    case NO_LOCATION_SERVICES:
        builder.setTitle(DIALOG_LOCATION_NO_LOCATION_SERVICES_TITLE);
        builder.setMessage(DIALOG_LOCATION_NO_LOCATION_SERVICES_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        mAbortRequest = true;
        break;
    case USING_ONLY_GPS_LOCATION:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setMessage(DIALOG_LOCATION_ONLY_GPS_MESSAGE);
        builder.setNeutralButton(DIALOG_LOCATION_BUTTON_SETTINGS, noNetworkButton);
        builder.setView(mProgressBar);
        break;
    case USING_GPS_LOCATION_NETWORK_AVAILABLE:
        builder.setTitle(DIALOG_LOCATION_UPDATING_GPS_TITLE);
        builder.setPositiveButton(DIALOG_LOCATION_USE_NETWORK, null);
        builder.setView(mProgressBar);
        break;
    case USING_NETWORK_LOCATION:
        builder.setView(mProgressBar);
        builder.setTitle(DIALOG_LOCATION_UPDATING_NETWORK_TITLE);
        break;
    }

    builder.setNegativeButton(DIALOG_LOCATION_CANCEL, cancelListener);
    builder.setOnKeyListener(new DialogInterface.OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                mCallback.onLocationFound(null, mFragmentId);
                mLocationManager.removeUpdates(DialogLocation.this);
                Toast.makeText(getActivity(), "Location request cancelled", Toast.LENGTH_SHORT).show();
                dialog.cancel();
                return true;
            }
            return false;
        }
    });

    mRealDialog = builder.create();
    mRealDialog.setOnShowListener(usingNetwork);
    mRealDialog.setCanceledOnTouchOutside(false);
    return mRealDialog;
}

From source file:com.openerp.base.ir.Attachment.java

@Override
public void onClick(DialogInterface dialog, int which) {
    switch (mDialogType) {
    case IMAGE_OR_CAPTURE_IMAGE:
        requestAttachment((which == 0) ? Types.IMAGE : Types.CAPTURE_IMAGE);
        break;/*from   w  ww  .java2 s . c  om*/
    default:
    }
    dialog.cancel();
}

From source file:com.ecoplayer.beta.MainActivity.java

private void showAlertMessageGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(getResources().getString(R.string.gps_message)).setCancelable(false)
            .setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
                }//from ww  w.  j  av  a2  s.c  o  m
            }).setNegativeButton(getResources().getString(R.string.no), new DialogInterface.OnClickListener() {
                public void onClick(final DialogInterface dialog, final int id) {
                    dialog.cancel();
                }
            });
    final AlertDialog alert = builder.create();
    alert.show();
}