summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorke Lee <yorkelee@google.com>2013-07-30 16:02:40 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-07-30 16:02:40 +0000
commit877b420f80276c2513e0b062c7c8f977e6a87677 (patch)
tree7c28ffa4e511ca44eee9e50ff70685537f8c702c
parent9502a16be5958aa1caee283126b5d0141cb4d612 (diff)
parentbf34a90d6c738b7a697095c4ee1c3a108e8fea8d (diff)
Merge "Implement dialpad in XML"
-rw-r--r--res/layout/dialpad_key.xml43
-rw-r--r--res/layout/new_dialpad.xml61
-rw-r--r--res/layout/new_dialpad_fragment.xml4
-rw-r--r--res/values/strings.xml49
-rw-r--r--src/com/android/dialer/dialpad/DialpadKeyButton.java137
-rw-r--r--src/com/android/dialer/dialpad/NewDialpadFragment.java35
6 files changed, 274 insertions, 55 deletions
diff --git a/res/layout/dialpad_key.xml b/res/layout/dialpad_key.xml
new file mode 100644
index 000000000..eef12a12f
--- /dev/null
+++ b/res/layout/dialpad_key.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2013 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.
+-->
+
+<!-- A layout representing a single key in the dialpad -->
+<com.android.dialer.dialpad.DialpadKeyButton
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/dialpad_key"
+ style="@style/DialtactsDialpadButtonStyle"
+ android:clickable="true" >
+ <TextView
+ android:id="@+id/dialpad_key_number"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="#33b5e5"
+ android:textSize="40dp"
+ android:fontFamily="sans-serif-light"
+ android:layout_centerInParent="true"
+ />
+ <TextView
+ android:id="@+id/dialpad_key_letters"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textColor="#aaaaaa"
+ android:textSize="11dp"
+ android:paddingRight="11dp"
+ android:layout_alignBaseline="@id/dialpad_key_number"
+ android:fontFamily="sans-serif-light"
+ android:layout_alignParentRight="true"
+ />
+</com.android.dialer.dialpad.DialpadKeyButton> \ No newline at end of file
diff --git a/res/layout/new_dialpad.xml b/res/layout/new_dialpad.xml
index 29f9cf0e9..e71d4edf0 100644
--- a/res/layout/new_dialpad.xml
+++ b/res/layout/new_dialpad.xml
@@ -26,73 +26,38 @@
android:paddingStart="5dip"
android:paddingEnd="5dip"
android:paddingBottom="10dip"
+ android:stretchColumns="0,1,2"
android:layoutDirection="ltr" >
<TableRow
android:layout_height="0px"
android:layout_weight="1">
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/one" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_1_wht"
- android:contentDescription="@string/description_image_button_one" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/two" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_2_wht"
- android:contentDescription="@string/description_image_button_two" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/three" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_3_wht"
- android:contentDescription="@string/description_image_button_three" />
+ <include layout="@layout/dialpad_key" android:id="@+id/one"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/two"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/three"/>
</TableRow>
<TableRow
android:layout_height="0px"
android:layout_weight="1">
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/four" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_4_wht"
- android:contentDescription="@string/description_image_button_four" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/five" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_5_wht"
- android:contentDescription="@string/description_image_button_five" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/six" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_6_wht"
- android:contentDescription="@string/description_image_button_six" />
+ <include layout="@layout/dialpad_key" android:id="@+id/four"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/five"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/six"/>
</TableRow>
<TableRow
android:layout_height="0px"
android:layout_weight="1">
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/seven" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_7_wht"
- android:contentDescription="@string/description_image_button_seven" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/eight" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_8_wht"
- android:contentDescription="@string/description_image_button_eight" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/nine" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_9_wht"
- android:contentDescription="@string/description_image_button_nine" />
+ <include layout="@layout/dialpad_key" android:id="@+id/seven"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/eight"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/nine"/>
</TableRow>
<TableRow
android:layout_height="0px"
android:layout_weight="1">
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/star" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_star_wht"
- android:contentDescription="@string/description_image_button_star" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/zero" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_0_wht"
- android:contentDescription="@string/description_image_button_zero" />
- <com.android.dialer.dialpad.DialpadImageButton
- android:id="@+id/pound" style="@style/DialtactsDialpadButtonStyle"
- android:src="@drawable/dial_num_pound_wht"
- android:contentDescription="@string/description_image_button_pound" />
+ <include layout="@layout/dialpad_key" android:id="@+id/star"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/zero"/>
+ <include layout="@layout/dialpad_key" android:id="@+id/pound"/>
</TableRow>
</TableLayout>
diff --git a/res/layout/new_dialpad_fragment.xml b/res/layout/new_dialpad_fragment.xml
index 2026781fe..c357d4752 100644
--- a/res/layout/new_dialpad_fragment.xml
+++ b/res/layout/new_dialpad_fragment.xml
@@ -19,7 +19,7 @@
android:layout_height="match_parent"
android:orientation="vertical" >
<!-- spacer view -->
- <View
+ <Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
@@ -119,4 +119,4 @@
/>
</LinearLayout>
-</view> \ No newline at end of file
+</view>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 944d94450..7d4a4d9b4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -545,4 +545,53 @@
<!-- Title of activity that displays a list of all calls -->
<string name="call_log_activity_title">History</string>
+
+ <!-- Do not translate. -->
+ <string name="dialpad_0_number">0</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_0_letters">+</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_1_number">1</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_1_letters"></string>
+ <!-- Do not translate. -->
+ <string name="dialpad_2_number">2</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_2_letters">ABC</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_3_number">3</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_3_letters">DEF</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_4_number">4</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_4_letters">GHI</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_5_number">5</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_5_letters">JKL</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_6_number">6</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_6_letters">MNO</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_7_number">7</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_7_letters">PQRS</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_8_number">8</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_8_letters">TUV</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_9_number">9</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_9_letters">WXYZ</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_star_number">*</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_star_letters"></string>
+ <!-- Do not translate. -->
+ <string name="dialpad_pound_number">#</string>
+ <!-- Do not translate. -->
+ <string name="dialpad_pound_letters"></string>
</resources>
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.