am 2035fc54: (-s ours) Reconcile with jb-mr2-release - do not merge

* commit '2035fc54a53c541e00c1ca7357401950469fc458':
  Fix crash in Dialer in landscape mode
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index bde0775..0efe21d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -49,7 +49,11 @@
         android:label="@string/applicationLabel"
         android:icon="@mipmap/ic_launcher_phone"
         android:hardwareAccelerated="true"
-        android:supportsRtl="true">
+        android:supportsRtl="true"
+        android:backupAgent='com.android.dialer.DialerBackupAgent'>
+
+        <meta-data android:name="com.google.android.backup.api_key"
+            android:value="AEdPqrEAAAAIBXgtCEKQ6W0PXVnW-ZVia2KmlV2AxsTw3GjAeQ" />
 
         <!-- The entrance point for Phone UI.
              stateAlwaysHidden is set to suppress keyboard show up on
diff --git a/res/values-ro/strings.xml b/res/values-ro/strings.xml
index f8a86b0..3a092a9 100644
--- a/res/values-ro/strings.xml
+++ b/res/values-ro/strings.xml
@@ -26,11 +26,11 @@
     <string name="recentCalls_editNumberBeforeCall" msgid="7756171675833267857">"Modificaţi numărul înainte de apelare"</string>
     <string name="recentCalls_addToContact" msgid="1429899535546487008">"Adăugaţi la persoane din agendă"</string>
     <string name="recentCalls_removeFromRecentList" msgid="401662244636511330">"Eliminaţi din jurnalul de apeluri"</string>
-    <string name="recentCalls_deleteAll" msgid="6352364392762163704">"Ştergeţi jurnalul de apeluri"</string>
-    <string name="recentCalls_trashVoicemail" msgid="7604696960787435655">"Ştergeţi mesajul vocal"</string>
+    <string name="recentCalls_deleteAll" msgid="6352364392762163704">"Ștergeţi jurnalul de apeluri"</string>
+    <string name="recentCalls_trashVoicemail" msgid="7604696960787435655">"Ștergeţi mesajul vocal"</string>
     <string name="recentCalls_shareVoicemail" msgid="1416112847592942840">"Distribuiţi mesajul vocal"</string>
     <string name="recentCalls_empty" msgid="247053222448663107">"Jurnalul de apeluri este gol."</string>
-    <string name="clearCallLogConfirmation_title" msgid="6427524640461816332">"Ştergeţi apelurile?"</string>
+    <string name="clearCallLogConfirmation_title" msgid="6427524640461816332">"Ștergeţi apelurile?"</string>
     <string name="clearCallLogConfirmation" msgid="5043563133171583152">"Toate înregistrările apelurilor dvs. vor fi şterse."</string>
     <string name="clearCallLogProgress_title" msgid="8365943000154295771">"Se goleşte jurnalul de apeluri..."</string>
   <plurals name="notification_voicemail_title">
diff --git a/res/values-sw/strings.xml b/res/values-sw/strings.xml
index 8792b43..e26db2d 100644
--- a/res/values-sw/strings.xml
+++ b/res/values-sw/strings.xml
@@ -29,7 +29,7 @@
     <string name="recentCalls_deleteAll" msgid="6352364392762163704">"Futa rekodi ya simu"</string>
     <string name="recentCalls_trashVoicemail" msgid="7604696960787435655">"Futa barua ya sauti"</string>
     <string name="recentCalls_shareVoicemail" msgid="1416112847592942840">"Shiriki barua ya sauti"</string>
-    <string name="recentCalls_empty" msgid="247053222448663107">"Orodha ya kupiga simu ni tupu."</string>
+    <string name="recentCalls_empty" msgid="247053222448663107">"Orodha ya kupiga simu haina chochote."</string>
     <string name="clearCallLogConfirmation_title" msgid="6427524640461816332">"Futa rekodi ya simu?"</string>
     <string name="clearCallLogConfirmation" msgid="5043563133171583152">"Kumbukumbu zako zote za simu zitafutwa."</string>
     <string name="clearCallLogProgress_title" msgid="8365943000154295771">"Inafuta rekodi ya simu ..."</string>
@@ -50,7 +50,7 @@
     <string name="call_log_incoming_header" msgid="2787722299753674684">"Simu zinazoingia tu"</string>
     <string name="call_log_outgoing_header" msgid="761009180766735769">"Simu zinazotoka tu"</string>
     <string name="call_log_missed_header" msgid="8017148056610855956">"Simu zisizojibiwa tu"</string>
-    <string name="voicemail_status_voicemail_not_available" msgid="3021980206152528883">"Haiwezi kuunganisha kwa seva ya ujumbe wa sauti."</string>
+    <string name="voicemail_status_voicemail_not_available" msgid="3021980206152528883">"Imeshindwa kuunganisha kwenye seva ya ujumbe wa sauti."</string>
     <string name="voicemail_status_messages_waiting" msgid="7113421459602803605">"Imeshindwa kuwasiliana na seva ya ujumbe wa sauti. Mawasiliano mapya ya sauti yanasubiri kusikilizwa."</string>
     <string name="voicemail_status_configure_voicemail" msgid="3738537770636895689">"Sanidi ujumbe wako wa sauti."</string>
     <string name="voicemail_status_audio_not_available" msgid="3369618334553341626">"Sauti haipatikani."</string>
diff --git a/res/values-zh-rCN/strings.xml b/res/values-zh-rCN/strings.xml
index 6f1b958..0ef6ba8 100644
--- a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -128,7 +128,7 @@
     <string name="contact_list_loading" msgid="5488620820563977329">"正在加载..."</string>
     <string name="imei" msgid="3045126336951684285">"移动通信国际识别码"</string>
     <string name="meid" msgid="6210568493746275750">"MEID"</string>
-    <string name="simContacts_emptyLoading" msgid="6700035985448642408">"正从 SIM 卡中载入..."</string>
+    <string name="simContacts_emptyLoading" msgid="6700035985448642408">"正从 SIM 卡中加载..."</string>
     <string name="simContacts_title" msgid="27341688347689769">"SIM 卡联系人"</string>
     <string name="add_contact_not_available" msgid="1419207765446461366">"必须重新启用联系人应用才能使用此功能。"</string>
 </resources>
diff --git a/res/values-zh-rTW/strings.xml b/res/values-zh-rTW/strings.xml
index 4667ce1..4e7c5cc 100644
--- a/res/values-zh-rTW/strings.xml
+++ b/res/values-zh-rTW/strings.xml
@@ -20,19 +20,19 @@
     <string name="applicationLabel" msgid="8490255569343340580">"撥號"</string>
     <string name="launcherDialer" msgid="8636288196618486553">"電話"</string>
     <string name="dialerIconLabel" msgid="6500826552823403796">"電話"</string>
-    <string name="recentCallsIconLabel" msgid="1419116422359067949">"通話記錄"</string>
+    <string name="recentCallsIconLabel" msgid="1419116422359067949">"通話紀錄"</string>
     <string name="menu_sendTextMessage" msgid="6937343460284499306">"傳送簡訊"</string>
     <string name="recentCalls_callNumber" msgid="1756372533999226126">"撥電話給<xliff:g id="NAME">%s</xliff:g>"</string>
     <string name="recentCalls_editNumberBeforeCall" msgid="7756171675833267857">"撥打電話前編輯號碼"</string>
     <string name="recentCalls_addToContact" msgid="1429899535546487008">"新增至通訊錄"</string>
-    <string name="recentCalls_removeFromRecentList" msgid="401662244636511330">"從通話記錄中移除"</string>
-    <string name="recentCalls_deleteAll" msgid="6352364392762163704">"清除通話記錄"</string>
+    <string name="recentCalls_removeFromRecentList" msgid="401662244636511330">"從通話紀錄中移除"</string>
+    <string name="recentCalls_deleteAll" msgid="6352364392762163704">"清除通話紀錄"</string>
     <string name="recentCalls_trashVoicemail" msgid="7604696960787435655">"刪除語音留言"</string>
     <string name="recentCalls_shareVoicemail" msgid="1416112847592942840">"分享語音信箱"</string>
-    <string name="recentCalls_empty" msgid="247053222448663107">"無通話記錄。"</string>
-    <string name="clearCallLogConfirmation_title" msgid="6427524640461816332">"確定要清除通話記錄?"</string>
-    <string name="clearCallLogConfirmation" msgid="5043563133171583152">"即將刪除您所有的通話記錄。"</string>
-    <string name="clearCallLogProgress_title" msgid="8365943000154295771">"正在清除通話記錄…"</string>
+    <string name="recentCalls_empty" msgid="247053222448663107">"無通話紀錄。"</string>
+    <string name="clearCallLogConfirmation_title" msgid="6427524640461816332">"確定要清除通話紀錄?"</string>
+    <string name="clearCallLogConfirmation" msgid="5043563133171583152">"即將刪除您所有的通話紀錄。"</string>
+    <string name="clearCallLogProgress_title" msgid="8365943000154295771">"正在清除通話紀錄…"</string>
   <plurals name="notification_voicemail_title">
     <item quantity="one" msgid="1746619685488504230">"語音留言"</item>
     <item quantity="other" msgid="5513481419205061254">"<xliff:g id="COUNT">%1$d</xliff:g> 則語音留言"</item>
