diff options
author | Joe Onorato <joeo@android.com> | 2009-12-02 22:39:53 -0800 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2009-12-02 22:39:53 -0800 |
commit | 03cd88b3ffee71fc22a2355eb462b6f99891411c (patch) | |
tree | 1aeb60b4498b5114f7582954c8776237ddf08a7e /graphics | |
parent | 47970a3003b9db5ead4a2301df3247c912b3daf5 (diff) | |
parent | c7a63eea8d3d346addaaf892b5bbe0aa80651640 (diff) | |
download | frameworks_base-03cd88b3ffee71fc22a2355eb462b6f99891411c.zip frameworks_base-03cd88b3ffee71fc22a2355eb462b6f99891411c.tar.gz frameworks_base-03cd88b3ffee71fc22a2355eb462b6f99891411c.tar.bz2 |
am c7a63eea: Add a new field to Intent that allows you to give a hint about what on screen caused the intent to be sent.
Merge commit 'c7a63eea8d3d346addaaf892b5bbe0aa80651640' into eclair-plus-aosp
* commit 'c7a63eea8d3d346addaaf892b5bbe0aa80651640':
Add a new field to Intent that allows you to give a hint about what on screen caused the intent to
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/Rect.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/graphics/java/android/graphics/Rect.java b/graphics/java/android/graphics/Rect.java index 42a14ce..98ffb8b 100644 --- a/graphics/java/android/graphics/Rect.java +++ b/graphics/java/android/graphics/Rect.java @@ -20,6 +20,8 @@ import android.os.Parcel; import android.os.Parcelable; import java.io.PrintWriter; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Rect holds four integer coordinates for a rectangle. The rectangle is @@ -34,6 +36,9 @@ public final class Rect implements Parcelable { public int right; public int bottom; + private static final Pattern FLATTENED_PATTERN = Pattern.compile( + "(-?\\d+) (-?\\d+) (-?\\d+) (-?\\d+)"); + /** * Create a new empty Rect. All coordinates are initialized to 0. */ @@ -105,6 +110,43 @@ public final class Rect implements Parcelable { sb.append(','); sb.append(bottom); sb.append(']'); return sb.toString(); } + + /** + * Return a string representation of the rectangle in a well-defined format. + * + * <p>You can later recover the Rect from this string through + * {@link #unflattenFromString(String)}. + * + * @return Returns a new String of the form "left top right bottom" + */ + public String flattenToString() { + StringBuilder sb = new StringBuilder(32); + // WARNING: Do not change the format of this string, it must be + // preserved because Rects are saved in this flattened format. + sb.append(left); + sb.append(' '); + sb.append(top); + sb.append(' '); + sb.append(right); + sb.append(' '); + sb.append(bottom); + return sb.toString(); + } + + /** + * Returns a Rect from a string of the form returned by {@link #flattenToString}, + * or null if the string is not of that form. + */ + public static Rect unflattenFromString(String str) { + Matcher matcher = FLATTENED_PATTERN.matcher(str); + if (!matcher.matches()) { + return null; + } + return new Rect(Integer.parseInt(matcher.group(1)), + Integer.parseInt(matcher.group(2)), + Integer.parseInt(matcher.group(3)), + Integer.parseInt(matcher.group(4))); + } /** * Print short representation to given writer. |