diff options
| author | Sudheer Shanka <sudheersai@google.com> | 2017-01-18 13:37:02 -0800 |
|---|---|---|
| committer | Sudheer Shanka <sudheersai@google.com> | 2017-01-30 17:19:49 -0800 |
| commit | 09971befd7e5eb506eca65afd61bd9248b78c723 (patch) | |
| tree | 27578a8320a87e42ac65ef513cc6fb9da40e5d3d /core/java/android | |
| parent | c2410cb9e576b420d96de627f2ed1043a4d7f93f (diff) | |
Add new api ClipDescription.getTimestamp.
ClipDescription.getTimestamp can be used to know the time
at which the associated ClipData is copied to global clipboard.
Bug: 30873580
Test: cts-tradefed run singleCommand cts-dev --module CtsContentTestCases -t \
android.content.cts.ClipDescriptionTest
Change-Id: I9486ab3fe0696959d42f6b4c98e40f5becee3019
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/content/ClipDescription.java | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/core/java/android/content/ClipDescription.java b/core/java/android/content/ClipDescription.java index b33a915ad2a5..621136290fab 100644 --- a/core/java/android/content/ClipDescription.java +++ b/core/java/android/content/ClipDescription.java @@ -19,7 +19,9 @@ package android.content; import android.os.Parcel; import android.os.Parcelable; import android.os.PersistableBundle; +import android.os.SystemClock; import android.text.TextUtils; +import android.util.TimeUtils; import java.util.ArrayList; import java.util.Arrays; @@ -92,6 +94,7 @@ public class ClipDescription implements Parcelable { final CharSequence mLabel; private final ArrayList<String> mMimeTypes; private PersistableBundle mExtras; + private long mTimeStamp; /** * Create a new clip. @@ -113,6 +116,7 @@ public class ClipDescription implements Parcelable { public ClipDescription(ClipDescription o) { mLabel = o.mLabel; mMimeTypes = new ArrayList<String>(o.mMimeTypes); + mTimeStamp = o.mTimeStamp; } /** @@ -142,6 +146,29 @@ public class ClipDescription implements Parcelable { } /** + * Used for setting the timestamp at which the associated {@link ClipData} is copied to + * global clipboard. + * + * @param timeStamp at which the associated {@link ClipData} is copeid to clipboard in + * {@link SystemClock#elapsedRealtime()} time base. + * @hide + */ + public void setTimestamp(long timeStamp) { + mTimeStamp = timeStamp; + } + + /** + * Return the timestamp at which the associated {@link ClipData} is copied to global clipboard + * in the {@link SystemClock#elapsedRealtime()} time base. + * + * @return timestamp at which the associated {@link ClipData} is copied to global clipboard + * or {@code 0} if it is not copied to clipboard. + */ + public long getTimestamp() { + return mTimeStamp; + } + + /** * Return the label for this clip. */ public CharSequence getLabel() { @@ -285,6 +312,13 @@ public class ClipDescription implements Parcelable { first = false; b.append(mExtras.toString()); } + if (mTimeStamp > 0) { + if (!first) { + b.append(' '); + } + first = false; + TimeUtils.formatDuration(mTimeStamp, b); + } return !first; } @@ -312,12 +346,14 @@ public class ClipDescription implements Parcelable { TextUtils.writeToParcel(mLabel, dest, flags); dest.writeStringList(mMimeTypes); dest.writePersistableBundle(mExtras); + dest.writeLong(mTimeStamp); } ClipDescription(Parcel in) { mLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); mMimeTypes = in.createStringArrayList(); mExtras = in.readPersistableBundle(); + mTimeStamp = in.readLong(); } public static final Parcelable.Creator<ClipDescription> CREATOR = |
