OSDN Git Service

Index TTS-Settings and dedupe TTS-engine in search result.
authorFan Zhang <zhfan@google.com>
Wed, 16 Aug 2017 22:18:33 +0000 (15:18 -0700)
committerFan Zhang <zhfan@google.com>
Wed, 16 Aug 2017 22:46:41 +0000 (15:46 -0700)
Fixes: 63022866
Test: robotests
Change-Id: I5c711e7bafba4e413ee271768c58742be05d8640

res/xml/tts_engine_picker.xml
src/com/android/settings/accessibility/AccessibilitySettings.java
src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
src/com/android/settings/search/SearchIndexableResources.java
src/com/android/settings/tts/TextToSpeechSettings.java
src/com/android/settings/tts/TtsEnginePreferenceFragment.java
tests/robotests/assets/grandfather_not_implementing_indexable

index d7a76d4..c0a464c 100644 (file)
@@ -15,7 +15,7 @@
 -->
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
-        android:title="@string/tts_settings_title">
+        android:title="@string/tts_engine_preference_title">
 
     <PreferenceCategory android:key="tts_engine_preference_category"/>
 
index 51b676d..a335c83 100644 (file)
@@ -107,6 +107,8 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
             "magnification_preference_screen";
     private static final String FONT_SIZE_PREFERENCE_SCREEN =
             "font_size_preference_screen";
+    private static final String TTS_SETTINGS_PREFERENCE =
+            "tts_settings_preference";
     private static final String AUTOCLICK_PREFERENCE_SCREEN =
             "autoclick_preference_screen";
     private static final String DISPLAY_DALTONIZER_PREFERENCE_SCREEN =
@@ -743,6 +745,9 @@ public class AccessibilitySettings extends SettingsPreferenceFragment implements
             keys.add(FONT_SIZE_PREFERENCE_SCREEN);
             keys.add(DisplaySettings.KEY_DISPLAY_SIZE);
 
+            // Duplicates in Language & Input
+            keys.add(TTS_SETTINGS_PREFERENCE);
+
             return keys;
         }
     };
index c0ce3b9..b0abec4 100644 (file)
@@ -249,6 +249,10 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
                 final String uri = tile.metaData.getString(META_DATA_PREFERENCE_ICON_URI);
                 final Pair<String, Integer> iconInfo = TileUtils.getIconFromUri(
                         mContext, packageName, uri, providerMap);
+                if (iconInfo == null) {
+                    Log.w(TAG, "Failed to get icon from uri " + uri);
+                    return;
+                }
                 tile.icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
                 ThreadUtils.postOnMainThread(() ->
                         preference.setIcon(tile.icon.loadDrawable(preference.getContext()))
index c20d2a0..d67e8eb 100644 (file)
@@ -81,6 +81,7 @@ import com.android.settings.sim.SimSettings;
 import com.android.settings.support.SupportDashboardActivity;
 import com.android.settings.system.ResetDashboardFragment;
 import com.android.settings.system.SystemDashboardFragment;
+import com.android.settings.tts.TextToSpeechSettings;
 import com.android.settings.tts.TtsEnginePreferenceFragment;
 import com.android.settings.users.UserSettings;
 import com.android.settings.wallpaper.WallpaperTypeSettings;
@@ -199,6 +200,7 @@ public final class SearchIndexableResources {
                 R.drawable.ic_devices_other);
         addIndex(EnterprisePrivacySettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_about);
         addIndex(PaymentSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_nfc_payment);
+        addIndex(TextToSpeechSettings.class, NO_DATA_RES_ID, R.drawable.ic_settings_accessibility);
         addIndex(
                 TtsEnginePreferenceFragment.class, NO_DATA_RES_ID, R.drawable.ic_settings_language);
         addIndex(LockscreenDashboardFragment.class, R.xml.security_lockscreen_settings,
index 4ea422b..9092c0d 100644 (file)
@@ -23,8 +23,10 @@ import static android.provider.Settings.Secure.TTS_DEFAULT_SYNTH;
 import android.app.AlertDialog;
 import android.content.ActivityNotFoundException;
 import android.content.ContentResolver;
+import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.provider.SearchIndexableResource;
 import android.speech.tts.TextToSpeech;
 import android.speech.tts.TextToSpeech.EngineInfo;
 import android.speech.tts.TtsEngines;
@@ -39,11 +41,14 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
 import com.android.settings.widget.ActionButtonPreference;
 import com.android.settings.widget.GearPreference;
 import com.android.settings.widget.SeekBarPreference;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
@@ -55,7 +60,7 @@ import java.util.Set;
 
 public class TextToSpeechSettings extends SettingsPreferenceFragment
         implements Preference.OnPreferenceChangeListener,
-                GearPreference.OnGearClickListener {
+        GearPreference.OnGearClickListener, Indexable {
 
     private static final String STATE_KEY_LOCALE_ENTRIES = "locale_entries";
     private static final String STATE_KEY_LOCALE_ENTRY_VALUES = "locale_entry_values";
@@ -225,7 +230,8 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
             // Do set pitch correctly after it may have changed, and unlike speed, it doesn't change
             // immediately.
             final ContentResolver resolver = getContentResolver();
-            mTts.setPitch(android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH, TextToSpeech.Engine.DEFAULT_PITCH)/100.0f);
+            mTts.setPitch(android.provider.Settings.Secure.getInt(resolver, TTS_DEFAULT_PITCH,
+                    TextToSpeech.Engine.DEFAULT_PITCH) / 100.0f);
         }
 
         Locale ttsDefaultLocale = mTts.getDefaultLanguage();
@@ -241,10 +247,12 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
         }
         mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
             @Override
-            public void onStart(String utteranceId) {}
+            public void onStart(String utteranceId) {
+            }
 
             @Override
-            public void onDone(String utteranceId) {}
+            public void onDone(String utteranceId) {
+            }
 
             @Override
             public void onError(String utteranceId) {
@@ -313,7 +321,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
             EngineInfo info = mEnginesHelper.getEngineInfo(mCurrentEngine);
 
 
-
             Preference mEnginePreference = findPreference(KEY_TTS_ENGINE_PREFERENCE);
             ((GearPreference) mEnginePreference).setOnGearClickListener(this);
             mEnginePreference.setSummary(info.label);
@@ -364,7 +371,10 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
                                 }
                             });
         } else {
-            if (DBG) Log.d(TAG, "TTS engine for settings screen failed to initialize successfully.");
+            if (DBG) {
+                Log.d(TAG,
+                        "TTS engine for settings screen failed to initialize successfully.");
+            }
             updateWidgetState(false);
         }
     }
