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:dev.ukanth.ufirewall.Api.java

public static void saveSharedPreferencesToFileConfirm(final Context ctx) {
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setMessage(ctx.getString(R.string.exportConfirm)).setCancelable(false)
            .setPositiveButton(ctx.getString(R.string.Yes), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    if (saveSharedPreferencesToFile(ctx)) {
                        Api.alert(ctx, ctx.getString(R.string.export_rules_success) + " "
                                + Environment.getExternalStorageDirectory().getPath() + "/afwall/");
                    } else {
                        Api.alert(ctx, ctx.getString(R.string.export_rules_fail));
                    }//from  ww  w .j  a  va  2  s .c  o m
                }
            }).setNegativeButton(ctx.getString(R.string.No), new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates an alert with an OK button.//from w ww  .j ava 2  s. c om
 * 
 * @param context
 * @param msgResourceId
 */
public static void dialog_showAlertOkDialog(Context context, int titleResourceId, int msgResourceId) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(context.getResources().getString(msgResourceId)).setCancelable(false)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

    if (titleResourceId != 0) {
        builder.setTitle(context.getResources().getString(titleResourceId));
    }

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

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates an alert with an OK button.//from w w  w .jav  a  2  s  . co m
 * 
 * @param context
 * @param message
 */
public static void dialog_showAlertOkDialog(Context context, String tittle, String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(message).setCancelable(false).setPositiveButton("Ok",
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });

    if (tittle != null && tittle.length() > 0) {
        builder.setTitle(tittle);
    }

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

From source file:com.cm.android.beercellar.ui.ImageDetailFragment.java

private void deleteImage() {
    AlertDialog.Builder builder = new AlertDialog.Builder(ImageDetailFragment.this.getActivity());

    builder.setMessage("Delete?").setPositiveButton("Delete now", new DialogInterface.OnClickListener() {
        @Override//from  ww w  .j  av  a2 s .  c o  m
        public void onClick(DialogInterface dialog, int id) {
            // Yes-code
            mProgressBar.setVisibility(View.VISIBLE);
            //String[] params = {mImageUrl, mThumbnailUrl};
            //new DeleteImageAsyncTask().execute(params);

            try {
                //delete files under Pictures
                File imageFile = new File(mImageUrl);
                File thumbnailFile = new File(mThumbnailUrl);
                //delete thumbnail first for better ux
                if (thumbnailFile.delete() && imageFile.delete()) {
                    List<Object> data = new ArrayList<Object>();
                    //delete thumbnail first
                    data.add(mThumbnailUrl);
                    data.add(mImageUrl);
                    //delete files in the cache
                    mImageFetcher.deleteImages(data, ImageDetailFragment.this);
                    //database
                    mDbHelper.deleteNote(mRowId);

                } else {
                    Log.e(ImageDetailFragment.class.getName(), "Unable to delete files");
                    Toast.makeText(getActivity(), "Unable to delete", Toast.LENGTH_SHORT).show();
                }

            } catch (Exception e) {
                Log.e(ImageDetailFragment.class.getName(), e.getMessage());
            }

            //getActivity().finish();
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    }).show();
}

From source file:cgeo.geocaching.cgeocaches.java

private void importGpxAttachement() {
    new AlertDialog.Builder(this).setTitle(res.getString(R.string.gpx_import_title))
            .setMessage(res.getString(R.string.gpx_import_confirm)).setCancelable(false)
            .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
                @Override//from  ww  w  . ja v a 2  s.c o m
                public void onClick(DialogInterface dialog, int id) {
                    new GPXImporter(cgeocaches.this, listId, importGpxAttachementFinishedHandler).importGPX();
                }
            }).setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).create().show();
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showDynamicPricingPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    String message = "Apply Dynamic Pricing";
    String positiveButtonText = "Apply";
    final Utils.DPRequestType[] dpRequestType = new Utils.DPRequestType[1];
    ScrollView scrollView = new ScrollView(getActivity());
    LinearLayout linearLayout = (LinearLayout) getActivity().getLayoutInflater()
            .inflate(R.layout.dynamic_pricing_input_layout, null);
    final EditText editTransactionAmount = (EditText) linearLayout.findViewById(R.id.edit_txn_amount);
    final EditText editCouponCode = (EditText) linearLayout.findViewById(R.id.edit_coupon_code);
    final EditText editAlteredAmount = (EditText) linearLayout.findViewById(R.id.edit_altered_amount);
    final LinearLayout layoutCouponCode = (LinearLayout) linearLayout.findViewById(R.id.layout_for_coupon_code);
    final LinearLayout layoutAlteredAmount = (LinearLayout) linearLayout
            .findViewById(R.id.layout_for_altered_amount);
    Spinner spinner = (Spinner) linearLayout.findViewById(R.id.spinner_dp_request_type);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from   w  w w  .  ja v a  2 s. c  om*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            switch (position) {
            case 0:
                dpRequestType[0] = Utils.DPRequestType.SEARCH_AND_APPLY;
                layoutCouponCode.setVisibility(View.GONE);
                layoutAlteredAmount.setVisibility(View.GONE);
                break;
            case 1:
                dpRequestType[0] = Utils.DPRequestType.CALCULATE_PRICING;
                layoutCouponCode.setVisibility(View.VISIBLE);
                layoutAlteredAmount.setVisibility(View.GONE);
                break;
            case 2:
                dpRequestType[0] = Utils.DPRequestType.VALIDATE_RULE;
                layoutCouponCode.setVisibility(View.VISIBLE);
                layoutAlteredAmount.setVisibility(View.VISIBLE);
                break;
            }
        }

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

        }
    });

    alert.setTitle("Perform Dynamic Pricing");
    alert.setMessage(message);

    scrollView.addView(linearLayout);
    alert.setView(scrollView);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editTransactionAmount.getText().toString();
            String alteredAmount = editAlteredAmount.getText().toString();
            String couponCode = editCouponCode.getText().toString();

            mListener.onPaymentTypeSelected(dpRequestType[0], new Amount(amount), couponCode,
                    new Amount(alteredAmount));

            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editTransactionAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editTransactionAmount.requestFocus();
    alert.show();
}

