Format the number by the convention of the country the user is in

Change-Id: I1d44e4cfebcd983585c4b9d0ba57bb4a5849a25d
diff --git a/src/com/android/contacts/ContactsUtils.java b/src/com/android/contacts/ContactsUtils.java
index 94dabba..68e7c6a 100644
--- a/src/com/android/contacts/ContactsUtils.java
+++ b/src/com/android/contacts/ContactsUtils.java
@@ -29,6 +29,8 @@
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.drawable.Drawable;
+import android.location.Country;
+import android.location.CountryDetector;
 import android.net.Uri;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Data;
@@ -490,4 +492,15 @@
         }
         return TextUtils.equals(a.getAction(), b.getAction());
     }
+
+    /**
+     * @return The ISO 3166-1 two letters country code of the country the user
+     *         is in.
+     */
+    public static final String getCurrentCountryIso(Context context) {
+        CountryDetector detector =
+                (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
+        Country country = detector.detectCountry();
+        return country.getCountryIso();
+    }
 }
diff --git a/src/com/android/contacts/TwelveKeyDialer.java b/src/com/android/contacts/TwelveKeyDialer.java
index bb4f496..5feecfc 100644
--- a/src/com/android/contacts/TwelveKeyDialer.java
+++ b/src/com/android/contacts/TwelveKeyDialer.java
@@ -268,7 +268,8 @@
     }
 
     protected void maybeAddNumberFormatting() {
-        mDigits.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
+        mDigits.addTextChangedListener(
+                new PhoneNumberFormattingTextWatcher(ContactsUtils.getCurrentCountryIso(this)));
     }
 
     /**
diff --git a/src/com/android/contacts/ui/widget/GenericEditorView.java b/src/com/android/contacts/ui/widget/GenericEditorView.java
index d313b48..a0f77fa 100644
--- a/src/com/android/contacts/ui/widget/GenericEditorView.java
+++ b/src/com/android/contacts/ui/widget/GenericEditorView.java
@@ -403,7 +403,8 @@
             int inputType = field.inputType;
             fieldView.setInputType(inputType);
             if (inputType == InputType.TYPE_CLASS_PHONE) {
-                fieldView.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
+                fieldView.addTextChangedListener(new PhoneNumberFormattingTextWatcher(
+                        ContactsUtils.getCurrentCountryIso(mContext)));
             }
             fieldView.setMinLines(field.minLines);