From 5fa4c0fc8474432085966a4d1feee9f0a927c042 Mon Sep 17 00:00:00 2001 From: linyuh Date: Wed, 1 Nov 2017 10:19:07 -0700 Subject: Show dual alphabets on the dialpad if a secondary alphabet is available. Bug: 30215380 Test: Manual PiperOrigin-RevId: 174197504 Change-Id: Ide61f65a9dc1c104fa5bf136143c34e193c21396 --- .../dialer/dialpadview/DialpadAlphabets.java | 80 ++++++++++++++++++++++ .../android/dialer/dialpadview/DialpadView.java | 67 ++++++++++-------- .../dialpadview/res/layout-land/dialpad_key.xml | 4 ++ .../dialer/dialpadview/res/layout/dialpad_key.xml | 4 ++ .../dialer/dialpadview/res/values-land/styles.xml | 2 +- .../dialer/dialpadview/res/values/attrs.xml | 2 + .../dialer/dialpadview/res/values/dimens.xml | 3 +- .../dialer/dialpadview/res/values/strings.xml | 13 ---- .../dialer/dialpadview/res/values/styles.xml | 11 ++- .../android/incallui/res/values-sw360dp/dimens.xml | 4 ++ java/com/android/incallui/res/values/dimens.xml | 4 ++ java/com/android/incallui/res/values/styles.xml | 6 ++ 12 files changed, 155 insertions(+), 45 deletions(-) create mode 100644 java/com/android/dialer/dialpadview/DialpadAlphabets.java (limited to 'java/com/android') diff --git a/java/com/android/dialer/dialpadview/DialpadAlphabets.java b/java/com/android/dialer/dialpadview/DialpadAlphabets.java new file mode 100644 index 000000000..f02ca4395 --- /dev/null +++ b/java/com/android/dialer/dialpadview/DialpadAlphabets.java @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2017 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.dialpadview; + +import android.support.v4.util.SimpleArrayMap; + +/** A class containing key-letter mappings for the dialpad. */ +public class DialpadAlphabets { + + // The default mapping (the Latin alphabet) + private static final String[] def = { + "+" /* 0 */, + "" /* 1 */, + "ABC" /* 2 */, + "DEF" /* 3 */, + "GHI" /* 4 */, + "JKL" /* 5 */, + "MNO" /* 6 */, + "PQRS" /* 7 */, + "TUV" /* 8 */, + "WXYZ" /* 9 */, + "" /* * */, + "" /* # */, + }; + + // Russian + private static final String[] rus = { + "" /* 0 */, + "" /* 1 */, + "АБВГ" /* 2 */, + "ДЕЖЗ" /* 3 */, + "ИЙКЛ" /* 4 */, + "МНОП" /* 5 */, + "РСТУ" /* 6 */, + "ФХЦЧ" /* 7 */, + "ШЩЪЫ" /* 8 */, + "ЬЭЮЯ" /* 9 */, + "" /* * */, + "" /* # */, + }; + + // A map in which each key is an ISO 639-2 language code and the corresponding key is an array + // defining key-letter mappings + private static final SimpleArrayMap alphabets = new SimpleArrayMap<>(); + + static { + alphabets.put("rus", rus); + } + + /** + * Returns the alphabet (a key-letter mapping) of the given ISO 639-2 language code or null if + * + * + */ + public static String[] getAlphabetForLanguage(String languageCode) { + return alphabets.get(languageCode); + } + + /** Returns the default key-letter mapping (the one that uses the Latin alphabet). */ + public static String[] getDefaultAlphabet() { + return def; + } +} diff --git a/java/com/android/dialer/dialpadview/DialpadView.java b/java/com/android/dialer/dialpadview/DialpadView.java index 5e79cb59f..38ab383a8 100644 --- a/java/com/android/dialer/dialpadview/DialpadView.java +++ b/java/com/android/dialer/dialpadview/DialpadView.java @@ -29,6 +29,7 @@ import android.text.Spannable; import android.text.TextUtils; import android.text.style.TtsSpan; import android.util.AttributeSet; +import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -73,38 +74,21 @@ public class DialpadView extends LinearLayout { R.id.pound }; - // Resource IDs for the button-letter mapping - private static final int[] LETTER_MAPPING_IDS = - 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 - }; - - // Whether the device is in landscape mode - private final boolean mIsLandscape; - - // Whether the dialpad is shown in a right-to-left locale - private final boolean mIsRtl; + private final AttributeSet mAttributeSet; + private final ColorStateList mRippleColor; + private final String[] mPrimaryLettersMapping; + private final String[] mSecondaryLettersMapping; + private final boolean mIsLandscape; // whether the device is in landscape mode + private final boolean mIsRtl; // whether the dialpad is shown in a right-to-left locale + private final int mTranslateDistance; private EditText mDigits; private ImageButton mDelete; private View mOverflowMenuButton; - private ColorStateList mRippleColor; private ViewGroup mRateContainer; private TextView mIldCountry; private TextView mIldRate; private boolean mCanDigitsBeEdited; - private int mTranslateDistance; public DialpadView(Context context) { this(context, null); @@ -116,6 +100,7 @@ public class DialpadView extends LinearLayout { public DialpadView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + mAttributeSet = attrs; TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Dialpad); mRippleColor = a.getColorStateList(R.styleable.Dialpad_dialpad_key_button_touch_tint); @@ -128,6 +113,10 @@ public class DialpadView extends LinearLayout { getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; mIsRtl = TextUtils.getLayoutDirectionFromLocale(Locale.getDefault()) == View.LAYOUT_DIRECTION_RTL; + + mPrimaryLettersMapping = DialpadAlphabets.getDefaultAlphabet(); + mSecondaryLettersMapping = + DialpadAlphabets.getAlphabetForLanguage(CompatUtils.getLocale(context).getISO3Language()); } @Override @@ -180,7 +169,7 @@ public class DialpadView extends LinearLayout { // The content description is used for Talkback key presses. The number is // separated by a "," to introduce a slight delay. Convert letters into a verbatim // span so that they are read as letters instead of as one word. - String letters = resources.getString(LETTER_MAPPING_IDS[i]); + String letters = mPrimaryLettersMapping[i]; Spannable spannable = Spannable.Factory.getInstance().newSpannable(numberString + "," + letters); spannable.setSpan( @@ -202,9 +191,31 @@ public class DialpadView extends LinearLayout { dialpadKey.setContentDescription(numberContentDescription); dialpadKey.setBackground(rippleBackground); - TextView lettersView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_letters); - if (lettersView != null) { - lettersView.setText(resources.getString(LETTER_MAPPING_IDS[i])); + TextView primaryLettersView = (TextView) dialpadKey.findViewById(R.id.dialpad_key_letters); + TextView secondaryLettersView = + (TextView) dialpadKey.findViewById(R.id.dialpad_key_secondary_letters); + if (primaryLettersView != null) { + primaryLettersView.setText(mPrimaryLettersMapping[i]); + } + if (primaryLettersView != null && secondaryLettersView != null) { + if (mSecondaryLettersMapping == null) { + secondaryLettersView.setVisibility(View.GONE); + } else { + secondaryLettersView.setVisibility(View.VISIBLE); + secondaryLettersView.setText(mSecondaryLettersMapping[i]); + + // Adjust the font size of the letters if a secondary alphabet is available. + TypedArray a = + getContext() + .getTheme() + .obtainStyledAttributes(mAttributeSet, R.styleable.Dialpad, 0, 0); + int textSize = + a.getDimensionPixelSize( + R.styleable.Dialpad_dialpad_key_letters_size_for_dual_alphabets, 0); + a.recycle(); + primaryLettersView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + secondaryLettersView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); + } } } diff --git a/java/com/android/dialer/dialpadview/res/layout-land/dialpad_key.xml b/java/com/android/dialer/dialpadview/res/layout-land/dialpad_key.xml index 769e2d8bb..d61c636d4 100644 --- a/java/com/android/dialer/dialpadview/res/layout-land/dialpad_key.xml +++ b/java/com/android/dialer/dialpadview/res/layout-land/dialpad_key.xml @@ -42,6 +42,10 @@ + diff --git a/java/com/android/dialer/dialpadview/res/layout/dialpad_key.xml b/java/com/android/dialer/dialpadview/res/layout/dialpad_key.xml index bb9ec63f6..01cbc92a0 100644 --- a/java/com/android/dialer/dialpadview/res/layout/dialpad_key.xml +++ b/java/com/android/dialer/dialpadview/res/layout/dialpad_key.xml @@ -34,6 +34,10 @@ + diff --git a/java/com/android/dialer/dialpadview/res/values-land/styles.xml b/java/com/android/dialer/dialpadview/res/values-land/styles.xml index de9ef1fbf..abf55584b 100644 --- a/java/com/android/dialer/dialpadview/res/values-land/styles.xml +++ b/java/com/android/dialer/dialpadview/res/values-land/styles.xml @@ -50,7 +50,7 @@