diff options
author | emancebo <emancebo@cyngn.com> | 2015-01-02 16:53:53 -0800 |
---|---|---|
committer | Rohit Yengisetty <rohit@cyngn.com> | 2015-11-16 17:00:45 -0800 |
commit | d5b621e0910d21f6753cf90a9c9c8ee6964d6c46 (patch) | |
tree | 9a95e161b24bcf6125cc56dec03f8855e0ed4d5f /src | |
parent | 50f9fc3c585ccc1e686d89a55a4f8c980e73843f (diff) | |
download | android_packages_apps_PhoneCommon-d5b621e0910d21f6753cf90a9c9c8ee6964d6c46.tar.gz android_packages_apps_PhoneCommon-d5b621e0910d21f6753cf90a9c9c8ee6964d6c46.tar.bz2 android_packages_apps_PhoneCommon-d5b621e0910d21f6753cf90a9c9c8ee6964d6c46.zip |
Refactor dialpad layout to support t9 search in multiple languages
* Moves t9 labels to the side in portrait mode to make room for secondary labels
* Adds resources for alternate language t9 labels
Change-Id: Ie9b12afc6b1b74cc9dea48f10ab663e16b06501b
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/phone/common/dialpad/DialpadTextView.java | 72 | ||||
-rw-r--r-- | src/com/android/phone/common/dialpad/DialpadView.java | 47 | ||||
-rw-r--r-- | src/com/android/phone/common/util/SettingsUtil.java | 20 |
3 files changed, 65 insertions, 74 deletions
diff --git a/src/com/android/phone/common/dialpad/DialpadTextView.java b/src/com/android/phone/common/dialpad/DialpadTextView.java deleted file mode 100644 index 2802b32..0000000 --- a/src/com/android/phone/common/dialpad/DialpadTextView.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2014 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.phone.common.dialpad; - -import android.content.Context; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.util.AttributeSet; -import android.widget.TextView; - -/** - * This is a custom text view intended only for rendering the numerals (and star and pound) on the - * dialpad. TextView has built in top/bottom padding to help account for ascenders/descenders. - * - * Since vertical space is at a premium on the dialpad, particularly if the font size is scaled to - * a larger default, for the dialpad we use this class to more precisely render characters according - * to the precise amount of space they need. - */ -public class DialpadTextView extends TextView { - private Rect mTextBounds = new Rect(); - private String mTextStr; - - public DialpadTextView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - /** - * Draw the text to fit within the height/width which have been specified during measurement. - */ - @Override - public void draw(Canvas canvas) { - Paint paint = getPaint(); - - // Without this, the draw does not respect the style's specified text color. - paint.setColor(getCurrentTextColor()); - - // The text bounds values are relative and can be negative,, so rather than specifying a - // standard origin such as 0, 0, we need to use negative of the left/top bounds. - // For example, the bounds may be: Left: 11, Right: 37, Top: -77, Bottom: 0 - canvas.drawText(mTextStr, -mTextBounds.left, -mTextBounds.top, paint); - } - - /** - * Calculate the pixel-accurate bounds of the text when rendered, and use that to specify the - * height and width. - */ - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - mTextStr = getText().toString(); - getPaint().getTextBounds(mTextStr, 0, mTextStr.length(), mTextBounds); - - int width = resolveSize(mTextBounds.width(), widthMeasureSpec); - int height = resolveSize(mTextBounds.height(), heightMeasureSpec); - setMeasuredDimension(width, height); - } -} diff --git a/src/com/android/phone/common/dialpad/DialpadView.java b/src/com/android/phone/common/dialpad/DialpadView.java index 938379d..3911093 100644 --- a/src/com/android/phone/common/dialpad/DialpadView.java +++ b/src/com/android/phone/common/dialpad/DialpadView.java @@ -26,6 +26,7 @@ import android.graphics.drawable.RippleDrawable; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; +import android.util.TypedValue; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -38,6 +39,7 @@ import android.widget.TextView; import com.android.phone.common.R; import com.android.phone.common.animation.AnimUtils; +import com.android.phone.common.util.SettingsUtil; import java.text.DecimalFormat; import java.text.NumberFormat; @@ -124,6 +126,10 @@ public class DialpadView extends LinearLayout { } } + public void refreshKeypad() { + setupKeypad(); + } + private void setupKeypad() { 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, @@ -137,11 +143,21 @@ public class DialpadView extends LinearLayout { R.string.dialpad_8_labels, R.string.dialpad_9_labels, R.string.dialpad_star_labels, R.string.dialpad_pound_labels}; - final Resources resources = getContext().getResources(); + final int[] letter2Ids = new int[] { + R.string.dialpad_0_2_letters, R.string.dialpad_1_2_letters, + R.string.dialpad_2_2_letters, R.string.dialpad_3_2_letters, + R.string.dialpad_4_2_letters, R.string.dialpad_5_2_letters, + R.string.dialpad_6_2_letters, R.string.dialpad_7_2_letters, + R.string.dialpad_8_2_letters, R.string.dialpad_9_2_letters, + R.string.dialpad_star_2_letters, R.string.dialpad_pound_2_letters}; + + Locale t9SearchInputLocale = SettingsUtil.getT9SearchInputLocale(getContext()); + final Resources resources = getResourcesForLocale(t9SearchInputLocale); DialpadKeyButton dialpadKey; TextView numberView; TextView lettersView; + TextView letters2View; TextView labelsView; final Locale currentLocale = resources.getConfiguration().locale; @@ -201,6 +217,25 @@ public class DialpadView extends LinearLayout { labelsView.setVisibility(View.GONE); } } + + String secondaryLabel = resources.getString(letter2Ids[i]); + if (letters2View != null) { + if (!TextUtils.isEmpty(secondaryLabel)) { + letters2View.setText(secondaryLabel); + letters2View.setVisibility(View.VISIBLE); + + // use smaller text size when both labels are present + if (lettersView != null) { + float size = + resources.getDimension( + R.dimen.dialpad_key_letters_small_size); + letters2View.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + lettersView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size); + } + } else { + letters2View.setVisibility(View.GONE); + } + } } final DialpadKeyButton one = (DialpadKeyButton) findViewById(R.id.one); @@ -439,4 +474,12 @@ public class DialpadView extends LinearLayout { Log.wtf(TAG, "Attempted to get animation duration for invalid key button id."); return 0; } -} + + private Resources getResourcesForLocale(Locale locale) { + Configuration defaultConfig = getContext().getResources().getConfiguration(); + Configuration overrideConfig = new Configuration(defaultConfig); + overrideConfig.setLocale(locale); + Context localeContext = getContext().createConfigurationContext(overrideConfig); + return localeContext.getResources(); + } +}
\ No newline at end of file diff --git a/src/com/android/phone/common/util/SettingsUtil.java b/src/com/android/phone/common/util/SettingsUtil.java index c297e1e..d2fd58b 100644 --- a/src/com/android/phone/common/util/SettingsUtil.java +++ b/src/com/android/phone/common/util/SettingsUtil.java @@ -35,6 +35,7 @@ import com.android.phone.common.R; import java.lang.CharSequence; import java.lang.String; +import java.util.Locale; public class SettingsUtil { private static final String DEFAULT_NOTIFICATION_URI_STRING = @@ -100,4 +101,23 @@ public class SettingsUtil { } handler.sendMessage(handler.obtainMessage(msg, summary)); } + + public static Locale getT9SearchInputLocale(Context context) { + // Use system locale by default + Locale locale = context.getResources().getConfiguration().locale; + + // Override with t9 search input locale from settings if provided + String overrideLocaleString = android.provider.Settings.System.getString( + context.getContentResolver(), + android.provider.Settings.System.T9_SEARCH_INPUT_LOCALE); + if (overrideLocaleString != null && !overrideLocaleString.isEmpty()) { + String[] tokens = overrideLocaleString.split("_"); + String lang = tokens.length > 0 ? tokens[0] : ""; + String country = tokens.length > 1 ? tokens[1] : ""; + String variant = tokens.length > 2 ? tokens[2] : ""; + locale = new Locale(lang, country, variant); + } + + return locale; + } } |