am dbed5350: am b28632a5: 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 'dbed53504f515337ccc2f60248bb589dff0f24fb'

* commit 'dbed53504f515337ccc2f60248bb589dff0f24fb':
  Add a new field to Intent that allows you to give a hint about what on screen caused the intent to
This commit is contained in:
Joe Onorato
2009-12-03 10:51:34 -08:00
committed by Android Git Automerger
3 changed files with 169 additions and 1 deletions

View File

@@ -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.