diff options
Diffstat (limited to 'InCallUI/src/com/android/incallui/DialpadFragment.java')
-rw-r--r-- | InCallUI/src/com/android/incallui/DialpadFragment.java | 129 |
1 files changed, 117 insertions, 12 deletions
diff --git a/InCallUI/src/com/android/incallui/DialpadFragment.java b/InCallUI/src/com/android/incallui/DialpadFragment.java index 5087561e6..236b38c9c 100644 --- a/InCallUI/src/com/android/incallui/DialpadFragment.java +++ b/InCallUI/src/com/android/incallui/DialpadFragment.java @@ -17,16 +17,22 @@ package com.android.incallui; import android.content.Context; +import android.content.res.Resources; import android.os.Bundle; import android.text.Editable; import android.text.method.DialerKeyListener; +import android.util.AttributeSet; import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.ViewTreeObserver; import android.view.accessibility.AccessibilityManager; import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TableRow; +import android.widget.TextView; import java.util.HashMap; @@ -37,6 +43,61 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadPrese implements DialpadPresenter.DialpadUi, View.OnTouchListener, View.OnKeyListener, View.OnHoverListener, View.OnClickListener { + private static final float DIALPAD_SLIDE_FRACTION = 1.0f; + + /** + * LinearLayout with getter and setter methods for the translationY property using floats, + * for animation purposes. + */ + public static class DialpadSlidingLinearLayout extends LinearLayout { + + public DialpadSlidingLinearLayout(Context context) { + super(context); + } + + public DialpadSlidingLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public DialpadSlidingLinearLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public float getYFraction() { + final int height = getHeight(); + if (height == 0) return 0; + return getTranslationY() / height; + } + + public void setYFraction(float yFraction) { + setTranslationY(yFraction * getHeight()); + } + } + + /** + * LinearLayout that always returns true for onHoverEvent callbacks, to fix + * problems with accessibility due to the dialpad overlaying other fragments. + */ + public static class HoverIgnoringLinearLayout extends LinearLayout { + + public HoverIgnoringLinearLayout(Context context) { + super(context); + } + + public HoverIgnoringLinearLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public HoverIgnoringLinearLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + public boolean onHoverEvent(MotionEvent event) { + return true; + } + } + private EditText mDtmfDialerField; /** Hash Map to map a view id to a character*/ @@ -254,9 +315,8 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadPrese @Override public void onClick(View v) { - Log.d(this, "onClick"); final AccessibilityManager accessibilityManager = (AccessibilityManager) - getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE); + v.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); // When accessibility is on, simulate press and release to preserve the // semantic meaning of performClick(). Required for Braille support. if (accessibilityManager.isEnabled()) { @@ -273,7 +333,7 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadPrese // When touch exploration is turned on, lifting a finger while inside // the button's hover target bounds should perform a click action. final AccessibilityManager accessibilityManager = (AccessibilityManager) - getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE); + v.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (accessibilityManager.isEnabled() && accessibilityManager.isTouchExplorationEnabled()) { @@ -382,6 +442,29 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadPrese setupKeypad(parent); } + + final ViewTreeObserver vto = parent.getViewTreeObserver(); + // Adjust the translation of the DialpadFragment in a preDrawListener instead of in + // DialtactsActivity, because at the point in time when the DialpadFragment is added, + // its views have not been laid out yet. + final ViewTreeObserver.OnPreDrawListener + preDrawListener = new ViewTreeObserver.OnPreDrawListener() { + @Override + public boolean onPreDraw() { + if (isHidden()) return true; + if (parent.getTranslationY() == 0) { + ((DialpadSlidingLinearLayout) parent) + .setYFraction(DIALPAD_SLIDE_FRACTION); + } + final ViewTreeObserver vto = parent.getViewTreeObserver(); + vto.removeOnPreDrawListener(this); + return true; + } + + }; + + vto.addOnPreDrawListener(preDrawListener); + return parent; } @@ -440,21 +523,43 @@ public class DialpadFragment extends BaseFragment<DialpadPresenter, DialpadPrese } } - /** - * setup the keys on the dialer activity, using the keymaps. - */ - private void setupKeypad(View parent) { - // for each view id listed in the displaymap + private void setupKeypad(View fragmentView) { + final int[] buttonIds = new int[] {R.id.zero, R.id.one, R.id.two, R.id.three, R.id.four, + R.id.five, R.id.six, R.id.seven, R.id.eight, R.id.nine, R.id.star, R.id.pound}; + + final int[] numberIds = new int[] {R.string.dialpad_0_number, R.string.dialpad_1_number, + R.string.dialpad_2_number, R.string.dialpad_3_number, R.string.dialpad_4_number, + R.string.dialpad_5_number, R.string.dialpad_6_number, R.string.dialpad_7_number, + R.string.dialpad_8_number, R.string.dialpad_9_number, R.string.dialpad_star_number, + R.string.dialpad_pound_number}; + + final int[] letterIds = new int[] {R.string.dialpad_0_letters, R.string.dialpad_1_letters, + R.string.dialpad_2_letters, R.string.dialpad_3_letters, R.string.dialpad_4_letters, + R.string.dialpad_5_letters, R.string.dialpad_6_letters, R.string.dialpad_7_letters, + R.string.dialpad_8_letters, R.string.dialpad_9_letters, + R.string.dialpad_star_letters, R.string.dialpad_pound_letters}; + + final Resources resources = getResources(); + View button; - for (int viewId : mDisplayMap.keySet()) { - // locate the view - button = parent.findViewById(viewId); - // Setup the listeners for the buttons + TextView numberView; + TextView lettersView; + + for (int i = 0; i < buttonIds.length; i++) { + button = fragmentView.findViewById(buttonIds[i]); button.setOnTouchListener(this); button.setClickable(true); button.setOnKeyListener(this); button.setOnHoverListener(this); button.setOnClickListener(this); + numberView = (TextView) button.findViewById(R.id.dialpad_key_number); + lettersView = (TextView) button.findViewById(R.id.dialpad_key_letters); + final String numberString = resources.getString(numberIds[i]); + numberView.setText(numberString); + button.setContentDescription(numberString); + if (lettersView != null) { + lettersView.setText(resources.getString(letterIds[i])); + } } } } |