summaryrefslogtreecommitdiff
path: root/java/com/android/dialer/app
diff options
context:
space:
mode:
authorzachh <zachh@google.com>2017-08-16 12:42:37 -0700
committerEric Erfanian <erfanian@google.com>2017-08-30 14:19:48 +0000
commit780a361bb4416d1b3e34ed8bb3dab213070fcd17 (patch)
treea69f15cd01acde8a4903dc5b83d9131aead94733 /java/com/android/dialer/app
parent24dbc840985b12a8e61e6e190e8508c72d58bcae (diff)
Init PhoneNumberFormattingTextWatcher on background thread.
A strict violation was being caused by calling this on the main thread: android.telephony.PhoneNumberFormattingTextWatcher.<init>(PhoneNumberFormattingTextWatcher.java:71) We now initialize the watcher on a background thread and pass it back to the main thread to be attached to the textview. Behavior before: Dialpad fragment would fail to appear until libphonenumber finished (verified by adding sleep and observing) Behavior after: Dialpad fragment loads immediately, but formatting is not enabled until libphonenumber finishes reading metadata. When adding sleeps, I could type "4084" before init finished and it would remain unformatted. When init finished I could type another character like "6" and the text view would be correctly updated to "408-46". Bug: 64716944 Test: manual PiperOrigin-RevId: 165480191 Change-Id: Ie1136a5a0e0b7ed66d4882e96c5830ca1e7523f0
Diffstat (limited to 'java/com/android/dialer/app')
-rw-r--r--java/com/android/dialer/app/dialpad/DialpadFragment.java36
1 files changed, 33 insertions, 3 deletions
diff --git a/java/com/android/dialer/app/dialpad/DialpadFragment.java b/java/com/android/dialer/app/dialpad/DialpadFragment.java
index 3cd3ac27c..d58caa50a 100644
--- a/java/com/android/dialer/app/dialpad/DialpadFragment.java
+++ b/java/com/android/dialer/app/dialpad/DialpadFragment.java
@@ -42,6 +42,7 @@ import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.provider.Contacts.PhonesColumns;
import android.provider.Settings;
+import android.support.annotation.Nullable;
import android.support.annotation.VisibleForTesting;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
@@ -82,6 +83,9 @@ import com.android.dialer.callintent.CallInitiationType;
import com.android.dialer.callintent.CallIntentBuilder;
import com.android.dialer.calllogutils.PhoneAccountUtils;
import com.android.dialer.common.LogUtil;
+import com.android.dialer.common.concurrent.DialerExecutor;
+import com.android.dialer.common.concurrent.DialerExecutor.Worker;
+import com.android.dialer.common.concurrent.DialerExecutors;
import com.android.dialer.dialpadview.DialpadKeyButton;
import com.android.dialer.dialpadview.DialpadView;
import com.android.dialer.location.GeoUtil;
@@ -178,6 +182,8 @@ public class DialpadFragment extends Fragment
private boolean mFirstLaunch = false;
private boolean mAnimate = false;
+ private DialerExecutor<String> initPhoneNumberFormattingTextWatcherExecutor;
+
/**
* Determines whether an add call operation is requested.
*
@@ -346,6 +352,14 @@ public class DialpadFragment extends Fragment
mCallStateReceiver = new CallStateReceiver();
getActivity().registerReceiver(mCallStateReceiver, callStateIntentFilter);
}
+
+ initPhoneNumberFormattingTextWatcherExecutor =
+ DialerExecutors.createUiTaskBuilder(
+ getFragmentManager(),
+ "DialpadFragment.initPhoneNumberFormattingTextWatcher",
+ new InitPhoneNumberFormattingTextWatcherWorker())
+ .onSuccess(watcher -> mDialpadView.getDigits().addTextChangedListener(watcher))
+ .build();
Trace.endSection();
}
@@ -371,9 +385,8 @@ public class DialpadFragment extends Fragment
mDigits.addTextChangedListener(this);
mDigits.setElegantTextHeight(false);
- PhoneNumberFormattingTextWatcher watcher =
- new PhoneNumberFormattingTextWatcher(GeoUtil.getCurrentCountryIso(getActivity()));
- mDigits.addTextChangedListener(watcher);
+ initPhoneNumberFormattingTextWatcherExecutor.executeSerial(
+ GeoUtil.getCurrentCountryIso(getActivity()));
// Check for the presence of the keypad
View oneButton = fragmentView.findViewById(R.id.one);
@@ -1707,4 +1720,21 @@ public class DialpadFragment extends Fragment
}
}
}
+
+ /**
+ * Input: the ISO 3166-1 two letters country code of the country the user is in
+ *
+ * <p>Output: PhoneNumberFormattingTextWatcher. Note: It is unusual to return a non-data value
+ * from a worker, but it is a limitation in libphonenumber API that the watcher cannot be
+ * initialized on the main thread.
+ */
+ private static class InitPhoneNumberFormattingTextWatcherWorker
+ implements Worker<String, PhoneNumberFormattingTextWatcher> {
+
+ @Nullable
+ @Override
+ public PhoneNumberFormattingTextWatcher doInBackground(@Nullable String countryCode) {
+ return new PhoneNumberFormattingTextWatcher(countryCode);
+ }
+ }
}