Merge "Add a script to rename fonts for SDK. [DO NOT MERGE]" into jb-mr1.1-dev
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 3fcd987..efcb35c 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -560,7 +560,7 @@
         StyleResourceValue customStyleValues = null;
         if (customStyle != null) {
             ResourceValue item = mRenderResources.findResValue(customStyle,
-                    false /*forceFrameworkOnly*/);
+                    isPlatformFile /*forceFrameworkOnly*/);
 
             // resolve it in case it links to something else
             item = mRenderResources.resolveResValue(item);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
index 9082e27..1fe07bb 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java
@@ -16,18 +16,14 @@
 
 package com.android.layoutlib.bridge.bars;
 
-import com.android.annotations.NonNull;
 import com.android.annotations.Nullable;
 import com.android.ide.common.rendering.api.ActionBarCallback;
 import com.android.ide.common.rendering.api.ActionBarCallback.HomeButtonStyle;
 import com.android.ide.common.rendering.api.RenderResources;
 import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.ide.common.rendering.api.SessionParams;
-import com.android.ide.common.rendering.api.SystemViewCookie;
 import com.android.internal.R;
 import com.android.internal.app.ActionBarImpl;
-import com.android.internal.util.Predicate;
-import com.android.internal.view.menu.ActionMenuView;
 import com.android.internal.view.menu.MenuBuilder;
 import com.android.internal.view.menu.MenuBuilderAccessor;
 import com.android.internal.view.menu.MenuItemImpl;
@@ -60,18 +56,16 @@
 
 import java.util.ArrayList;
 
-import static com.android.ide.common.rendering.api.SystemViewCookie.ACTION_BAR_OVERFLOW;
-
 /**
  * A layout representing the action bar.
  */
 public class ActionBarLayout extends LinearLayout {
 
     // Store another reference to the context so that we don't have to cast it repeatedly.
-    @NonNull private final BridgeContext mBridgeContext;
-    @NonNull private final Context mThemedContext;
+    private final BridgeContext mBridgeContext;
+    private final Context mThemedContext;
 
-    @NonNull private final ActionBar mActionBar;
+    private final ActionBar mActionBar;
 
     // Data for Action Bar.
     @Nullable private final String mIcon;
@@ -82,17 +76,17 @@
     private final int mNavMode;
 
     // Helper fields.
-    @NonNull private final MenuBuilder mMenuBuilder;
+    private final MenuBuilder mMenuBuilder;
     private final int mPopupMaxWidth;
-    @NonNull private final RenderResources res;
+    private final RenderResources res;
     @Nullable private final ActionBarView mActionBarView;
     @Nullable private FrameLayout mContentRoot;
-    @NonNull private final ActionBarCallback mCallback;
+    private final ActionBarCallback mCallback;
 
     // A fake parent for measuring views.
     @Nullable private ViewGroup mMeasureParent;
 
-    public ActionBarLayout(@NonNull BridgeContext context, @NonNull SessionParams params) {
+    public ActionBarLayout(BridgeContext context, SessionParams params) {
 
         super(context);
         setOrientation(LinearLayout.HORIZONTAL);
@@ -176,29 +170,6 @@
             mActionBarView.setSplitActionBar(mSplit);
 
             inflateMenus();
-
-            // Find if the Overflow Menu Button (the three dots) exists. If yes,
-            // add the view cookie.
-            Predicate<View> overflowMenuButtonTest = new Predicate<View>() {
-                @Override
-                public boolean apply(View view) {
-                    ViewGroup.LayoutParams lp = view.getLayoutParams();
-                    return lp instanceof ActionMenuView.LayoutParams &&
-                            ((ActionMenuView.LayoutParams) lp).isOverflowButton;
-                }
-            };
-            View overflowMenu = null;
-            if (mSplit) {
-                if (splitView != null) {
-                    overflowMenu = splitView.findViewByPredicate(overflowMenuButtonTest);
-                }
-            }
-            else {
-                overflowMenu = mActionBarView.findViewByPredicate(overflowMenuButtonTest);
-            }
-            if (overflowMenu != null) {
-                mBridgeContext.addViewKey(overflowMenu, new SystemViewCookie(ACTION_BAR_OVERFLOW));
-            }
         }
     }
 
@@ -245,7 +216,7 @@
     }
 
     @Nullable
