TextLinks API updates.
1. Add get/setReferenceTime to TextLinks 2. Make TextLinks.getText() public Bug: 143873595 Test: atest FrameworksCoreTests:android.view.textclassifier Test: atest android.view.textclassifier.cts.TextClassifierValueObjectsTest Change-Id: I720e0e1fe9e4d05de0d7a1427f7d7ded01287aff
This commit is contained in:
@@ -54814,6 +54814,7 @@ package android.view.textclassifier {
|
||||
method public int describeContents();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method @NonNull public java.util.Collection<android.view.textclassifier.TextLinks.TextLink> getLinks();
|
||||
method @NonNull public String getText();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final int APPLY_STRATEGY_IGNORE = 0; // 0x0
|
||||
field public static final int APPLY_STRATEGY_REPLACE = 1; // 0x1
|
||||
@@ -54840,6 +54841,7 @@ package android.view.textclassifier {
|
||||
method @Nullable public android.os.LocaleList getDefaultLocales();
|
||||
method @Nullable public android.view.textclassifier.TextClassifier.EntityConfig getEntityConfig();
|
||||
method @NonNull public android.os.Bundle getExtras();
|
||||
method @Nullable public java.time.ZonedDateTime getReferenceTime();
|
||||
method @NonNull public CharSequence getText();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field @NonNull public static final android.os.Parcelable.Creator<android.view.textclassifier.TextLinks.Request> CREATOR;
|
||||
@@ -54851,6 +54853,7 @@ package android.view.textclassifier {
|
||||
method @NonNull public android.view.textclassifier.TextLinks.Request.Builder setDefaultLocales(@Nullable android.os.LocaleList);
|
||||
method @NonNull public android.view.textclassifier.TextLinks.Request.Builder setEntityConfig(@Nullable android.view.textclassifier.TextClassifier.EntityConfig);
|
||||
method public android.view.textclassifier.TextLinks.Request.Builder setExtras(@Nullable android.os.Bundle);
|
||||
method @NonNull public android.view.textclassifier.TextLinks.Request.Builder setReferenceTime(@Nullable java.time.ZonedDateTime);
|
||||
}
|
||||
|
||||
public static final class TextLinks.TextLink implements android.os.Parcelable {
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.android.internal.util.Preconditions;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -109,7 +110,6 @@ public final class TextLinks implements Parcelable {
|
||||
|
||||
/**
|
||||
* Returns the text that was used to generate these links.
|
||||
* @hide
|
||||
*/
|
||||
@NonNull
|
||||
public String getText() {
|
||||
@@ -341,6 +341,7 @@ public final class TextLinks implements Parcelable {
|
||||
private final boolean mLegacyFallback;
|
||||
@Nullable private String mCallingPackageName;
|
||||
private final Bundle mExtras;
|
||||
@Nullable private final ZonedDateTime mReferenceTime;
|
||||
@UserIdInt
|
||||
private int mUserId = UserHandle.USER_NULL;
|
||||
|
||||
@@ -349,11 +350,13 @@ public final class TextLinks implements Parcelable {
|
||||
LocaleList defaultLocales,
|
||||
EntityConfig entityConfig,
|
||||
boolean legacyFallback,
|
||||
ZonedDateTime referenceTime,
|
||||
Bundle extras) {
|
||||
mText = text;
|
||||
mDefaultLocales = defaultLocales;
|
||||
mEntityConfig = entityConfig;
|
||||
mLegacyFallback = legacyFallback;
|
||||
mReferenceTime = referenceTime;
|
||||
mExtras = extras;
|
||||
}
|
||||
|
||||
@@ -393,6 +396,15 @@ public final class TextLinks implements Parcelable {
|
||||
return mLegacyFallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return reference time based on which relative dates (e.g. "tomorrow") should be
|
||||
* interpreted.
|
||||
*/
|
||||
@Nullable
|
||||
public ZonedDateTime getReferenceTime() {
|
||||
return mReferenceTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the package that is sending this request.
|
||||
* <p>
|
||||
@@ -453,6 +465,7 @@ public final class TextLinks implements Parcelable {
|
||||
@Nullable private EntityConfig mEntityConfig;
|
||||
private boolean mLegacyFallback = true; // Use legacy fall back by default.
|
||||
@Nullable private Bundle mExtras;
|
||||
@Nullable private ZonedDateTime mReferenceTime;
|
||||
|
||||
public Builder(@NonNull CharSequence text) {
|
||||
mText = Preconditions.checkNotNull(text);
|
||||
@@ -509,6 +522,19 @@ public final class TextLinks implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param referenceTime reference time based on which relative dates (e.g. "tomorrow"
|
||||
* should be interpreted. This should usually be the time when the text was
|
||||
* originally composed.
|
||||
*
|
||||
* @return this builder
|
||||
*/
|
||||
@NonNull
|
||||
public Builder setReferenceTime(@Nullable ZonedDateTime referenceTime) {
|
||||
mReferenceTime = referenceTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns the request object.
|
||||
*/
|
||||
@@ -516,7 +542,7 @@ public final class TextLinks implements Parcelable {
|
||||
public Request build() {
|
||||
return new Request(
|
||||
mText, mDefaultLocales, mEntityConfig,
|
||||
mLegacyFallback,
|
||||
mLegacyFallback, mReferenceTime,
|
||||
mExtras == null ? Bundle.EMPTY : mExtras);
|
||||
}
|
||||
}
|
||||
@@ -534,6 +560,7 @@ public final class TextLinks implements Parcelable {
|
||||
dest.writeString(mCallingPackageName);
|
||||
dest.writeInt(mUserId);
|
||||
dest.writeBundle(mExtras);
|
||||
dest.writeString(mReferenceTime == null ? null : mReferenceTime.toString());
|
||||
}
|
||||
|
||||
private static Request readFromParcel(Parcel in) {
|
||||
@@ -543,9 +570,12 @@ public final class TextLinks implements Parcelable {
|
||||
final String callingPackageName = in.readString();
|
||||
final int userId = in.readInt();
|
||||
final Bundle extras = in.readBundle();
|
||||
final String referenceTimeString = in.readString();
|
||||
final ZonedDateTime referenceTime = referenceTimeString == null
|
||||
? null : ZonedDateTime.parse(referenceTimeString);
|
||||
|
||||
final Request request = new Request(text, defaultLocales, entityConfig,
|
||||
/* legacyFallback= */ true, extras);
|
||||
/* legacyFallback= */ true, referenceTime, extras);
|
||||
request.setCallingPackageName(callingPackageName);
|
||||
request.setUserId(userId);
|
||||
return request;
|
||||
|
||||
@@ -29,6 +29,9 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -77,6 +80,7 @@ public class TextLinksTest {
|
||||
final TextLinks result = TextLinks.CREATOR.createFromParcel(parcel);
|
||||
final List<TextLinks.TextLink> resultList = new ArrayList<>(result.getLinks());
|
||||
|
||||
assertEquals(fullText, result.getText());
|
||||
assertEquals(2, resultList.size());
|
||||
assertEquals(0, resultList.get(0).getStart());
|
||||
assertEquals(4, resultList.get(0).getEnd());
|
||||
@@ -103,10 +107,13 @@ public class TextLinksTest {
|
||||
Arrays.asList(TextClassifier.HINT_TEXT_IS_EDITABLE),
|
||||
Arrays.asList("a", "b", "c"),
|
||||
Arrays.asList("b"));
|
||||
final ZonedDateTime referenceTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(1000L),
|
||||
ZoneId.of("UTC"));
|
||||
final TextLinks.Request reference = new TextLinks.Request.Builder("text")
|
||||
.setDefaultLocales(new LocaleList(Locale.US, Locale.GERMANY))
|
||||
.setEntityConfig(entityConfig)
|
||||
.setExtras(BUNDLE)
|
||||
.setReferenceTime(referenceTime)
|
||||
.build();
|
||||
reference.setCallingPackageName(packageName);
|
||||
|
||||
@@ -124,5 +131,6 @@ public class TextLinksTest {
|
||||
result.getEntityConfig().resolveEntityListModifications(Collections.emptyList()));
|
||||
assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY));
|
||||
assertEquals(packageName, result.getCallingPackageName());
|
||||
assertEquals(referenceTime, result.getReferenceTime());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user