@@ -411,8 +421,8 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
 
             for (String loc : mAvailableStrLocals) {
                 if (loc.equalsIgnoreCase(defaultLocaleStr)) {
-                  notInAvailableLangauges = false;
-                  break;
+                    notInAvailableLangauges = false;
+                    break;
                 }
             }
         } catch (MissingResourceException e) {
@@ -572,7 +582,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
     private boolean isNetworkRequiredForSynthesis() {
         Set<String> features = mTts.getFeatures(mCurrentDefaultLocale);
         if (features == null) {
-          return false;
+            return false;
         }
         return features.contains(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS) &&
                 !features.contains(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS);
@@ -735,7 +745,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
             return;
         }
 
-        if (data == null){
+        if (data == null) {
             Log.e(TAG, "Engine failed voice data integrity check (null return)" +
                     mTts.getCurrentEngine());
             return;
@@ -744,7 +754,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
         android.provider.Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, engine);
 
         mAvailableStrLocals = data.getStringArrayListExtra(
-            TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
+                TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
         if (mAvailableStrLocals == null) {
             Log.e(TAG, "Voice data check complete, but no available voices found");
             // Set mAvailableStrLocals to empty list
@@ -764,4 +774,22 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment
         }
     }
 
+    public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+            new BaseSearchIndexProvider() {
+                @Override
+                public List<SearchIndexableResource> getXmlResourcesToIndex(
+                        Context context, boolean enabled) {
+                    final SearchIndexableResource sir = new SearchIndexableResource(context);
+                    sir.xmlResId = R.xml.tts_settings;
+                    return Arrays.asList(sir);
+                }
+
+                @Override
+                public List<String> getNonIndexableKeys(Context context) {
+                    final List<String> keys = super.getNonIndexableKeys(context);
+                    keys.add("tts_engine_preference");
+                    return keys;
+                }
+            };
+
 }
index e0ed8b7..8e6cfec 100644 (file)
@@ -23,7 +23,7 @@ import java.util.Arrays;
 
 public class TtsEnginePreferenceFragment extends SettingsPreferenceFragment //implements
         implements RadioButtonGroupState, Indexable {
-    private static final String TAG = "TtsEnginePreferenceFragment";
+    private static final String TAG = "TtsEnginePrefFragment";
 
     private static final int VOICE_DATA_INTEGRITY_CHECK = 1977;
 
@@ -185,7 +185,6 @@ public class TtsEnginePreferenceFragment extends SettingsPreferenceFragment //im
                 @Override
                 public List<SearchIndexableResource> getXmlResourcesToIndex(
                         Context context, boolean enabled) {
-                    Log.i(TAG, "Indexing");
                     final SearchIndexableResource sir = new SearchIndexableResource(context);
                     sir.xmlResId = R.xml.tts_engine_picker;
                     return Arrays.asList(sir);
index be5a99b..695342e 100644 (file)
@@ -36,7 +36,6 @@ com.android.settings.accessibility.ToggleAutoclickPreferenceFragment
 com.android.settings.applications.AppLaunchSettings
 com.android.settings.fuelgauge.BatterySaverSettings
 com.android.settings.location.ScanningSettings
-com.android.settings.tts.TextToSpeechSettings
 com.android.settings.applications.ProcessStatsUi
 com.android.settings.notification.ZenModeScheduleRuleSettings
 com.android.settings.datausage.BillingCycleSettings