diff --git a/res/values-zu/strings.xml b/res/values-zu/strings.xml
index 91dd0be..f89060a 100644
--- a/res/values-zu/strings.xml
+++ b/res/values-zu/strings.xml
@@ -29,7 +29,7 @@
     <string name="recentCalls_deleteAll" msgid="6352364392762163704">"Sula ifayela lokungena"</string>
     <string name="recentCalls_trashVoicemail" msgid="7604696960787435655">"Susa imeyili yezwi"</string>
     <string name="recentCalls_shareVoicemail" msgid="1416112847592942840">"Abelana nemeyili yezwi"</string>
-    <string name="recentCalls_empty" msgid="247053222448663107">"Ifayela lokungena lekholi alinalutho."</string>
+    <string name="recentCalls_empty" msgid="247053222448663107">"Ilogu yamakholi alinalutho."</string>
     <string name="clearCallLogConfirmation_title" msgid="6427524640461816332">"Sula ifayela lokungena"</string>
     <string name="clearCallLogConfirmation" msgid="5043563133171583152">"Yonke imininingwane eqoshiwe iyosuswa."</string>
     <string name="clearCallLogProgress_title" msgid="8365943000154295771">"Isula imininingwane yokushaya..."</string>
@@ -50,7 +50,7 @@
     <string name="call_log_incoming_header" msgid="2787722299753674684">"Amakholi angenayo kuphela"</string>
     <string name="call_log_outgoing_header" msgid="761009180766735769">"Amakholi aphumayo kuphela"</string>
     <string name="call_log_missed_header" msgid="8017148056610855956">"Amakholi agejiwe kuphela"</string>
-    <string name="voicemail_status_voicemail_not_available" msgid="3021980206152528883">"Ayikwazi ukuxhuma kusiphakeli se-imeyli yezwi."</string>
+    <string name="voicemail_status_voicemail_not_available" msgid="3021980206152528883">"Ayikwazi ukuxhuma kuseva yevoyisimeyili."</string>
     <string name="voicemail_status_messages_waiting" msgid="7113421459602803605">"Ayikwazi ukuxhumana nesiphakeli semeyli yezwi. Ama-imeyli ezwi amasha alindile"</string>
     <string name="voicemail_status_configure_voicemail" msgid="3738537770636895689">"Setha umyalezo wakho wephimbo."</string>
     <string name="voicemail_status_audio_not_available" msgid="3369618334553341626">"Umsindo awutholakali"</string>
@@ -114,7 +114,7 @@
     <string name="description_send_text_message" msgid="7803126439934046891">"Hambisa umyalezo ku <xliff:g id="NAME">%1$s</xliff:g>"</string>
     <string name="description_call_log_unheard_voicemail" msgid="118101684236996786">"I-imeyli yezwi engazwakalanga"</string>
     <string name="call_log_empty_gecode" msgid="5588904744812100846">"-"</string>
-    <string name="menu_callNumber" msgid="997146291983360266">"Shayela u-<xliff:g id="NUMBER">%s</xliff:g>"</string>
+    <string name="menu_callNumber" msgid="997146291983360266">"Shayela <xliff:g id="NUMBER">%s</xliff:g>"</string>
     <string name="unknown" msgid="740067747858270469">"Akwaziwa"</string>
     <string name="voicemail" msgid="3851469869202611441">"Ivoyisimeyili"</string>
     <string name="private_num" msgid="6374339738119166953">"Inombolo yangasese"</string>
diff --git a/src/com/android/dialer/DialerBackupAgent.java b/src/com/android/dialer/DialerBackupAgent.java
new file mode 100644
index 0000000..0eef689
--- /dev/null
+++ b/src/com/android/dialer/DialerBackupAgent.java
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package com.android.dialer;
+
+import android.app.backup.BackupAgentHelper;
+import android.app.backup.BackupDataInput;
+import android.app.backup.SharedPreferencesBackupHelper;
+import android.content.Context;
+
+/**
+ * The Dialer backup agent backs up the shared preferences settings of the
+ * Dialer App. Right now it backs up the whole shared preference file. This
+ * can be modified in the future to accommodate partical backup.
+ */
+public class DialerBackupAgent extends BackupAgentHelper
+{
+    private static final String SHARED_KEY = "shared_pref";
+
+    @Override
+    public void onCreate() {
+        addHelper(SHARED_KEY, new SharedPreferencesBackupHelper(this,
+               DialtactsActivity.SHARED_PREFS_NAME));
+    }
+}
diff --git a/src/com/android/dialer/DialtactsActivity.java b/src/com/android/dialer/DialtactsActivity.java
index 32339d2..2a2d11b 100644
--- a/src/com/android/dialer/DialtactsActivity.java
+++ b/src/com/android/dialer/DialtactsActivity.java
@@ -21,6 +21,7 @@
 import android.app.ActionBar.Tab;
 import android.app.ActionBar.TabListener;
 import android.app.Activity;
+import android.app.backup.BackupManager;
 import android.app.Fragment;
 import android.app.FragmentManager;
 import android.app.FragmentTransaction;
@@ -108,6 +109,8 @@
 
     private SharedPreferences mPrefs;
 
+    public static final String SHARED_PREFS_NAME = "com.android.dialer_preferences";
+
     /** Last manually selected tab index */
     private static final String PREF_LAST_MANUALLY_SELECTED_TAB =
             "DialtactsActivity_last_manually_selected_tab";
@@ -328,7 +331,7 @@
             }
 
             // During the call, we don't remember the tab position.
