Commit 6bcf394e authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Post-process Currency conversion answer text.

This change ensures that currency conversion answers are shortened to
offer just final result, eg. instead of:

   1,000 United State Dollar = 1,330.75 Canadian Dollar
   1000 usd to cad

this will show:

   1,330.75 Canadian Dollar
   1000 usd to cad

Bug: 936730
Change-Id: I1222c5fba17e6cca07947e37bc2494f89abec98e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1500915Reviewed-by: default avatarTheresa <twellington@chromium.org>
Commit-Queue: Ender <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#637855}
parent 4ac0c190
......@@ -93,6 +93,10 @@ abstract class AnswerText {
*/
@SuppressWarnings("deprecation") // Update usage of Html.fromHtml when API min is 24
protected void appendAndStyleText(String text, MetricAffectingSpan[] styles) {
// Unescape HTML entities (e.g. "&quot;", "&gt;").
text = Html.fromHtml(text).toString();
text = processAnswerText(text);
// Determine the maximum height of the TextAppearanceSpans that are applied for this field.
for (MetricAffectingSpan style : styles) {
if (!(style instanceof TextAppearanceSpan)) continue;
......@@ -101,12 +105,9 @@ abstract class AnswerText {
if (mHeightSp < textHeightSp) mHeightSp = textHeightSp;
}
// Unescape HTML entities (e.g. "&quot;", "&gt;").
text = Html.fromHtml(text).toString();
// Append as HTML (answer responses contain simple markup).
int start = mText.length();
mText.append(Html.fromHtml(text));
mText.append(text);
int end = mText.length();
for (MetricAffectingSpan style : styles) {
......@@ -121,4 +122,14 @@ abstract class AnswerText {
* @return TextAppearanceSpan array specifying styles to be used to present text field.
*/
protected abstract MetricAffectingSpan[] getAppearanceForText(@AnswerTextType int type);
/**
* Process (if desired) content of the answer text.
*
* @param text Source text.
* @return Either original or modified text.
*/
protected String processAnswerText(String text) {
return text;
}
}
......@@ -90,6 +90,27 @@ class AnswerTextNewLayout extends AnswerText {
appendAndStyleText(text, getAppearanceForText(AnswerTextType.SUGGESTION));
}
/**
* Process (if desired) content of the answer text.
*
* @param text Source text.
* @return Either original or modified text.
*/
@Override
protected String processAnswerText(String text) {
if (mIsAnswer && mAnswerType == AnswerType.CURRENCY) {
// Modify the content of answer to present only the value after conversion, that is:
// 1,000 United State Dollar = 1,330.75 Canadian Dollar
// becomes
// 1,330.75 Canadian Dollar
int offset = text.indexOf(" = ");
if (offset > 0) {
text = text.substring(offset + 3);
}
}
return text;
}
/**
* Return the TextAppearanceSpan array specifying text decorations for a given field type.
*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment