From a1f3e4aef19882b4b81075d9205bd363efe1e66d Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Thu, 4 Jun 2009 15:10:46 -0700 Subject: 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. --- core/java/android/view/ViewDebug.java | 87 ++++++++++++++-------------- core/java/android/widget/RelativeLayout.java | 12 ++-- 2 files changed, 50 insertions(+), 49 deletions(-) (limited to 'core/java') diff --git a/core/java/android/view/ViewDebug.java b/core/java/android/view/ViewDebug.java index aaaadef..46aea02 100644 --- a/core/java/android/view/ViewDebug.java +++ b/core/java/android/view/ViewDebug.java @@ -87,17 +87,17 @@ public class ViewDebug { * check that this value is set to true as not to affect performance. */ public static final boolean TRACE_RECYCLER = false; - + /** * 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 - */ + */ static final String SYSTEM_PROPERTY_CAPTURE_VIEW = "debug.captureview"; - + /** * The system property of dynamic switch for capturing event information * when it is set, we log key events, touch/motion and trackball events - */ + */ static final String SYSTEM_PROPERTY_CAPTURE_EVENT = "debug.captureevent"; /** @@ -216,7 +216,7 @@ public class ViewDebug { *
          *
          * A specified String is output when the following is true:
-         * 
+         *
          * @return An array of int to String mappings
          */
         FlagToString[] flagMapping() default { };
@@ -228,7 +228,7 @@ public class ViewDebug {
          *
          * @return true if the properties of this property should be dumped
          *
-         * @see #prefix() 
+         * @see #prefix()
          */
         boolean deepExport() default false;
 
@@ -313,15 +313,15 @@ public class ViewDebug {
     @Retention(RetentionPolicy.RUNTIME)
     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()
-         * we will set retrieveReturn = true on the annotation of 
+         * we will set retrieveReturn = true on the annotation of
          * 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, Method[]> mCapturedViewMethodsForClasses = null;
     private static HashMap, Field[]> mCapturedViewFieldsForClasses = null;
 
@@ -401,7 +401,7 @@ public class ViewDebug {
      */
     public static long getViewRootInstanceCount() {
         return ViewRoot.getInstanceCount();
-    }    
+    }
 
     /**
      * 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.
      *
-     * @see #startHierarchyTracing(String, View) 
+     * @see #startHierarchyTracing(String, View)
      * @see #trace(View, android.view.ViewDebug.HierarchyTraceType)
      */
     public static void stopHierarchyTracing() {
@@ -671,7 +671,7 @@ public class ViewDebug {
 
         sHierarhcyRoot = null;
     }
-    
+
     static void dispatchCommand(View view, String command, String parameters,
             OutputStream clientStream) throws IOException {
 
@@ -1039,10 +1039,10 @@ public class ViewDebug {
 
         final ArrayList foundMethods = new ArrayList();
         methods = klass.getDeclaredMethods();
-        
+
         int count = methods.length;
         for (int i = 0; i < count; i++) {
-            final Method method = methods[i];            
+            final Method method = methods[i];
             if (method.getParameterTypes().length == 0 &&
                     method.isAnnotationPresent(ExportedProperty.class) &&
                     method.getReturnType() != Void.class) {
@@ -1075,7 +1075,7 @@ public class ViewDebug {
             klass = klass.getSuperclass();
         } while (klass != Object.class);
     }
-    
+
     private static void exportMethods(Context context, Object view, BufferedWriter out,
             Class klass, String prefix) throws IOException {
 
@@ -1260,7 +1260,7 @@ public class ViewDebug {
 
         for (int j = 0; j < valuesCount; j++) {
             String name;
-            String value;
+            String value = null;
 
             final int intValue = array[j];
 
@@ -1276,7 +1276,6 @@ public class ViewDebug {
                 }
             }
 
-            value = String.valueOf(intValue);
             if (hasMapping) {
                 int mappingCount = mapping.length;
                 for (int k = 0; k < mappingCount; k++) {
@@ -1289,7 +1288,9 @@ public class ViewDebug {
             }
 
             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);
@@ -1397,10 +1398,10 @@ public class ViewDebug {
 
         final ArrayList foundMethods = new ArrayList();
         methods = klass.getMethods();
-        
+
         int count = methods.length;
         for (int i = 0; i < count; i++) {
-            final Method method = methods[i];            
+            final Method method = methods[i];
             if (method.getParameterTypes().length == 0 &&
                     method.isAnnotationPresent(CapturedViewProperty.class) &&
                     method.getReturnType() != Void.class) {
@@ -1414,14 +1415,14 @@ public class ViewDebug {
 
         return methods;
     }
-              
-    private static String capturedViewExportMethods(Object obj, Class klass, 
+
+    private static String capturedViewExportMethods(Object obj, Class klass,
             String prefix) {
 
         if (obj == null) {
             return "null";
         }
-        
+
         StringBuilder sb = new StringBuilder();
         final Method[] methods = capturedViewGetPropertyMethods(klass);
 
@@ -1431,41 +1432,41 @@ public class ViewDebug {
             try {
                 Object methodValue = method.invoke(obj, (Object[]) null);
                 final Class returnType = method.getReturnType();
-                
+
                 CapturedViewProperty property = method.getAnnotation(CapturedViewProperty.class);
                 if (property.retrieveReturn()) {
                     //we are interested in the second level data only
                     sb.append(capturedViewExportMethods(methodValue, returnType, method.getName() + "#"));
-                } else {                    
+                } else {
                     sb.append(prefix);
                     sb.append(method.getName());
                     sb.append("()=");
-                    
+
                     if (methodValue != null) {
-                        final String value = methodValue.toString().replace("\n", "\\n");                        
-                        sb.append(value);                        
+                        final String value = methodValue.toString().replace("\n", "\\n");
+                        sb.append(value);
                     } else {
                         sb.append("null");
                     }
                     sb.append("; ");
                 }
               } catch (IllegalAccessException e) {
-                  //Exception IllegalAccess, it is OK here 
+                  //Exception IllegalAccess, it is OK here
                   //we simply ignore this method
               } catch (InvocationTargetException e) {
-                  //Exception InvocationTarget, it is OK here 
+                  //Exception InvocationTarget, it is OK here
                   //we simply ignore this method
-              }              
-        }        
+              }
+        }
         return sb.toString();
     }
 
     private static String capturedViewExportFields(Object obj, Class klass, String prefix) {
-        
+
         if (obj == null) {
             return "null";
         }
-        
+
         StringBuilder sb = new StringBuilder();
         final Field[] fields = capturedViewGetPropertyFields(klass);
 
@@ -1487,25 +1488,25 @@ public class ViewDebug {
                 }
                 sb.append(' ');
             } catch (IllegalAccessException e) {
-                //Exception IllegalAccess, it is OK here 
+                //Exception IllegalAccess, it is OK here
                 //we simply ignore this field
             }
         }
         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
-     * to the log. 
+     * to the log.
      * @param tag for log
      * @param view for dump
      */
-    public static void dumpCapturedView(String tag, Object view) {        
+    public static void dumpCapturedView(String tag, Object view) {
         Class klass = view.getClass();
         StringBuilder sb = new StringBuilder(klass.getName() + ": ");
         sb.append(capturedViewExportFields(view, klass, ""));
-        sb.append(capturedViewExportMethods(view, klass, ""));        
-        Log.d(tag, sb.toString());        
+        sb.append(capturedViewExportMethods(view, klass, ""));
+        Log.d(tag, sb.toString());
     }
 }
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index ef240e0..84cf2c8 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -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
  * 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.
- * 
+ *
  * 

* 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 * {@link android.view.ViewGroup.LayoutParams#WRAP_CONTENT WRAP_CONTENT} and a child set to * {@link #ALIGN_PARENT_BOTTOM}. *

- * + * *

* Also see {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams} for * layout attributes *

- * + * * @attr ref android.R.styleable#RelativeLayout_gravity * @attr ref android.R.styleable#RelativeLayout_ignoreGravity */ @@ -327,7 +327,7 @@ public class RelativeLayout extends ViewGroup { } 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 width += mPaddingRight; @@ -339,7 +339,7 @@ public class RelativeLayout extends ViewGroup { width = resolveSize(width, widthMeasureSpec); } 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 height += mPaddingBottom; @@ -881,7 +881,7 @@ public class RelativeLayout extends ViewGroup { @ViewDebug.IntToString(from = RIGHT_OF, to = "rightOf") }, mapping = { @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]; -- cgit v1.1