summaryrefslogtreecommitdiffstats
path: root/src/com/android/dialer/dialpad/SmartDialPrefix.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dialer/dialpad/SmartDialPrefix.java')
-rw-r--r--src/com/android/dialer/dialpad/SmartDialPrefix.java55
1 files changed, 42 insertions, 13 deletions
diff --git a/src/com/android/dialer/dialpad/SmartDialPrefix.java b/src/com/android/dialer/dialpad/SmartDialPrefix.java
index 6f993e4c1..1c2c46b1c 100644
--- a/src/com/android/dialer/dialpad/SmartDialPrefix.java
+++ b/src/com/android/dialer/dialpad/SmartDialPrefix.java
@@ -23,12 +23,20 @@ import android.preference.PreferenceManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import com.android.dialer.database.DialerDatabaseHelper;
+import com.android.dialerbind.DatabaseHelperManager;
+import com.android.phone.common.util.SettingsUtil;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
+import java.util.Locale;
+import java.util.Map;
+import java.util.HashMap;
+
+import android.util.Log;
/**
* Smart Dial utility class to find prefixes of contacts. It contains both methods to find supported
@@ -69,6 +77,27 @@ public class SmartDialPrefix {
private static boolean sNanpInitialized = false;
+ private static final Map<String, SmartDialMap> languageToSmartDialMap = new HashMap<String, SmartDialMap>();
+ static {
+ languageToSmartDialMap.put("ko", new KoreanSmartDialMap());
+ languageToSmartDialMap.put("el", new GreekSmartDialMap());
+ languageToSmartDialMap.put("ru", new RussianSmartDialMap());
+ // Per Locale.java documentation:
+ // Note that Java uses several deprecated two-letter codes. The Hebrew ("he") language
+ // code is rewritten as "iw"
+ languageToSmartDialMap.put("iw", new HebrewSmartDialMap());
+ languageToSmartDialMap.put("zh", new ChineseSmartDialMap());
+ }
+
+ private static final Map<String, SmartDialMap> countryToSmartDialMap = new HashMap<String, SmartDialMap>();
+ static {
+ languageToSmartDialMap.put("KR", new KoreanSmartDialMap());
+ languageToSmartDialMap.put("GR", new GreekSmartDialMap());
+ languageToSmartDialMap.put("RU", new RussianSmartDialMap());
+ languageToSmartDialMap.put("IL", new HebrewSmartDialMap());
+ languageToSmartDialMap.put("CN", new ChineseSmartDialMap());
+ }
+
/** Initializes the Nanp settings, and finds out whether user is in a NANP region.*/
public static void initializeNanpSettings(Context context){
final TelephonyManager manager = (TelephonyManager) context.getSystemService(
@@ -90,23 +119,23 @@ public class SmartDialPrefix {
/** Queries the NANP country list to find out whether user is in a NANP region.*/
sUserInNanpRegion = isCountryNanp(sUserSimCountryCode);
- /** Sets a layout for SmartDial depending on current UI language.*/
- String locale = context.getResources().getConfiguration().locale.getCountry();
- if (locale.equals("RU")) {
- mMap = new RussianSmartDialMap();
- } else if (locale.equals("GR")) {
- mMap = new GreekSmartDialMap();
- } else if (locale.equals("IL")) {
- mMap = new HebrewSmartDialMap();
- } else if (locale.equals("KR")) {
- mMap = new KoreanSmartDialMap();
- } else {
+ /** Sets a layout for SmartDial based on locale. Lookup by language first and fallback to country */
+ Locale locale = SettingsUtil.getT9SearchInputLocale(context);
+ mMap = languageToSmartDialMap.get(locale.getLanguage());
+ if (mMap == null)
+ mMap = countryToSmartDialMap.get(locale.getCountry());
+ if (mMap == null)
mMap = new LatinSmartDialMap();
- }
sNanpInitialized = true;
}
+ // for testing only
+ @VisibleForTesting
+ static void setSmartDialMap(SmartDialMap map) {
+ mMap = map;
+ }
+
/**
* Explicitly setting the user Nanp to the given boolean
*/
@@ -180,7 +209,7 @@ public class SmartDialPrefix {
*/
public static ArrayList<String> generateNamePrefixes(String index) {
final ArrayList<String> result = Lists.newArrayList();
-
+ index = mMap.transliterateName(index);
/** Parses the name into a list of tokens.*/
final ArrayList<String> indexTokens = parseToIndexTokens(index);