Blocked Numbers A11Y fixes & polish.

- Increase touch target for x button.
- Make all phone numbers read as phone numbers.
- Format numbers as phone numbers as they are entered
  then strip formatting before writing to provider.
- Change padding of add blocked number dialog.

- Depend on provider api isntead of directly checking if isPrimaryUser

Yet to add snackbars.

Bug: 27709645
Bug: 27495710
Change-Id: I217a3c0332c97e515407f4b4c07b614c59c2d9cf
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index be77220..2457f25 100644
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -23,7 +23,8 @@
 
     <dimen name="blocked_numbers_large_padding">16dp</dimen>
     <dimen name="blocked_numbers_extra_large_padding">32dp</dimen>
-    <dimen name="blocked_numbers_delete_icon_size">24dp</dimen>
+    <dimen name="blocked_numbers_dialog_padding">24dp</dimen>
+    <dimen name="blocked_numbers_delete_icon_padding">12dp</dimen>
     <dimen name="blocked_numbers_progress_bar_padding">100dp</dimen>
     <dimen name="blocked_numbers_font_size">16sp</dimen>
     <dimen name="blocked_numbers_secondary_font_size">14sp</dimen>
diff --git a/res/xml/add_blocked_number_dialog.xml b/res/xml/add_blocked_number_dialog.xml
index c1a2d28..b3462fd 100644
--- a/res/xml/add_blocked_number_dialog.xml
+++ b/res/xml/add_blocked_number_dialog.xml
@@ -20,21 +20,19 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:orientation="vertical"
-        android:paddingLeft="@dimen/blocked_numbers_extra_large_padding"
-        android:paddingRight="@dimen/blocked_numbers_extra_large_padding">
+        android:padding="@dimen/blocked_numbers_dialog_padding">
     <TextView
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:text="@string/add_blocked_dialog_body"
             android:paddingTop="@dimen/blocked_numbers_large_padding"
             android:paddingBottom="@dimen/blocked_numbers_large_padding"
-            style="@style/BlockedNumbersText" />
+            style="@style/BlockedNumbersTitleText" />
     <EditText
             android:id="@+id/add_blocked_number"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:paddingTop="@dimen/blocked_numbers_large_padding"
-            android:paddingBottom="@dimen/blocked_numbers_large_padding"
             android:hint="@string/add_blocked_number_hint"
             android:inputType="phone" />
 </LinearLayout>
\ No newline at end of file
diff --git a/res/xml/layout_blocked_number.xml b/res/xml/layout_blocked_number.xml
index e6475a4..e8fd4d1 100644
--- a/res/xml/layout_blocked_number.xml
+++ b/res/xml/layout_blocked_number.xml
@@ -30,12 +30,13 @@
         android:paddingBottom="@dimen/blocked_numbers_extra_large_padding"
         android:layout_toLeftOf="@+id/delete" />
 
-    <ImageButton
-        android:id="@+id/delete_blocked_number"
-        android:layout_width="@dimen/blocked_numbers_delete_icon_size"
-        android:layout_height="@dimen/blocked_numbers_delete_icon_size"
-        android:src="@drawable/ic_close_grey_24dp"
-        android:layout_alignParentRight="true"
-        android:contentDescription="@string/delete_icon_description"
-        android:background="?android:attr/selectableItemBackgroundBorderless" />
+    <ImageView
+            android:id="@+id/delete_blocked_number"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:padding="@dimen/blocked_numbers_delete_icon_padding"
+            android:src="@drawable/ic_close_grey_24dp"
+            android:layout_alignParentRight="true"
+            android:contentDescription="@string/delete_icon_description"
+            android:background="?android:attr/selectableItemBackgroundBorderless" />
 </RelativeLayout>
