List of usage examples for android.app AlertDialog getListView
public ListView getListView()
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 *//*from www .ja v a2 s . c o 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:nl.spellenclubeindhoven.dominionshuffle.SelectActivity.java
@Override protected void onPrepareDialog(int id, Dialog dialog) { if (DIALOG_MINIMUM <= id && id <= DIALOG_MINIMUM + dialogMimimumCount) { AlertDialog alertDialog = (AlertDialog) dialog; ListView list = alertDialog.getListView(); int pos;/*from w ww . j ava2 s.co m*/ if (cardSelector.getCondition(selectedGroup) == null) { pos = cardSelector.getLimitMinimum(selectedGroup); if (pos >= 1) pos++; } else { pos = 1; } list.clearChoices(); list.setItemChecked(pos, true); list.setSelectionFromTop(pos, list.getHeight() / 2); } else if (DIALOG_MAXIMUM <= id && id <= DIALOG_MAXIMUM + dialogMaximumCount) { AlertDialog alertDialog = (AlertDialog) dialog; ListView list = alertDialog.getListView(); int pos = cardSelector.getLimitMaximum(selectedGroup); list.clearChoices(); list.setItemChecked(pos, true); list.setSelectionFromTop(pos, list.getHeight() / 2); } switch (id) { case DIALOG_SOLVE_ERROR: { AlertDialog alertDialog = (AlertDialog) dialog; alertDialog.setMessage(dialogMessage); break; } default: break; } super.onPrepareDialog(id, dialog); }
From source file:com.ADORCE.controls.MainViewActivity.java
private void showThemeChooserDialog() { AlertDialog.Builder b = new AlertDialog.Builder(this); Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice, getResources().getStringArray(R.array.theme_items)); b.setTitle(getString(R.string.theme_chooser_dialog_title)).setSingleChoiceItems((ListAdapter) adapter, PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0), new DialogInterface.OnClickListener() { @Override// w w w. j a v a2 s. co m public void onClick(DialogInterface dialog, int which) { //Invokes method initTheme(int) - next method based on chosen theme initTheme(which); } }); AlertDialog d = b.create(); d.show(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = this.getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setTextColor(typedValue.data); Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE); ok.setTextColor(typedValue.data); d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); ListView lv = d.getListView(); int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding)); int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding)); lv.setPadding(0, paddingTop, 0, paddingBottom); }
From source file:org.inaturalist.android.GuideDetails.java
private void showEditDownloadDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); // Set the adapter String[] items = { getResources().getString(R.string.delete_download), getResources().getString(R.string.re_download), getResources().getString(R.string.cancel) }; builder.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items), null); final AlertDialog alertDialog = builder.create(); ListView listView = alertDialog.getListView(); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w.j a v a 2 s.c o m*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { alertDialog.dismiss(); if (position == 0) { // Delete download mGuideXml.deleteOfflineGuide(); refreshGuideSideMenu(); } else if (position == 1) { // Re-download mGuideXml.deleteOfflineGuide(); downloadGuide(); } else { // Cancel } } }); alertDialog.show(); }
From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_SEARCH: mBottomBarControls.showSearch(true); return true; case MENU_PLAYBACK: openPlaybackActivity();//from www . j a v a2 s .c o m return true; case MENU_SORT: { MediaAdapter adapter = (MediaAdapter) mCurrentAdapter; LinearLayout header = (LinearLayout) getLayoutInflater().inflate(R.layout.sort_dialog, null); CheckBox reverseSort = (CheckBox) header.findViewById(R.id.reverse_sort); int[] itemIds = adapter.getSortEntries(); String[] items = new String[itemIds.length]; Resources res = getResources(); for (int i = itemIds.length; --i != -1;) { items[i] = res.getString(itemIds[i]); } int mode = adapter.getSortMode(); if (mode < 0) { mode = ~mode; reverseSort.setChecked(true); } AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.sort_by); builder.setSingleChoiceItems(items, mode + 1, this); // add 1 for header builder.setNeutralButton(R.string.done, null); AlertDialog dialog = builder.create(); dialog.getListView().addHeaderView(header); dialog.setOnDismissListener(this); dialog.show(); return true; } default: return super.onOptionsItemSelected(item); } }
From source file:com.nttec.everychan.ui.NewTabFragment.java
private void openChansList() { final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) { private LayoutInflater inflater = LayoutInflater.from(activity); private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f); {/* ww w . j a v a 2s . com*/ for (ChanModule chan : MainApplication.getInstance().chanModulesList) add(chan); } @Override public View getView(int position, View convertView, ViewGroup parent) { ChanModule chan = getItem(position); TextView view = (TextView) (convertView == null ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false) : convertView); view.setText(chan.getDisplayingName()); view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null); view.setCompoundDrawablePadding(drawablePadding); return view; } }; DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ChanModule chan = chansAdapter.getItem(which); UrlPageModel model = new UrlPageModel(); model.chanName = chan.getChanName(); model.type = UrlPageModel.TYPE_INDEXPAGE; openNewTab(chan.buildUrl(model)); } }; final AlertDialog chansListDialog = new AlertDialog.Builder(activity) .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected) .setNegativeButton(android.R.string.cancel, null).create(); chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() { @SuppressLint("InlinedApi") @Override public boolean onMenuItemClick(MenuItem item) { final ChanModule chan = chansAdapter .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position); switch (item.getItemId()) { case R.id.context_menu_favorites_from_fragment: if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null, null)) { MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null, null, null); } else { try { UrlPageModel indexPage = new UrlPageModel(); indexPage.chanName = chan.getChanName(); indexPage.type = UrlPageModel.TYPE_INDEXPAGE; MainApplication.getInstance().database.addFavorite(chan.getChanName(), null, null, null, chan.getChanName(), chan.buildUrl(indexPage)); } catch (Exception e) { Logger.e(TAG, e); } } return true; case R.id.context_menu_quickaccess_add: QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); return true; case R.id.context_menu_quickaccess_custom_board: LinearLayout dialogLayout = new LinearLayout(activity); dialogLayout.setOrientation(LinearLayout.VERTICAL); final EditText boardField = new EditText(activity); final EditText descriptionField = new EditText(activity); boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode); descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc); LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); dialogLayout.addView(boardField, fieldsParams); dialogLayout.addView(descriptionField, fieldsParams); DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String boardName = boardField.getText().toString(); for (QuickAccess.Entry entry : list) if (entry.boardName != null && entry.chan != null) if (entry.chan.getChanName().equals(chan.getChanName()) && entry.boardName.equals(boardName)) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_already_exists, Toast.LENGTH_LONG).show(); return; } try { if (boardName.trim().length() == 0) throw new Exception(); UrlPageModel boardPageModel = new UrlPageModel(); boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE; boardPageModel.chanName = chan.getChanName(); boardPageModel.boardName = boardName; boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE; chan.buildUrl(boardPageModel); //, ?? ? } catch (Exception e) { Toast.makeText(activity, R.string.newtab_quickaccess_addcustom_incorrect_code, Toast.LENGTH_LONG).show(); return; } QuickAccess.Entry newEntry = new QuickAccess.Entry(); newEntry.chan = chan; newEntry.boardName = boardName; newEntry.boardDescription = descriptionField.getText().toString(); list.add(0, newEntry); adapter.notifyDataSetChanged(); saveQuickAccessToPreferences(); chansListDialog.dismiss(); } }; new AlertDialog.Builder(activity) .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title, chan.getChanName())) .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked) .setNegativeButton(android.R.string.cancel, null).show(); return true; } return false; } }; String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position) .getChanName(); boolean canAddToQuickAccess = true; for (QuickAccess.Entry entry : list) if (entry.boardName == null && entry.chan != null && entry.chan.getChanName().equals(thisChanName)) { canAddToQuickAccess = false; break; } menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1, MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null) ? R.string.context_menu_remove_favorites : R.string.context_menu_add_favorites) .setOnMenuItemClickListener(contextMenuHandler); menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add) .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess); menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3, R.string.context_menu_quickaccess_custom_board) .setOnMenuItemClickListener(contextMenuHandler); if (isSingleboardChan( chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position))) menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false); } }); chansListDialog.show(); }
From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case MENU_SEARCH: mBottomBarControls.showSearch(true); break;//from w w w.j a v a2 s . c om case MENU_PLAYBACK: openPlaybackActivity(); break; case MENU_GO_HOME: mPagerAdapter.setLimiter(FileSystemAdapter.buildHomeLimiter(getApplicationContext())); updateLimiterViews(); break; case MENU_SORT: { SortableAdapter adapter = (SortableAdapter) mCurrentAdapter; LinearLayout list = (LinearLayout) getLayoutInflater().inflate(R.layout.sort_dialog, null); CheckBox reverseSort = (CheckBox) list.findViewById(R.id.reverse_sort); int[] itemIds = adapter.getSortEntries(); String[] items = new String[itemIds.length]; Resources res = getResources(); for (int i = 0; i < itemIds.length; i++) { items[i] = res.getString(itemIds[i]); } int mode = adapter.getSortModeIndex(); reverseSort.setChecked(adapter.isSortDescending()); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.sort_by); builder.setSingleChoiceItems(items, mode, this); builder.setPositiveButton(R.string.done, null); AlertDialog dialog = builder.create(); dialog.getListView().addFooterView(list); dialog.setOnDismissListener(this); dialog.show(); break; } default: return super.onOptionsItemSelected(item); } return true; }
From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java
@Override protected void onPrepareDialog(int id, Dialog dialog) { switch (id) { case TIME_DIALOG_ID: ((TimePickerDialog) dialog).updateTime(mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE)); break;/* w w w. j a v a 2s .c o m*/ case DATE_DIALOG_ID: ((DatePickerDialog) dialog).updateDate(mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH)); break; case DIALOG_MULTIPLE_CATEGORY: final AlertDialog alert = (AlertDialog) dialog; final ListView list = alert.getListView(); // been // selected, then uncheck // selected categories if (mVectorCategories.size() > 0) { for (String s : mVectorCategories) { try { // @inoran fix if (list != null) { list.setItemChecked(mCategoryLength - Integer.parseInt(s), true); } } catch (NumberFormatException e) { log("NumberFormatException", e); } } } else { if (list != null) { list.clearChoices(); } } break; } }
From source file:com.hctrom.romcontrol.MainViewActivity.java
private void showThemeChooserDialog() { AlertDialog.Builder b = new AlertDialog.Builder(this); Adapter adapter = new ArrayAdapter<>(this, R.layout.simple_list_item_single_choice, getResources().getStringArray(R.array.theme_items)); b.setIcon(R.drawable.ic_htc_personalize).setTitle(getString(R.string.theme_chooser_dialog_title)) .setSingleChoiceItems((ListAdapter) adapter, PreferenceManager.getDefaultSharedPreferences(this).getInt("theme_prefs", 0), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //Invokes method initTheme(int) - next method based on chosen theme initTheme(which); }//from ww w . ja v a 2 s.co m }); AlertDialog d = b.create(); d.show(); TypedValue typedValue = new TypedValue(); Resources.Theme theme = this.getTheme(); theme.resolveAttribute(R.attr.colorAccent, typedValue, true); Button cancel = d.getButton(AlertDialog.BUTTON_NEGATIVE); cancel.setTextColor(typedValue.data); Button ok = d.getButton(AlertDialog.BUTTON_POSITIVE); ok.setTextColor(typedValue.data); d.getWindow().setBackgroundDrawableResource(R.drawable.dialog_bg); ListView lv = d.getListView(); int paddingTop = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_top_padding)); int paddingBottom = Math.round(this.getResources().getDimension(R.dimen.dialog_listView_bottom_padding)); lv.setPadding(0, paddingTop, 0, paddingBottom); }
From source file:org.apps8os.motivator.ui.MoodHistoryActivity.java
/** * Actions for the menu items.//w w w . j a v a 2 s . co m */ @Override public boolean onOptionsItemSelected(MenuItem item) { MoodHistoryWeekFragment weekFragment; switch (item.getItemId()) { // Search functionality for the search button case R.id.mood_history_search: // Spawn a dialog fragment so that the user can select a day. DialogFragment dialog = new DatePickerFragment(); dialog.show(getFragmentManager(), "datePicker"); return true; case R.id.mood_history_attribute_drinking: // Setting the selected attribute in landscape view. mSelectedAttribute = DayInHistory.AMOUNT_OF_DRINKS; weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem()); weekFragment.updateSelectedAttribute(DayInHistory.AMOUNT_OF_DRINKS, false); return true; case R.id.mood_history_attribute_moods: mSelectedAttribute = DayInHistory.MOODS; weekFragment = mPagerAdapterWeek.getWeekFragment(mViewPager.getCurrentItem()); weekFragment.updateSelectedAttribute(DayInHistory.MOODS, false); return true; case R.id.mood_history_change_sprint: // Spawn a dialog where the user can select the sprint depicted in this history. AlertDialog.Builder builder = new AlertDialog.Builder(this); final Sprint[] sprints = new SprintDataHandler(this).getSprints(); // Get the string representations of the sprints. String[] sprintsAsString = new String[sprints.length]; for (int i = 0; i < sprints.length; i++) { sprintsAsString[i] = sprints[i].getSprintTitle() + " " + sprints[i].getStartTimeInString(this); } builder.setTitle(getString(R.string.select_sprint)).setSingleChoiceItems(sprintsAsString, sprints.length - 1, null); final AlertDialog alertDialog = builder.create(); final Activity thisActivity = this; alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Start this activity again with the selected sprint as the passed Parcelable Sprint. // This is done so that the activity can update itself to the selected sprint. mCurrentSprint = sprints[alertDialog.getListView().getCheckedItemPosition()]; Intent intent = new Intent(thisActivity, MoodHistoryActivity.class); intent.putExtra(Sprint.CURRENT_SPRINT, mCurrentSprint); startActivity(intent); alertDialog.dismiss(); thisActivity.finish(); } }); alertDialog.show(); default: return super.onOptionsItemSelected(item); } }