When displaying a html anchor link in a TextView, make sure there is

a space before and after the anchor link.
This commit is contained in:
Jimmy Shih
2012-09-07 10:45:12 -07:00
parent 7079c787be
commit 9cbfa40320
3 changed files with 28 additions and 9 deletions
@@ -17,6 +17,7 @@
package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.fragments.AboutDialogFragment;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import android.os.Bundle;
@@ -37,14 +38,13 @@ public class HelpActivity extends AbstractMyTracksActivity {
setContentView(R.layout.help);
TextView mapsPublicUnlisted = (TextView) findViewById(R.id.help_maps_public_unlisted_answer);
mapsPublicUnlisted.setText(getString(
R.string.help_maps_public_unlisted_answer, getString(R.string.maps_public_unlisted_url)));
mapsPublicUnlisted.setText(StringUtils.getHtml(
this, R.string.help_maps_public_unlisted_answer, R.string.maps_public_unlisted_url));
TextView sendTrack = (TextView) findViewById(R.id.help_send_track_answer);
sendTrack.setText(getString(R.string.help_send_track_answer,
getString(R.string.send_google_maps_url),
getString(R.string.send_google_fusion_tables_url),
getString(R.string.send_google_docs_url)));
sendTrack.setText(StringUtils.getHtml(
this, R.string.help_send_track_answer, R.string.send_google_maps_url,
R.string.send_google_fusion_tables_url, R.string.send_google_docs_url));
findViewById(R.id.help_ok).setOnClickListener(new OnClickListener() {
public void onClick(View v) {
@@ -19,6 +19,7 @@ package com.google.android.apps.mytracks.io.sendtogoogle;
import com.google.android.apps.mytracks.util.DialogUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.apps.mytracks.util.StringUtils;
import com.google.android.maps.mytracks.R;
import android.app.Activity;
@@ -62,9 +63,9 @@ public class ConfirmSharingActivity extends Activity {
View view = getLayoutInflater().inflate(R.layout.confirm_sharing, null);
TextView textView = (TextView) view.findViewById(R.id.confirm_sharing_text_view);
textView.setText(getString(
R.string.share_track_confirm_message, getString(R.string.maps_public_unlisted_url)));
textView.setText(StringUtils.getHtml(
this, R.string.share_track_confirm_message, R.string.maps_public_unlisted_url));
checkBox = (CheckBox) view.findViewById(R.id.confirm_sharing_check_box);
DialogInterface.OnClickListener okListener = new DialogInterface.OnClickListener() {
@Override
@@ -18,6 +18,8 @@ package com.google.android.apps.mytracks.util;
import com.google.android.maps.mytracks.R;
import android.content.Context;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils;
@@ -265,4 +267,20 @@ public class StringUtils {
parts[2] = minutes / 60;
return parts;
}
/**
* Gets the html.
*
* @param context the context
* @param resId the string resource id
* @param formatArgs the string resource ids of the format arguments
*/
public static Spanned getHtml(Context context, int resId, Object... formatArgs) {
Object[] args = new Object[formatArgs.length];
for (int i = 0; i < formatArgs.length; i++) {
String url = context.getString((Integer) formatArgs[i]);
args[i] = " <a href='" + url + "'>" + url + "</a> ";
}
return Html.fromHtml(context.getString(resId, args));
}
}