From fbf7ee3329bf91214273d47d33449a064aece30d Mon Sep 17 00:00:00 2001 From: Andrew Lee Date: Fri, 6 Jun 2014 15:20:51 -0700 Subject: Always show options menu in Dialer dialpad. We disable options if there are no digits in the text field. The PopUpMenu does not reflect this visually right now though. This also fixes bad centering of the "dial to add call" text, because now the text field will have equal left/right margins from the edges of the screen.. Bug: 15453278 Change-Id: I6f4a7a597ed289fb1b59c9fcac261d151144b642 --- .../android/dialer/dialpad/DialpadFragment.java | 36 +++++++++++++--------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'src/com/android/dialer/dialpad/DialpadFragment.java') diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index 3eedcdaef..134c2a7f4 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -174,7 +174,7 @@ public class DialpadFragment extends Fragment /** Remembers if we need to clear digits field when the screen is completely gone. */ private boolean mClearDigitsOnStop; - private View mOverflowMenuButton; + private PopupMenu mOverflowPopupMenu; private View mDelete; private ToneGenerator mToneGenerator; private final Object mToneGeneratorLock = new Object(); @@ -310,10 +310,6 @@ public class DialpadFragment extends Fragment if (isDigitsEmpty()) { mDigitsFilledByIntent = false; mDigits.setCursorVisible(false); - // Set to INVISIBLE instead of GONE so that text (eg. "Type number to add") is centered. - mOverflowMenuButton.setVisibility(View.INVISIBLE); - } else if (mDialpadView.canDigitsBeEdited()){ - mOverflowMenuButton.setVisibility(View.VISIBLE); } if (mDialpadQueryListener != null) { @@ -392,9 +388,6 @@ public class DialpadFragment extends Fragment mDialpadChooser = (ListView) fragmentView.findViewById(R.id.dialpadChooser); mDialpadChooser.setOnItemClickListener(this); - mOverflowMenuButton = mDialpadView.getOverflowMenuButton(); - mOverflowMenuButton.setOnClickListener(this); - return fragmentView; } @@ -657,8 +650,10 @@ public class DialpadFragment extends Fragment mSmsPackageComponentName = DialerUtils.getSmsComponent(activity); - final PopupMenu overflowMenu = buildOptionsMenu(mOverflowMenuButton); - mOverflowMenuButton.setOnTouchListener(overflowMenu.getDragToOpenListener()); + View overflowMenuButton = mDialpadView.getOverflowMenuButton(); + mOverflowPopupMenu = buildOptionsMenu(overflowMenuButton); + overflowMenuButton.setOnTouchListener(mOverflowPopupMenu.getDragToOpenListener()); + overflowMenuButton.setOnClickListener(this); } @Override @@ -851,11 +846,22 @@ public class DialpadFragment extends Fragment * @param invoker the View that invoked the options menu, to act as an anchor location. */ private PopupMenu buildOptionsMenu(View invoker) { - final PopupMenu popupMenu = new PopupMenu(getActivity(), invoker); + final PopupMenu popupMenu = new PopupMenu(getActivity(), invoker) { + @Override + public void show() { + final Menu menu = getMenu(); + final MenuItem sendMessage = menu.findItem(R.id.menu_send_message); + sendMessage.setVisible(mSmsPackageComponentName != null); + + boolean enable = !isDigitsEmpty(); + for (int i = 0; i < menu.size(); i++) { + menu.getItem(i).setEnabled(enable); + } + + super.show(); + } + }; popupMenu.inflate(R.menu.dialpad_options); - final Menu menu = popupMenu.getMenu(); - final MenuItem sendMessage = menu.findItem(R.id.menu_send_message); - sendMessage.setVisible(mSmsPackageComponentName != null); popupMenu.setOnMenuItemClickListener(this); return popupMenu; } @@ -883,7 +889,7 @@ public class DialpadFragment extends Fragment return; } case R.id.dialpad_overflow: { - buildOptionsMenu(view).show(); + mOverflowPopupMenu.show(); break; } default: { -- cgit v1.2.3