/** * @param activity that supports onCreateDialog({@link #PROGRESS_DIALOG}) and returns @param * progressdialog * @param progressDialog - it should be exactly the same as onCreateDialog * @return */ public void checkApplicationIsBeingInitialized(Activity activity, ProgressDialog progressDialog) { // start application if it was previously closed startApplication(); synchronized (OsmandApplication.this) { if (startDialog != null) { try { SpecialPhrases.setLanguage(this, osmandSettings); } catch (IOException e) { LOG.error("I/O exception", e); Toast error = Toast.makeText( this, "Error while reading the special phrases. Restart OsmAnd if possible", Toast.LENGTH_LONG); error.show(); } progressDialog.setTitle(getString(R.string.loading_data)); progressDialog.setMessage(getString(R.string.reading_indexes)); activity.showDialog(PROGRESS_DIALOG); startDialog.setDialog(progressDialog); } else if (startingWarnings != null) { showWarnings(startingWarnings, activity); } } }
public static String getPoiStringWithoutType(Amenity amenity, boolean en) { String type = SpecialPhrases.getSpecialPhrase(amenity.getSubType()); String n = amenity.getName(en); if (type == null) { type = amenity.getSubType(); } if (n.indexOf(type) != -1) { // type is contained in name e.g. // n = "Bakery the Corner" // type = "Bakery" // no need to repeat this return n; } if (n.length() == 0) { return type; } return type + " " + n; // $NON-NLS-1$ }
private void showDialog(final AmenityType amenity) { ListView lv = EditPOIFilterActivity.this.getListView(); final int index = lv.getFirstVisiblePosition(); View v = lv.getChildAt(0); final int top = (v == null) ? 0 : v.getTop(); Builder builder = new AlertDialog.Builder(this); ScrollView scroll = new ScrollView(this); ListView listView = new ListView(this); final LinkedHashSet<String> subCategories = new LinkedHashSet<String>(MapRenderingTypes.getDefault().getAmenitySubCategories(amenity)); Set<String> acceptedCategories = filter.getAcceptedSubtypes(amenity); if (acceptedCategories != null) { for (String s : acceptedCategories) { if (!subCategories.contains(s)) { subCategories.add(s); } } } final String[] array = subCategories.toArray(new String[0]); final Collator cl = Collator.getInstance(); cl.setStrength(Collator.SECONDARY); Arrays.sort( array, 0, array.length, new Comparator<String>() { @Override public int compare(String object1, String object2) { String v1 = SpecialPhrases.getSpecialPhrase(object1).replace('_', ' '); String v2 = SpecialPhrases.getSpecialPhrase(object2).replace('_', ' '); return cl.compare(v1, v2); } }); final String[] visibleNames = new String[array.length]; final boolean[] selected = new boolean[array.length]; for (int i = 0; i < array.length; i++) { visibleNames[i] = SpecialPhrases.getSpecialPhrase(array[i]).replace('_', ' '); if (acceptedCategories == null) { selected[i] = true; } else { selected[i] = acceptedCategories.contains(array[i]); } } scroll.addView(listView); builder.setView(scroll); builder.setNeutralButton( EditPOIFilterActivity.this.getText(R.string.close), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { LinkedHashSet<String> accepted = new LinkedHashSet<String>(); for (int i = 0; i < selected.length; i++) { if (selected[i]) { accepted.add(array[i]); } } if (subCategories.size() == accepted.size()) { filter.selectSubTypesToAccept(amenity, null); } else if (accepted.size() == 0) { filter.setTypeToAccept(amenity, false); } else { filter.selectSubTypesToAccept(amenity, accepted); } helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter(); la.notifyDataSetInvalidated(); lv.setSelectionFromTop(index, top); } }); builder.setPositiveButton( EditPOIFilterActivity.this.getText(R.string.default_buttons_selectall), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { filter.selectSubTypesToAccept(amenity, null); helper.editPoiFilter(filter); ListView lv = EditPOIFilterActivity.this.getListView(); AmenityAdapter la = (AmenityAdapter) EditPOIFilterActivity.this.getListAdapter(); la.notifyDataSetInvalidated(); lv.setSelectionFromTop(index, top); } }); builder.setMultiChoiceItems( visibleNames, selected, new DialogInterface.OnMultiChoiceClickListener() { @Override public void onClick(DialogInterface dialog, int item, boolean isChecked) { selected[item] = isChecked; } }); builder.show(); }