-    private Drawable getDrawable(@NonNull String name, boolean isFramework) {
+    private Drawable getDrawable(String name, boolean isFramework) {
         ResourceValue value = res.findResValue(name, isFramework);
         value = res.resolveResValue(value);
         if (value != null) {
@@ -286,7 +257,6 @@
      * Returns a {@link LinearLayout} containing the menu list view to be embedded in a
      * {@link RelativeLayout}
      */
-    @NonNull
     private View createMenuView() {
         DisplayMetrics metrics = mBridgeContext.getMetrics();
         OverflowMenuAdapter adapter = new OverflowMenuAdapter(mMenuBuilder, mThemedContext);
@@ -343,7 +313,7 @@
     }
 
     // Copied from com.android.internal.view.menu.MenuPopHelper.measureContentWidth()
-    private int measureContentWidth(@NonNull ListAdapter adapter) {
+    private int measureContentWidth(ListAdapter adapter) {
         // Menus don't tend to be long, so this is more sane than it looks.
         int maxWidth = 0;
         View itemView = null;
@@ -377,7 +347,7 @@
         return maxWidth;
     }
 
-    private int getPixelValue(@NonNull String value, @NonNull DisplayMetrics metrics) {
+    private int getPixelValue(String value, DisplayMetrics metrics) {
         TypedValue typedValue = ResourceHelper.getValue(null, value, false /*requireUnit*/);
         return (int) typedValue.getDimension(metrics);
     }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 2f23137..9a7fe18 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -37,8 +37,10 @@
 import com.android.ide.common.rendering.api.SessionParams;
 import com.android.ide.common.rendering.api.SessionParams.RenderingMode;
 import com.android.ide.common.rendering.api.ViewInfo;
+import com.android.ide.common.rendering.api.ViewType;
 import com.android.internal.util.XmlUtils;
 import com.android.internal.view.menu.ActionMenuItemView;
+import com.android.internal.view.menu.ActionMenuView;
 import com.android.internal.view.menu.BridgeMenuItemImpl;
 import com.android.internal.view.menu.IconMenuItemView;
 import com.android.internal.view.menu.ListMenuItemView;
@@ -83,7 +85,9 @@
 import android.view.ViewGroup;
 import android.view.ViewGroup.LayoutParams;
 import android.view.ViewGroup.MarginLayoutParams;
+import android.view.ViewParent;
 import android.view.WindowManagerGlobal_Delegate;
+import android.view.ViewParent;
 import android.widget.AbsListView;
 import android.widget.AbsSpinner;
 import android.widget.AdapterView;
@@ -1474,16 +1478,49 @@
 
         ViewInfo result;
         if (isContentFrame) {
+            // The view is part of the layout added by the user. Hence,
+            // the ViewCookie may be obtained only through the Context.
             result = new ViewInfo(view.getClass().getName(),
-                    getViewKey(view),
+                    getContext().getViewKey(view),
                     view.getLeft(), view.getTop() + offset, view.getRight(),
                     view.getBottom() + offset, view, view.getLayoutParams());
-
         } else {
-            result = new SystemViewInfo(view.getClass().getName(),
+            // We are part of the system decor.
+            SystemViewInfo r = new SystemViewInfo(view.getClass().getName(),
                     getViewKey(view),
                     view.getLeft(), view.getTop(), view.getRight(),
                     view.getBottom(), view, view.getLayoutParams());
+            result = r;
+            // We currently mark three kinds of views:
+            // 1. Menus in the Action Bar
+            // 2. Menus in the Overflow popup.
+            // 3. The overflow popup button.
+            if (view instanceof ListMenuItemView) {
+                // Mark 2.
+                // All menus in the popup are of type ListMenuItemView.
+                r.setViewType(ViewType.ACTION_BAR_OVERFLOW_MENU);
+            } else {
+                // Mark 3.
+                ViewGroup.LayoutParams lp = view.getLayoutParams();
+                if (lp instanceof ActionMenuView.LayoutParams &&
+                        ((ActionMenuView.LayoutParams) lp).isOverflowButton) {
+                    r.setViewType(ViewType.ACTION_BAR_OVERFLOW);
+                } else {
+                    // Mark 1.
+                    // A view is a menu in the Action Bar is it is not the overflow button and of
+                    // its parent is of type ActionMenuView. We can also check if the view is
+                    // instanceof ActionMenuItemView but that will fail for menus using
+                    // actionProviderClass.
+                    ViewParent parent = view.getParent();
+                    while (parent != mViewRoot && parent instanceof ViewGroup) {
+                        if (parent instanceof ActionMenuView) {
+                            r.setViewType(ViewType.ACTION_BAR_MENU);
+                            break;
+                        }
+                        parent = parent.getParent();
+                    }
+                }
+            }
         }
 
         if (setExtendedInfo) {
@@ -1502,7 +1539,7 @@
         return result;
     }
 
-    /**
+    /* (non-Javadoc)
      * The cookie for menu items are stored in menu item and not in the map from View stored in
      * BridgeContext.
      */
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java
index 5c267df..9fea167 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/SystemViewInfo.java
@@ -17,9 +17,15 @@
 package com.android.layoutlib.bridge.impl;
 
 import com.android.ide.common.rendering.api.ViewInfo;
+import com.android.ide.common.rendering.api.ViewType;
 
+/**
+ * ViewInfo for views added by the platform.
+ */
 public class SystemViewInfo extends ViewInfo {
 
+    private ViewType mViewType;
+
     public SystemViewInfo(String name, Object cookie, int left, int top,
             int right, int bottom) {
         super(name, cookie, left, top, right, bottom);
@@ -32,7 +38,14 @@
     }
 
     @Override
-    public boolean isSystemView() {
-        return true;
+    public ViewType getViewType() {
+        if (mViewType != null) {
+            return mViewType;
+        }
+        return ViewType.SYSTEM_UNKNOWN;
+    }
+
+    public void setViewType(ViewType type) {
+        mViewType = type;
     }
 }