Beispiel #1
0
  @Override
  public OnClickListener getActionListener(List<String> actionsList, Object o) {
    final Amenity a = (Amenity) o;
    int ind = 0;
    final int phoneIndex = a.getPhone() != null ? ind++ : -1;
    final int siteIndex = a.getSite() != null ? ind++ : -1;
    final int descriptionIndex = a.getDescription() != null ? ind++ : -1;
    if (a.getPhone() != null) {
      actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_call));
    }
    if (a.getSite() != null) {
      actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_website));
    }
    if (a.getDescription() != null) {
      actionsList.add(
          this.view.getResources().getString(R.string.poi_context_menu_showdescription));
    }
    final int modifyInd = ind++;
    actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_modify));
    final int deleteInd = ind++;
    actionsList.add(this.view.getResources().getString(R.string.poi_context_menu_delete));

    final EditingPOIActivity edit = activity.getPoiActions();
    return new DialogInterface.OnClickListener() {

      @Override
      public void onClick(DialogInterface dialog, int which) {
        if (which == modifyInd) {
          edit.showEditDialog(a);
        } else if (which == deleteInd) {
          edit.showDeleteDialog(a);
        } else if (which == phoneIndex) {
          try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("tel:" + a.getPhone())); // $NON-NLS-1$
            view.getContext().startActivity(intent);
          } catch (RuntimeException e) {
            log.error("Failed to invoke call", e); // $NON-NLS-1$
            AccessibleToast.makeText(view.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
          }
        } else if (which == siteIndex) {
          try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse(a.getSite()));
            view.getContext().startActivity(intent);
          } catch (RuntimeException e) {
            log.error("Failed to invoke call", e); // $NON-NLS-1$
            AccessibleToast.makeText(view.getContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
          }
        } else if (which == descriptionIndex) {
          showDescriptionDialog(a);
        } else {
        }
      }
    };
  }
Beispiel #2
0
 private void showDescriptionDialog(Amenity a) {
   Builder bs = new AlertDialog.Builder(view.getContext());
   bs.setTitle(
       OsmAndFormatter.getPoiSimpleFormat(
           a, view.getContext(), view.getSettings().USE_ENGLISH_NAMES.get()));
   bs.setMessage(a.getDescription());
   bs.show();
 }
  @Override
  public void buildInternal(View view) {
    boolean hasWiki = false;
    MapPoiTypes poiTypes = app.getPoiTypes();
    String preferredLang = app.getSettings().MAP_PREFERRED_LOCALE.get();
    if (Algorithms.isEmpty(preferredLang)) {
      preferredLang = app.getLanguage();
    }
    List<AmenityDescription> descriptions = new LinkedList<>();

    for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
      int iconId;
      Drawable icon = null;
      int textColor = 0;
      String key = e.getKey();
      String vl = e.getValue();

      String textPrefix = "";
      boolean isWiki = false;
      boolean isText = false;
      boolean needLinks = !"population".equals(key);

      if (amenity.getType().isWiki()) {
        if (!hasWiki) {
          iconId = R.drawable.ic_action_note_dark;
          String lng = amenity.getContentSelected("content", preferredLang, "en");
          if (Algorithms.isEmpty(lng)) {
            lng = "en";
          }

          final String langSelected = lng;
          String content = amenity.getDescription(langSelected);
          vl = Html.fromHtml(content).toString();
          if (vl.length() > 300) {
            vl = vl.substring(0, 300);
          }
          hasWiki = true;
          isWiki = true;
        } else {
          continue;
        }
      } else if (key.startsWith("name:")) {
        continue;
      } else if (Amenity.OPENING_HOURS.equals(key)) {
        iconId = R.drawable.ic_action_time;

        OpeningHoursParser.OpeningHours rs =
            OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
        if (rs != null) {
          Calendar inst = Calendar.getInstance();
          inst.setTimeInMillis(System.currentTimeMillis());
          boolean opened = rs.isOpenedForTime(inst);
          if (opened) {
            textColor = R.color.color_ok;
          } else {
            textColor = R.color.color_invalid;
          }
        }

      } else if (Amenity.PHONE.equals(key)) {
        iconId = R.drawable.ic_action_call_dark;
      } else if (Amenity.WEBSITE.equals(key)) {
        iconId = R.drawable.ic_world_globe_dark;
        vl = vl.replace(' ', '_');
      } else {
        if (Amenity.DESCRIPTION.equals(key)) {
          iconId = R.drawable.ic_action_note_dark;
        } else {
          iconId = R.drawable.ic_action_info_dark;
        }
        AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
        if (pt != null) {
          PoiType pType = (PoiType) pt;
          if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) {
            icon =
                getRowIcon(
                    view.getContext(),
                    ((PoiType) pType.getParentType()).getOsmTag()
                        + "_"
                        + pType.getOsmTag().replace(':', '_')
                        + "_"
                        + pType.getOsmValue());
          }
          if (!pType.isText()) {
            vl = pType.getTranslation();
          } else {
            isText = true;
            iconId = R.drawable.ic_action_note_dark;
            textPrefix = pType.getTranslation();
            vl = amenity.unzipContent(e.getValue());
          }
        } else {
          textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey());
          vl = amenity.unzipContent(e.getValue());
        }
      }

      if (isText && iconId == R.drawable.ic_action_note_dark) {
        descriptions.add(new AmenityDescription(key, textPrefix, vl));
      } else if (icon != null) {
        buildRow(view, icon, vl, textPrefix, textColor, isWiki, isText, needLinks);
      } else {
        buildRow(view, iconId, vl, textPrefix, textColor, isWiki, isText, needLinks);
      }
    }

    String langSuffix = ":" + preferredLang;
    AmenityDescription descInPrefLang = null;
    for (AmenityDescription desc : descriptions) {
      if (desc.key.length() > langSuffix.length()
          && desc.key
              .substring(desc.key.length() - langSuffix.length(), desc.key.length())
              .equals(langSuffix)) {
        descInPrefLang = desc;
        break;
      }
    }
    if (descInPrefLang != null) {
      descriptions.remove(descInPrefLang);
      descriptions.add(0, descInPrefLang);
    }

    for (AmenityDescription desc : descriptions) {
      buildRow(
          view, R.drawable.ic_action_note_dark, desc.text, desc.textPrefix, 0, false, true, true);
    }
  }