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:info.snowhow.plugin.RecorderService.java

private void showNoGPSAlert() {
    Log.i(LOG_TAG, "No GPS available --- show Dialog");
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setMessage("GPS is disabled on your device. Would you like to enable it?")
            .setCancelable(false).setPositiveButton("GPS Settings", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Intent callGPSSettingIntent = new Intent(
                            android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    callGPSSettingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(callGPSSettingIntent);
                }//  w  w  w.  j a v  a  2s  .  c  om
            });
    alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            stopRecording();
            dialog.cancel();
        }
    });
    AlertDialog alert = alertDialogBuilder.create();
    alert.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
    alert.show();
}

From source file:com.dwdesign.tweetings.fragment.StatusFragment.java

protected void translate(final ParcelableStatus status) {
    ThreadPolicy tp = ThreadPolicy.LAX;
    StrictMode.setThreadPolicy(tp);//from  w ww  .j  av  a  2s  .  co  m

    String language = Locale.getDefault().getLanguage();
    String url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?contentType="
            + URLEncoder.encode("text/plain") + "&appId=" + BING_TRANSLATE_API_KEY + "&from=&to=" + language
            + "&text=";
    url = url + URLEncoder.encode(status.text_plain);
    try {
        HttpClient httpClient = new DefaultHttpClient();
        HttpResponse response = httpClient.execute(new HttpGet(url));

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();

        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
        String finalString = s.toString();
        finalString = finalString
                .replace("<string xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">", "");
        finalString = finalString.replace("</string>", "");

        AlertDialog.Builder builder = new AlertDialog.Builder(this.getActivity());
        builder.setTitle(getString(R.string.translate));
        builder.setMessage(finalString);
        builder.setCancelable(true);
        builder.setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
            }
        });

        AlertDialog alert = builder.create();
        alert.show();
        //Toast.makeText(getActivity(), finalString, Toast.LENGTH_LONG).show();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.app.blockydemo.ui.fragment.ScriptFragment.java

private void showConfirmDeleteDialog(boolean fromContextMenu) {
    this.deleteScriptFromContextMenu = fromContextMenu;
    int titleId;/* w w  w.  j a v a  2 s .  c o  m*/
    if ((deleteScriptFromContextMenu && scriptToEdit.getBrickList().size() == 0)
            || adapter.getAmountOfCheckedItems() == 1) {
        titleId = R.string.dialog_confirm_delete_brick_title;
    } else {
        titleId = R.string.dialog_confirm_delete_multiple_bricks_title;
    }

    AlertDialog.Builder builder = new CustomAlertDialogBuilder(getActivity());
    builder.setTitle(titleId);
    builder.setMessage(R.string.dialog_confirm_delete_brick_message);
    builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            if (deleteScriptFromContextMenu) {
                adapter.handleScriptDelete(sprite, scriptToEdit);
            } else {
                deleteCheckedBricks();
                clearCheckedBricksAndEnableButtons();
            }
        }
    });
    builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
            if (!deleteScriptFromContextMenu) {
                clearCheckedBricksAndEnableButtons();
            }
        }
    });

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

From source file:ca.cmput301f13t03.adventure_datetime.view.AuthorEdit.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
    case R.id.action_back:
        finish();//from  www.java  2  s  .co m
        break;
    case R.id.action_save:
        _adapter.saveFragment();
        Toast.makeText(getApplicationContext(), "Saved Fragment!", Toast.LENGTH_SHORT).show();
        break;
    case R.id.action_discard:
        /* Ensure user is not retarded and actually wants to do this */
        new AlertDialog.Builder(this).setTitle("Delete Story Fragment")
                .setMessage("Deletes only currently selected fragment.\nYou cannot undo.").setCancelable(true)
                .setPositiveButton("Delete", new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (_story.getHeadFragmentId().equals(_fragment.getFragmentID())) {
                            Toast.makeText(getApplicationContext(), "Cannot delete Head Fragment",
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Locator.getAuthorController().deleteFragment(_fragment.getFragmentID());
                            Locator.getAuthorController().selectFragment(_story.getHeadFragmentId());
                        }
                    }
                }).setNegativeButton("Cancel", new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create().show();
        break;
    default:
    }
    return super.onOptionsItemSelected(item);
}

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

