protected boolean addFilter(PoiFilter p, SQLiteConnection db, boolean addOnlyCategories) {
   if (db != null) {
     if (!addOnlyCategories) {
       db.execSQL(
           "INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",
           new Object[] {
             p.getName(), p.getFilterId(), p.getFilterByName()
           }); //$NON-NLS-1$ //$NON-NLS-2$
     }
     Map<AmenityType, LinkedHashSet<String>> types = p.getAcceptedTypes();
     SQLiteStatement insertCategories =
         db.compileStatement(
             "INSERT INTO "
                 + CATEGORIES_NAME
                 + " VALUES (?, ?, ?)"); //$NON-NLS-1$ //$NON-NLS-2$
     for (AmenityType a : types.keySet()) {
       if (types.get(a) == null) {
         insertCategories.bindString(1, p.getFilterId());
         insertCategories.bindString(2, AmenityType.valueToString(a));
         insertCategories.bindNull(3);
         insertCategories.execute();
       } else {
         for (String s : types.get(a)) {
           insertCategories.bindString(1, p.getFilterId());
           insertCategories.bindString(2, AmenityType.valueToString(a));
           insertCategories.bindString(3, s);
           insertCategories.execute();
         }
       }
     }
     insertCategories.close();
     return true;
   }
   return false;
 }
  @Override
  public Node loadNode(Amenity n) {
    if (n.getId() % 2 == 1) {
      // that's way id
      return null;
    }
    long nodeId = n.getId() >> 1;

    //		EntityId id = new Entity.EntityId(EntityType.NODE, nodeId);
    Node entity = new Node(n.getLocation().getLatitude(), n.getLocation().getLongitude(), nodeId);

    Map<AmenityType, Map<String, String>> typeNameToTagVal =
        MapRenderingTypes.getDefault().getAmenityTypeNameToTagVal();
    AmenityType type = n.getType();
    String tag = type.getDefaultTag();
    String subType = n.getSubType();
    String val = subType;
    if (typeNameToTagVal.containsKey(type)) {
      Map<String, String> map = typeNameToTagVal.get(type);
      if (map.containsKey(subType)) {
        String res = map.get(subType);
        if (res != null) {
          int i = res.indexOf(' ');
          if (i != -1) {
            tag = res.substring(0, i);
            val = res.substring(i + 1);
          } else {
            tag = res;
          }
        }
      }
    }
    entity.putTag(tag, val);
    entity.putTag(OSMTagKey.NAME.getValue(), n.getName());
    entity.putTag(OSMTagKey.OPENING_HOURS.getValue(), n.getOpeningHours());

    // check whether this is node (because id of node could be the same as relation)
    if (entity != null && MapUtils.getDistance(entity.getLatLon(), n.getLocation()) < 50) {
      return entity;
    }
    return null;
  }
  @Override
  public void onCreate(final Bundle icicle) {
    Bundle bundle = this.getIntent().getExtras();
    String filterId = bundle.getString(AMENITY_FILTER);
    helper = ((OsmandApplication) getApplication()).getPoiFilters();
    filter = helper.getFilterById(filterId);
    super.onCreate(icicle);

    setContentView(R.layout.editing_poi_filter);
    getSupportActionBar().setTitle(R.string.filterpoi_activity);
    getSupportActionBar().setIcon(R.drawable.tab_search_poi_icon);

    getSupportActionBar().setSubtitle(filter.getName());
    setListAdapter(new AmenityAdapter(AmenityType.getCategories()));
  }
 public List<PoiFilter> getOsmDefinedPoiFilters() {
   if (cacheOsmDefinedFilters == null) {
     cacheOsmDefinedFilters = new ArrayList<PoiFilter>();
     for (AmenityType t : AmenityType.values()) {
       cacheOsmDefinedFilters.add(new PoiFilter(t, application));
     }
     final Collator instance = Collator.getInstance();
     Collections.sort(
         cacheOsmDefinedFilters,
         new Comparator<PoiFilter>() {
           @Override
           public int compare(PoiFilter object1, PoiFilter object2) {
             return instance.compare(object1.getName(), object2.getName());
           }
         });
     cacheOsmDefinedFilters.add(0, new PoiFilter(null, application));
   }
   return Collections.unmodifiableList(cacheOsmDefinedFilters);
 }
Exemple #5
0
 public static String valueToString(AmenityType a) {
   return a.getCategoryName();
 }
    protected List<PoiFilter> getFilters(SQLiteConnection conn) {
      ArrayList<PoiFilter> list = new ArrayList<PoiFilter>();
      if (conn != null) {
        SQLiteCursor query =
            conn.rawQuery(
                "SELECT "
                    + CATEGORIES_FILTER_ID
                    + ", "
                    + CATEGORIES_COL_CATEGORY
                    + ","
                    + CATEGORIES_COL_SUBCATEGORY
                    + " FROM "
                    + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    CATEGORIES_NAME,
                null);
        Map<String, Map<AmenityType, LinkedHashSet<String>>> map =
            new LinkedHashMap<String, Map<AmenityType, LinkedHashSet<String>>>();
        if (query.moveToFirst()) {
          do {
            String filterId = query.getString(0);
            if (!map.containsKey(filterId)) {
              map.put(filterId, new LinkedHashMap<AmenityType, LinkedHashSet<String>>());
            }
            Map<AmenityType, LinkedHashSet<String>> m = map.get(filterId);
            AmenityType a = AmenityType.fromString(query.getString(1));
            String subCategory = query.getString(2);
            if (subCategory == null) {
              m.put(a, null);
            } else {
              if (m.get(a) == null) {
                m.put(a, new LinkedHashSet<String>());
              }
              m.get(a).add(subCategory);
            }
          } while (query.moveToNext());
        }
        query.close();

        query =
            conn.rawQuery(
                "SELECT "
                    + FILTER_COL_ID
                    + ", "
                    + FILTER_COL_NAME
                    + ","
                    + FILTER_COL_FILTERBYNAME
                    + " FROM "
                    + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    FILTER_NAME,
                null);
        if (query.moveToFirst()) {
          do {
            String filterId = query.getString(0);
            if (map.containsKey(filterId)) {
              PoiFilter filter =
                  new PoiFilter(query.getString(1), filterId, map.get(filterId), application);
              filter.setFilterByName(query.getString(2));
              list.add(filter);
            }
          } while (query.moveToNext());
        }
        query.close();
      }
      return list;
    }