From 526c0b832e27dc38a8dc6eae1f16c50acb51c6e8 Mon Sep 17 00:00:00 2001 From: Ihab Awad Date: Thu, 27 Feb 2014 12:55:36 -0800 Subject: New appearance and look and feel for dialpad. http://b/13189041 Change-Id: I91028c8fdee31c1f76610573a4396eb979c30170 --- .../android/dialer/dialpad/DialpadFragment.java | 137 ++++++++------------- 1 file changed, 52 insertions(+), 85 deletions(-) (limited to 'src/com/android/dialer/dialpad') diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java index 0d2337819..ae9700f33 100644 --- a/src/com/android/dialer/dialpad/DialpadFragment.java +++ b/src/com/android/dialer/dialpad/DialpadFragment.java @@ -35,11 +35,9 @@ import android.net.Uri; import android.os.Bundle; import android.os.RemoteException; import android.os.ServiceManager; -import android.provider.ContactsContract.Contacts; import android.provider.Contacts.People; import android.provider.Contacts.Phones; import android.provider.Contacts.PhonesColumns; -import android.provider.ContactsContract.Intents; import android.provider.Settings; import android.telephony.PhoneNumberUtils; import android.telephony.PhoneStateListener; @@ -50,17 +48,13 @@ import android.text.TextUtils; import android.text.TextWatcher; import android.text.style.RelativeSizeSpan; import android.util.AttributeSet; -import android.util.DisplayMetrics; import android.util.Log; -import android.util.TypedValue; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; -import android.view.MenuInflater; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; -import android.view.ViewConfiguration; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnPreDrawListener; @@ -76,17 +70,12 @@ import android.widget.TextView; import com.android.contacts.common.CallUtil; import com.android.contacts.common.GeoUtil; -import com.android.contacts.common.activity.TransactionSafeActivity; -import com.android.contacts.common.preference.ContactsPreferences; import com.android.contacts.common.util.PhoneNumberFormatter; import com.android.contacts.common.util.StopWatch; import com.android.dialer.NeededForReflection; import com.android.dialer.DialtactsActivity; import com.android.dialer.R; import com.android.dialer.SpecialCharSequenceMgr; -import com.android.dialer.database.DialerDatabaseHelper; -import com.android.dialer.interactions.PhoneNumberInteraction; -import com.android.dialer.util.OrientationUtil; import com.android.internal.telephony.ITelephony; import com.android.phone.common.CallLogAsync; import com.android.phone.common.HapticFeedback; @@ -105,8 +94,19 @@ public class DialpadFragment extends Fragment DialpadKeyButton.OnPressedListener { private static final String TAG = DialpadFragment.class.getSimpleName(); - public interface OnDialpadFragmentStartedListener { - public void onDialpadFragmentStarted(); + /** + * This interface allows the DialpadFragment to tell its hosting Activity when and when not + * to display the "dial" button. While this is logically part of the DialpadFragment, the + * need to have a particular kind of slick animation puts the "dial" button in the parent. + * + * The parent calls dialButtonPressed() and optionsMenuInvoked() on the dialpad fragment + * when appropriate. + * + * TODO: Refactor the app so this interchange is a bit cleaner. + */ + public interface HostInterface { + void setDialButtonEnabled(boolean enabled); + void setDialButtonContainerVisible(boolean visible); } /** @@ -210,8 +210,6 @@ public class DialpadFragment extends Fragment */ private final HashSet mPressedDialpadKeys = new HashSet(12); - private View mDialButtonContainer; - private View mDialButton; private ListView mDialpadChooser; private DialpadChooserAdapter mDialpadChooserAdapter; @@ -396,7 +394,6 @@ public class DialpadFragment extends Fragment // Load up the resources for the text field. Resources r = getResources(); - mDialButtonContainer = fragmentView.findViewById(R.id.dialButtonContainer); mDigitsContainer = fragmentView.findViewById(R.id.digits_container); mDigits = (EditText) fragmentView.findViewById(R.id.digits); mDigits.setKeyListener(UnicodeDialerKeyListener.INSTANCE); @@ -411,15 +408,6 @@ public class DialpadFragment extends Fragment setupKeypad(fragmentView); } - mDialButton = fragmentView.findViewById(R.id.dialButton); - if (r.getBoolean(R.bool.config_show_onscreen_dial_button)) { - mDialButton.setOnClickListener(this); - mDialButton.setOnLongClickListener(this); - } else { - mDialButton.setVisibility(View.GONE); // It's VISIBLE by default - mDialButton = null; - } - mDelete = fragmentView.findViewById(R.id.deleteButton); if (mDelete != null) { mDelete.setOnClickListener(this); @@ -457,18 +445,6 @@ public class DialpadFragment extends Fragment @Override public void onStart() { super.onStart(); - - final Activity activity = getActivity(); - - try { - ((OnDialpadFragmentStartedListener) activity).onDialpadFragmentStarted(); - } catch (ClassCastException e) { - throw new ClassCastException(activity.toString() - + " must implement OnDialpadFragmentStartedListener"); - } - - final View overflowButton = getView().findViewById(R.id.overflow_menu_on_dialpad); - overflowButton.setOnClickListener(this); } private boolean isLayoutReady() { @@ -654,10 +630,6 @@ public class DialpadFragment extends Fragment dialpadKey.setContentDescription(numberString); if (lettersView != null) { lettersView.setText(resources.getString(letterIds[i])); - if (buttonIds[i] == R.id.zero) { - lettersView.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension( - R.dimen.dialpad_key_plus_size)); - } } } @@ -881,7 +853,7 @@ public class DialpadFragment extends Fragment switch (view.getId()) { case R.id.digits: if (keyCode == KeyEvent.KEYCODE_ENTER) { - dialButtonPressed(); + handleDialButtonPressed(); return true; } break; @@ -963,27 +935,37 @@ public class DialpadFragment extends Fragment } } + /** + * Called by the containing Activity to tell this Fragment that the gesture to display the + * "options" menu has been invoked. + * + * @param invoker the View that invoked the options menu, to act as an anchor location. + */ + public void optionsMenuInvoked(View invoker) { + final PopupMenu popupMenu = new PopupMenu(getActivity(), invoker); + final Menu menu = popupMenu.getMenu(); + popupMenu.inflate(R.menu.dialpad_options); + popupMenu.setOnMenuItemClickListener(this); + setupMenuItems(menu); + popupMenu.show(); + } + + /** + * Called by the containing Activity to tell this Fragment that the dial button has been + * pressed. + */ + public void dialButtonPressed() { + mHaptic.vibrate(); + handleDialButtonPressed(); + } + @Override public void onClick(View view) { switch (view.getId()) { - case R.id.overflow_menu_on_dialpad: { - final PopupMenu popupMenu = new PopupMenu(getActivity(), view); - final Menu menu = popupMenu.getMenu(); - popupMenu.inflate(R.menu.dialpad_options); - popupMenu.setOnMenuItemClickListener(this); - setupMenuItems(menu); - popupMenu.show(); - break; - } case R.id.deleteButton: { keyPressed(KeyEvent.KEYCODE_DEL); return; } - case R.id.dialButton: { - mHaptic.vibrate(); // Vibrate here too, just like we do for the regular keys - dialButtonPressed(); - return; - } case R.id.digits: { if (!isDigitsEmpty()) { mDigits.setCursorVisible(true); @@ -1058,16 +1040,6 @@ public class DialpadFragment extends Fragment mDigits.setCursorVisible(true); return false; } - case R.id.dialButton: { - if (isDigitsEmpty()) { - handleDialButtonClickWithEmptyDigits(); - // This event should be consumed so that onClick() won't do the exactly same - // thing. - return true; - } else { - return false; - } - } } return false; } @@ -1160,7 +1132,7 @@ public class DialpadFragment extends Fragment * user needs to press the dial button again, to dial it (general * case described above). */ - public void dialButtonPressed() { + private void handleDialButtonPressed() { if (isDigitsEmpty()) { // No number entered. handleDialButtonClickWithEmptyDigits(); } else { @@ -1330,7 +1302,7 @@ public class DialpadFragment extends Fragment mDigits.setVisibility(View.GONE); } if (mDialpad != null) mDialpad.setVisibility(View.GONE); - if (mDialButtonContainer != null) mDialButtonContainer.setVisibility(View.GONE); + ((HostInterface) getActivity()).setDialButtonContainerVisible(false); mDialpadChooser.setVisibility(View.VISIBLE); @@ -1348,7 +1320,7 @@ public class DialpadFragment extends Fragment mDigits.setVisibility(View.VISIBLE); } if (mDialpad != null) mDialpad.setVisibility(View.VISIBLE); - if (mDialButtonContainer != null) mDialButtonContainer.setVisibility(View.VISIBLE); + ((HostInterface) getActivity()).setDialButtonContainerVisible(true); mDialpadChooser.setVisibility(View.GONE); } } @@ -1597,23 +1569,18 @@ public class DialpadFragment extends Fragment */ private void updateDialAndDeleteButtonEnabledState() { final boolean digitsNotEmpty = !isDigitsEmpty(); - - if (mDialButton != null) { - // On CDMA phones, if we're already on a call, we *always* - // enable the Dial button (since you can press it without - // entering any digits to send an empty flash.) - if (phoneIsCdma() && phoneIsOffhook()) { - mDialButton.setEnabled(true); - } else { - // Common case: GSM, or CDMA but not on a call. - // Enable the Dial button if some digits have - // been entered, or if there is a last dialed number - // that could be redialed. - mDialButton.setEnabled(digitsNotEmpty || - !TextUtils.isEmpty(mLastNumberDialed)); - } - } mDelete.setEnabled(digitsNotEmpty); + // On CDMA phones, if we're already on a call, we *always* enable the Dial button (since + // you can press it without entering any digits to send an empty flash.) + if (phoneIsCdma() && phoneIsOffhook()) { + ((HostInterface) getActivity()).setDialButtonEnabled(true); + } else { + // Common case: GSM, or CDMA but not on a call. Enable the Dial button if something + // has been entered into the digits field, or if there is a last dialed number that + // could be redialed. + ((HostInterface) getActivity()).setDialButtonEnabled( + digitsNotEmpty || !TextUtils.isEmpty(mLastNumberDialed)); + } } /** -- cgit v1.2.3