From source file:com.shafiq.myfeedle.core.MyfeedleComments.java

@Override
public void onClick(View v) {
    if (v == mSend) {
        if ((mMessage.getText().toString() != null) && (mMessage.getText().toString().length() > 0)
                && (mSid != null) && (mEsid != null)) {
            mMessage.setEnabled(false);/*from   w ww .  j a  v  a  2  s .  c om*/
            mSend.setEnabled(false);
            // post or comment!
            final ProgressDialog loadingDialog = new ProgressDialog(this);
            final AsyncTask<Void, String, String> asyncTask = new AsyncTask<Void, String, String>() {
                @Override
                protected String doInBackground(Void... arg0) {
                    List<NameValuePair> params;
                    String message;
                    String response = null;
                    HttpPost httpPost;
                    MyfeedleOAuth myfeedleOAuth;
                    String serviceName = Myfeedle.getServiceName(getResources(), mService);
                    publishProgress(serviceName);
                    switch (mService) {
                    case TWITTER:
                        // limit tweets to 140, breaking up the message if necessary
                        myfeedleOAuth = new MyfeedleOAuth(TWITTER_KEY, TWITTER_SECRET, mToken, mSecret);
                        message = mMessage.getText().toString();
                        while (message.length() > 0) {
                            final String send;
                            if (message.length() > 140) {
                                // need to break on a word
                                int end = 0;
                                int nextSpace = 0;
                                for (int i = 0, i2 = message.length(); i < i2; i++) {
                                    end = nextSpace;
                                    if (message.substring(i, i + 1).equals(" ")) {
                                        nextSpace = i;
                                    }
                                }
                                // in case there are no spaces, just break on 140
                                if (end == 0) {
                                    end = 140;
                                }
                                send = message.substring(0, end);
                                message = message.substring(end + 1);
                            } else {
                                send = message;
                                message = "";
                            }
                            httpPost = new HttpPost(String.format(TWITTER_UPDATE, TWITTER_BASE_URL));
                            // resolve Error 417 Expectation by Twitter
                            httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false);
                            params = new ArrayList<NameValuePair>();
                            params.add(new BasicNameValuePair(Sstatus, send));
                            params.add(new BasicNameValuePair(Sin_reply_to_status_id, mSid));
                            try {
                                httpPost.setEntity(new UrlEncodedFormEntity(params));
                                response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                        myfeedleOAuth.getSignedRequest(httpPost));
                            } catch (UnsupportedEncodingException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                        break;
                    case FACEBOOK:
                        httpPost = new HttpPost(String.format(FACEBOOK_COMMENTS, FACEBOOK_BASE_URL, mSid,
                                Saccess_token, mToken));
                        params = new ArrayList<NameValuePair>();
                        params.add(new BasicNameValuePair(Smessage, mMessage.getText().toString()));
                        try {
                            httpPost.setEntity(new UrlEncodedFormEntity(params));
                            response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost);
                        } catch (UnsupportedEncodingException e) {
                            Log.e(TAG, e.toString());
                        }
                        break;
                    case MYSPACE:
                        myfeedleOAuth = new MyfeedleOAuth(MYSPACE_KEY, MYSPACE_SECRET, mToken, mSecret);
                        try {
                            httpPost = new HttpPost(String.format(MYSPACE_URL_STATUSMOODCOMMENTS,
                                    MYSPACE_BASE_URL, mEsid, mSid));
                            httpPost.setEntity(new StringEntity(String.format(MYSPACE_STATUSMOODCOMMENTS_BODY,
                                    mMessage.getText().toString())));
                            response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                    myfeedleOAuth.getSignedRequest(httpPost));
                        } catch (IOException e) {
                            Log.e(TAG, e.toString());
                        }
                        break;
                    case FOURSQUARE:
                        try {
                            message = URLEncoder.encode(mMessage.getText().toString(), "UTF-8");
                            httpPost = new HttpPost(String.format(FOURSQUARE_ADDCOMMENT, FOURSQUARE_BASE_URL,
                                    mSid, message, mToken));
                            response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost);
                        } catch (UnsupportedEncodingException e) {
                            Log.e(TAG, e.toString());
                        }
                        break;
                    case LINKEDIN:
                        myfeedleOAuth = new MyfeedleOAuth(LINKEDIN_KEY, LINKEDIN_SECRET, mToken, mSecret);
                        try {
                            httpPost = new HttpPost(
                                    String.format(LINKEDIN_UPDATE_COMMENTS, LINKEDIN_BASE_URL, mSid));
                            httpPost.setEntity(new StringEntity(
                                    String.format(LINKEDIN_COMMENT_BODY, mMessage.getText().toString())));
                            httpPost.addHeader(new BasicHeader("Content-Type", "application/xml"));
                            response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                    myfeedleOAuth.getSignedRequest(httpPost));
                        } catch (IOException e) {
                            Log.e(TAG, e.toString());
                        }
                        break;
                    case IDENTICA:
                        // limit tweets to 140, breaking up the message if necessary
                        myfeedleOAuth = new MyfeedleOAuth(IDENTICA_KEY, IDENTICA_SECRET, mToken, mSecret);
                        message = mMessage.getText().toString();
                        while (message.length() > 0) {
                            final String send;
                            if (message.length() > 140) {
                                // need to break on a word
                                int end = 0;
                                int nextSpace = 0;
                                for (int i = 0, i2 = message.length(); i < i2; i++) {
                                    end = nextSpace;
                                    if (message.substring(i, i + 1).equals(" ")) {
                                        nextSpace = i;
                                    }
                                }
                                // in case there are no spaces, just break on 140
                                if (end == 0) {
                                    end = 140;
                                }
                                send = message.substring(0, end);
                                message = message.substring(end + 1);
                            } else {
                                send = message;
                                message = "";
                            }
                            httpPost = new HttpPost(String.format(IDENTICA_UPDATE, IDENTICA_BASE_URL));
                            // resolve Error 417 Expectation by Twitter
                            httpPost.getParams().setBooleanParameter("http.protocol.expect-continue", false);
                            params = new ArrayList<NameValuePair>();
                            params.add(new BasicNameValuePair(Sstatus, send));
                            params.add(new BasicNameValuePair(Sin_reply_to_status_id, mSid));
                            try {
                                httpPost.setEntity(new UrlEncodedFormEntity(params));
                                response = MyfeedleHttpClient.httpResponse(mHttpClient,
                                        myfeedleOAuth.getSignedRequest(httpPost));
                            } catch (UnsupportedEncodingException e) {
                                Log.e(TAG, e.toString());
                            }
                        }
                        break;
                    case GOOGLEPLUS:
                        break;
                    case CHATTER:
                        httpPost = new HttpPost(String.format(CHATTER_URL_COMMENT, mChatterInstance, mSid,
                                Uri.encode(mMessage.getText().toString())));
                        httpPost.setHeader("Authorization", "OAuth " + mChatterToken);
                        response = MyfeedleHttpClient.httpResponse(mHttpClient, httpPost);
                        break;
                    }
                    return ((response == null) && (mService == MYSPACE)) ? null
                            : serviceName + " "
                                    + getString(response != null ? R.string.success : R.string.failure);
                }

                @Override
                protected void onProgressUpdate(String... params) {
                    loadingDialog.setMessage(String.format(getString(R.string.sending), params[0]));
                }

                @Override
                protected void onPostExecute(String result) {
                    if (result != null) {
                        (Toast.makeText(MyfeedleComments.this, result, Toast.LENGTH_LONG)).show();
                    } else if (mService == MYSPACE) {
                        // myspace permissions
                        (Toast.makeText(MyfeedleComments.this,
                                MyfeedleComments.this.getResources()
                                        .getStringArray(R.array.service_entries)[MYSPACE]
                                        + getString(R.string.failure) + " "
                                        + getString(R.string.myspace_permissions_message),
                                Toast.LENGTH_LONG)).show();
                    }
                    if (loadingDialog.isShowing())
                        loadingDialog.dismiss();
                    finish();
                }

            };
            loadingDialog.setMessage(getString(R.string.loading));
            loadingDialog.setCancelable(true);
            loadingDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    if (!asyncTask.isCancelled())
                        asyncTask.cancel(true);
                }
            });
            loadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.cancel();
                        }
                    });
            loadingDialog.show();
            asyncTask.execute();
        } else {
            (Toast.makeText(MyfeedleComments.this, "error parsing message body", Toast.LENGTH_LONG)).show();
            mMessage.setEnabled(true);
            mSend.setEnabled(true);
        }
    }
}

