summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorerfanian <erfanian@google.com>2017-12-05 14:04:02 -0800
committerCopybara-Service <copybara-piper@google.com>2017-12-07 11:04:22 -0800
commit9a50cda3294e4e0830c0e99984563fe0275b41fc (patch)
tree38fea98b4b763e4d4b2f9448fc9b5813a087ca23 /java
parentd524f75074f4b04fee80719ea56d27d56f2bec16 (diff)
Display the automatically detected home country in assisted dialing settings.
Some degenerative cases are considered, like detected home countries that are currently unavailable. Bug: 68775522 Test: unit tests PiperOrigin-RevId: 178007559 Change-Id: Id85d7a2af1aa67757450bbbc80fd3ee67790b21c
Diffstat (limited to 'java')
-rw-r--r--java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java41
-rw-r--r--java/com/android/dialer/assisteddialing/ui/res/values/strings.xml7
-rw-r--r--java/com/android/dialer/assisteddialing/ui/res/xml/assisted_dialing_setting.xml2
3 files changed, 43 insertions, 7 deletions
diff --git a/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java b/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java
index 03418940a..d4fb3f64b 100644
--- a/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java
+++ b/java/com/android/dialer/assisteddialing/ui/AssistedDialingSettingFragment.java
@@ -22,15 +22,18 @@ import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
-import android.text.TextUtils;
+import android.telephony.TelephonyManager;
+import com.android.dialer.assisteddialing.AssistedDialingMediator;
import com.android.dialer.assisteddialing.ConcreteCreator;
import com.android.dialer.assisteddialing.CountryCodeProvider;
+import com.android.dialer.common.LogUtil;
import com.android.dialer.configprovider.ConfigProviderBindings;
import com.android.dialer.logging.DialerImpression;
import com.android.dialer.logging.Logger;
import com.google.auto.value.AutoValue;
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
/** The setting for Assisted Dialing */
@TargetApi(VERSION_CODES.N)
@@ -38,6 +41,7 @@ import java.util.List;
public class AssistedDialingSettingFragment extends PreferenceFragment {
private CountryCodeProvider countryCodeProvider;
+ private AssistedDialingMediator assistedDialingMediator;
@AutoValue
abstract static class DisplayNameAndCountryCodeTuple {
@@ -59,6 +63,10 @@ public class AssistedDialingSettingFragment extends PreferenceFragment {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ assistedDialingMediator =
+ ConcreteCreator.createNewAssistedDialingMediator(
+ getContext().getSystemService(TelephonyManager.class), getContext());
+
countryCodeProvider =
ConcreteCreator.getCountryCodeProvider(ConfigProviderBindings.get(getContext()));
@@ -73,14 +81,39 @@ public class AssistedDialingSettingFragment extends PreferenceFragment {
findPreference(getContext().getString(R.string.assisted_dialing_setting_cc_key));
updateCountryChoices(countryChooserPref);
+ updateCountryChooserSummary(countryChooserPref);
- if (!TextUtils.isEmpty(countryChooserPref.getEntry())) {
- countryChooserPref.setSummary(countryChooserPref.getEntry());
- }
countryChooserPref.setOnPreferenceChangeListener(this::updateListSummary);
switchPref.setOnPreferenceChangeListener(this::logIfUserDisabledFeature);
}
+ private void updateCountryChooserSummary(ListPreference countryChooserPref) {
+ String defaultSummaryText = countryChooserPref.getEntries()[0].toString();
+
+ if (countryChooserPref.getEntry().equals(defaultSummaryText)) {
+ Optional<String> userHomeCountryCode = assistedDialingMediator.userHomeCountryCode();
+ if (userHomeCountryCode.isPresent()) {
+ CharSequence[] entries = countryChooserPref.getEntries();
+ try {
+ CharSequence regionalDisplayName =
+ entries[countryChooserPref.findIndexOfValue(userHomeCountryCode.get())];
+ countryChooserPref.setSummary(
+ getContext()
+ .getString(
+ R.string.assisted_dialing_setting_cc_default_summary, regionalDisplayName));
+ } catch (ArrayIndexOutOfBoundsException e) {
+ // This might happen if there is a mismatch between the automatically
+ // detected home country, and the countries currently eligible to select in the settings.
+ LogUtil.i(
+ "AssistedDialingSettingFragment.onCreate",
+ "Failed to find human readable mapping for country code, using default.");
+ }
+ }
+ } else {
+ countryChooserPref.setSummary(countryChooserPref.getEntry());
+ }
+ }
+
/**
* Filters the default entries in the country chooser by only showing those countries in which the
* feature in enabled.
diff --git a/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml b/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml
index 3a81780a9..35aa2f147 100644
--- a/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml
+++ b/java/com/android/dialer/assisteddialing/ui/res/values/strings.xml
@@ -23,7 +23,10 @@
<string name="assisted_dialing_setting_summary">Predict and add a country code when you call while traveling abroad</string>
<!-- Indicates the default state for the home country selector-->
- <string name="assisted_dialing_setting_cc_default_summary">Automatically detected</string>
+ <string name="assisted_dialing_setting_cc_default_summary">Automatically detected • <xliff:g example="United Kingdom (+44)" id="ad_country_code_info">%1$s</xliff:g></string>
+
+ <!-- Indicates the default failure state for the home country selector-->
+ <string name="assisted_dialing_setting_cc_default_summary_fallback">Automatically detected</string>
<!-- Category title for the country code picker in assisted dialing [CHAR LIMIT=40]-->
<string name="assisted_dialing_setting_cc_category_title">Home country</string>
@@ -36,7 +39,7 @@
<!-- Excluding ['Antarctica', 'Bouvet Island', 'French Southern Territories (the)', 'Heard Island and McDonald Islands', 'Pitcairn', 'South Georgia and the South Sandwich Islands', 'United States Minor Outlying Islands (the)'] -->
<!-- Options for the country codes used in assisted dialing. DO NOT TRANSLATE NUMBERS. [CHAR LIMIT=40] -->
<string-array name="assisted_dialing_cc_entries">
- <item>@string/assisted_dialing_setting_cc_default_summary</item>
+ <item>@string/assisted_dialing_setting_cc_default_summary_fallback</item>
<item>Afghanistan <xliff:g>(+93)</xliff:g></item>
<item>Åland Islands <xliff:g>(+358)</xliff:g></item>
<item>Albania <xliff:g>(+355)</xliff:g></item>
diff --git a/java/com/android/dialer/assisteddialing/ui/res/xml/assisted_dialing_setting.xml b/java/com/android/dialer/assisteddialing/ui/res/xml/assisted_dialing_setting.xml
index c1706b2ed..9fb61a159 100644
--- a/java/com/android/dialer/assisteddialing/ui/res/xml/assisted_dialing_setting.xml
+++ b/java/com/android/dialer/assisteddialing/ui/res/xml/assisted_dialing_setting.xml
@@ -31,7 +31,7 @@
android:entries="@array/assisted_dialing_cc_entries"
android:entryValues="@array/assisted_dialing_cc_values"
android:key="@string/assisted_dialing_setting_cc_key"
- android:summary="@string/assisted_dialing_setting_cc_default_summary"
+ android:summary="@string/assisted_dialing_setting_cc_default_summary_fallback"
android:title="@string/assisted_dialing_setting_cc_title"/>
</PreferenceCategory>