List of usage examples for android.widget ArrayAdapter addAll
public void addAll(T... items)
From source file:org.matrix.console.fragments.ConsoleMessageListFragment.java
private void save(final Message message, final String mediaUrl, final String mediaMimeType) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); builderSingle.setTitle(getActivity().getText(R.string.save_files_in)); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.dialog_room_selection); ArrayList<String> entries = new ArrayList<String>(); entries.add(getActivity().getText(R.string.downloads).toString()); if ((null == mediaMimeType) || mediaMimeType.startsWith("image/")) { entries.add(getActivity().getText(R.string.gallery).toString()); }//from w w w .ja va 2 s . c o m if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { entries.add(getActivity().getText(R.string.other).toString()); } arrayAdapter.addAll(entries); final ArrayList<String> fEntries = entries; builderSingle.setNegativeButton(getActivity().getText(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, final int which) { dialog.dismiss(); MXMediasCache cache = getMXMediasCache(); File cacheFile = cache.mediaCacheFile(mediaUrl, mediaMimeType); String entry = fEntries.get(which); String savedFilename = null; if (getActivity().getText(R.string.gallery).toString().equals(entry)) { // save in the gallery savedFilename = CommonActivityUtils.saveImageIntoGallery(getActivity(), cacheFile); } else if (getActivity().getText(R.string.downloads).toString().equals(entry)) { String filename = null; if (message instanceof FileMessage) { filename = ((FileMessage) message).body; } // save into downloads savedFilename = CommonActivityUtils.saveMediaIntoDownloads(getActivity(), cacheFile, filename, mediaMimeType); } else { if (getActivity() instanceof RoomActivity) { ((RoomActivity) getActivity()).createDocument(message, mediaUrl, mediaMimeType); } } if (null != savedFilename) { final String fSavedFilename = new File(savedFilename).getName(); getActivity().runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(getActivity(), getActivity().getString(R.string.file_is_saved, fSavedFilename), Toast.LENGTH_SHORT).show(); } }); } } }); // GA issue // can not perform this action after onSaveInstanceState.... // it seems that the linked activity is stopped. try { builderSingle.show(); } catch (Exception e) { } }
From source file:com.esri.arcgisruntime.sample.offlinegeocode.MainActivity.java
private void setSearchView() { mSearchview = (SearchView) findViewById(R.id.searchView1); mSearchview.setIconifiedByDefault(true); mSearchview.setQueryHint(getResources().getString(R.string.search_hint)); mSearchview.setOnQueryTextListener(new OnQueryTextListener() { @Override/*from w ww . j a v a 2 s . co m*/ public boolean onQueryTextSubmit(String query) { hideKeyboard(); geoCodeTypedAddress(query); mSearchview.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); mSpinner = (Spinner) findViewById(R.id.spinner); // Create an ArrayAdapter using the string array and a default spinner layout final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_dropdown_item) { @Override public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); if (position == getCount()) { mSearchview.clearFocus(); } return v; } @Override public int getCount() { return super.getCount() - 1; // you dont display last item. It is used as hint. } }; // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); adapter.addAll(getResources().getStringArray(R.array.suggestion_items)); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // set vertical offset to spinner dropdown for API less than 21 mSpinner.setDropDownVerticalOffset(80); } // Apply the adapter to the spinner mSpinner.setAdapter(adapter); mSpinner.setSelection(adapter.getCount()); mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (position == adapter.getCount()) { mSearchview.clearFocus(); } else { hideKeyboard(); mSearchview.setQuery(getResources().getStringArray(R.array.suggestion_items)[position], false); geoCodeTypedAddress(getResources().getStringArray(R.array.suggestion_items)[position]); mSearchview.setIconified(false); mSearchview.clearFocus(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:it.iziozi.iziozi.gui.IOBoardActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.action_settings: { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); View layoutView = inflater.inflate(R.layout.settings_layout, null); Integer rows = mActualLevel.getBoardAtIndex(mActualIndex).getRows(); Integer columns = mActualLevel.getBoardAtIndex(mActualIndex).getCols(); final CheckBox bordersCheckbox = (CheckBox) layoutView.findViewById(R.id.bordersCheckbox); bordersCheckbox.setChecked(mActiveConfig.getShowBorders()); builder.setTitle(getResources().getString(R.string.settings)).setView(layoutView).setPositiveButton( getResources().getString(R.string.apply), new DialogInterface.OnClickListener() { @Override/*from w ww . j ava 2 s.c om*/ public void onClick(DialogInterface dialog, int which) { if (newCols == 0) newCols++; if (newRows == 0) newRows++; mActualLevel.getBoardAtIndex(mActualIndex).setCols(newCols); mActualLevel.getBoardAtIndex(mActualIndex).setRows(newRows); IOBoardActivity.this.mActiveConfig.setShowBorders(bordersCheckbox.isChecked()); //TODO:createView(); refreshView(); } }).setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("dialog", "dismiss and discard"); } }); SeekBar sRows = (SeekBar) layoutView.findViewById(R.id.seekRows); SeekBar sCols = (SeekBar) layoutView.findViewById(R.id.seekCols); final TextView rowsLbl = (TextView) layoutView.findViewById(R.id.numRowsLbl); final TextView colsLbl = (TextView) layoutView.findViewById(R.id.numColsLbl); sRows.setProgress(rows); sCols.setProgress(columns); newRows = rows; newCols = columns; rowsLbl.setText("" + rows); colsLbl.setText("" + columns); sRows.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (seekBar.getProgress() == 0) seekBar.setProgress(1); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.d("seeking", "seek rows " + progress); newRows = progress; rowsLbl.setText("" + progress); } }); sCols.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { if (seekBar.getProgress() == 0) seekBar.setProgress(1); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { Log.d("seeking", "seek cols " + progress); newCols = progress; colsLbl.setText("" + progress); } }); builder.create().show(); break; } case R.id.editMode: { Log.d("options menu", "edit mode selected"); item.setChecked(!item.isChecked()); toggleEditing(); break; } case R.id.scanMode: { Log.d("options menu", "scan mode selected"); item.setChecked(!item.isChecked()); IOGlobalConfiguration.isScanMode = item.isChecked(); if (IOGlobalConfiguration.isScanMode) startScanMode(); else stopScanMode(); break; } case R.id.action_new: { new AlertDialog.Builder(this).setTitle(getResources().getString(R.string.warning)) .setMessage(getString(R.string.new_board_alert)) .setPositiveButton(getResources().getString(R.string.yes), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { FragmentManager fm = getSupportFragmentManager(); while (fm.getBackStackEntryCount() > 0) fm.popBackStackImmediate(); mActiveConfig = new IOConfiguration(); fm.beginTransaction() .replace(mFrameLayout.getId(), IOPaginatedBoardFragment.newInstance(mActiveConfig.getLevel())) .commit(); if (!IOGlobalConfiguration.isEditing) toggleEditing(); } }) .setNegativeButton(getResources().getString(R.string.cancel), null).setCancelable(false) .create().show(); break; } case R.id.action_save: { if (null == mActualConfigName) IOBoardActivity.this.mActiveConfig.save(); else IOBoardActivity.this.mActiveConfig.saveAs(mActualConfigName); break; } case R.id.action_save_as: { final AlertDialog.Builder alert = new AlertDialog.Builder(this); View contentView = getLayoutInflater().inflate(R.layout.rename_alert_layout, null); final EditText inputText = (EditText) contentView.findViewById(R.id.newNameEditText); alert.setView(contentView); alert.setPositiveButton(getString(R.string.confirm), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = inputText.getText().toString().trim(); if (value.indexOf(".xml") != -1) value = value.replace(".xml", ""); File dirFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), IOApplication.APPLICATION_NAME + "/boards"); File file = new File(dirFile.toString(), value + ".xml"); if (file.exists()) { dialog.cancel(); new AlertDialog.Builder(IOBoardActivity.this).setTitle(getString(R.string.warning)) .setMessage(getString(R.string.file_already_exists)) .setPositiveButton(getString(R.string.continue_string), null).create().show(); } else { IOBoardActivity.this.mActiveConfig.saveAs(value); mActualConfigName = value; } } }); alert.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { dialog.cancel(); } }); alert.show(); break; } case R.id.action_load: { File dirFile = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), IOApplication.APPLICATION_NAME + "/boards"); if (!dirFile.exists()) dirFile.mkdirs(); final String[] configFiles = dirFile.list(new FilenameFilter() { @Override public boolean accept(File dir, String filename) { if (filename.indexOf(".xml") != -1) return true; return false; } }); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.select_dialog_item); adapter.addAll(configFiles); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getResources().getString(R.string.choose)) .setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.d("media_debug", "click on item " + which); String fileName = configFiles[which]; Log.d("board_debug", fileName); FragmentManager fm = getSupportFragmentManager(); while (fm.getBackStackEntryCount() > 0) fm.popBackStackImmediate(); mActiveConfig = IOConfiguration.getSavedConfiguration(fileName); fm.beginTransaction() .replace(mFrameLayout.getId(), IOPaginatedBoardFragment.newInstance(mActiveConfig.getLevel())) .commit(); } }).setNegativeButton(getResources().getString(R.string.cancel), null).create().show(); break; } case R.id.action_about: { Intent aboutIntent = new Intent(getApplicationContext(), IOAboutActivity.class); startActivity(aboutIntent); break; } case R.id.action_exit: { finish(); break; } case R.id.action_lock: { if (IOGlobalConfiguration.isEditing) toggleEditing(); lockUI(); break; } default: break; } return super.onOptionsItemSelected(item); }
From source file:de.gebatzens.sia.dialog.FilterDialog.java
@Override public void onResume() { super.onResume(); final AlertDialog d = (AlertDialog) getDialog(); final Filter.FilterList list = SIAApp.SIA_APP.filters; final AutoCompleteTextView ed = (AutoCompleteTextView) d.findViewById(R.id.filter_text); final AppCompatSpinner spinner = (AppCompatSpinner) d.findViewById(R.id.filter_spinner); final CheckBox cb = (CheckBox) d.findViewById(R.id.checkbox_contains); final TextView label = (TextView) d.findViewById(R.id.filter_label); final TextWatcher watcher; ed.setSelectAllOnFocus(true);// w ww. ja va2s .c o m if (isMainFilterDialog()) { ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, new String[] { getString(R.string.school_class), getString(R.string.teacher) }); spinner.setAdapter(adapter); if (getMainFilterPosition() == -1) { ed.setText(""); Subst.GGPlans plans = (Subst.GGPlans) SIAApp.SIA_APP.school.fragments .getByType(FragmentData.FragmentType.PLAN).get(0).getData(); //could confuse people /*if(plans != null) { ed.setAdapter(new ArrayAdapter<String>(ed.getContext(), android.R.layout.simple_dropdown_item_1line, plans.getAllClasses())); }*/ spinner.setSelection(0); } else { ed.setText(list.including.get(getMainFilterPosition()).getFilter()); spinner.setSelection( list.including.get(getMainFilterPosition()).getType() == Filter.FilterType.CLASS ? 0 : 1); } cb.setVisibility(View.GONE); label.setVisibility(View.GONE); } else { ed.setHint(getString(R.string.subject_course_name)); ArrayAdapter<Filter.IncludingFilter> adapter = new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item); adapter.addAll(list.including); spinner.setAdapter(adapter); cb.setEnabled(true); cb.setText(getString(R.string.all_subjects_including_disabled)); int p = getUpdatePosition(); if (p != -1) { Filter.ExcludingFilter f = list.including.get(getMainFilterPosition()).excluding .get(getUpdatePosition()); cb.setChecked(f.contains); cb.setText(getString(R.string.all_subjects_including, f.getFilter())); ed.setText(f.getFilter()); label.setText(f.getParentFilter().toString()); label.setVisibility(View.VISIBLE); spinner.setVisibility(View.GONE); } else { label.setVisibility(View.GONE); } } ed.addTextChangedListener(watcher = 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) { String str = s.toString().trim(); int op = isMainFilterDialog() ? getMainFilterPosition() : getUpdatePosition(); List<? extends Filter> flist = isMainFilterDialog() ? list.including : list.including.get(spinner.getSelectedItemPosition()).excluding; Filter.FilterType currentType = isMainFilterDialog() ? (spinner.getSelectedItemPosition() == 0 ? Filter.FilterType.CLASS : Filter.FilterType.TEACHER) : Filter.FilterType.SUBJECT; for (int i = 0; i < flist.size(); i++) { if (i == op && (!isMainFilterDialog() || flist.get(op).getType() == currentType)) { continue; } Filter f = flist.get(i); if (f.getType() == currentType && SIAApp.deleteNonAlphanumeric(f.getFilter()) .equals(SIAApp.deleteNonAlphanumeric(str))) { ed.setError(getString(R.string.filter_exists)); d.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false); } else { //ed.setError(null); d.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true); } } if (!isMainFilterDialog()) { if (str.length() == 0) { cb.setEnabled(false); cb.setText(getString(R.string.all_subjects_including_disabled)); } else { cb.setEnabled(true); cb.setText(getString(R.string.all_subjects_including, str)); } } } }); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (isMainFilterDialog()) { ed.setHint((String) spinner.getSelectedItem()); } watcher.afterTextChanged(ed.getText()); //ed.setError(null); //ed.setText(ed.getText()); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }