List of usage examples for android.content DialogInterface cancel
void cancel();
From source file:applab.search.client.SynchronizationManager.java
/** * Show an error dialog that allows the user to either choose "Retry" to attempt synchronization again, or "Cancel" * to abandon the process//w w w . j av a 2s . c o m */ private void showErrorDialog(int errorText) { // if the progress dialog is still showing, remove it since // we're replacing the UI with an error dialog ProgressDialogManager.tryDestroyProgressDialog(); // For retries we don't need to claim the lock, since we already have it DialogInterface.OnClickListener onClickRetry = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); startSynchronization(currentContext, completionCallback); } }; // for the error-out case, release the lock and we'll try again later DialogInterface.OnClickListener onClickCancel = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); SynchronizationManager.completeSynchronization(); } }; ErrorDialogManager.show(errorText, this.currentContext, onClickRetry, "Retry", onClickCancel, "Cancel"); }
From source file:com.android.gallery3d.app.AbstractGalleryActivity.java
@Override protected void onStart() { super.onStart(); if (getExternalCacheDir() == null) { OnCancelListener onCancel = new OnCancelListener() { @Override/* w ww.j a va 2 s.co m*/ public void onCancel(DialogInterface dialog) { finish(); } }; OnClickListener onClick = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }; AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(R.string.no_external_storage_title) .setMessage(R.string.no_external_storage).setNegativeButton(android.R.string.cancel, onClick) .setOnCancelListener(onCancel); if (ApiHelper.HAS_SET_ICON_ATTRIBUTE) { setAlertDialogIconAttribute(builder); } else { builder.setIcon(android.R.drawable.ic_dialog_alert); } mAlertDialog = builder.show(); registerReceiver(mMountReceiver, mMountFilter); } mPanoramaViewHelper.onStart(); }
From source file:com.safecell.ManageProfile_Activity.java
private boolean updateProfile() { profileResponse = accountUpdatetoProfile(); dialogDismiss = false;/*from www .ja v a 2s.co m*/ if (profileResponse != null) { UpdateAccountsDetailsResponseHandler updateAccountsDetailsResponseHandler = new UpdateAccountsDetailsResponseHandler( context); updateAccountsDetailsResponseHandler.updateAccountResponse(profileResponse); dialogDismiss = true; } else { dialogDismiss = true; new AlertDialog.Builder(context).setMessage(message) .setNeutralButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); } return dialogDismiss; }
From source file:com.example.amapapplicationtest.MainActivity.java
public void onProviderDisabled(String provider) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Phone is in airplane mode"); builder.setCancelable(false);//from ww w. ja v a 2 s . c o m builder.setPositiveButton("Enable GPS", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Intent startGps = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(startGps); } }); builder.setNegativeButton("Leave GPS off", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.actinarium.kinetic.ui.ResultsFragment.java
/** * Called when either X button or Back button is pressed *//*w w w . jav a 2 s . com*/ void onDiscard() { new AlertDialog.Builder(getContext()).setMessage(R.string.dialog_discard_message) .setPositiveButton(R.string.discard, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mHost.onRecordingDiscarded(); } }).setNegativeButton(R.string.keep_editing, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).show(); }
From source file:app.CT.BTCCalculator.fragments.ProfitFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); View view = getView();/* w w w.ja va 2s. c om*/ 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:com.example.haber.ui.activity.CallActivity.java
private void showBWselected(final MenuItem item) { if (dialog == null) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("").setSingleChoiceItems(callBWs, -1, new DialogInterface.OnClickListener() { @Override//from www. j a v a2 s . co m public void onClick(DialogInterface dialog, int which) { currentDefaultBW = Integer.parseInt(callBWs[which]); item.setTitle("" + currentDefaultBW); dialog.cancel(); } }); dialog = builder.show(); } else { dialog.show(); } }
From source file:com.ideabytes.dgsms.ca.HomeActivity.java
/** * Show alert to handle apk update/*from ww w. ja v a 2s. c o m*/ * @param message * @param code */ private void showAlertOnUpdate(final String message, final int code) { android.app.AlertDialog.Builder builder; builder = new android.app.AlertDialog.Builder(HomeActivity.this); builder.setTitle(Utils.getResString(getApplicationContext(), R.string.Dialog_Alert_Title)); builder.setMessage(message); builder.setCancelable(false); //when 404 show only one button,else two buttons means no force update if (code != 404) { builder.setPositiveButton(Utils.getResString(getApplicationContext(), R.string.btn_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { MyAppData.getInstance().setApkUpdated(false); dialog.cancel(); } }); } builder.setNegativeButton(Utils.getResString(getApplicationContext(), R.string.btn_update), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String url = ""; if (NetworkUtil.getConnectivityStatus(getApplicationContext()) != 0) { url = "https://play.google.com/store/apps/details?id=com.ideabytes.dgsms.landstar"; if (APP_NAME.equalsIgnoreCase("DGMOBI_US_GENERIC")) { url = "https://play.google.com/store/apps/details?id=com.ideabytes.dgsms.generic"; } Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); MyAppData.getInstance().setApkUpdated(false); dialog.cancel(); } else { //show alert to user to connect network AlertDialog alertDialog = new AlertDialog(HomeActivity.this); alertDialog.showDialg(Utils.getResString(R.string.alert_msg_conn_nw)); } } }); android.app.AlertDialog alertDialog = builder.create(); alertDialog.show(); }
From source file:ch.ethz.twimight.activities.TwimightBaseActivity.java
/** * Asks the user if she really want to log out *//* www .j ava 2 s . co m*/ private void showLogoutDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage(R.string.logout_question).setCancelable(false) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { LoginActivity.logout(TwimightBaseActivity.this.getApplicationContext()); finish(); } }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); }
From source file:com.safecell.AccountFormActivity.java
private void selectLicenseFromDialog() { if (licenseProgressDialog.isShowing() == false && scLicenseArrayList.size() > 0) { final CharSequence[] items = new CharSequence[scLicenseArrayList.size()]; for (int i = 0; i < scLicenseArrayList.size(); i++) { items[i] = scLicenseArrayList.get(i).getName(); }// w w w. ja va 2 s. co m new AlertDialog.Builder(AccountFormActivity.this).setTitle("Select Licenses") .setSingleChoiceItems(items, licensesSelectIndex, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { licensesButton.setText(items[item]); licensesSelectIndex = item; dialog.cancel(); } }).show(); } }