\ No newline at end of file
diff --git a/src/com/android/server/telecom/settings/BlockedNumbersActivity.java b/src/com/android/server/telecom/settings/BlockedNumbersActivity.java
index 5afe33a..b32b9b6 100644
--- a/src/com/android/server/telecom/settings/BlockedNumbersActivity.java
+++ b/src/com/android/server/telecom/settings/BlockedNumbersActivity.java
@@ -26,6 +26,8 @@
 import android.os.Bundle;
 import android.os.UserManager;
 import android.provider.BlockedNumberContract;
+import android.telephony.PhoneNumberFormattingTextWatcher;
+import android.telephony.PhoneNumberUtils;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
@@ -84,8 +86,7 @@
             actionBar.setDisplayHomeAsUpEnabled(true);
         }
 
-        UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
-        if (!userManager.isPrimaryUser()) {
+        if (!BlockedNumberContract.canCurrentUserBlockNumbers(this)) {
             TextView nonPrimaryUserText = (TextView) findViewById(R.id.non_primary_user);
             nonPrimaryUserText.setVisibility(View.VISIBLE);
 
@@ -184,12 +185,14 @@
         LayoutInflater inflater = this.getLayoutInflater();
         View dialogView = inflater.inflate(R.xml.add_blocked_number_dialog, null);
         final EditText editText = (EditText) dialogView.findViewById(R.id.add_blocked_number);
+        editText.addTextChangedListener(new PhoneNumberFormattingTextWatcher());
         editText.addTextChangedListener(this);
         AlertDialog dialog = new AlertDialog.Builder(this)
                 .setView(dialogView)
                 .setPositiveButton(R.string.block_button, new DialogInterface.OnClickListener() {
                     public void onClick(DialogInterface dialog, int id) {
-                        addBlockedNumber(editText.getText().toString());
+                        addBlockedNumber(PhoneNumberUtils.stripSeparators(
+                                editText.getText().toString()));
                     }
                 })
                 .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
diff --git a/src/com/android/server/telecom/settings/BlockedNumbersAdapter.java b/src/com/android/server/telecom/settings/BlockedNumbersAdapter.java
index 3d56459..5da230b 100644
--- a/src/com/android/server/telecom/settings/BlockedNumbersAdapter.java
+++ b/src/com/android/server/telecom/settings/BlockedNumbersAdapter.java
@@ -23,6 +23,8 @@
 import android.database.Cursor;
 import android.provider.BlockedNumberContract;
 import android.telephony.PhoneNumberUtils;
+import android.text.Spannable;
+import android.text.SpannableString;
 import android.view.View;
 import android.widget.SimpleCursorAdapter;
 import android.widget.TextView;
@@ -46,7 +48,9 @@
         final String finalFormattedNumber = formattedNumber == null ? rawNumber : formattedNumber;
 
         TextView numberView = (TextView) view.findViewById(R.id.blocked_number);
-        numberView.setText(finalFormattedNumber);
+        Spannable numberSpannable = new SpannableString(finalFormattedNumber);
+        PhoneNumberUtils.addTtsSpan(numberSpannable, 0, numberSpannable.length());
+        numberView.setText(numberSpannable);
 
         View deleteButton = view.findViewById(R.id.delete_blocked_number);
         deleteButton.setOnClickListener(new View.OnClickListener() {
@@ -67,8 +71,13 @@
 
     private void showDeleteBlockedNumberDialog(final Context context, final String rawNumber,
             final String formattedNumber) {
+        String message = context.getString(R.string.unblock_dialog_body, formattedNumber);
+        int startingPosition = message.indexOf(formattedNumber);
+        Spannable messageSpannable = new SpannableString(message);
+        PhoneNumberUtils.addTtsSpan(messageSpannable, startingPosition,
+                startingPosition + formattedNumber.length());
         new AlertDialog.Builder(context)
-                .setMessage(context.getString(R.string.unblock_dialog_body, formattedNumber))
+                .setMessage(messageSpannable)
                 .setPositiveButton(R.string.unblock_button,
                         new DialogInterface.OnClickListener() {
                             public void onClick(DialogInterface dialog, int id) {