List of usage examples for android.app AlertDialog dismiss
@Override public void dismiss()
From source file:se.frikod.payday.DailyBudgetFragment.java
public void editBudgetItem(final View v, final int currentIndex) { LayoutInflater inflater = activity.getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.daily_budget_edit_budget_item, null); AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); builder.setTitle(getString(R.string.edit_budget_item_title)); final BudgetItem budgetItem; final EditText titleView = (EditText) dialogView.findViewById(R.id.budget_item_title); final Spinner typeView = (Spinner) dialogView.findViewById(R.id.budget_item_type); final EditText amountView = (EditText) dialogView.findViewById(R.id.budget_item_amount); if (currentIndex == NEW_BUDGET_ITEM) { budgetItem = null;/*from ww w. j av a 2 s. c o m*/ builder.setTitle(getString(R.string.add_budget_item_dialog_title)); builder.setPositiveButton(R.string.add_budget_item, null); } else { builder.setTitle(getString(R.string.edit_budget_item_title)); budgetItem = budget.budgetItems.get(currentIndex); String title = budgetItem.title; BigDecimal amount = budgetItem.amount; int type; if (amount.signum() < 0) { type = 0; amount = amount.negate(); } else { type = 1; } titleView.setText(title); typeView.setSelection(type); amountView.setText(amount.toString()); builder.setNeutralButton(getString(R.string.delete_budget_item_yes), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(100); budget.budgetItems.remove(currentIndex); budget.saveBudgetItems(); updateBudgetItems(); dialog.dismiss(); } }); builder.setPositiveButton(R.string.update_budget_item, null); } builder.setNegativeButton(getString(R.string.delete_budget_item_no), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); /* onClick listener for update needs to be setup like this to prevent closing dialog on error */ final AlertDialog d = builder.create(); d.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { Button b = d.getButton(AlertDialog.BUTTON_POSITIVE); assert b != null; b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { BigDecimal amount; try { amount = new BigDecimal(amountView.getText().toString()); if (typeView.getSelectedItemId() == 0) amount = amount.negate(); } catch (NumberFormatException e) { Toast.makeText(activity.getApplicationContext(), getString(R.string.new_budget_item_no_amount_specified), Toast.LENGTH_SHORT) .show(); return; } String title = titleView.getText().toString(); if (budgetItem != null) { budgetItem.amount = amount; budgetItem.title = title; } else { budget.budgetItems.add(new BudgetItem(title, amount)); } budget.saveBudgetItems(); updateBudgetItems(); d.dismiss(); } }); } }); d.setView(dialogView); d.show(); }
From source file:com.df.app.procedures.CarRecogniseLayout.java
/** * ?//from w ww . ja va 2 s. c o m * @param array * @param mCallback * @throws JSONException */ private void showModelChooseDialog(String[] array, final OnChooseModelFinished mCallback) throws JSONException { array[array.length - 1] = ""; View view1 = ((Activity) getContext()).getLayoutInflater().inflate(R.layout.popup_layout, null); final AlertDialog dialog = new AlertDialog.Builder(getContext()).setView(view1).create(); TableLayout contentArea = (TableLayout) view1.findViewById(R.id.contentArea); final ListView listView = new ListView(view1.getContext()); listView.setAdapter( new ArrayAdapter<String>(view1.getContext(), android.R.layout.simple_list_item_1, array)); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { try { mCallback.onFinished(i); dialog.dismiss(); } catch (JSONException e) { e.printStackTrace(); } } }); contentArea.addView(listView); setTextView(view1, R.id.title, getResources().getString(R.string.select_model)); dialog.show(); }
From source file:cm.aptoide.pt.RemoteInSearch.java
@Override protected void onListItemClick(ListView l, View v, final int position, long id) { super.onListItemClick(l, v, position, id); Vector<String> tmp_get = db.getApk(apk_lst.get(position).apkid); String tmp_path = this.getString(R.string.icons_path) + apk_lst.get(position).apkid; File test_icon = new File(tmp_path); LayoutInflater li = LayoutInflater.from(this); View view = li.inflate(R.layout.alertscroll, null); Builder alrt = new AlertDialog.Builder(this).setView(view); final AlertDialog p = alrt.create(); if (test_icon.exists() && test_icon.length() > 0) { p.setIcon(new BitmapDrawable(tmp_path)); } else {//from w w w .ja v a2s. co m p.setIcon(android.R.drawable.sym_def_app_icon); } p.setTitle(apk_lst.get(position).name); TextView t1 = (TextView) view.findViewById(R.id.n11); t1.setText(tmp_get.firstElement()); TextView t2 = (TextView) view.findViewById(R.id.n22); t2.setText(tmp_get.get(1)); TextView t3 = (TextView) view.findViewById(R.id.n33); t3.setText(tmp_get.get(2)); TextView t4 = (TextView) view.findViewById(R.id.n44); t4.setText(tmp_get.get(3)); TextView t5 = (TextView) view.findViewById(R.id.n55); String tmpi = db.getDescript(apk_lst.get(position).apkid); if (!(tmpi == null)) { t5.setText(tmpi); } else { t5.setText("No info availale on server. Search market by pressing the button below for more info."); } p.setButton2("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { return; } }); if (tmp_get.get(2).equalsIgnoreCase("\tno\n")) { p.setButton(getString(R.string.install), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); new Thread() { public void run() { String apk_pkg = downloadFile(position); if (apk_pkg == null) { Message msg = new Message(); msg.arg1 = 1; download_handler.sendMessage(msg); download_error_handler.sendEmptyMessage(0); } else { installApk(apk_pkg, position); } } }.start(); } }); p.setButton3("Search Market", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + apk_lst.get(position).apkid)); startActivity(intent); } }); } else { p.setButton(getString(R.string.rem), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String apk_pkg = apk_lst.get(position).apkid; removeApk(apk_pkg, position); } }); if (apk_lst.get(position).status == 2) { p.setButton3(getString(R.string.update), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); new Thread() { public void run() { String apk_pkg = downloadFile(position); if (apk_pkg == null) { //Toast.makeText(RemoteInSearch.this, "Could not connect to server!", Toast.LENGTH_LONG).show(); Message msg = new Message(); msg.arg1 = 1; download_handler.sendMessage(msg); download_error_handler.sendEmptyMessage(0); } else { installApk(apk_pkg, position); } } }.start(); } }); } else { p.setButton3("Search Market", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { p.dismiss(); Intent intent = new Intent(); intent.setAction(android.content.Intent.ACTION_VIEW); intent.setData(Uri.parse("market://details?id=" + apk_lst.get(position).apkid)); startActivity(intent); } }); } } p.show(); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
/** * Displays a dialog which informs the user of polar low information in their current position. *///www . j a va 2 s . c o m public void showPolarLowDialog() { boolean success = false; GpsLocationTracker mGpsLocationTracker = new GpsLocationTracker(getContext()); double latitude, longitude = 0; if (mGpsLocationTracker.canGetLocation()) { latitude = mGpsLocationTracker.getLatitude(); longitude = mGpsLocationTracker.getLongitude(); System.out.println("This is lat: " + latitude + "\nThis is lon: " + longitude); } else { mGpsLocationTracker.showSettingsAlert(); return; } // TODO: add polar low API call using current position here. AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog dialog; builder.setTitle(R.string.polar_low); if (success) { // TODO: add results from API call here. builder.setMessage(getText(R.string.check_polar_low_info) + ""); } else { builder.setMessage(R.string.check_polar_low_error); } builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); dialog = builder.create(); dialog.show(); dialog.setCanceledOnTouchOutside(false); }
From source file:org.akvo.caddisfly.sensor.colorimetry.liquid.CalibrateListActivity.java
/** * Load the calibrated swatches from the calibration text file * * @param callback callback to be initiated once the loading is complete *///ww w . j av a2 s . co m private void loadCalibration(@NonNull final Context context, @NonNull final Handler.Callback callback) { try { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(context, R.layout.row_text); final File path = FileHelper.getFilesDir(FileHelper.FileType.CALIBRATION, CaddisflyApp.getApp().getCurrentTestInfo().getId()); File[] listFilesTemp = null; if (path.exists() && path.isDirectory()) { listFilesTemp = path.listFiles(); } final File[] listFiles = listFilesTemp; if (listFiles != null && listFiles.length > 0) { Arrays.sort(listFiles); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }); builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); try { final List<Swatch> swatchList = SwatchHelper.loadCalibrationFromFile(getBaseContext(), fileName); (new AsyncTask<Void, Void, Void>() { @Nullable @Override protected Void doInBackground(Void... params) { SwatchHelper.saveCalibratedSwatches(context, swatchList); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } catch (Exception ex) { AlertUtil.showError(context, R.string.error, getString(R.string.errorLoadingFile), null, R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(@NonNull DialogInterface dialog, int which) { dialog.dismiss(); } }, null, null); } } }); final AlertDialog alertDialog = builder.create(); alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alertDialog.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtil.askQuestion(context, R.string.delete, R.string.deleteConfirm, R.string.delete, R.string.cancel, true, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtil.deleteFile(path, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); alertDialog.dismiss(); Toast.makeText(context, R.string.deleted, Toast.LENGTH_SHORT) .show(); } }, null); return true; } }); } }); alertDialog.show(); } else { AlertUtil.showMessage(context, R.string.notFound, R.string.loadFilesNotAvailable); } } catch (ActivityNotFoundException ignored) { } callback.handleMessage(null); }
From source file:com.ninetwozero.battlelog.fragments.ForumThreadFragment.java
public Dialog generateDialogLinkList(final Context context, final List<String> links) { // Attributes final AlertDialog.Builder builder = new AlertDialog.Builder(context); final LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final View layout = inflater.inflate(R.layout.dialog_thread_link, (ViewGroup) getActivity().findViewById(R.id.dialog_root)); // Set the title builder.setTitle(R.string.info_forum_link_title); // Dialog options builder.setNegativeButton(/*from www . j a va 2 s. c o m*/ android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } } ); // Padding fix final AlertDialog theDialog = builder.create(); theDialog.setView(layout, 0, 0, 0, 0); // Grab the fields ListView listView = (ListView) layout.findViewById(R.id.list_links); listView.setAdapter(new ArrayAdapter<String>(context, R.layout.list_item_plain, android.R.id.text1, links)); listView.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Get the current link String currentLink = links.get(arg2); new AsyncLinkHandling(context).execute(currentLink, sharedPreferences.getString(Constants.SP_BL_PROFILE_CHECKSUM, "")); // Dismiss the dialog theDialog.dismiss(); } } ); return theDialog; }
From source file:com.ubuntuone.android.files.activity.FilesActivity.java
private Dialog buildInsufficientSpaceDialog(long needed, long free) { final String message = String.format(getString(R.string.dialog_no_space_message_fmt), FileUtilities.getHumanReadableSize(needed), FileUtilities.getHumanReadableSize(free)); final AlertDialog dialog = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert) .setTitle(R.string.dialog_no_space_title).setMessage(message) .setPositiveButton(R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); removeDialog(DIALOG_DOWNLOAD_ID); }/* ww w .j a v a2s.c om*/ }).create(); return dialog; }
From source file:com.ubuntuone.android.files.activity.FilesActivity.java
private Dialog buildEmptyDirDialog(final Bundle extras) { final String title = extras.getString(MetaService.EXTRA_NAME); final AlertDialog dialog = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(title).setMessage(R.string.dialog_nothing_to_download) .setPositiveButton(R.string.ok, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); removeDialog(DIALOG_EMPTY_DIRECTORY_ID); }/*from w w w. j a va 2 s . c om*/ }).create(); return dialog; }
From source file:com.oasis.sdk.activity.GooglePlayBillingActivity.java
/** * ??????//ww w. j a v a 2s. co m * @param purchase */ void alert(final Purchase purchase) { final AlertDialog d = new AlertDialog.Builder(this).create(); d.show(); d.setContentView(BaseUtils.getResourceValue("layout", "oasisgames_sdk_common_dialog_notitle")); d.setCanceledOnTouchOutside(false); d.setCancelable(false); TextView retry = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_sure")); retry.setText(getResources() .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_alert_retry"))); retry.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // ? d.dismiss(); setWaitScreen(true); check(purchase); } }); TextView close = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_cancle")); close.setText(getResources() .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_alert_close"))); close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { d.dismiss(); setResultInfo(OASISPlatformConstant.RESULT_EXCEPTION_GOOGLEPAY_EXCEPTION, "?????"); close(); } }); TextView content = (TextView) d .findViewById(BaseUtils.getResourceValue("id", "oasisgames_sdk_common_dialog_notitle_content")); content.setText(getResources() .getString(BaseUtils.getResourceValue("string", "oasisgames_sdk_pay_google_notice_alert_content"))); }
From source file:com.picogram.awesomeness.SettingsActivity.java
public boolean onPreferenceClick(final Preference preference) { if (preference.getKey().equals("statistics")) { //TODO//from w w w .j ava 2 s .co m Crouton.makeText(this, "This is not yet implemented", Style.INFO).show(); final AlertDialog dialog = new AlertDialog.Builder(this).create(); final String[] scoresTitles = new String[] { "Games Played", "Games Won", "Taps", "Taps per Puzzle", "Tapes per Minute", "Times Played" }; final int gamesPlayed = 0, gamesWon = 0, taps = 0, tapsPerPuzzle = 0, tapsPerMinute = 0, timePlayed = 0; final int[] scores = { gamesPlayed, gamesWon, taps, tapsPerPuzzle, tapsPerMinute, timePlayed }; // TODO: Implement the preferences and what not. final LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.VERTICAL); for (int i = 0; i != scores.length; ++i) { final LinearLayout sub = new LinearLayout(this); sub.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT)); sub.setOrientation(LinearLayout.HORIZONTAL); TextView tv = new TextView(this); tv.setLayoutParams(new TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); tv.setText(scoresTitles[i]); sub.addView(tv); tv = new TextView(this); tv.setLayoutParams(new TableLayout.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); tv.setText(scores[i] + ""); sub.addView(tv); ll.addView(sub); } dialog.setView(ll); dialog.setButton("OK", new DialogInterface.OnClickListener() { public void onClick(final DialogInterface dialog, final int which) { dialog.dismiss(); } }); dialog.getWindow().getAttributes().windowAnimations = R.style.DialogTheme; dialog.show(); dialog.dismiss(); return true; } else if (preference.getKey().equals("changelog")) { // Launch change log dialog final ChangeLogDialog _ChangelogDialog = new ChangeLogDialog(this); _ChangelogDialog.show(); } else if (preference.getKey().equals("licenses")) { // Launch the licenses stuff. Dialog ld = new LicensesDialog(this, R.raw.licenses, false, false).create(); ld.getWindow().getAttributes().windowAnimations = R.style.DialogTheme; ld.show(); } else if (preference.getKey().equals("email")) { final String email = "warner.73+Picogram@wright.edu"; final String subject = "Picogram - <SUBJECT>"; final String message = "Picogram,\n\n<MESSAGE>"; // Contact me. final Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] { email }); emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject); emailIntent.putExtra(Intent.EXTRA_TEXT, message); emailIntent.setType("message/rfc822"); this.startActivity(Intent.createChooser(emailIntent, "Send Mail Using :")); overridePendingTransition(R.anim.fadein, R.anim.exit_left); } else if (preference.getKey().equals("rateapp")) { // TODO fix this when we publish. this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=Picogram"))); overridePendingTransition(R.anim.fadein, R.anim.exit_left); final Editor editor = this.prefs.edit(); editor.putBoolean(RateMeMaybe.PREF.DONT_SHOW_AGAIN, true); editor.commit(); } else if (preference.getKey().equals("logoutgoogle")) { //TODO Crouton.makeText(this, "This is not currently supported.", Style.INFO).show(); } else if (preference.getKey().equals("logoutfacebook")) { //TODO Crouton.makeText(this, "This is not currently supported.", Style.INFO).show(); } else if (preference.getKey().equals("resetusername")) { Util.getPreferences(this).edit().putString("username", "").commit(); Util.getPreferences(this).edit().putBoolean("hasLoggedInUsername", false).commit(); } return false; }