@Override
protected void onResume() {
    super.onResume();
    Intent intent = getIntent();/*from  w w  w. java 2  s.  c  o m*/
    if (intent != null) {
        if (intent.hasExtra(Widgets.INSTANT_UPLOAD)) {
            mFilePath = intent.getStringExtra(Widgets.INSTANT_UPLOAD);
            Log.d(TAG, "upload photo?" + mFilePath);
        } else {
            mData = intent.getData();
            if (mData != null) {
                mData = intent.getData();
                if (intent.hasExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS))
                    mRect = intent.getParcelableExtra(LauncherIntent.Extra.Scroll.EXTRA_SOURCE_BOUNDS);
                else
                    mRect = intent.getSourceBounds();
                Log.d(TAG, "data:" + mData.toString());
                // need to use a thread here to avoid anr
                mLoadingDialog = new ProgressDialog(this);
                mLoadingDialog.setMessage(getString(R.string.status_loading));
                mLoadingDialog.setCancelable(true);
                mLoadingDialog.setOnCancelListener(new OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface arg0) {
                        if (mStatusLoader != null)
                            mStatusLoader.cancel(true);
                        finish();
                    }
                });
                mLoadingDialog.setButton(ProgressDialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                        new OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                                finish();
                            }
                        });
                mLoadingDialog.show();
                mStatusLoader = new StatusLoader();
                mStatusLoader.execute();
            }
        }
    }
    if (mFilePath != null) {
        mDialog = (new AlertDialog.Builder(this)).setTitle(R.string.uploadprompt)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        startActivityForResult(
                                Myfeedle.getPackageIntent(getApplicationContext(), MyfeedleCreatePost.class)
                                        .putExtra(Widgets.INSTANT_UPLOAD, mFilePath),
                                RESULT_REFRESH);
                        dialog.dismiss();
                    }
                }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                        StatusDialog.this.finish();
                    }
                }).create();
        mDialog.show();
    } else {
        // check if the dialog is still loading
        if (mFinish)
            finish();
        else if ((mLoadingDialog == null) || !mLoadingDialog.isShowing())
            showDialog();
    }
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment31.java

public void deleteBeacon(int position) {
    final String beaconmac = mMyDeviceAdapter.getDeviceList().get(position).getBdAddr();

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle("  ?");
    alertDialog.setMessage("? ? ?");
    alertDialog.setIcon(R.drawable.alert);

    alertDialog.setPositiveButton("", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            updateEvent("BEACON_DELETE");
            DeleteBeacon deleteBeacon = new DeleteBeacon();
            deleteBeacon.execute("http://125.131.73.198:3000/beconDelete", beaconmac);
        }/*from  ww  w.ja  v a2 s  .co  m*/
    });

    alertDialog.setNegativeButton("", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    alertDialog.show();
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment31.java

private void stopUseBeacon(int position) {
    final String beaconmac = mMyDeviceAdapter.getDeviceList().get(position).getBdAddr();

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(getActivity());
    alertDialog.setTitle("   ?");
    alertDialog.setMessage("? ?   ?");
    alertDialog.setIcon(R.drawable.alert);

    alertDialog.setPositiveButton("", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            updateEvent("BEACON_STOP");
            StopUseBeacon stopUseBeacon = new StopUseBeacon();
            stopUseBeacon.execute("http://125.131.73.198:3000/beaconStop", beaconmac);
        }//from  ww  w. ja  v  a  2  s  .  co  m
    });

    alertDialog.setNegativeButton("", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });
    alertDialog.show();
}

