diff options
author | Yorke Lee <yorkelee@google.com> | 2013-07-30 16:02:40 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-07-30 16:02:40 +0000 |
commit | 877b420f80276c2513e0b062c7c8f977e6a87677 (patch) | |
tree | 7c28ffa4e511ca44eee9e50ff70685537f8c702c /src | |
parent | 9502a16be5958aa1caee283126b5d0141cb4d612 (diff) | |
parent | bf34a90d6c738b7a697095c4ee1c3a108e8fea8d (diff) |
Merge "Implement dialpad in XML"
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/dialpad/DialpadKeyButton.java | 137 | ||||
-rw-r--r-- | src/com/android/dialer/dialpad/NewDialpadFragment.java | 35 |
2 files changed, 167 insertions, 5 deletions
diff --git a/src/com/android/dialer/dialpad/DialpadKeyButton.java b/src/com/android/dialer/dialpad/DialpadKeyButton.java new file mode 100644 index 000000000..9aae631a5 --- /dev/null +++ b/src/com/android/dialer/dialpad/DialpadKeyButton.java @@ -0,0 +1,137 @@ +/* + * Copyright (C) 2012 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.dialer.dialpad; + +import android.content.Context; +import android.graphics.Rect; +import android.os.Bundle; +import android.util.AttributeSet; +import android.view.MotionEvent; +import android.view.View; +import android.view.accessibility.AccessibilityEvent; +import android.view.accessibility.AccessibilityManager; +import android.view.accessibility.AccessibilityNodeInfo; +import android.widget.RelativeLayout; + +/** + * Custom class for dialpad buttons. + * <p> + * This class implements lift-to-type interaction when touch exploration is + * enabled. + */ +public class DialpadKeyButton extends RelativeLayout { + /** Accessibility manager instance used to check touch exploration state. */ + private AccessibilityManager mAccessibilityManager; + + /** Bounds used to filter HOVER_EXIT events. */ + private Rect mHoverBounds = new Rect(); + + public interface OnPressedListener { + public void onPressed(View view, boolean pressed); + } + + private OnPressedListener mOnPressedListener; + + public void setOnPressedListener(OnPressedListener onPressedListener) { + mOnPressedListener = onPressedListener; + } + + public DialpadKeyButton(Context context, AttributeSet attrs) { + super(context, attrs); + initForAccessibility(context); + } + + public DialpadKeyButton(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + initForAccessibility(context); + } + + private void initForAccessibility(Context context) { + mAccessibilityManager = (AccessibilityManager) context.getSystemService( + Context.ACCESSIBILITY_SERVICE); + } + + @Override + public void setPressed(boolean pressed) { + super.setPressed(pressed); + if (mOnPressedListener != null) { + mOnPressedListener.onPressed(this, pressed); + } + } + + @Override + public void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + + mHoverBounds.left = getPaddingLeft(); + mHoverBounds.right = w - getPaddingRight(); + mHoverBounds.top = getPaddingTop(); + mHoverBounds.bottom = h - getPaddingBottom(); + } + + @Override + public boolean performAccessibilityAction(int action, Bundle arguments) { + if (action == AccessibilityNodeInfo.ACTION_CLICK) { + simulateClickForAccessibility(); + return true; + } + + return super.performAccessibilityAction(action, arguments); + } + + @Override + public boolean onHoverEvent(MotionEvent event) { + // When touch exploration is turned on, lifting a finger while inside + // the button's hover target bounds should perform a click action. + if (mAccessibilityManager.isEnabled() + && mAccessibilityManager.isTouchExplorationEnabled()) { + switch (event.getActionMasked()) { + case MotionEvent.ACTION_HOVER_ENTER: + // Lift-to-type temporarily disables double-tap activation. + setClickable(false); + break; + case MotionEvent.ACTION_HOVER_EXIT: + if (mHoverBounds.contains((int) event.getX(), (int) event.getY())) { + simulateClickForAccessibility(); + } + setClickable(true); + break; + } + } + + return super.onHoverEvent(event); + } + + /** + * When accessibility is on, simulate press and release to preserve the + * semantic meaning of performClick(). Required for Braille support. + */ + private void simulateClickForAccessibility() { + // Checking the press state prevents double activation. + if (isPressed()) { + return; + } + + setPressed(true); + + // Stay consistent with performClick() by sending the event after + // setting the pressed state but before performing the action. + sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); + + setPressed(false); + } +} diff --git a/src/com/android/dialer/dialpad/NewDialpadFragment.java b/src/com/android/dialer/dialpad/NewDialpadFragment.java index 15627c797..659c608c2 100644 --- a/src/com/android/dialer/dialpad/NewDialpadFragment.java +++ b/src/com/android/dialer/dialpad/NewDialpadFragment.java @@ -69,6 +69,7 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupMenu; +import android.widget.TableRow; import android.widget.TextView; import com.android.contacts.common.CallUtil; @@ -98,7 +99,7 @@ public class NewDialpadFragment extends Fragment View.OnLongClickListener, View.OnKeyListener, AdapterView.OnItemClickListener, TextWatcher, PopupMenu.OnMenuItemClickListener, - DialpadImageButton.OnPressedListener { + DialpadKeyButton.OnPressedListener { private static final String TAG = NewDialpadFragment.class.getSimpleName(); public interface OnDialpadFragmentStartedListener { @@ -577,10 +578,34 @@ public class NewDialpadFragment extends Fragment } private void setupKeypad(View fragmentView) { - int[] buttonIds = new int[] { 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.zero, R.id.star, R.id.pound}; - for (int id : buttonIds) { - ((DialpadImageButton) fragmentView.findViewById(id)).setOnPressedListener(this); + 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}; + + DialpadKeyButton dialpadKey; + TextView numberView; + TextView lettersView; + final Resources resources = getResources(); + for (int i = 0; i < buttonIds.length; i++) { + dialpadKey = (DialpadKeyButton) fragmentView.findViewById(buttonIds[i]); + dialpadKey.setLayoutParams(new TableRow.LayoutParams( + TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT)); + dialpadKey.setOnPressedListener(this); + numberView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_number); + lettersView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_letters); + numberView.setText(resources.getString(numberIds[i])); + lettersView.setText(resources.getString(letterIds[i])); } // Long-pressing one button will initiate Voicemail. |