From source file:cgeo.geocaching.CacheListActivity.java

public void removeFromHistoryCheck() {
    final int message = (adapter != null && adapter.getCheckedCount() > 0) ? R.string.cache_remove_from_history
            : R.string.cache_clear_history;
    Dialogs.confirmYesNo(this, R.string.caches_removing_from_history, message,
            new DialogInterface.OnClickListener() {
                @Override/*ww  w .  j  a  v a2s. co m*/
                public void onClick(final DialogInterface dialog, final int id) {
                    removeFromHistory();
                    dialog.cancel();
                }
            });
}

From source file:cgeo.geocaching.CacheListActivity.java

public void refreshStored(final List<Geocache> caches) {
    if (type == CacheListType.OFFLINE && caches.size() > REFRESH_WARNING_THRESHOLD) {
        Dialogs.confirmYesNo(this, R.string.caches_refresh_all, R.string.caches_refresh_all_warning,
                new DialogInterface.OnClickListener() {
                    @Override/*  w  w  w .ja  v a  2s  .  co  m*/
                    public void onClick(final DialogInterface dialog, final int id) {
                        refreshStoredConfirmed(caches);
                        dialog.cancel();
                    }
                });
    } else {
        refreshStoredConfirmed(caches);
    }
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showCashoutPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    String message = "Please enter account details.";
    String positiveButtonText = "Withdraw";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelAccountNo = new TextView(getActivity());
    final EditText editAccountNo = new EditText(getActivity());
    editAccountNo.setSingleLine(true);/*from   w w  w .ja v  a2  s  .c o m*/
    final TextView labelAccountHolderName = new TextView(getActivity());
    final EditText editAccountHolderName = new EditText(getActivity());
    editAccountHolderName.setSingleLine(true);
    final TextView labelIfscCode = new TextView(getActivity());
    final EditText editIfscCode = new EditText(getActivity());
    editIfscCode.setSingleLine(true);

    labelAmount.setText("Withdrawal Amount");
    labelAccountNo.setText("Account Number");
    labelAccountHolderName.setText("Account Holder Name");
    labelIfscCode.setText("IFSC Code");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelAccountNo.setLayoutParams(layoutParams);
    labelAccountHolderName.setLayoutParams(layoutParams);
    labelIfscCode.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editAccountNo.setLayoutParams(layoutParams);
    editAccountHolderName.setLayoutParams(layoutParams);
    editIfscCode.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelAccountNo);
    linearLayout.addView(editAccountNo);
    linearLayout.addView(labelAccountHolderName);
    linearLayout.addView(editAccountHolderName);
    linearLayout.addView(labelIfscCode);
    linearLayout.addView(editIfscCode);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

    alert.setTitle("Withdraw Money To Your Account");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String accontNo = editAccountNo.getText().toString();
            String accountHolderName = editAccountHolderName.getText().toString();
            String ifsc = editIfscCode.getText().toString();

            CashoutInfo cashoutInfo = new CashoutInfo(new Amount(amount), accontNo, accountHolderName, ifsc);
            mListener.onCashoutSelected(cashoutInfo);

            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.cancel();
        }
    });

    editAmount.requestFocus();
    alert.show();
}