Merge change 3227 into donut

* changes:
  Fix int to string mapping of exported properties. The value generated by the mapping in a @ViewDebug.ExportedProperty annotation was always overriden by the resolveId attribute.
This commit is contained in:
Android (Google) Code Review
2009-06-04 15:12:06 -07:00
2 changed files with 50 additions and 49 deletions

View File

@ -87,17 +87,17 @@ public class ViewDebug {
* check that this value is set to true as not to affect performance. * check that this value is set to true as not to affect performance.
*/ */
public static final boolean TRACE_RECYCLER = false; public static final boolean TRACE_RECYCLER = false;
/** /**
* The system property of dynamic switch for capturing view information * The system property of dynamic switch for capturing view information
* when it is set, we dump interested fields and methods for the view on focus * when it is set, we dump interested fields and methods for the view on focus
*/ */
static final String SYSTEM_PROPERTY_CAPTURE_VIEW = "debug.captureview"; static final String SYSTEM_PROPERTY_CAPTURE_VIEW = "debug.captureview";
/** /**
* The system property of dynamic switch for capturing event information * The system property of dynamic switch for capturing event information
* when it is set, we log key events, touch/motion and trackball events * when it is set, we log key events, touch/motion and trackball events
*/ */
static final String SYSTEM_PROPERTY_CAPTURE_EVENT = "debug.captureevent"; static final String SYSTEM_PROPERTY_CAPTURE_EVENT = "debug.captureevent";
/** /**
@ -216,7 +216,7 @@ public class ViewDebug {
* <pre> * <pre>
* *
* A specified String is output when the following is true: * A specified String is output when the following is true:
* *
* @return An array of int to String mappings * @return An array of int to String mappings
*/ */
FlagToString[] flagMapping() default { }; FlagToString[] flagMapping() default { };
@ -228,7 +228,7 @@ public class ViewDebug {
* *
* @return true if the properties of this property should be dumped * @return true if the properties of this property should be dumped
* *
* @see #prefix() * @see #prefix()
*/ */
boolean deepExport() default false; boolean deepExport() default false;
@ -313,15 +313,15 @@ public class ViewDebug {
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
public @interface CapturedViewProperty { public @interface CapturedViewProperty {
/** /**
* When retrieveReturn is true, we need to retrieve second level methods * When retrieveReturn is true, we need to retrieve second level methods
* e.g., we need myView.getFirstLevelMethod().getSecondLevelMethod() * e.g., we need myView.getFirstLevelMethod().getSecondLevelMethod()
* we will set retrieveReturn = true on the annotation of * we will set retrieveReturn = true on the annotation of
* myView.getFirstLevelMethod() * myView.getFirstLevelMethod()
* @return true if we need the second level methods * @return true if we need the second level methods
*/ */
boolean retrieveReturn() default false; boolean retrieveReturn() default false;
} }
private static HashMap<Class<?>, Method[]> mCapturedViewMethodsForClasses = null; private static HashMap<Class<?>, Method[]> mCapturedViewMethodsForClasses = null;
private static HashMap<Class<?>, Field[]> mCapturedViewFieldsForClasses = null; private static HashMap<Class<?>, Field[]> mCapturedViewFieldsForClasses = null;
@ -401,7 +401,7 @@ public class ViewDebug {
*/ */
public static long getViewRootInstanceCount() { public static long getViewRootInstanceCount() {
return ViewRoot.getInstanceCount(); return ViewRoot.getInstanceCount();
} }
/** /**
* Outputs a trace to the currently opened recycler traces. The trace records the type of * Outputs a trace to the currently opened recycler traces. The trace records the type of
@ -624,7 +624,7 @@ public class ViewDebug {
* *
* This method will return immediately if TRACE_HIERARCHY is false. * This method will return immediately if TRACE_HIERARCHY is false.
* *
* @see #startHierarchyTracing(String, View) * @see #startHierarchyTracing(String, View)
* @see #trace(View, android.view.ViewDebug.HierarchyTraceType) * @see #trace(View, android.view.ViewDebug.HierarchyTraceType)
*/ */
public static void stopHierarchyTracing() { public static void stopHierarchyTracing() {
@ -671,7 +671,7 @@ public class ViewDebug {
sHierarhcyRoot = null; sHierarhcyRoot = null;
} }
static void dispatchCommand(View view, String command, String parameters, static void dispatchCommand(View view, String command, String parameters,
OutputStream clientStream) throws IOException { OutputStream clientStream) throws IOException {
@ -1039,10 +1039,10 @@ public class ViewDebug {
final ArrayList<Method> foundMethods = new ArrayList<Method>(); final ArrayList<Method> foundMethods = new ArrayList<Method>();
methods = klass.getDeclaredMethods(); methods = klass.getDeclaredMethods();
int count = methods.length; int count = methods.length;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final Method method = methods[i]; final Method method = methods[i];
if (method.getParameterTypes().length == 0 && if (method.getParameterTypes().length == 0 &&
method.isAnnotationPresent(ExportedProperty.class) && method.isAnnotationPresent(ExportedProperty.class) &&
method.getReturnType() != Void.class) { method.getReturnType() != Void.class) {
@ -1075,7 +1075,7 @@ public class ViewDebug {
klass = klass.getSuperclass(); klass = klass.getSuperclass();
} while (klass != Object.class); } while (klass != Object.class);
} }
private static void exportMethods(Context context, Object view, BufferedWriter out, private static void exportMethods(Context context, Object view, BufferedWriter out,
Class<?> klass, String prefix) throws IOException { Class<?> klass, String prefix) throws IOException {
@ -1260,7 +1260,7 @@ public class ViewDebug {
for (int j = 0; j < valuesCount; j++) { for (int j = 0; j < valuesCount; j++) {
String name; String name;
String value; String value = null;
final int intValue = array[j]; final int intValue = array[j];
@ -1276,7 +1276,6 @@ public class ViewDebug {
} }
} }
value = String.valueOf(intValue);
if (hasMapping) { if (hasMapping) {
int mappingCount = mapping.length; int mappingCount = mapping.length;
for (int k = 0; k < mappingCount; k++) { for (int k = 0; k < mappingCount; k++) {
@ -1289,7 +1288,9 @@ public class ViewDebug {
} }
if (resolveId) { if (resolveId) {
value = (String) resolveId(context, intValue); if (value == null) value = (String) resolveId(context, intValue);
} else {
value = String.valueOf(intValue);
} }
writeEntry(out, prefix, name, suffix, value); writeEntry(out, prefix, name, suffix, value);
@ -1397,10 +1398,10 @@ public class ViewDebug {
final ArrayList<Method> foundMethods = new ArrayList<Method>(); final ArrayList<Method> foundMethods = new ArrayList<Method>();
methods = klass.getMethods(); methods = klass.getMethods();
int count = methods.length; int count = methods.length;
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
final Method method = methods[i]; final Method method = methods[i];
if (method.getParameterTypes().length == 0 && if (method.getParameterTypes().length == 0 &&
method.isAnnotationPresent(CapturedViewProperty.class) && method.isAnnotationPresent(CapturedViewProperty.class) &&
method.getReturnType() != Void.class) { method.getReturnType() != Void.class) {
@ -1414,14 +1415,14 @@ public class ViewDebug {
return methods; return methods;
} }
private static String capturedViewExportMethods(Object obj, Class<?> klass, private static String capturedViewExportMethods(Object obj, Class<?> klass,
String prefix) { String prefix) {
if (obj == null) { if (obj == null) {
return "null"; return "null";
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
final Method[] methods = capturedViewGetPropertyMethods(klass); final Method[] methods = capturedViewGetPropertyMethods(klass);
@ -1431,41 +1432,41 @@ public class ViewDebug {
try { try {
Object methodValue = method.invoke(obj, (Object[]) null); Object methodValue = method.invoke(obj, (Object[]) null);
final Class<?> returnType = method.getReturnType(); final Class<?> returnType = method.getReturnType();
CapturedViewProperty property = method.getAnnotation(CapturedViewProperty.class); CapturedViewProperty property = method.getAnnotation(CapturedViewProperty.class);
if (property.retrieveReturn()) { if (property.retrieveReturn()) {
//we are interested in the second level data only //we are interested in the second level data only
sb.append(capturedViewExportMethods(methodValue, returnType, method.getName() + "#")); sb.append(capturedViewExportMethods(methodValue, returnType, method.getName() + "#"));
} else { } else {
sb.append(prefix); sb.append(prefix);
sb.append(method.getName()); sb.append(method.getName());
sb.append("()="); sb.append("()=");
if (methodValue != null) { if (methodValue != null) {
final String value = methodValue.toString().replace("\n", "\\n"); final String value = methodValue.toString().replace("\n", "\\n");
sb.append(value); sb.append(value);
} else { } else {
sb.append("null"); sb.append("null");
} }
sb.append("; "); sb.append("; ");
} }
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
//Exception IllegalAccess, it is OK here //Exception IllegalAccess, it is OK here
//we simply ignore this method //we simply ignore this method
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
//Exception InvocationTarget, it is OK here //Exception InvocationTarget, it is OK here
//we simply ignore this method //we simply ignore this method
} }
} }
return sb.toString(); return sb.toString();
} }
private static String capturedViewExportFields(Object obj, Class<?> klass, String prefix) { private static String capturedViewExportFields(Object obj, Class<?> klass, String prefix) {
if (obj == null) { if (obj == null) {
return "null"; return "null";
} }
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
final Field[] fields = capturedViewGetPropertyFields(klass); final Field[] fields = capturedViewGetPropertyFields(klass);
@ -1487,25 +1488,25 @@ public class ViewDebug {
} }
sb.append(' '); sb.append(' ');
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
//Exception IllegalAccess, it is OK here //Exception IllegalAccess, it is OK here
//we simply ignore this field //we simply ignore this field
} }
} }
return sb.toString(); return sb.toString();
} }
/** /**
* Dump view info for id based instrument test generation * Dump view info for id based instrument test generation
* (and possibly further data analysis). The results are dumped * (and possibly further data analysis). The results are dumped
* to the log. * to the log.
* @param tag for log * @param tag for log
* @param view for dump * @param view for dump
*/ */
public static void dumpCapturedView(String tag, Object view) { public static void dumpCapturedView(String tag, Object view) {
Class<?> klass = view.getClass(); Class<?> klass = view.getClass();
StringBuilder sb = new StringBuilder(klass.getName() + ": "); StringBuilder sb = new StringBuilder(klass.getName() + ": ");
sb.append(capturedViewExportFields(view, klass, "")); sb.append(capturedViewExportFields(view, klass, ""));
sb.append(capturedViewExportMethods(view, klass, "")); sb.append(capturedViewExportMethods(view, klass, ""));
Log.d(tag, sb.toString()); Log.d(tag, sb.toString());
} }
} }

View File

@ -37,19 +37,19 @@ import java.util.TreeSet;
* A Layout where the positions of the children can be described in relation to each other or to the * A Layout where the positions of the children can be described in relation to each other or to the
* parent. For the sake of efficiency, the relations between views are evaluated in one pass, so if * parent. For the sake of efficiency, the relations between views are evaluated in one pass, so if
* view Y is dependent on the position of view X, make sure the view X comes first in the layout. * view Y is dependent on the position of view X, make sure the view X comes first in the layout.
* *
* <p> * <p>
* Note that you cannot have a circular dependency between the size of the RelativeLayout and the * Note that you cannot have a circular dependency between the size of the RelativeLayout and the
* position of its children. For example, you cannot have a RelativeLayout whose height is set to * position of its children. For example, you cannot have a RelativeLayout whose height is set to
* {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT WRAP_CONTENT} and a child set to * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT WRAP_CONTENT} and a child set to
* {@link #ALIGN_PARENT_BOTTOM}. * {@link #ALIGN_PARENT_BOTTOM}.
* </p> * </p>
* *
* <p> * <p>
* Also see {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams} for * Also see {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams} for
* layout attributes * layout attributes
* </p> * </p>
* *
* @attr ref android.R.styleable#RelativeLayout_gravity * @attr ref android.R.styleable#RelativeLayout_gravity
* @attr ref android.R.styleable#RelativeLayout_ignoreGravity * @attr ref android.R.styleable#RelativeLayout_ignoreGravity
*/ */
@ -327,7 +327,7 @@ public class RelativeLayout extends ViewGroup {
} }
if (widthMode != MeasureSpec.EXACTLY) { if (widthMode != MeasureSpec.EXACTLY) {
// Width already has left padding in it since it was calculated by looking at // Width already has left padding in it since it was calculated by looking at
// the right of each child view // the right of each child view
width += mPaddingRight; width += mPaddingRight;
@ -339,7 +339,7 @@ public class RelativeLayout extends ViewGroup {
width = resolveSize(width, widthMeasureSpec); width = resolveSize(width, widthMeasureSpec);
} }
if (heightMode != MeasureSpec.EXACTLY) { if (heightMode != MeasureSpec.EXACTLY) {
// Height already has top padding in it since it was calculated by looking at // Height already has top padding in it since it was calculated by looking at
// the bottom of each child view // the bottom of each child view
height += mPaddingBottom; height += mPaddingBottom;
@ -881,7 +881,7 @@ public class RelativeLayout extends ViewGroup {
@ViewDebug.IntToString(from = RIGHT_OF, to = "rightOf") @ViewDebug.IntToString(from = RIGHT_OF, to = "rightOf")
}, mapping = { }, mapping = {
@ViewDebug.IntToString(from = TRUE, to = "true"), @ViewDebug.IntToString(from = TRUE, to = "true"),
@ViewDebug.IntToString(from = 0, to = "FALSE/NO_ID") @ViewDebug.IntToString(from = 0, to = "false/NO_ID")
}) })
private int[] mRules = new int[VERB_COUNT]; private int[] mRules = new int[VERB_COUNT];