-            if (!DialpadFragment.phoneIsInUse()) {
+            if (mDialpadFragment == null || !mDialpadFragment.phoneIsInUse()) {
                 // Remember this tab index. This function is also called, if the tab is set
                 // automatically in which case the setter (setCurrentTab) has to set this to its old
                 // value afterwards
@@ -526,7 +529,7 @@
         getActionBar().setDisplayShowHomeEnabled(false);
 
         // Load the last manually loaded tab
-        mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+        mPrefs = this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
         mLastManuallySelectedFragment = mPrefs.getInt(PREF_LAST_MANUALLY_SELECTED_TAB,
                 PREF_LAST_MANUALLY_SELECTED_TAB_DEFAULT);
         if (mLastManuallySelectedFragment >= TAB_INDEX_COUNT) {
@@ -711,6 +714,12 @@
 
         mPrefs.edit().putInt(PREF_LAST_MANUALLY_SELECTED_TAB, mLastManuallySelectedFragment)
                 .apply();
+        requestBackup();
+    }
+
+    private void requestBackup() {
+        final BackupManager bm = new BackupManager(this);
+        bm.dataChanged();
     }
 
     private void fixIntent(Intent intent) {
@@ -794,7 +803,8 @@
         final int savedTabIndex = mLastManuallySelectedFragment;
 
         final int tabIndex;
-        if (DialpadFragment.phoneIsInUse() || isDialIntent(intent)) {
+        if ((mDialpadFragment != null && mDialpadFragment.phoneIsInUse())
+                || isDialIntent(intent)) {
             tabIndex = TAB_INDEX_DIALER;
         } else if (recentCallsRequest) {
             tabIndex = TAB_INDEX_CALL_LOG;
@@ -1113,7 +1123,8 @@
         final Tab tab = actionBar.getSelectedTab();
 
         // User can search during the call, but we don't want to remember the status.
-        if (tab != null && !DialpadFragment.phoneIsInUse()) {
+        if (tab != null && (mDialpadFragment == null ||
+                        !mDialpadFragment.phoneIsInUse())) {
             mLastManuallySelectedFragment = tab.getPosition();
         }
 
diff --git a/src/com/android/dialer/dialpad/DialpadFragment.java b/src/com/android/dialer/dialpad/DialpadFragment.java
index 5f70312..a8984bd 100644
--- a/src/com/android/dialer/dialpad/DialpadFragment.java
+++ b/src/com/android/dialer/dialpad/DialpadFragment.java
@@ -157,6 +157,12 @@
     private SmartDialController mSmartDialAdapter;
 
     private SmartDialCache mSmartDialCache;
+
+    /**
+     * Use latin character map by default
+     */
+    private SmartDialMap mSmartDialMap = new LatinSmartDialMap();
+
     /**
      * Master switch controlling whether or not smart dialing is enabled, and whether the
      * smart dialing suggestion strip is visible.
@@ -246,6 +252,10 @@
         return intent;
     }
 
+    private TelephonyManager getTelephonyManager() {
+        return (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
+    }
+
     @Override
     public void beforeTextChanged(CharSequence s, int start, int count, int after) {
         mWasEmptyBeforeTextChange = TextUtils.isEmpty(s);
@@ -392,6 +402,12 @@
      * @return true when {@link #mDigits} is actually filled by the Intent.
      */
     private boolean fillDigitsIfNecessary(Intent intent) {
+        // Only fills digits from an intent if it is a new intent.
+        // Otherwise falls back to the previously used number.
+        if (!mFirstLaunch && !mStartedFromNewIntent) {
+            return false;
+        }
+
         final String action = intent.getAction();
         if (Intent.ACTION_DIAL.equals(action) || Intent.ACTION_VIEW.equals(action)) {
             Uri uri = intent.getData();
@@ -430,7 +446,6 @@
                 }
             }
         }
-
         return false;
     }
 
@@ -454,7 +469,17 @@
      * Checks the given Intent and changes dialpad's UI state. For example, if the Intent requires
      * the screen to enter "Add Call" mode, this method will show correct UI for the mode.
      */
-    private void configureScreenFromIntent(Intent intent) {
+    private void configureScreenFromIntent(Activity parent) {
+        // If we were not invoked with a DIAL intent,
+        if (!(parent instanceof DialtactsActivity)) {
+            setStartedFromNewIntent(false);
+            return;
+        }
+
+        // See if we were invoked with a DIAL intent. If we were, fill in the appropriate
+        // digits in the dialer field.
+        Intent intent = parent.getIntent();
+
         if (!isLayoutReady()) {
             // This happens typically when parent's Activity#onNewIntent() is called while
             // Fragment#onCreateView() isn't called yet, and thus we cannot configure Views at
@@ -490,8 +515,8 @@
 
             }
         }
-
         showDialpadChooser(needToShowDialpadChooser);
+        setStartedFromNewIntent(false);
     }
 
     public void setStartedFromNewIntent(boolean value) {
@@ -531,13 +556,6 @@
     }
 
     @Override
-    public void onStart() {
-        super.onStart();
-        configureScreenFromIntent(getActivity().getIntent());
-        setStartedFromNewIntent(false);
-    }
-
-    @Override
     public void onResume() {
         super.onResume();
 
@@ -586,21 +604,14 @@
         // the dialpad edittext to prevent entries from being loaded from a null cache.
         initializeSmartDialingState();
 
-        Activity parent = getActivity();
-        if (parent instanceof DialtactsActivity) {
-            // See if we were invoked with a DIAL intent. If we were, fill in the appropriate
-            // digits in the dialer field.
-            fillDigitsIfNecessary(parent.getIntent());
-        }
+        configureScreenFromIntent(getActivity());
 
         stopWatch.lap("fdin");
 
         // While we're in the foreground, listen for phone state changes,
         // purely so that we can take down the "dialpad chooser" if the
         // phone becomes idle while the chooser UI is visible.
-        TelephonyManager telephonyManager =
-                (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
-        telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
+        getTelephonyManager().listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
 
         stopWatch.lap("tm");
 
@@ -643,9 +654,7 @@
         super.onPause();
 
         // Stop listening for phone state changes.
-        TelephonyManager telephonyManager =
-                (TelephonyManager) getActivity().getSystemService(Context.TELEPHONY_SERVICE);
-        telephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
+        getTelephonyManager().listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
 
         // Make sure we don't leave this activity with a tone still playing.
         stopTone();
@@ -1453,45 +1462,22 @@
      * @return true if the phone is "in use", meaning that at least one line
      *              is active (ie. off hook or ringing or dialing).
      */
-    public static boolean phoneIsInUse() {
-        boolean phoneInUse = false;
-        try {
-            ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
-            if (phone != null) phoneInUse = !phone.isIdle();
-        } catch (RemoteException e) {
-            Log.w(TAG, "phone.isIdle() failed", e);
-        }
-        return phoneInUse;
+    public boolean phoneIsInUse() {
+        return getTelephonyManager().getCallState() != TelephonyManager.CALL_STATE_IDLE;
     }
 
     /**
      * @return true if the phone is a CDMA phone type
      */
     private boolean phoneIsCdma() {
-        boolean isCdma = false;
-        try {
-            ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
-            if (phone != null) {
-                isCdma = (phone.getActivePhoneType() == TelephonyManager.PHONE_TYPE_CDMA);
-            }
-        } catch (RemoteException e) {
-            Log.w(TAG, "phone.getActivePhoneType() failed", e);
-        }
-        return isCdma;
+        return getTelephonyManager().getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA;
     }
 
     /**
      * @return true if the phone state is OFFHOOK
      */
     private boolean phoneIsOffhook() {
-        boolean phoneOffhook = false;
-        try {
-            ITelephony phone = ITelephony.Stub.asInterface(ServiceManager.checkService("phone"));
-            if (phone != null) phoneOffhook = phone.isOffhook();
-        } catch (RemoteException e) {
-            Log.w(TAG, "phone.isOffhook() failed", e);
-        }
-        return phoneOffhook;
+        return getTelephonyManager().getCallState() == TelephonyManager.CALL_STATE_OFFHOOK;
     }
 
     /**
@@ -1586,7 +1572,7 @@
      */
     private boolean isVoicemailAvailable() {
         try {
-            return (TelephonyManager.getDefault().getVoiceMailNumber() != null);
+            return getTelephonyManager().getVoiceMailNumber() != null;
         } catch (SecurityException se) {
             // Possibly no READ_PHONE_STATE privilege.
             Log.w(TAG, "SecurityException is thrown. Maybe privilege isn't sufficient.");
@@ -1670,11 +1656,13 @@
     @Override
     public void setUserVisibleHint(boolean isVisibleToUser) {
         super.setUserVisibleHint(isVisibleToUser);
-        if (mSmartDialEnabled && isVisibleToUser) {
-            // This is called if the dialpad fragment is swiped into to view for the very first
-            // time in the activity's lifecycle, or the user starts the dialer for the first time
-            // and the dialpad fragment is displayed immediately, and is what causes the initial
-            // caching process to happen.
+        if (mSmartDialEnabled && isVisibleToUser && mSmartDialCache != null) {
+            // This is called every time the dialpad fragment comes into view. The first
+            // time the dialer is launched, mSmartDialEnabled is always false as it has not been
+            // read from settings(in onResume) yet at the point where setUserVisibleHint is called
+            // for the first time, so the caching on first launch will happen in onResume instead.
+            // This covers only the case where the dialer is launched in the call log or
+            // contacts tab, and then the user swipes to the dialpad.
             mSmartDialCache.cacheIfNeeded(false);
         }
     }
@@ -1693,7 +1681,8 @@
         }
 
         // Update only when the digits have changed.
-        final String digits = SmartDialNameMatcher.normalizeNumber(mDigits.getText().toString());
+        final String digits = SmartDialNameMatcher.normalizeNumber(mDigits.getText().toString(),
+                mSmartDialMap);
         if (TextUtils.equals(digits, mLastDigitsForSmartDial)) {
             return;
         }
@@ -1720,15 +1709,16 @@
         if (mSmartDialEnabled) {
             mSmartDialContainer.setVisibility(View.VISIBLE);
             mSmartDialCache = SmartDialCache.getInstance(getActivity(),
-                    mContactsPrefs.getDisplayOrder());
+                    mContactsPrefs.getDisplayOrder(), mSmartDialMap);
             // Don't force recache if this is the first time onResume is being called, since
             // caching should already happen in setUserVisibleHint.
-            if (!mFirstLaunch) {
-                // This forced recache covers the case where the dialer was previously running, and
-                // was brought back into the foreground. If the dialpad fragment hasn't actually
-                // become visible throughout the entire activity's lifecycle, it is possible that
-                // caching hasn't happened yet. In this case, we can force a recache anyway, since
-                // we are not worried about startup performance anymore.
+            if (!mFirstLaunch || getUserVisibleHint()) {
+                // This forced recache covers the cases where the dialer was running before and
+                // was brought back into the foreground, or the dialer was launched for the first
+                // time and displays the dialpad fragment immediately. If the dialpad fragment
+                // hasn't actually become visible throughout the entire activity's lifecycle, it
+                // is possible that caching hasn't happened yet. In this case, we can force a
+                // recache anyway, since we are not worried about startup performance anymore.
                 mSmartDialCache.cacheIfNeeded(true);
             }
         } else {
diff --git a/src/com/android/dialer/dialpad/LatinSmartDialMap.java b/src/com/android/dialer/dialpad/LatinSmartDialMap.java
new file mode 100644
index 0000000..ef1ec0a
--- /dev/null
+++ b/src/com/android/dialer/dialpad/LatinSmartDialMap.java
@@ -0,0 +1,413 @@
+package com.android.dialer.dialpad;
+
+public class LatinSmartDialMap implements SmartDialMap {
+
+    private static final char[] LATIN_LETTERS_TO_DIGITS = {
+        '2', '2', '2', // A,B,C -> 2
+        '3', '3', '3', // D,E,F -> 3
+        '4', '4', '4', // G,H,I -> 4
+        '5', '5', '5', // J,K,L -> 5
+        '6', '6', '6', // M,N,O -> 6
+        '7', '7', '7', '7', // P,Q,R,S -> 7
+        '8', '8', '8', // T,U,V -> 8
+        '9', '9', '9', '9' // W,X,Y,Z -> 9
+    };
+
+    @Override
+    public boolean isValidDialpadAlphabeticChar(char ch) {
+        return (ch >= 'a' && ch <= 'z');
+    }
+
+    @Override
+    public boolean isValidDialpadNumericChar(char ch) {
+        return (ch >= '0' && ch <= '9');
+    }
+
+    @Override
+    public boolean isValidDialpadCharacter(char ch) {
+        return (isValidDialpadAlphabeticChar(ch) || isValidDialpadNumericChar(ch));
+    }
+
+    /*
+     * The switch statement in this function was generated using the python code:
+     * from unidecode import unidecode
+     * for i in range(192, 564):
+     *     char = unichr(i)
+     *     decoded = unidecode(char)
+     *     # Unicode characters that decompose into multiple characters i.e.
+     *     #  into ss are not supported for now
+     *     if (len(decoded) == 1 and decoded.isalpha()):
+     *         print "case '" + char + "': return '" + unidecode(char) +  "';"
+     *
+     * This gives us a way to map characters containing accents/diacritics to their
+     * alphabetic equivalents. The unidecode library can be found at:
+     * http://pypi.python.org/pypi/Unidecode/0.04.1
+     *
+     * Also remaps all upper case latin characters to their lower case equivalents.
+     */
+    @Override
+    public char normalizeCharacter(char ch) {
+        switch (ch) {
+            case 'À': return 'a';
+            case 'Á': return 'a';
+            case 'Â': return 'a';
+            case 'Ã': return 'a';
+            case 'Ä': return 'a';
+            case 'Å': return 'a';
+            case 'Ç': return 'c';
+            case 'È': return 'e';
+            case 'É': return 'e';
+            case 'Ê': return 'e';
+            case 'Ë': return 'e';
+            case 'Ì': return 'i';
+            case 'Í': return 'i';
+            case 'Î': return 'i';
+            case 'Ï': return 'i';
+            case 'Ð': return 'd';
+            case 'Ñ': return 'n';
+            case 'Ò': return 'o';
+            case 'Ó': return 'o';
+            case 'Ô': return 'o';
+            case 'Õ': return 'o';
+            case 'Ö': return 'o';
+            case '×': return 'x';
+            case 'Ø': return 'o';
+            case 'Ù': return 'u';
+            case 'Ú': return 'u';
+            case 'Û': return 'u';
+            case 'Ü': return 'u';
+            case 'Ý': return 'u';
+            case 'à': return 'a';
+            case 'á': return 'a';
+            case 'â': return 'a';
+            case 'ã': return 'a';
+            case 'ä': return 'a';
+            case 'å': return 'a';
+            case 'ç': return 'c';
+            case 'è': return 'e';
+            case 'é': return 'e';
+            case 'ê': return 'e';
+            case 'ë': return 'e';
+            case 'ì': return 'i';
+            case 'í': return 'i';
+            case 'î': return 'i';
+            case 'ï': return 'i';
+            case 'ð': return 'd';
+            case 'ñ': return 'n';
+            case 'ò': return 'o';
+            case 'ó': return 'o';
+            case 'ô': return 'o';
+            case 'õ': return 'o';
+            case 'ö': return 'o';
+            case 'ø': return 'o';
+            case 'ù': return 'u';
+            case 'ú': return 'u';
+            case 'û': return 'u';
+            case 'ü': return 'u';
+            case 'ý': return 'y';
+            case 'ÿ': return 'y';
+            case 'Ā': return 'a';
+            case 'ā': return 'a';
+            case 'Ă': return 'a';
+            case 'ă': return 'a';
+            case 'Ą': return 'a';
+            case 'ą': return 'a';
+            case 'Ć': return 'c';
+            case 'ć': return 'c';
+            case 'Ĉ': return 'c';
+            case 'ĉ': return 'c';
+            case 'Ċ': return 'c';
+            case 'ċ': return 'c';
+            case 'Č': return 'c';
+            case 'č': return 'c';
+            case 'Ď': return 'd';
+            case 'ď': return 'd';
+            case 'Đ': return 'd';
+            case 'đ': return 'd';
+            case 'Ē': return 'e';
+            case 'ē': return 'e';
+            case 'Ĕ': return 'e';
+            case 'ĕ': return 'e';
+            case 'Ė': return 'e';
+            case 'ė': return 'e';
+            case 'Ę': return 'e';
+            case 'ę': return 'e';
+            case 'Ě': return 'e';
+            case 'ě': return 'e';
+            case 'Ĝ': return 'g';
+            case 'ĝ': return 'g';
+            case 'Ğ': return 'g';
+            case 'ğ': return 'g';
+            case 'Ġ': return 'g';
+            case 'ġ': return 'g';
+            case 'Ģ': return 'g';
+            case 'ģ': return 'g';
+            case 'Ĥ': return 'h';
+            case 'ĥ': return 'h';
+            case 'Ħ': return 'h';
+            case 'ħ': return 'h';
+            case 'Ĩ': return 'i';
+            case 'ĩ': return 'i';
+            case 'Ī': return 'i';
+            case 'ī': return 'i';
+            case 'Ĭ': return 'i';
+            case 'ĭ': return 'i';
+            case 'Į': return 'i';
+            case 'į': return 'i';
+            case 'İ': return 'i';
+            case 'ı': return 'i';
+            case 'Ĵ': return 'j';
+            case 'ĵ': return 'j';
+            case 'Ķ': return 'k';
+            case 'ķ': return 'k';
+            case 'ĸ': return 'k';
+            case 'Ĺ': return 'l';
+            case 'ĺ': return 'l';
+            case 'Ļ': return 'l';
+            case 'ļ': return 'l';
+            case 'Ľ': return 'l';
+            case 'ľ': return 'l';
+            case 'Ŀ': return 'l';
+            case 'ŀ': return 'l';
+            case 'Ł': return 'l';
+            case 'ł': return 'l';
+            case 'Ń': return 'n';
+            case 'ń': return 'n';
+            case 'Ņ': return 'n';
+            case 'ņ': return 'n';
+            case 'Ň': return 'n';
+            case 'ň': return 'n';
+            case 'Ō': return 'o';
+            case 'ō': return 'o';
+            case 'Ŏ': return 'o';
+            case 'ŏ': return 'o';
+            case 'Ő': return 'o';
+            case 'ő': return 'o';
+            case 'Ŕ': return 'r';
+            case 'ŕ': return 'r';
+            case 'Ŗ': return 'r';
+            case 'ŗ': return 'r';
+            case 'Ř': return 'r';
+            case 'ř': return 'r';
+            case 'Ś': return 's';
+            case 'ś': return 's';
+            case 'Ŝ': return 's';
+            case 'ŝ': return 's';
+            case 'Ş': return 's';
+            case 'ş': return 's';
+            case 'Š': return 's';
+            case 'š': return 's';
+            case 'Ţ': return 't';
+            case 'ţ': return 't';
+            case 'Ť': return 't';
+            case 'ť': return 't';
+            case 'Ŧ': return 't';
+            case 'ŧ': return 't';
+            case 'Ũ': return 'u';
+            case 'ũ': return 'u';
+            case 'Ū': return 'u';
+            case 'ū': return 'u';
+            case 'Ŭ': return 'u';
+            case 'ŭ': return 'u';
+            case 'Ů': return 'u';
+            case 'ů': return 'u';
+            case 'Ű': return 'u';
+            case 'ű': return 'u';
+            case 'Ų': return 'u';
+            case 'ų': return 'u';
+            case 'Ŵ': return 'w';
+            case 'ŵ': return 'w';
+            case 'Ŷ': return 'y';
+            case 'ŷ': return 'y';
+            case 'Ÿ': return 'y';
+            case 'Ź': return 'z';
+            case 'ź': return 'z';
+            case 'Ż': return 'z';
+            case 'ż': return 'z';
+            case 'Ž': return 'z';
+            case 'ž': return 'z';
+            case 'ſ': return 's';
+            case 'ƀ': return 'b';
+            case 'Ɓ': return 'b';
+            case 'Ƃ': return 'b';
+            case 'ƃ': return 'b';
+            case 'Ɔ': return 'o';
+            case 'Ƈ': return 'c';
+            case 'ƈ': return 'c';
+            case 'Ɖ': return 'd';
+            case 'Ɗ': return 'd';
+            case 'Ƌ': return 'd';
+            case 'ƌ': return 'd';
+            case 'ƍ': return 'd';
+            case 'Ɛ': return 'e';
+            case 'Ƒ': return 'f';
+            case 'ƒ': return 'f';
+            case 'Ɠ': return 'g';
+            case 'Ɣ': return 'g';
+            case 'Ɩ': return 'i';
+            case 'Ɨ': return 'i';
+            case 'Ƙ': return 'k';
+            case 'ƙ': return 'k';
+            case 'ƚ': return 'l';
+            case 'ƛ': return 'l';
+            case 'Ɯ': return 'w';
+            case 'Ɲ': return 'n';
+            case 'ƞ': return 'n';
+            case 'Ɵ': return 'o';
+            case 'Ơ': return 'o';
+            case 'ơ': return 'o';
+            case 'Ƥ': return 'p';
+            case 'ƥ': return 'p';
+            case 'ƫ': return 't';
+            case 'Ƭ': return 't';
+            case 'ƭ': return 't';
+            case 'Ʈ': return 't';
+            case 'Ư': return 'u';
+            case 'ư': return 'u';
+            case 'Ʊ': return 'y';
+            case 'Ʋ': return 'v';
+            case 'Ƴ': return 'y';
+            case 'ƴ': return 'y';
+            case 'Ƶ': return 'z';
+            case 'ƶ': return 'z';
+            case 'ƿ': return 'w';
+            case 'Ǎ': return 'a';
+            case 'ǎ': return 'a';
+            case 'Ǐ': return 'i';
+            case 'ǐ': return 'i';
+            case 'Ǒ': return 'o';
+            case 'ǒ': return 'o';
+            case 'Ǔ': return 'u';
+            case 'ǔ': return 'u';
+            case 'Ǖ': return 'u';
+            case 'ǖ': return 'u';
+            case 'Ǘ': return 'u';
+            case 'ǘ': return 'u';
+            case 'Ǚ': return 'u';
+            case 'ǚ': return 'u';
+            case 'Ǜ': return 'u';
+            case 'ǜ': return 'u';
+            case 'Ǟ': return 'a';
+            case 'ǟ': return 'a';
+            case 'Ǡ': return 'a';
+            case 'ǡ': return 'a';
+            case 'Ǥ': return 'g';
+            case 'ǥ': return 'g';
+            case 'Ǧ': return 'g';
+            case 'ǧ': return 'g';
+            case 'Ǩ': return 'k';
+            case 'ǩ': return 'k';
+            case 'Ǫ': return 'o';
+            case 'ǫ': return 'o';
+            case 'Ǭ': return 'o';
+            case 'ǭ': return 'o';
+            case 'ǰ': return 'j';
+            case 'Dz': return 'd';
+            case 'Ǵ': return 'g';
+            case 'ǵ': return 'g';
+            case 'Ƿ': return 'w';
+            case 'Ǹ': return 'n';
+            case 'ǹ': return 'n';
+            case 'Ǻ': return 'a';
+            case 'ǻ': return 'a';
+            case 'Ǿ': return 'o';
+            case 'ǿ': return 'o';
+            case 'Ȁ': return 'a';
+            case 'ȁ': return 'a';
+            case 'Ȃ': return 'a';
+            case 'ȃ': return 'a';
+            case 'Ȅ': return 'e';
+            case 'ȅ': return 'e';
+            case 'Ȇ': return 'e';
+            case 'ȇ': return 'e';
+            case 'Ȉ': return 'i';
+            case 'ȉ': return 'i';
+            case 'Ȋ': return 'i';
+            case 'ȋ': return 'i';
+            case 'Ȍ': return 'o';
+            case 'ȍ': return 'o';
+            case 'Ȏ': return 'o';
+            case 'ȏ': return 'o';
+            case 'Ȑ': return 'r';
+            case 'ȑ': return 'r';
+            case 'Ȓ': return 'r';
+            case 'ȓ': return 'r';
+            case 'Ȕ': return 'u';
+            case 'ȕ': return 'u';
+            case 'Ȗ': return 'u';
+            case 'ȗ': return 'u';
+            case 'Ș': return 's';
+            case 'ș': return 's';
+            case 'Ț': return 't';
+            case 'ț': return 't';
+            case 'Ȝ': return 'y';
+            case 'ȝ': return 'y';
+            case 'Ȟ': return 'h';
+            case 'ȟ': return 'h';
+            case 'Ȥ': return 'z';
+            case 'ȥ': return 'z';
+            case 'Ȧ': return 'a';
+            case 'ȧ': return 'a';
+            case 'Ȩ': return 'e';
+            case 'ȩ': return 'e';
+            case 'Ȫ': return 'o';
+            case 'ȫ': return 'o';
+            case 'Ȭ': return 'o';
+            case 'ȭ': return 'o';
+            case 'Ȯ': return 'o';
+            case 'ȯ': return 'o';
+            case 'Ȱ': return 'o';
+            case 'ȱ': return 'o';
+            case 'Ȳ': return 'y';
+            case 'ȳ': return 'y';
+            case 'A': return 'a';
+            case 'B': return 'b';
+            case 'C': return 'c';
+            case 'D': return 'd';
+            case 'E': return 'e';
+            case 'F': return 'f';
+            case 'G': return 'g';
+            case 'H': return 'h';
+            case 'I': return 'i';
+            case 'J': return 'j';
+            case 'K': return 'k';
+            case 'L': return 'l';
+            case 'M': return 'm';
+            case 'N': return 'n';
+            case 'O': return 'o';
+            case 'P': return 'p';
+            case 'Q': return 'q';
+            case 'R': return 'r';
+            case 'S': return 's';
+            case 'T': return 't';
+            case 'U': return 'u';
+            case 'V': return 'v';
+            case 'W': return 'w';
+            case 'X': return 'x';
+            case 'Y': return 'y';
+            case 'Z': return 'z';
+            default:
+                return ch;
+        }
+    }
+
+    @Override
+    public byte getDialpadIndex(char ch) {
+        if (ch >= '0' && ch <= '9') {
+            return (byte) (ch - '0');
+        } else if (ch >= 'a' && ch <= 'z') {
+            return (byte) (LATIN_LETTERS_TO_DIGITS[ch - 'a'] - '0');
+        } else {
+            return -1;
+        }
+    }
+
+    @Override
+    public char getDialpadNumericCharacter(char ch) {
+        if (ch >= 'a' && ch <= 'z') {
+            return LATIN_LETTERS_TO_DIGITS[ch - 'a'];
+        }
+        return ch;
+    }
+
+}
diff --git a/src/com/android/dialer/dialpad/SmartDialCache.java b/src/com/android/dialer/dialpad/SmartDialCache.java
index 3294bfb..3d4a563 100644
--- a/src/com/android/dialer/dialpad/SmartDialCache.java
+++ b/src/com/android/dialer/dialpad/SmartDialCache.java
@@ -144,6 +144,7 @@
 
     private SmartDialTrie mContactsCache;
     private static AtomicInteger mCacheStatus;
+    private final SmartDialMap mMap;
     private final int mNameDisplayOrder;
     private final Context mContext;
     private final static Object mLock = new Object();
@@ -162,8 +163,9 @@
 
     private static final boolean DEBUG = false;
 
-    private SmartDialCache(Context context, int nameDisplayOrder) {
+    private SmartDialCache(Context context, int nameDisplayOrder, SmartDialMap map) {
         mNameDisplayOrder = nameDisplayOrder;
+        mMap = map;
         Preconditions.checkNotNull(context, "Context must not be null");
         mContext = context.getApplicationContext();
         mCacheStatus = new AtomicInteger(CACHE_NEEDS_RECACHE);
@@ -201,9 +203,10 @@
      *        {@link android.provider.ContactsContract.Preferences#DISPLAY_ORDER}.
      * @return An instance of SmartDialCache
      */
-    public static synchronized SmartDialCache getInstance(Context context, int nameDisplayOrder) {
+    public static synchronized SmartDialCache getInstance(Context context, int nameDisplayOrder,
+            SmartDialMap map) {
         if (instance == null) {
-            instance = new SmartDialCache(context, nameDisplayOrder);
+            instance = new SmartDialCache(context, nameDisplayOrder, map);
         }
         return instance;
     }
@@ -236,8 +239,7 @@
                 mCacheStatus.getAndSet(CACHE_NEEDS_RECACHE);
                 return;
             }
-            final SmartDialTrie cache = new SmartDialTrie(
-                    SmartDialNameMatcher.LATIN_LETTERS_TO_DIGITS, sUserInNanpRegion);
+            final SmartDialTrie cache = new SmartDialTrie(mMap, sUserInNanpRegion);
             try {
                 c.moveToPosition(-1);
                 int affinityCount = 0;
@@ -350,6 +352,10 @@
 
     }
 
+    public SmartDialMap getMap() {
+        return mMap;
+    }
+
     public boolean getUserInNanpRegion() {
         return sUserInNanpRegion;
     }
diff --git a/src/com/android/dialer/dialpad/SmartDialLoaderTask.java b/src/com/android/dialer/dialpad/SmartDialLoaderTask.java
index 216697d..d584c17 100644
--- a/src/com/android/dialer/dialpad/SmartDialLoaderTask.java
+++ b/src/com/android/dialer/dialpad/SmartDialLoaderTask.java
@@ -68,8 +68,9 @@
     public SmartDialLoaderTask(SmartDialLoaderCallback callback, String query,
             SmartDialCache cache) {
         this.mCallback = callback;
-        this.mNameMatcher = new SmartDialNameMatcher(PhoneNumberUtils.normalizeNumber(query));
         this.mContactsCache = cache;
+        this.mNameMatcher = new SmartDialNameMatcher(PhoneNumberUtils.normalizeNumber(query),
+                cache.getMap());
         this.mQuery = query;
     }
 
@@ -127,7 +128,7 @@
                     Contacts.getLookupUri(contact.id, contact.lookupKey),
                     contact.phoneNumber,
                     mNameMatcher.getMatchPositions(),
-                    SmartDialNameMatcher.matchesNumber(contact.phoneNumber,
+                    mNameMatcher.matchesNumber(contact.phoneNumber,
                             mNameMatcher.getQuery(), matchNanp)
                     ));
             if (candidates.size() >= MAX_ENTRIES) {
diff --git a/src/com/android/dialer/dialpad/SmartDialMap.java b/src/com/android/dialer/dialpad/SmartDialMap.java
new file mode 100644
index 0000000..b51891a
--- /dev/null
+++ b/src/com/android/dialer/dialpad/SmartDialMap.java
@@ -0,0 +1,43 @@
+package com.android.dialer.dialpad;
+
+/**
+ * Note: These methods currently take characters as arguments. For future planned language support,
+ * they will need to be changed to use codepoints instead of characters.
+ *
+ * http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#codePointAt(int)
+ *
+ * If/when this change is made, LatinSmartDialMap(which operates on chars) will continue to work
+ * by simply casting from a codepoint to a character.
+ */
+public interface SmartDialMap {
+    /*
+     * Returns true if the provided character can be mapped to a key on the dialpad
+     */
+    public boolean isValidDialpadCharacter(char ch);
+
+    /*
+     * Returns true if the provided character is a letter, and can be mapped to a key on the dialpad
+     */
+    public boolean isValidDialpadAlphabeticChar(char ch);
+
+    /*
+     * Returns true if the provided character is a digit, and can be mapped to a key on the dialpad
+     */
+    public boolean isValidDialpadNumericChar(char ch);
+
+    /*
+     * Get the index of the key on the dialpad which the character corresponds to
+     */
+    public byte getDialpadIndex(char ch);
+
+    /*
+     * Get the actual numeric character on the dialpad which the character corresponds to
+     */
+    public char getDialpadNumericCharacter(char ch);
+
+    /*
+     * Converts uppercase characters to lower case ones, and on a best effort basis, strips accents
+     * from accented characters.
+     */
+    public char normalizeCharacter(char ch);
+}
diff --git a/src/com/android/dialer/dialpad/SmartDialNameMatcher.java b/src/com/android/dialer/dialpad/SmartDialNameMatcher.java
index f7ae1c2..d7d5ad5 100644
--- a/src/com/android/dialer/dialpad/SmartDialNameMatcher.java
+++ b/src/com/android/dialer/dialpad/SmartDialNameMatcher.java
@@ -36,17 +36,6 @@
 
     private final String mQuery;
 
-    public static final char[] LATIN_LETTERS_TO_DIGITS = {
-        '2', '2', '2', // A,B,C -> 2
-        '3', '3', '3', // D,E,F -> 3
-        '4', '4', '4', // G,H,I -> 4
-        '5', '5', '5', // J,K,L -> 5
-        '6', '6', '6', // M,N,O -> 6
-        '7', '7', '7', '7', // P,Q,R,S -> 7
-        '8', '8', '8', // T,U,V -> 8
-        '9', '9', '9', '9' // W,X,Y,Z -> 9
-    };
-
     // Whether or not we allow matches like 57 - (J)ohn (S)mith
     private static final boolean ALLOW_INITIAL_MATCH = true;
 
@@ -54,371 +43,20 @@
     // positives
     private static final int INITIAL_LENGTH_LIMIT = 1;
 
-    /*
-     * The switch statement in this function was generated using the python code:
-     * from unidecode import unidecode
-     * for i in range(192, 564):
-     *     char = unichr(i)
-     *     decoded = unidecode(char)
-     *     # Unicode characters that decompose into multiple characters i.e.
-     *     #  into ss are not supported for now
-     *     if (len(decoded) == 1 and decoded.isalpha()):
-     *         print "case '" + char + "': return '" + unidecode(char) +  "';"
-     *
-     * This gives us a way to map characters containing accents/diacritics to their
-     * alphabetic equivalents. The unidecode library can be found at:
-     * http://pypi.python.org/pypi/Unidecode/0.04.1
-     *
-     * Also remaps all upper case latin characters to their lower case equivalents.
-     */
-    public static char remapAccentedChars(char c) {
-        switch (c) {
-            case 'À': return 'a';
-            case 'Á': return 'a';
-            case 'Â': return 'a';
-            case 'Ã': return 'a';
-            case 'Ä': return 'a';
-            case 'Å': return 'a';
-            case 'Ç': return 'c';
-            case 'È': return 'e';
-            case 'É': return 'e';
-            case 'Ê': return 'e';
-            case 'Ë': return 'e';
-            case 'Ì': return 'i';
-            case 'Í': return 'i';
-            case 'Î': return 'i';
-            case 'Ï': return 'i';
-            case 'Ð': return 'd';
-            case 'Ñ': return 'n';
-            case 'Ò': return 'o';
-            case 'Ó': return 'o';
-            case 'Ô': return 'o';
-            case 'Õ': return 'o';
-            case 'Ö': return 'o';
-            case '×': return 'x';
-            case 'Ø': return 'o';
-            case 'Ù': return 'u';
-            case 'Ú': return 'u';
-            case 'Û': return 'u';
-            case 'Ü': return 'u';
-            case 'Ý': return 'u';
-            case 'à': return 'a';
-            case 'á': return 'a';
-            case 'â': return 'a';
-            case 'ã': return 'a';
-            case 'ä': return 'a';
-            case 'å': return 'a';
-            case 'ç': return 'c';
-            case 'è': return 'e';
-            case 'é': return 'e';
-            case 'ê': return 'e';
-            case 'ë': return 'e';
-            case 'ì': return 'i';
-            case 'í': return 'i';
-            case 'î': return 'i';
-            case 'ï': return 'i';
-            case 'ð': return 'd';
-            case 'ñ': return 'n';
-            case 'ò': return 'o';
-            case 'ó': return 'o';
-            case 'ô': return 'o';
-            case 'õ': return 'o';
-            case 'ö': return 'o';
-            case 'ø': return 'o';
-            case 'ù': return 'u';
-            case 'ú': return 'u';
-            case 'û': return 'u';
-            case 'ü': return 'u';
-            case 'ý': return 'y';
-            case 'ÿ': return 'y';
-            case 'Ā': return 'a';
-            case 'ā': return 'a';
-            case 'Ă': return 'a';
-            case 'ă': return 'a';
-            case 'Ą': return 'a';
-            case 'ą': return 'a';
-            case 'Ć': return 'c';
-            case 'ć': return 'c';
-            case 'Ĉ': return 'c';
-            case 'ĉ': return 'c';
-            case 'Ċ': return 'c';
-            case 'ċ': return 'c';
-            case 'Č': return 'c';
-            case 'č': return 'c';
-            case 'Ď': return 'd';
-            case 'ď': return 'd';
-            case 'Đ': return 'd';
-            case 'đ': return 'd';
-            case 'Ē': return 'e';
-            case 'ē': return 'e';
-            case 'Ĕ': return 'e';
-            case 'ĕ': return 'e';
-            case 'Ė': return 'e';
-            case 'ė': return 'e';
-            case 'Ę': return 'e';
-            case 'ę': return 'e';
-            case 'Ě': return 'e';
-            case 'ě': return 'e';
-            case 'Ĝ': return 'g';
-            case 'ĝ': return 'g';
-            case 'Ğ': return 'g';
-            case 'ğ': return 'g';
-            case 'Ġ': return 'g';
-            case 'ġ': return 'g';
-            case 'Ģ': return 'g';
-            case 'ģ': return 'g';
-            case 'Ĥ': return 'h';
-            case 'ĥ': return 'h';
-            case 'Ħ': return 'h';
-            case 'ħ': return 'h';
-            case 'Ĩ': return 'i';
-            case 'ĩ': return 'i';
-            case 'Ī': return 'i';
-            case 'ī': return 'i';
-            case 'Ĭ': return 'i';
-            case 'ĭ': return 'i';
-            case 'Į': return 'i';
-            case 'į': return 'i';
-            case 'İ': return 'i';
-            case 'ı': return 'i';
-            case 'Ĵ': return 'j';
-            case 'ĵ': return 'j';
-            case 'Ķ': return 'k';
-            case 'ķ': return 'k';
-            case 'ĸ': return 'k';
-            case 'Ĺ': return 'l';
-            case 'ĺ': return 'l';
-            case 'Ļ': return 'l';
-            case 'ļ': return 'l';
-            case 'Ľ': return 'l';
-            case 'ľ': return 'l';
-            case 'Ŀ': return 'l';
-            case 'ŀ': return 'l';
-            case 'Ł': return 'l';
-            case 'ł': return 'l';
-            case 'Ń': return 'n';
-            case 'ń': return 'n';
-            case 'Ņ': return 'n';
-            case 'ņ': return 'n';
-            case 'Ň': return 'n';
-            case 'ň': return 'n';
-            case 'Ō': return 'o';
-            case 'ō': return 'o';
-            case 'Ŏ': return 'o';
-            case 'ŏ': return 'o';
-            case 'Ő': return 'o';
-            case 'ő': return 'o';
-            case 'Ŕ': return 'r';
-            case 'ŕ': return 'r';
-            case 'Ŗ': return 'r';
-            case 'ŗ': return 'r';
-            case 'Ř': return 'r';
-            case 'ř': return 'r';
-            case 'Ś': return 's';
-            case 'ś': return 's';
-            case 'Ŝ': return 's';
-            case 'ŝ': return 's';
-            case 'Ş': return 's';
-            case 'ş': return 's';
-            case 'Š': return 's';
-            case 'š': return 's';
-            case 'Ţ': return 't';
-            case 'ţ': return 't';
-            case 'Ť': return 't';
-            case 'ť': return 't';
-            case 'Ŧ': return 't';
-            case 'ŧ': return 't';
-            case 'Ũ': return 'u';
-            case 'ũ': return 'u';
-            case 'Ū': return 'u';
-            case 'ū': return 'u';
-            case 'Ŭ': return 'u';
-            case 'ŭ': return 'u';
-            case 'Ů': return 'u';
-            case 'ů': return 'u';
-            case 'Ű': return 'u';
-            case 'ű': return 'u';
-            case 'Ų': return 'u';
-            case 'ų': return 'u';
-            case 'Ŵ': return 'w';
-            case 'ŵ': return 'w';
-            case 'Ŷ': return 'y';
-            case 'ŷ': return 'y';
-            case 'Ÿ': return 'y';
-            case 'Ź': return 'z';
-            case 'ź': return 'z';
-            case 'Ż': return 'z';
-            case 'ż': return 'z';
-            case 'Ž': return 'z';
-            case 'ž': return 'z';
-            case 'ſ': return 's';
-            case 'ƀ': return 'b';
-            case 'Ɓ': return 'b';
-            case 'Ƃ': return 'b';
-            case 'ƃ': return 'b';
-            case 'Ɔ': return 'o';
-            case 'Ƈ': return 'c';
-            case 'ƈ': return 'c';
-            case 'Ɖ': return 'd';
-            case 'Ɗ': return 'd';
-            case 'Ƌ': return 'd';
-            case 'ƌ': return 'd';
-            case 'ƍ': return 'd';
-            case 'Ɛ': return 'e';
-            case 'Ƒ': return 'f';
-            case 'ƒ': return 'f';
-            case 'Ɠ': return 'g';
-            case 'Ɣ': return 'g';
-            case 'Ɩ': return 'i';
-            case 'Ɨ': return 'i';
-            case 'Ƙ': return 'k';
-            case 'ƙ': return 'k';
-            case 'ƚ': return 'l';
-            case 'ƛ': return 'l';
-            case 'Ɯ': return 'w';
-            case 'Ɲ': return 'n';
-            case 'ƞ': return 'n';
-            case 'Ɵ': return 'o';
-            case 'Ơ': return 'o';
-            case 'ơ': return 'o';
-            case 'Ƥ': return 'p';
-            case 'ƥ': return 'p';
-            case 'ƫ': return 't';
-            case 'Ƭ': return 't';
-            case 'ƭ': return 't';
-            case 'Ʈ': return 't';
-            case 'Ư': return 'u';
-            case 'ư': return 'u';
-            case 'Ʊ': return 'y';
-            case 'Ʋ': return 'v';
-            case 'Ƴ': return 'y';
-            case 'ƴ': return 'y';
-            case 'Ƶ': return 'z';
-            case 'ƶ': return 'z';
-            case 'ƿ': return 'w';
-            case 'Ǎ': return 'a';
-            case 'ǎ': return 'a';
-            case 'Ǐ': return 'i';
-            case 'ǐ': return 'i';
-            case 'Ǒ': return 'o';
-            case 'ǒ': return 'o';
-            case 'Ǔ': return 'u';
-            case 'ǔ': return 'u';
-            case 'Ǖ': return 'u';
-            case 'ǖ': return 'u';
-            case 'Ǘ': return 'u';
-            case 'ǘ': return 'u';
-            case 'Ǚ': return 'u';
-            case 'ǚ': return 'u';
-            case 'Ǜ': return 'u';
-            case 'ǜ': return 'u';
-            case 'Ǟ': return 'a';
-            case 'ǟ': return 'a';
-            case 'Ǡ': return 'a';
-            case 'ǡ': return 'a';
-            case 'Ǥ': return 'g';
-            case 'ǥ': return 'g';
-            case 'Ǧ': return 'g';
-            case 'ǧ': return 'g';
-            case 'Ǩ': return 'k';
-            case 'ǩ': return 'k';
-            case 'Ǫ': return 'o';
-            case 'ǫ': return 'o';
-            case 'Ǭ': return 'o';
-            case 'ǭ': return 'o';
-            case 'ǰ': return 'j';
-            case 'Dz': return 'd';
-            case 'Ǵ': return 'g';
-            case 'ǵ': return 'g';
-            case 'Ƿ': return 'w';
-            case 'Ǹ': return 'n';
-            case 'ǹ': return 'n';
-            case 'Ǻ': return 'a';
-            case 'ǻ': return 'a';
-            case 'Ǿ': return 'o';
-            case 'ǿ': return 'o';
-            case 'Ȁ': return 'a';
-            case 'ȁ': return 'a';
-            case 'Ȃ': return 'a';
-            case 'ȃ': return 'a';
-            case 'Ȅ': return 'e';
-            case 'ȅ': return 'e';
-            case 'Ȇ': return 'e';
-            case 'ȇ': return 'e';
-            case 'Ȉ': return 'i';
-            case 'ȉ': return 'i';
-            case 'Ȋ': return 'i';
-            case 'ȋ': return 'i';
-            case 'Ȍ': return 'o';
-            case 'ȍ': return 'o';
-            case 'Ȏ': return 'o';
-            case 'ȏ': return 'o';
-            case 'Ȑ': return 'r';
-            case 'ȑ': return 'r';
-            case 'Ȓ': return 'r';
-            case 'ȓ': return 'r';
-            case 'Ȕ': return 'u';
-            case 'ȕ': return 'u';
-            case 'Ȗ': return 'u';
-            case 'ȗ': return 'u';
-            case 'Ș': return 's';
-            case 'ș': return 's';
-            case 'Ț': return 't';
-            case 'ț': return 't';
-            case 'Ȝ': return 'y';
-            case 'ȝ': return 'y';
-            case 'Ȟ': return 'h';
-            case 'ȟ': return 'h';
-            case 'Ȥ': return 'z';
-            case 'ȥ': return 'z';
-            case 'Ȧ': return 'a';
-            case 'ȧ': return 'a';
-            case 'Ȩ': return 'e';
-            case 'ȩ': return 'e';
-            case 'Ȫ': return 'o';
-            case 'ȫ': return 'o';
-            case 'Ȭ': return 'o';
-            case 'ȭ': return 'o';
-            case 'Ȯ': return 'o';
-            case 'ȯ': return 'o';
-            case 'Ȱ': return 'o';
-            case 'ȱ': return 'o';
-            case 'Ȳ': return 'y';
-            case 'ȳ': return 'y';
-            case 'A': return 'a';
-            case 'B': return 'b';
-            case 'C': return 'c';
-            case 'D': return 'd';
-            case 'E': return 'e';
-            case 'F': return 'f';
-            case 'G': return 'g';
-            case 'H': return 'h';
-            case 'I': return 'i';
-            case 'J': return 'j';
-            case 'K': return 'k';
-            case 'L': return 'l';
-            case 'M': return 'm';
-            case 'N': return 'n';
-            case 'O': return 'o';
-            case 'P': return 'p';
-            case 'Q': return 'q';
-            case 'R': return 'r';
-            case 'S': return 's';
-            case 'T': return 't';
-            case 'U': return 'u';
-            case 'V': return 'v';
-            case 'W': return 'w';
-            case 'X': return 'x';
-            case 'Y': return 'y';
-            case 'Z': return 'z';
-            default: return c;
-        }
-    }
-
     private final ArrayList<SmartDialMatchPosition> mMatchPositions = Lists.newArrayList();
 
+    private static final SmartDialMap LATIN_SMART_DIAL_MAP = new LatinSmartDialMap();
+
+    private final SmartDialMap mMap;
+
+    @VisibleForTesting
     public SmartDialNameMatcher(String query) {
+        this(query, LATIN_SMART_DIAL_MAP);
+    }
+
+    public SmartDialNameMatcher(String query, SmartDialMap map) {
         mQuery = query;
+        mMap = map;
     }
 
     /**
@@ -427,8 +65,8 @@
      * @param number Phone number we want to normalize
      * @return Phone number consisting of digits from 0-9
      */
-    public static String normalizeNumber(String number) {
-        return normalizeNumber(number, 0);
+    public static String normalizeNumber(String number, SmartDialMap map) {
+        return normalizeNumber(number, 0, map);
     }
 
     /**
@@ -438,11 +76,11 @@
      * @param offset Offset to start from
      * @return Phone number consisting of digits from 0-9
      */
-    public static String normalizeNumber(String number, int offset) {
+    public static String normalizeNumber(String number, int offset, SmartDialMap map) {
         final StringBuilder s = new StringBuilder();
         for (int i = offset; i < number.length(); i++) {
             char ch = number.charAt(i);
-            if (ch >= '0' && ch <= '9') {
+            if (map.isValidDialpadNumericChar(ch)) {
                 s.append(ch);
             }
         }
@@ -459,7 +97,7 @@
      * @return {@literal null} if the number and the query don't match, a valid
      *         SmartDialMatchPosition with the matching positions otherwise
      */
-    public static SmartDialMatchPosition matchesNumber(String phoneNumber, String query,
+    public SmartDialMatchPosition matchesNumber(String phoneNumber, String query,
             boolean matchNanp) {
         // Try matching the number as is
         SmartDialMatchPosition matchPos = matchesNumberWithOffset(phoneNumber, query, 0);
@@ -472,7 +110,8 @@
             }
             if (matchPos == null && matchNanp) {
                 // Try matching NANP numbers
-                final int[] offsets = SmartDialTrie.getOffsetForNANPNumbers(phoneNumber);
+                final int[] offsets = SmartDialTrie.getOffsetForNANPNumbers(phoneNumber,
+                        mMap);
                 for (int i = 0; i < offsets.length; i++) {
                     matchPos = matchesNumberWithOffset(phoneNumber, query, offsets[i]);
                     if (matchPos != null) break;
@@ -492,7 +131,7 @@
      * @return {@literal null} if the number and the query don't match, a valid
      *         SmartDialMatchPosition with the matching positions otherwise
      */
-    private static SmartDialMatchPosition matchesNumberWithOffset(String phoneNumber, String query,
+    private SmartDialMatchPosition matchesNumberWithOffset(String phoneNumber, String query,
             int offset) {
         if (TextUtils.isEmpty(phoneNumber) || TextUtils.isEmpty(query)) {
             return null;
@@ -504,7 +143,7 @@
                 break;
             }
             char ch = phoneNumber.charAt(i);
-            if (ch >= '0' && ch <= '9') {
+            if (mMap.isValidDialpadNumericChar(ch)) {
                 if (ch != query.charAt(queryAt)) {
                     return null;
                 }
@@ -592,11 +231,10 @@
         while (nameStart < nameLength && queryStart < queryLength) {
             char ch = displayName.charAt(nameStart);
             // Strip diacritics from accented characters if any
-            ch = remapAccentedChars(ch);
-            if (isLowercaseLatinLetterOrDigit(ch)) {
-                if (ch >= 'a' && ch <= 'z') {
-                    // a starts at index 0. If ch >= '0' && ch <= '9', we don't have to do anything
-                    ch = LATIN_LETTERS_TO_DIGITS[ch - 'a'];
+            ch = mMap.normalizeCharacter(ch);
+            if (mMap.isValidDialpadCharacter(ch)) {
+                if (mMap.isValidDialpadAlphabeticChar(ch)) {
+                    ch = mMap.getDialpadNumericCharacter(ch);
                 }
                 if (ch != query.charAt(queryStart)) {
                     // Failed to match the current character in the query.
@@ -615,11 +253,11 @@
                     // Yo-Yoghurt because the query match would fail on the 3rd character, and
                     // then skip to the end of the "Yoghurt" token.
 
-                    if (queryStart == 0 || isLowercaseLatinLetterOrDigit(remapAccentedChars(
+                    if (queryStart == 0 || mMap.isValidDialpadCharacter(mMap.normalizeCharacter(
                             displayName.charAt(nameStart - 1)))) {
                         // skip to the next token, in the case of 1 or 2.
                         while (nameStart < nameLength &&
-                                isLowercaseLatinLetterOrDigit(remapAccentedChars(
+                                mMap.isValidDialpadCharacter(mMap.normalizeCharacter(
                                         displayName.charAt(nameStart)))) {
                             nameStart++;
                         }
@@ -645,7 +283,7 @@
                         // find the next separator in the query string
                         int j;
                         for (j = nameStart; j < nameLength; j++) {
-                            if (!isLowercaseLatinLetterOrDigit(remapAccentedChars(
+                            if (!mMap.isValidDialpadCharacter(mMap.normalizeCharacter(
                                     displayName.charAt(j)))) {
                                 break;
                             }
@@ -699,13 +337,6 @@
         return false;
     }
 
-    /*
-     * Returns true if the character is a lowercase latin character or digit(i.e. non-separator).
-     */
-    private boolean isLowercaseLatinLetterOrDigit(char ch) {
-        return (ch >= 'a' && ch <= 'z') || (ch >= '0' && ch <= '9');
-    }
-
     public boolean matches(String displayName) {
         mMatchPositions.clear();
         return matchesCombination(displayName, mQuery, mMatchPositions);
diff --git a/src/com/android/dialer/dialpad/SmartDialTrie.java b/src/com/android/dialer/dialpad/SmartDialTrie.java
index ab935b7..c62210b 100644
--- a/src/com/android/dialer/dialpad/SmartDialTrie.java
+++ b/src/com/android/dialer/dialpad/SmartDialTrie.java
@@ -66,7 +66,7 @@
 
     final Node mRoot = new Node();
     private int mSize = 0;
-    private final char[] mCharacterMap;
+    private final SmartDialMap mMap;
     private final boolean mFormatNanp;
 
     private static final int LAST_TOKENS_FOR_INITIALS = 2;
@@ -77,7 +77,7 @@
 
     public SmartDialTrie() {
         // Use the latin letter to digit map by default if none provided
-        this(SmartDialNameMatcher.LATIN_LETTERS_TO_DIGITS, false);
+        this(new LatinSmartDialMap(), false);
     }
 
     /**
@@ -88,7 +88,7 @@
      */
     @VisibleForTesting
     public SmartDialTrie(boolean formatNanp) {
-        this(SmartDialNameMatcher.LATIN_LETTERS_TO_DIGITS, formatNanp);
+        this(new LatinSmartDialMap(), formatNanp);
     }
 
     /**
@@ -98,8 +98,8 @@
      * @param formatNanp True if inserted numbers are to be treated as NANP numbers
      * such that numbers are automatically broken up by country prefix and area code.
      */
-    public SmartDialTrie(char[] charMap, boolean formatNanp) {
-        mCharacterMap = charMap;
+    public SmartDialTrie(SmartDialMap map, boolean formatNanp) {
+        mMap = map;
         mFormatNanp = formatNanp;
     }
 
@@ -161,7 +161,7 @@
             if ((code.countryCode.equals("1") || code.offset == 0) && mFormatNanp) {
                 // Special case handling for NANP numbers (1-xxx-xxx-xxxx)
                 final String stripped = SmartDialNameMatcher.normalizeNumber(
-                        contact.phoneNumber, code.offset);
+                        contact.phoneNumber, code.offset, mMap);
                 if (!TextUtils.isEmpty(stripped)) {
                     int trunkPrefixOffset = 0;
                     if (stripped.charAt(0) == '1') {
@@ -211,14 +211,14 @@
      * and an array containing integer offsets for the number (starting after the '1' prefix,
      * and the area code prefix respectively.
      */
-    public static int[] getOffsetForNANPNumbers(String number) {
+    public static int[] getOffsetForNANPNumbers(String number, SmartDialMap map) {
         int validDigits = 0;
         boolean hasPrefix = false;
         int firstOffset = 0; // Tracks the location of the first digit after the '1' prefix
         int secondOffset = 0; // Tracks the location of the first digit after the area code
         for (int i = 0; i < number.length(); i++) {
             final char ch = number.charAt(i);
-            if (ch >= '0' && ch <= '9') {
+            if (map.isValidDialpadNumericChar(ch)) {
                 if (validDigits == 0) {
                     // Check the first digit to see if it is 1
                     if (ch == '1') {
@@ -264,19 +264,13 @@
         int tokenCount = 0;
         boolean atSeparator = true;
         for (int i = 0; i < length; i++) {
-            c = SmartDialNameMatcher.remapAccentedChars(chars.charAt(i));
-            if (c >= 'a' && c <= 'z' || c >= '0' && c <= '9') {
+            c = mMap.normalizeCharacter(chars.charAt(i));
+            if (mMap.isValidDialpadCharacter(c)) {
                 if (atSeparator) {
                     tokenCount++;
                 }
                 atSeparator = false;
-                if (c <= '9') {
-                    // 0-9
-                    result[i] = (byte) (c - '0');
-                } else {
-                    // a-z
-                    result[i] = (byte) (mCharacterMap[c - 'a'] - '0');
-                }
+                result[i] = mMap.getDialpadIndex(c);
             } else {
                 // Found the last character of the current token
                 if (!atSeparator) {
@@ -310,7 +304,7 @@
         char ch;
         for (int i = offSet; i < length; i++) {
             ch = phoneNumber.charAt(i);
-            if (ch >= '0' && ch <= '9') {
+            if (mMap.isValidDialpadNumericChar(ch)) {
                 current = current.getChild(ch, true);
             }
         }
diff --git a/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java b/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java
index eb6f050..47edaf3 100644
--- a/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java
+++ b/tests/src/com/android/dialer/dialpad/SmartDialNameMatcherTest.java
@@ -236,7 +236,8 @@
 
     private void checkMatchesNumber(String number, String query, boolean expectedMatches,
             boolean matchNanp, int matchStart, int matchEnd) {
-        final SmartDialMatchPosition pos = SmartDialNameMatcher.matchesNumber(number, query,
+        final SmartDialNameMatcher matcher = new SmartDialNameMatcher(query);
+        final SmartDialMatchPosition pos = matcher.matchesNumber(number, query,
                 matchNanp);
         assertEquals(expectedMatches, pos != null);
         if (expectedMatches) {