Fix problem where swiping upward in overflow menu did not display the
correct options menu items.

b/13441681

Change-Id: If4f6970a4dd92e20ab1c04eae5228a0475bf445c
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 8bca7dd..f302f29 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -151,6 +151,7 @@
     private View mDialpadButton;
     private View mDialButton;
     private PopupMenu mOverflowMenu;
+    private PopupMenu mDialpadOverflowMenu;
 
     // Padding view used to shift the fragment frame up when the dialpad is shown so that
     // the contents of the fragment frame continue to exist in a layout of the same height
@@ -337,9 +338,6 @@
 
         prepareSearchView();
 
-        hideDialpadFragment(false, false);
-        setupFakeActionBarItems();
-
         mDialerDatabaseHelper = DatabaseHelperManager.getDatabaseHelper(this);
         SmartDialPrefix.initializeNanpSettings(this);
     }
@@ -347,6 +345,7 @@
     @Override
     protected void onResume() {
         super.onResume();
+        setupFakeActionBarItems();
         if (mFirstLaunch) {
             displayFragment(getIntent());
         } else if (!phoneIsInUse() && mInCallDialpadUp) {
@@ -451,7 +450,7 @@
         switch (view.getId()) {
             case R.id.overflow_menu: {
                 if (isDialpadShowing()) {
-                    mDialpadFragment.optionsMenuInvoked(view);
+                    mDialpadOverflowMenu.show();
                 } else {
                     mOverflowMenu.show();
                 }
@@ -545,6 +544,7 @@
         ft.commit();
         mDialButton.setVisibility(shouldShowOnscreenDialButton() ? View.VISIBLE : View.GONE);
         mDialpadButton.setVisibility(View.GONE);
+        mMenuButton.setOnTouchListener(mDialpadOverflowMenu.getDragToOpenListener());
     }
 
     public void hideDialpadFragment(boolean animate, boolean clearDialpad) {
@@ -562,6 +562,7 @@
         ft.commit();
         mDialButton.setVisibility(View.GONE);
         mDialpadButton.setVisibility(View.VISIBLE);
+        mMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
     }
 
     private void prepareSearchView() {
@@ -664,16 +665,17 @@
                         });
     }
 
-
-    public void setupFakeActionBarItems() {
+    private void setupFakeActionBarItems() {
         mMenuButton = findViewById(R.id.overflow_menu);
         if (mMenuButton != null) {
             mMenuButton.setOnClickListener(this);
-
-            mOverflowMenu = new OverflowPopupMenu(DialtactsActivity.this, mMenuButton);
-            final Menu menu = mOverflowMenu.getMenu();
-            mOverflowMenu.inflate(R.menu.dialtacts_options);
-            mOverflowMenu.setOnMenuItemClickListener(this);
+            if (mOverflowMenu == null) {
+                mOverflowMenu = buildOptionsMenu(mMenuButton);
+            }
+            if (mDialpadOverflowMenu == null) {
+                mDialpadOverflowMenu = mDialpadFragment.buildOptionsMenu(mMenuButton);
+            }
+            // Initial state is with dialpad fragment not shown
             mMenuButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener());
         }
 
@@ -692,6 +694,13 @@
         mDialpadButton.setOnClickListener(this);
     }
 
+    private PopupMenu buildOptionsMenu(View invoker) {
+        PopupMenu menu = new OverflowPopupMenu(this, invoker);
+        menu.inflate(R.menu.dialtacts_options);
+        menu.setOnMenuItemClickListener(this);
+        return menu;
+    }
+
     private void fixIntent(Intent intent) {
         // This should be cleaned up: the call key used to send an Intent
         // that just said to go to the recent calls list.  It now sends this