List of usage examples for android.app AlertDialog.Builder setOnCancelListener
public void setOnCancelListener(@Nullable OnCancelListener listener)
From source file:com.mobicage.rogerthat.plugins.messaging.AttachmentViewerActivity.java
@SuppressLint({ "SetJavaScriptEnabled" }) protected void updateView(boolean isUpdate) { T.UI();//from w w w.jav a 2 s . c o m if (!isUpdate && mGenerateThumbnail) { File thumbnail = new File(mFile.getAbsolutePath() + ".thumb"); if (!thumbnail.exists()) { boolean isImage = mContentType.toLowerCase(Locale.US).startsWith("image/"); boolean isVideo = !isImage && mContentType.toLowerCase(Locale.US).startsWith("video/"); try { // Try to generate a thumbnail mMessagingPlugin.createAttachmentThumbnail(mFile.getAbsolutePath(), isImage, isVideo); } catch (Exception e) { L.e("Failed to generate attachment thumbnail", e); } } } final String fileOnDisk = "file://" + mFile.getAbsolutePath(); if (mContentType.toLowerCase(Locale.US).startsWith("video/")) { MediaController mediacontroller = new MediaController(this); mediacontroller.setAnchorView(mVideoview); Uri video = Uri.parse(fileOnDisk); mVideoview.setMediaController(mediacontroller); mVideoview.setVideoURI(video); mVideoview.requestFocus(); mVideoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mVideoview.start(); } }); mVideoview.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { L.e("Could not play video, what " + what + ", extra " + extra + ", content_type " + mContentType + ", and url " + mDownloadUrl); AlertDialog.Builder builder = new AlertDialog.Builder(AttachmentViewerActivity.this); builder.setMessage(R.string.error_please_try_again); builder.setCancelable(true); builder.setTitle(null); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); finish(); } }); builder.setPositiveButton(R.string.rogerthat, new SafeDialogInterfaceOnClickListener() { @Override public void safeOnClick(DialogInterface dialog, int which) { dialog.dismiss(); finish(); } }); builder.create().show(); return true; } }); } else if (CONTENT_TYPE_PDF.equalsIgnoreCase(mContentType)) { WebSettings settings = mWebview.getSettings(); settings.setJavaScriptEnabled(true); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { settings.setAllowUniversalAccessFromFileURLs(true); } mWebview.setWebViewClient(new WebViewClient() { @Override public WebResourceResponse shouldInterceptRequest(WebView view, String url) { if (fileOnDisk.equals(url)) { return null; } L.d("404: Expected: '" + fileOnDisk + "'\n Received: '" + url + "'"); return new WebResourceResponse("text/plain", "UTF-8", null); } }); try { mWebview.loadUrl("file:///android_asset/pdfjs/web/viewer.html?file=" + URLEncoder.encode(fileOnDisk, "UTF-8")); } catch (UnsupportedEncodingException uee) { L.bug(uee); } } else { WebSettings settings = mWebview.getSettings(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { settings.setAllowFileAccessFromFileURLs(true); } settings.setBuiltInZoomControls(true); settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); if (mContentType.toLowerCase(Locale.US).startsWith("image/")) { String html = "<html><head></head><body><img style=\"width: 100%;\" src=\"" + fileOnDisk + "\"></body></html>"; mWebview.loadDataWithBaseURL("", html, "text/html", "utf-8", ""); } else { mWebview.loadUrl(fileOnDisk); } } L.d("File on disk: " + fileOnDisk); }
From source file:org.apache.cordova.AndroidChromeClient.java
/** * Tell the client to display a javascript alert dialog. * * @param view/*from w w w . jav a2s. c o m*/ * @param url * @param message * @param result */ @Override public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { AlertDialog.Builder dlg = new AlertDialog.Builder(this.cordova.getActivity()); dlg.setMessage(message); dlg.setTitle("Alert"); //Don't let alerts break the back button dlg.setCancelable(true); dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }); dlg.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { result.cancel(); } }); dlg.setOnKeyListener(new DialogInterface.OnKeyListener() { //DO NOTHING public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { result.confirm(); return false; } else return true; } }); dlg.create(); dlg.show(); return true; }
From source file:org.catrobat.paintroid.dialog.DialogSaveFile.java
private void saveFile() { String editTextFilename = mEditText.getText().toString(); actualFilename = editTextFilename;/*from ww w . j a va 2 s .c o m*/ if (!editTextFilename.matches(FILENAME_REGEX)) { AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setTitle(R.string.dialog_unallowed_chars_title); builder.setMessage(R.string.dialog_unallowed_chars_text); builder.setNeutralButton(R.string.ok, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mBundle.putString(BUNDLE_RET_ACTION, ACTION.CANCEL.toString()); dialog.dismiss(); show(mContext.getSupportFragmentManager(), "dialogsave"); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { show(mContext.getSupportFragmentManager(), "dialogsave"); } }); builder.create().show(); return; } final String filename = editTextFilename.length() < 1 ? mDefaultFileName : editTextFilename; File testfile = FileIO.createNewEmptyPictureFile(mContext, filename + ".png"); if (testfile == null) { Log.e(PaintroidApplication.TAG, "Cannot save file!"); dismiss(); } else if (testfile.exists()) { Log.w(PaintroidApplication.TAG, testfile + " already exists."); // TODO // remove // logging AlertDialog.Builder builder = new AlertDialog.Builder(mContext); builder.setMessage(mContext.getString(R.string.dialog_overwrite_text)).setCancelable(false) .setPositiveButton(mContext.getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { mContext.saveFile(filename); mBundle.putString(BUNDLE_SAVEFILENAME, filename); dialog.dismiss(); } }).setNegativeButton(mContext.getString(R.string.no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { mBundle.putString(BUNDLE_RET_ACTION, ACTION.CANCEL.toString()); dialog.cancel(); show(mContext.getSupportFragmentManager(), "dialogsave"); } }); builder.show(); } else { mContext.saveFile(filename); mBundle.putString(BUNDLE_SAVEFILENAME, filename); dismiss(); } }
From source file:com.google.zxing.client.android.CaptureActivity.java
private void displayFrameworkBugMessageAndExit() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(EUExUtil.getResStringID("app_name"))); builder.setMessage(getString(EUExUtil.getResStringID("plugin_uexscanner_msg_camera_framework_bug"))); builder.setPositiveButton(EUExUtil.getResStringID("confirm"), new FinishListener(this)); builder.setOnCancelListener(new FinishListener(this)); builder.show();//from w w w .j a va 2 s. c o m }
From source file:com.microsoft.windowsazure.mobileservices.authentication.LoginManager.java
/** * Creates the UI for the interactive authentication process * * @param startUrl The initial URL for the authentication process * @param endUrl The final URL for the authentication process * @param context The context used to create the authentication dialog * @param callback Callback to invoke when the authentication process finishes *///from w w w. j a v a 2 s . c o m private void showLoginUIInternal(final String startUrl, final String endUrl, final Context context, LoginUIOperationCallback callback) { if (startUrl == null || startUrl == "") { throw new IllegalArgumentException("startUrl can not be null or empty"); } if (endUrl == null || endUrl == "") { throw new IllegalArgumentException("endUrl can not be null or empty"); } if (context == null) { throw new IllegalArgumentException("context can not be null"); } final LoginUIOperationCallback externalCallback = callback; final AlertDialog.Builder builder = new AlertDialog.Builder(context); // Create the Web View to show the login page final WebView wv = new WebView(context); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException("User Canceled")); } } }); wv.getSettings().setJavaScriptEnabled(true); DisplayMetrics displaymetrics = new DisplayMetrics(); ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); int webViewHeight = displaymetrics.heightPixels - 100; wv.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, webViewHeight)); wv.requestFocus(View.FOCUS_DOWN); wv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP) { if (!view.hasFocus()) { view.requestFocus(); } } return false; } }); // Create a LinearLayout and add the WebView to the Layout LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); layout.addView(wv); // Add a dummy EditText to the layout as a workaround for a bug // that prevents showing the keyboard for the WebView on some devices EditText dummyEditText = new EditText(context); dummyEditText.setVisibility(View.GONE); layout.addView(dummyEditText); // Add the layout to the dialog builder.setView(layout); final AlertDialog dialog = builder.create(); wv.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // If the URL of the started page matches with the final URL // format, the login process finished if (isFinalUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(url, null); } dialog.dismiss(); } super.onPageStarted(view, url, favicon); } // Checks if the given URL matches with the final URL's format private boolean isFinalUrl(String url) { if (url == null) { return false; } return url.startsWith(endUrl); } // Checks if the given URL matches with the start URL's format private boolean isStartUrl(String url) { if (url == null) { return false; } return url.startsWith(startUrl); } @Override public void onPageFinished(WebView view, String url) { if (isStartUrl(url)) { if (externalCallback != null) { externalCallback.onCompleted(null, new MobileServiceException( "Logging in with the selected authentication provider is not enabled")); } dialog.dismiss(); } } }); wv.loadUrl(startUrl); dialog.show(); }
From source file:com.kuaichumen.whistle.admin.CaptureActivity.java
private void displayFrameworkBugMessageAndExit() { // camera error AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(com.kuaichumen.whistle.R.string.app_name)); builder.setMessage("???"); builder.setPositiveButton("", new DialogInterface.OnClickListener() { @Override// ww w.j a va 2 s . c o m public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); builder.show(); }
From source file:org.skt.runtime.RuntimeChromeClient.java
/** * Tell the client to display a javascript alert dialog. * //from w w w. j av a 2 s. c om * @param view * @param url * @param message * @param result */ @Override public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { AlertDialog.Builder dlg = new AlertDialog.Builder(this.ctx); dlg.setMessage(message); dlg.setTitle("Alert"); //Don't let alerts break the back button dlg.setCancelable(true); dlg.setPositiveButton(android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }); dlg.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { result.confirm(); } }); dlg.setOnKeyListener(new DialogInterface.OnKeyListener() { //DO NOTHING public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { result.confirm(); return false; } else return true; } }); dlg.create(); dlg.show(); return true; }
From source file:com.getkickbak.plugin.NotificationPlugin.java
/** * Builds and shows a native Android alert with given Strings * /*from w w w . j a v a2s. com*/ * @param message * The message the alert should display * @param title * The title of the alert * @param buttonLabel * The label of the button * @param callbackContext * The callback context */ public synchronized void alert(final String message, final String title, final String buttonLabel, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; Runnable runnable = new Runnable() { public void run() { AlertDialog.Builder dlg = new AlertDialog.Builder(cordova.getActivity()); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(true); dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0)); } }); dlg.create(); dlg.show(); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.dtr.zxing.activity.CaptureActivity.java
private void displayFrameworkBugMessageAndExit() { // camera error AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.app_name)); builder.setMessage("???"); builder.setPositiveButton("", new DialogInterface.OnClickListener() { @Override/* w w w . ja v a 2s . c om*/ public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { finish(); } }); builder.show(); }
From source file:net.heroicefforts.viable.android.BugReporterActivity.java
/** * Issue already exists. Now prompt the user whether they want to add an additional comment. * // www. j a va 2s . c om * @param issue the defect */ private void showSupplementDialog(Issue issue) { if (Config.LOGD) Log.d(TAG, "Prompting user to comment on existing issue '" + issue.getIssueId() + "'."); final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.bug_comment); builder.setCancelable(true); builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { comment = true; } }); builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { finish(); } }); builder.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { finish(); } }); builder.setMessage(getString(R.string.bug_comment_prompt).replaceAll("\\{appName\\}", issue.getAppName())); builder.create().show(); }