/* * (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)); }
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); }