List of usage examples for android.app AlertDialog.Builder setCancelable
public void setCancelable(boolean flag)
From source file:com.death.yttorrents.activity.MainActivity.java
/** * @param item// ww w.j av a 2 s. c o m * @return */ @Override public boolean onOptionsItemSelected(MenuItem item) { if (item.getItemId() == R.id.seedr) { count += 1; Toast.makeText(MainActivity.this, "Sorting by minimum rating 8 on page " + count, Toast.LENGTH_SHORT) .show(); String url = "https://yts.ag/api/v2/list_movies.json?minimum_rating=8&limit=50&page=" + count; fetchMovies(url); } if (item.getItemId() == R.id.search) { count = 0; LayoutInflater li = LayoutInflater.from(MainActivity.this); View dialogView = li.inflate(R.layout.custom_query, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this, R.style.MyDialogTheme); alertDialogBuilder.setTitle(Html.fromHtml("<font color='#ffffff'>Search Movie</font>")); alertDialogBuilder.setIcon(R.drawable.ic_icon); alertDialogBuilder.setView(dialogView); final EditText userInput = (EditText) dialogView.findViewById(R.id.et_input); alertDialogBuilder.setCancelable(false) .setPositiveButton("Search", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { query = userInput.getText().toString(); String dataUrl = "https://yts.ag/api/v2/list_movies.json?query_term=" + query + "&limit=30"; fetchMovies(dataUrl); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); } if (item.getItemId() == R.id.mwiki) { startActivity(new Intent(MainActivity.this, MediaContainer.class)); } if (item.getItemId() == R.id.about) { startActivity(new Intent(MainActivity.this, About.class)); } return super.onOptionsItemSelected(item); }
From source file:com.securecomcode.text.ConversationListFragment.java
private void handleDeleteAllSelected() { AlertDialog.Builder alert = new AlertDialog.Builder(getActivity()); alert.setIcon(Dialogs.resolveIcon(getActivity(), R.attr.dialog_alert_icon)); alert.setTitle(R.string.ConversationListFragment_delete_threads_question); alert.setMessage(//from w w w . ja v a2 s . com R.string.ConversationListFragment_are_you_sure_you_wish_to_delete_all_selected_conversation_threads); alert.setCancelable(true); alert.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { final Set<Long> selectedConversations = ((ConversationListAdapter) getListAdapter()) .getBatchSelections(); if (!selectedConversations.isEmpty()) { new AsyncTask<Void, Void, Void>() { private ProgressDialog dialog; @Override protected void onPreExecute() { dialog = ProgressDialog.show(getActivity(), getSherlockActivity().getString(R.string.ConversationListFragment_deleting), getSherlockActivity() .getString(R.string.ConversationListFragment_deleting_selected_threads), true, false); } @Override protected Void doInBackground(Void... params) { DatabaseFactory.getThreadDatabase(getActivity()) .deleteConversations(selectedConversations); MessageNotifier.updateNotification(getActivity(), masterSecret); return null; } @Override protected void onPostExecute(Void result) { dialog.dismiss(); if (actionMode != null) { actionMode.finish(); actionMode = null; } } }.execute(); } } }); alert.setNegativeButton(android.R.string.cancel, null); alert.show(); }
From source file:com.asksven.commandcenter.BasicMasterFragment.java
/** execute the selected command */ private final void executeCommand(final Command cmd) { SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (!cmd.getCommandValues().equals("")) { // handle whatever values are defined for the command // values can be either a list of "|" separated items to pick from // or a sub-command to be executed first // sub-commands are of the form "??something??:somewhere" // allowed sub-commands are String strPickFile = "??pickfile??"; String strPickDir = "??pickdir??"; // using OpenIntent's FileManager: http://www.openintents.org/en/node/159 if ((cmd.getCommandValues().startsWith(strPickFile)) || (cmd.getCommandValues().startsWith(strPickDir))) { // check for additional params in the sub-command CharSequence[] tokens = cmd.getCommandValues().split("\\:"); String strSuggestion = ""; if (tokens.length > 1) { strSuggestion = (String) tokens[1]; }/*from ww w.j a va 2s . c om*/ Intent myIntent = null; if (cmd.getCommandValues().startsWith(strPickFile)) { myIntent = new Intent("org.openintents.action.PICK_FILE"); myIntent.putExtra("org.openintents.extra.TITLE", "Pick a file"); myIntent.putExtra("org.openintents.extra.BUTTON_TEXT", "Pick"); } if (cmd.getCommandValues().startsWith(strPickDir)) { myIntent = new Intent("org.openintents.action.PICK_DIRECTORY"); myIntent.putExtra("org.openintents.extra.TITLE", "Pick a directory"); myIntent.putExtra("org.openintents.extra.BUTTON_TEXT", "Pick"); } if (myIntent == null) { Toast.makeText(getActivity(), "sub-command could not be resolved, check the syntax of your command", Toast.LENGTH_SHORT).show(); return; } if (!strSuggestion.equals("")) { myIntent.setData(Uri.parse("file://" + strSuggestion)); } try { startActivityForResult(myIntent, REQUEST_CODE_PICK_FILE_OR_DIRECTORY); } catch (ActivityNotFoundException e) { // No compatible file manager was found. Toast.makeText(getActivity(), "You must install OpenIntent's FileManager to use this feature", Toast.LENGTH_SHORT).show(); } } else { final CharSequence[] items = cmd.getCommandValues().split("\\|"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Pick a Value"); builder.setCancelable(false); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { String strSelection = (String) items[item]; CharSequence[] tokens = strSelection.split("\\:"); strSelection = (String) tokens[0]; m_myCommand = cmd; // cmd.execute(strSelection); new ExecuteCommandTask().execute(strSelection); Toast.makeText(getActivity(), "Executing " + m_myCommand.getCommand(), Toast.LENGTH_LONG) .show(); //refreshList(); //refreshCommandsCache(); } }); AlertDialog alert = builder.show(); } } else { // ArrayList<String> myRes = m_myCommand.execute(); new ExecuteCommandTask().execute(""); Toast.makeText(getActivity(), "Executing " + m_myCommand.getCommand(), Toast.LENGTH_LONG).show(); // showDialog(myRes); //refreshList(); //refreshCommandsCache(); } }
From source file:edu.missouri.niaaa.ema.activity.AdminManageActivity.java
private Dialog assignConfirmDialog(Context context, String str, boolean startNewWeek) { LayoutInflater inflater = LayoutInflater.from(context); final View textEntryView = inflater.inflate(R.layout.remove_id, null); final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local); rm_check.setText(R.string.assign_new_week); AlertDialog.Builder builder = new AlertDialog.Builder(context); if (startNewWeek) { builder.setView(textEntryView);/*from w w w .ja va2 s . co m*/ } builder.setCancelable(false); builder.setTitle(R.string.assign_confirm_title); builder.setMessage(str); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { editor.putString(Utilities.SP_KEY_LOGIN_USERID, asID.getText().toString()); Log.d("here!!!", "id is " + asID.getText().toString()); //format check editor.putString(Utilities.SP_KEY_LOGIN_USERPWD, ""); editor.putString(Utilities.SP_KEY_LOGIN_STUDY_STARTTIME, "" + Calendar.getInstance().getTimeInMillis()); editor.commit(); //start new study week, if checked if (rm_check.isChecked()) { String UID = null; try { UID = Utilities.encryption(asID.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } ChangeStudyWeek changeStudyWeek = new ChangeStudyWeek(); changeStudyWeek.execute(UID); } setHints(); //continue with set user pin (8) setResult(Activity.RESULT_OK); finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub setHints(); } }); return builder.create(); }
From source file:app.CT.BTCCalculator.fragments.ProfitFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View view = getView();/*from w w w. j av a 2 s. c o m*/ BusProvider.getInstance().register(this); // Initialize text fields. assert view != null; btcBought = (EditText) view.findViewById(R.id.btcBought); btcBoughtPrice = (EditText) view.findViewById(R.id.btcBoughtPrice); btcSell = (EditText) view.findViewById(R.id.btcSell); btcSellPrice = (EditText) view.findViewById(R.id.btcSellPrice); transPercent = (EditText) view.findViewById(R.id.transPercent); feeTransResult = (TextView) view.findViewById(R.id.transFeeCost); subtotalResult = (TextView) view.findViewById(R.id.subtotal); totalProfitResult = (TextView) view.findViewById(R.id.totalProfit); Button calculate = (Button) view.findViewById(R.id.calculate); // EditText element is clicked 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); } }); btcSell.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSoftKeyboard(v); } }); btcSellPrice.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSoftKeyboard(v); } }); 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; } }); btcSellPrice.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; } }); calculate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { float buyAmount, buyCost, sellAmount, sellPrice, subtotalCost, subtotalPrice, subtotal, fee, total; boolean validTrans = true; boolean didItWork = 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(btcSell.getText().toString()); sellPrice = Float.valueOf(btcSellPrice.getText().toString()); feePercent = (Float.valueOf(transPercent.getText().toString())) / 100.0f; if (sellAmount > buyAmount) { // Create new dialog popup. final AlertDialog.Builder alertDialog = new 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(); validTrans = false; } // Calculations to output. subtotalCost = buyAmount * buyCost; subtotalPrice = sellPrice * sellAmount; subtotal = subtotalPrice - subtotalCost; fee = subtotalPrice * feePercent; total = subtotal - fee; if (validTrans) { feeTransResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(fee)))); subtotalResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(subtotal)))); totalProfitResult.setText(String.format("$%s", String.valueOf(roundTwoDecimals(total)))); } } 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:jp.watnow.plugins.dialog.Notification.java
/** * Builds and shows a native Android alert with given Strings * @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 *//* w ww.j av a2 s . c o m*/ public synchronized void list(final String title, final JSONArray data, final CallbackContext callbackContext) { final CordovaInterface cordova = this.cordova; final String[] options = new String[data.length()]; for (int i = 0; i < data.length(); i++) { try { options[i] = data.getString(i); } catch (JSONException e) { e.printStackTrace(); } } Runnable runnable = new Runnable() { public void run() { final JSONObject result = new JSONObject(); AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setTitle(title); dlg.setCancelable(false); dlg.setItems(options, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 1); result.put("selectedIndex", which); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); dlg.setNegativeButton("Cancel", new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); try { result.put("buttonIndex", 0); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); dlg.setOnCancelListener(new AlertDialog.OnCancelListener() { public void onCancel(DialogInterface dialog) { dialog.dismiss(); try { result.put("buttonIndex", 0); } catch (JSONException e) { e.printStackTrace(); } callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, result)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }
From source file:com.mobicage.rogerthat.plugins.messaging.AttachmentViewerActivity.java
@SuppressLint({ "SetJavaScriptEnabled" }) protected void updateView(boolean isUpdate) { T.UI();//from w w w . j av a2s .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:fi.mikuz.boarder.gui.internet.InternetMenu.java
@Override public void onConnectionSuccessful(ConnectionSuccessfulResponse connectionSuccessfulResponse) throws JSONException { ConnectionUtils.connectionSuccessful(InternetMenu.this, connectionSuccessfulResponse); if (ConnectionUtils.checkConnectionId(connectionSuccessfulResponse, InternetMenu.mGetServiceVersionURL)) { mDatabaseVersionChecked = true;//from w w w. ja va 2 s .co m int serviceVersion = connectionSuccessfulResponse.getJSONObject().getInt(ConnectionUtils.returnData); if (serviceVersion == -1) { AlertDialog.Builder builder = new AlertDialog.Builder(InternetMenu.this); builder.setTitle("Maintenance"); builder.setMessage("Boarder web service is under maintenance. Please try again later."); builder.setCancelable(false); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { InternetMenu.this.finish(); } }); builder.show(); } else if (mServiceVersion < serviceVersion) { AlertDialog.Builder builder = new AlertDialog.Builder(InternetMenu.this); builder.setTitle("Old version"); builder.setMessage( "You have an old version of Boarder. Your version is not compatible with Boarder web service.\n\n" + "Please update."); builder.setCancelable(false); builder.setPositiveButton("Update", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ExternalIntent.openGooglePlay(InternetMenu.this); InternetMenu.this.finish(); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { InternetMenu.this.finish(); } }); builder.show(); } } else if (ConnectionUtils.checkConnectionId(connectionSuccessfulResponse, InternetMenu.mGetSessionValidURL)) { mSessionValidityChecked = true; if (connectionSuccessfulResponse.getJSONObject().getInt(InternetMenu.SESSION_VALID_KEY) == 0) { startLogin(); } else { String accountMessage = connectionSuccessfulResponse.getJSONObject() .getString(InternetMenu.ACCOUNT_MESSAGE_KEY); updateAccountMessage(accountMessage); } } afterConnection(); }
From source file:edu.missouri.niaaa.pain.activity.AdminManageActivity.java
private Dialog assignConfirmDialog(final Context context, String str, boolean startNewWeek) { LayoutInflater inflater = LayoutInflater.from(context); final View textEntryView = inflater.inflate(R.layout.remove_id, null); final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local); rm_check.setText(R.string.assign_new_week); AlertDialog.Builder builder = new AlertDialog.Builder(context); if (startNewWeek) { builder.setView(textEntryView);// w w w. j av a 2 s.com } builder.setCancelable(false); builder.setTitle(R.string.assign_confirm_title); builder.setMessage(str); builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { editor.putString(Util.SP_LOGIN_KEY_USERID, asID.getText().toString()); Log.d("here!!!", "id is " + asID.getText().toString()); //format check editor.putString(Util.SP_LOGIN_KEY_USERPWD, ""); editor.putString(Util.SP_LOGIN_KEY_STUDY_STARTTIME, "" + Calendar.getInstance().getTimeInMillis()); editor.commit(); //start new study week, if checked if (rm_check.isChecked()) { String UID = null; try { UID = Util.encryption(context, asID.getText().toString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } ChangeStudyWeek changeStudyWeek = new ChangeStudyWeek(); changeStudyWeek.execute(UID); } setHints(); //continue with set user pin (8) setResult(Activity.RESULT_OK); finish(); } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub setHints(); } }); return builder.create(); }
From source file:jp.watnow.plugins.dialog.Notification.java
/** * Builds and shows a native Android alert with given Strings * @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 *//* w ww .j a v a2s . com*/ 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 = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT); dlg.setMessage(message); dlg.setTitle(title); dlg.setCancelable(false); 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)); } }); changeTextDirection(dlg); }; }; this.cordova.getActivity().runOnUiThread(runnable); }