OSDN Git Service

Add special system view cookie to OverflowButton. [DO NOT MERGE]
authorDeepanshu Gupta <deepanshu@google.com>
Fri, 25 Apr 2014 18:07:19 +0000 (11:07 -0700)
committerDeepanshu Gupta <deepanshu@google.com>
Sat, 3 May 2014 00:43:25 +0000 (17:43 -0700)
Add a special view cookie to enable the IDE to identify the overflow
menu button in the Action Bar.

Change-Id: Ida3ed776afb8c9fa8af23b73d4cf6d47eef0ab87
(cherry picked from commit c967d8dc62c429ecf3e27bf3714a953636e75cbf)

tools/layoutlib/bridge/src/com/android/layoutlib/bridge/bars/ActionBarLayout.java

index 76fc7f0..6fffbc5 100644 (file)
@@ -23,8 +23,10 @@ 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.MenuBuilder;
 import com.android.internal.view.menu.MenuBuilderAccessor;
 import com.android.internal.view.menu.MenuItemImpl;
@@ -57,6 +59,8 @@ import android.widget.RelativeLayout;
 
 import java.util.ArrayList;
 
+import static com.android.ide.common.rendering.api.SystemViewCookie.ACTION_BAR_OVERFLOW;
+
 /**
  * A layout representing the action bar.
  */
@@ -166,10 +170,33 @@ public class ActionBarLayout extends LinearLayout {
 
         if (mActionBarView != null) {
             // Set action bar to be split, if needed.
-            mActionBarView.setSplitView((ActionBarContainer) findViewById(R.id.split_action_bar));
+            ActionBarContainer splitView = (ActionBarContainer) findViewById(R.id.split_action_bar);
+            mActionBarView.setSplitView(splitView);
             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) {
+                    return view.getClass().getName()
+                            .equals("android.widget.ActionMenuPresenter$OverflowMenuButton");
+                }
+            };
+            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));
+            }
         }
     }