/*
   * (non-Javadoc)
   * @see org.odk.collect.android.widgets.IBinaryWidget#setBinaryData(java.lang.Object)
   */
  @Override
  public void setBinaryData(Object answer) {
    String s = (String) answer;
    mStringAnswer.setText(s);

    String[] sa = s.split(" ");
    mAnswerDisplay.setText(
        StringUtils.getStringSpannableRobust(getContext(), R.string.latitude)
            + ": "
            + formatGps(Double.parseDouble(sa[0]), "lat")
            + "\n"
            + StringUtils.getStringSpannableRobust(getContext(), R.string.longitude)
            + ": "
            + formatGps(Double.parseDouble(sa[1]), "lon")
            + "\n"
            + StringUtils.getStringSpannableRobust(getContext(), R.string.altitude)
            + ": "
            + truncateDouble(sa[2])
            + "m\n"
            + StringUtils.getStringSpannableRobust(getContext(), R.string.accuracy)
            + ": "
            + truncateDouble(sa[3])
            + "m");
    mWaitingForData = false;
  }
 /*
  * (non-Javadoc)
  * @see org.odk.collect.android.widgets.QuestionWidget#clearAnswer()
  */
 @Override
 public void clearAnswer() {
   mStringAnswer.setText(null);
   mAnswerDisplay.setText(null);
   mGetLocationButton.setText(
       StringUtils.getStringSpannableRobust(getContext(), R.string.get_location));
 }
Exemple #3
0
 /**
  * Identifies whether two strings are close enough that they are likely to be intended to be the
  * same string. Fuzzy matching is only performed on strings that are longer than a certain size.
  *
  * @return A pair with two values. First value represents a match: true if the two strings meet
  *     CommCare's fuzzy match definition, false otherwise. Second value is the actual string
  *     distance that was matched, in order to be able to rank or otherwise interpret results.
  */
 public static Pair<Boolean, Integer> fuzzyMatch(String a, String b) {
   // tweakable parameter: Minimum length before edit distance
   // starts being used (this is probably not necessary, and
   // basically only makes sure that "at" doesn't match "or" or similar
   if (b.length() > 3) {
     int distance = StringUtils.LevenshteinDistance(a, b);
     // tweakable parameter: edit distance past string length disparity
     if (distance <= 2) {
       return Pair.create(true, distance);
     }
   }
   return Pair.create(false, -1);
 }
  public GeoPointWidget(Context context, FormEntryPrompt prompt) {
    super(context, prompt);

    mWaitingForData = false;
    mUseMaps = false;
    String appearance = prompt.getAppearanceHint();
    if ("maps".equalsIgnoreCase(appearance)) {
      try {
        // use google maps it exists on the device
        Class.forName("com.google.android.maps.MapActivity");
        mUseMaps = true;
      } catch (ClassNotFoundException e) {
        mUseMaps = false;
      }
    }

    setOrientation(LinearLayout.VERTICAL);

    mStringAnswer = new TextView(getContext());
    mAnswerDisplay = new TextView(getContext());
    mAnswerDisplay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mAnswerFontsize);
    mAnswerDisplay.setGravity(Gravity.CENTER);

    Spannable locButtonText;
    boolean viewButtonEnabled;

    String s = prompt.getAnswerText();
    if (s != null && !("".equals(s))) {
      setBinaryData(s);

      locButtonText = StringUtils.getStringSpannableRobust(getContext(), R.string.replace_location);
      viewButtonEnabled = true;
    } else {
      locButtonText = StringUtils.getStringSpannableRobust(getContext(), R.string.get_location);
      viewButtonEnabled = false;
    }

    mGetLocationButton = new Button(getContext());
    WidgetUtils.setupButton(
        mGetLocationButton, locButtonText, mAnswerFontsize, !prompt.isReadOnly());

    mGetLocationButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent i;
            if (mUseMaps) {
              i = new Intent(getContext(), GeoPointMapActivity.class);
            } else {
              i = new Intent(getContext(), GeoPointActivity.class);
            }
            ((Activity) getContext()).startActivityForResult(i, FormEntryActivity.LOCATION_CAPTURE);
            mWaitingForData = true;
          }
        });

    // setup 'view location' button
    mViewButton = new Button(getContext());
    WidgetUtils.setupButton(
        mViewButton,
        StringUtils.getStringSpannableRobust(getContext(), R.string.show_location),
        mAnswerFontsize,
        viewButtonEnabled);

    // launch appropriate map viewer
    mViewButton.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            String s = mStringAnswer.getText().toString();
            String[] sa = s.split(" ");
            double gp[] = new double[4];
            gp[0] = Double.valueOf(sa[0]);
            gp[1] = Double.valueOf(sa[1]);
            gp[2] = Double.valueOf(sa[2]);
            gp[3] = Double.valueOf(sa[3]);
            Intent i = new Intent(getContext(), GeoPointMapActivity.class);
            i.putExtra(LOCATION, gp);
            getContext().startActivity(i);
          }
        });

    addView(mGetLocationButton);
    if (mUseMaps) {
      addView(mViewButton);
    }
    addView(mAnswerDisplay);
  }