Merge "TextLinks API updates."

This commit is contained in:
Joanne Chung
2019-12-23 02:11:45 +00:00
committed by Android (Google) Code Review
3 changed files with 44 additions and 3 deletions

View File

@@ -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;
@@ -110,7 +111,6 @@ public final class TextLinks implements Parcelable {
/**
* Returns the text that was used to generate these links.
* @hide
*/
@NonNull
public String getText() {
@@ -342,6 +342,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;
@@ -350,11 +351,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;
}
@@ -394,6 +397,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>
@@ -454,6 +466,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 = Objects.requireNonNull(text);
@@ -510,6 +523,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.
*/
@@ -517,7 +543,7 @@ public final class TextLinks implements Parcelable {
public Request build() {
return new Request(
mText, mDefaultLocales, mEntityConfig,
mLegacyFallback,
mLegacyFallback, mReferenceTime,
mExtras == null ? Bundle.EMPTY : mExtras);
}
}
@@ -535,6 +561,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) {
@@ -544,9 +571,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;