Merge "TextClassifier: Append http:// to url intents that need one." into oc-dev

am: 3baad0234b

Change-Id: Ia33a42abf1ef4d8d05498649979d5697b898c64e
This commit is contained in:
Abodunrinwa Toki
2017-05-03 18:56:42 +00:00
committed by android-build-merger
2 changed files with 18 additions and 2 deletions

View File

@@ -607,6 +607,7 @@ final class TextClassifierImpl implements TextClassifier {
@Nullable
public static Intent create(Context context, String type, String text) {
type = type.trim().toLowerCase(Locale.ENGLISH);
text = text.trim();
switch (type) {
case TextClassifier.TYPE_EMAIL:
return new Intent(Intent.ACTION_SENDTO)
@@ -618,6 +619,9 @@ final class TextClassifierImpl implements TextClassifier {
return new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(String.format("geo:0,0?q=%s", text)));
case TextClassifier.TYPE_URL:
if (!text.startsWith("https://") && !text.startsWith("http://")) {
text = "http://" + text;
}
return new Intent(Intent.ACTION_VIEW, Uri.parse(text))
.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
default:

View File

@@ -118,7 +118,7 @@ public class TextClassificationManagerTest {
if (isTextClassifierDisabled()) return;
String text = "Visit http://www.android.com for more information";
String classifiedText = "http://www.android.com";
String classifiedText = "www.android.com";
int startIndex = text.indexOf(classifiedText);
int endIndex = startIndex + classifiedText.length();
assertThat(mClassifier.classifyText(text, startIndex, endIndex, LOCALES),
@@ -193,7 +193,19 @@ public class TextClassificationManagerTest {
public boolean matches(Object o) {
if (o instanceof TextClassification) {
TextClassification result = (TextClassification) o;
return text.equals(result.getText())
final boolean typeRequirementSatisfied;
switch (type) {
case TextClassifier.TYPE_URL:
String scheme = result.getIntent().getData().getScheme();
typeRequirementSatisfied = "http".equalsIgnoreCase(scheme)
|| "https".equalsIgnoreCase(scheme);
break;
default:
typeRequirementSatisfied = true;
}
return typeRequirementSatisfied
&& text.equals(result.getText())
&& result.getEntityCount() > 0
&& type.equals(result.getEntity(0));
// TODO: Include other properties.