From source file:com.irccloud.android.activity.PastebinViewerActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();//from w ww .  ja v  a  2s  .co m
        if (getWindowManager().getDefaultDisplay().getWidth() < TypedValue
                .applyDimension(TypedValue.COMPLEX_UNIT_DIP, 800, getResources().getDisplayMetrics())
                || isMultiWindow())
            overridePendingTransition(R.anim.fade_in, R.anim.slide_out_right);
        return true;
    } else if (item.getItemId() == R.id.delete) {
        if (Uri.parse(url).getQueryParameter("own_paste").equals("1")) {
            AlertDialog.Builder builder = new AlertDialog.Builder(PastebinViewerActivity.this);
            builder.setTitle("Delete Snippet");
            builder.setMessage("Are you sure you want to delete this snippet?");
            builder.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    NetworkConnection.getInstance().delete_paste(Uri.parse(url).getQueryParameter("id"));
                    finish();
                    Toast.makeText(PastebinViewerActivity.this, "Snippet deleted", Toast.LENGTH_SHORT).show();
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    dialogInterface.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(PastebinViewerActivity.this);
            d.show();
        }
    } else if (item.getItemId() == R.id.action_linenumbers) {
        item.setChecked(!item.isChecked());
        mWebView.loadUrl("javascript:window.PASTEVIEW.doToggleLines()");
    } else if (item.getItemId() == R.id.action_browser) {
        if (!PreferenceManager
                .getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext())
                .getBoolean("browser", false)
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
            builder.setToolbarColor(ColorScheme.getInstance().navBarColor);
            builder.addDefaultShareMenuItem();
            builder.addMenuItem("Copy URL",
                    PendingIntent.getBroadcast(this, 0, new Intent(this, ChromeCopyLinkBroadcastReceiver.class),
                            PendingIntent.FLAG_UPDATE_CURRENT));

            CustomTabsIntent intent = builder.build();
            intent.intent.setData(Uri.parse(url.contains("?") ? url.substring(0, url.indexOf("?")) : url));
            if (Build.VERSION.SDK_INT >= 22)
                intent.intent.putExtra(Intent.EXTRA_REFERRER,
                        Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + getPackageName()));
            if (Build.VERSION.SDK_INT >= 16 && intent.startAnimationBundle != null) {
                startActivity(intent.intent, intent.startAnimationBundle);
            } else {
                startActivity(intent.intent);
            }
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW,
                    Uri.parse(url.contains("?") ? url.substring(0, url.indexOf("?")) : url));
            startActivity(intent);
        }
        finish();
        return true;
    } else if (item.getItemId() == R.id.action_copy) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
            android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            if (url.contains("?"))
                clipboard.setText(url.substring(0, url.indexOf("?")));
            else
                clipboard.setText(url);
        } else {
            @SuppressLint("ServiceCast")
            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(
                    CLIPBOARD_SERVICE);
            android.content.ClipData clip;
            if (url.contains("?"))
                clip = android.content.ClipData.newRawUri("IRCCloud Snippet URL",
                        Uri.parse(url.substring(0, url.indexOf("?"))));
            else
                clip = android.content.ClipData.newRawUri("IRCCloud Snippet URL", Uri.parse(url));
            clipboard.setPrimaryClip(clip);
        }
        Toast.makeText(PastebinViewerActivity.this, "Link copied to clipboard", Toast.LENGTH_SHORT).show();
    } else if (item.getItemId() == R.id.action_share) {
        if (getIntent() != null && getIntent().getDataString() != null) {
            Intent intent = new Intent(Intent.ACTION_SEND, Uri.parse(url));
            intent.setType("text/plain");
            if (url.contains("?"))
                intent.putExtra(Intent.EXTRA_TEXT, url.substring(0, url.indexOf("?")));
            else
                intent.putExtra(Intent.EXTRA_TEXT, url);
            intent.putExtra(ShareCompat.EXTRA_CALLING_PACKAGE, getPackageName());
            intent.putExtra(ShareCompat.EXTRA_CALLING_ACTIVITY,
                    getPackageManager().getLaunchIntentForPackage(getPackageName()).getComponent());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET | Intent.FLAG_ACTIVITY_NEW_TASK);

            startActivity(Intent.createChooser(intent, "Share Snippet"));
            Answers.getInstance().logShare(new ShareEvent().putContentType("Pastebin"));
        }
    } else if (item.getItemId() == R.id.action_edit) {
        mSpinner.setVisibility(View.VISIBLE);
        Intent i = new Intent(this, PastebinEditorActivity.class);
        i.putExtra("paste_id", Uri.parse(url).getQueryParameter("id"));
        startActivityForResult(i, 1);
    }
    return super.onOptionsItemSelected(item);
}

From source file:ch.ethz.twimight.activities.DmListActivity.java

/**
 * Asks the user if she wants to delete a dm.
 *//*ww  w. jav  a  2 s.  c  om*/
private void showDeleteDialog(final long tid, final long rowId) {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to delete your Direct Message?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    Uri uri = Uri.parse("content://" + DirectMessages.DM_AUTHORITY + "/" + DirectMessages.DMS
                            + "/" + rowId);

                    if (tid != 0) {
                        mCursor.moveToPosition(mSelectedPosition);
                        int flags = mCursor.getInt(mCursor.getColumnIndex(DirectMessages.COL_FLAGS));
                        getContentResolver().update(uri, setDeleteFlag(flags), null, null);
                    } else {
                        getContentResolver().delete(uri, null, null);
                    }

                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.itude.mobile.mobbl.core.controller.MBViewManager.java

private void buildAlertDialogButtons(AlertDialog.Builder builder, final MBElement element) {
    String label = element.getValueForAttribute("label");
    if (StringUtil.isNotBlank(label)) {
        if ("neutral".equals(element.getName())) {
            builder.setNeutralButton(MBLocalizationService.getInstance().getTextForKey(label),
                    new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String outcome = element.getValueForAttribute("outcome");
                            if (StringUtil.isBlank(outcome)) {
                                dialog.cancel();
                            } else {
                                MBApplicationController.getInstance()
                                        .handleOutcome(new MBOutcome(outcome, null));
                            }//from   w w w .  jav  a  2 s  .  c  o  m
                        }
                    });
        } else if ("positive".equals(element.getName())) {
            builder.setPositiveButton(MBLocalizationService.getInstance().getTextForKey(label),
                    new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String outcome = element.getValueForAttribute("outcome");
                            if (StringUtil.isBlank(outcome)) {
                                dialog.cancel();
                            } else {
                                MBApplicationController.getInstance()
                                        .handleOutcome(new MBOutcome(outcome, null));
                            }
                        }
                    });

        } else if ("negative".equals(element.getName())) {
            builder.setNegativeButton(MBLocalizationService.getInstance().getTextForKey(label),
                    new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            String outcome = element.getValueForAttribute("outcome");
                            if (StringUtil.isBlank(outcome)) {
                                dialog.cancel();
                            } else {
                                MBApplicationController.getInstance()
                                        .handleOutcome(new MBOutcome(outcome, null));
                            }
                        }
                    });

        }

    }

}